-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DTPP-142] PayPalWebPayments show stages of order (#311)
* [DTPP-142] PayPalWebPayments show stages of order
- Loading branch information
Showing
10 changed files
with
279 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 19 additions & 14 deletions
33
Demo/Demo/PayPalWebPayments/PayPalWebPaymentsView/PayPalWebPaymentsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...yPalWebPayments/PayPalWebPaymentsView/PayPalWebResultViews/PayPalApprovalResultView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import SwiftUI | ||
|
||
struct PayPalApprovalResultView: View { | ||
|
||
@ObservedObject var payPalWebViewModel: PayPalWebViewModel | ||
|
||
var body: some View { | ||
switch payPalWebViewModel.state.approveResultResponse { | ||
case .idle, .loading: | ||
EmptyView() | ||
case .error(let message): | ||
ErrorView(errorMessage: message) | ||
case .loaded(let approvalResult): | ||
getApprovalSuccessView(approvalResult: approvalResult) | ||
} | ||
} | ||
|
||
func getApprovalSuccessView(approvalResult: PayPalPaymentState.ApprovalResult) -> some View { | ||
VStack(alignment: .leading, spacing: 16) { | ||
Text("Approval Result") | ||
.font(.headline) | ||
LeadingText("Approval ID", weight: .bold) | ||
.font(.system(size: 20)) | ||
|
||
LeadingText(approvalResult.id) | ||
if let status = approvalResult.status { | ||
LeadingText("Status", weight: .bold) | ||
LeadingText(status) | ||
} | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding() | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.gray, lineWidth: 2) | ||
.padding(5) | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...Payments/PayPalWebPaymentsView/PayPalWebResultViews/PayPalOrderCompletionResultView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import SwiftUI | ||
|
||
struct PayPalOrderCompletionResultView: View { | ||
|
||
@ObservedObject var payPalWebViewModel: PayPalWebViewModel | ||
|
||
var body: some View { | ||
VStack { | ||
if case .loaded(let authorizedOrder) = payPalWebViewModel.state.authorizedOrderResponse { | ||
getCompletionSuccessView(order: authorizedOrder, intent: "Authorized") | ||
} | ||
if case .loaded(let capturedOrder) = payPalWebViewModel.state.capturedOrderResponse { | ||
getCompletionSuccessView(order: capturedOrder, intent: "Captured") | ||
} | ||
} | ||
} | ||
|
||
func getCompletionSuccessView(order: Order, intent: String) -> some View { | ||
VStack(alignment: .leading, spacing: 16) { | ||
Text("Order \(intent) Successfully") | ||
.font(.system(size: 20)) | ||
|
||
LabelViewText("Order ID:", bodyText: order.id) | ||
|
||
LabelViewText("Status:", bodyText: order.status) | ||
|
||
if let payerID = payPalWebViewModel.checkoutResult?.payerID { | ||
LabelViewText("Payer ID:", bodyText: payerID) | ||
} | ||
|
||
if let emailAddress = order.paymentSource?.paypal?.emailAddress { | ||
LabelViewText("Email:", bodyText: emailAddress) | ||
} | ||
|
||
if let vaultID = order.paymentSource?.paypal?.attributes?.vault.id { | ||
LabelViewText("Payment Token:", bodyText: vaultID) | ||
} | ||
|
||
if let customerID = order.paymentSource?.paypal?.attributes?.vault.customer?.id { | ||
LabelViewText("Customer ID:", bodyText: customerID) | ||
} | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding() | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.gray, lineWidth: 2) | ||
.padding(5) | ||
) | ||
} | ||
} |
27 changes: 12 additions & 15 deletions
27
...WebPaymentsView/PayPalWebResultView.swift → ...ltViews/PayPalOrderCreateResultView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Demo/Demo/PayPalWebPayments/PayPalWebViewModel/PayPalPaymentState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
import PayPalWebPayments | ||
|
||
struct PayPalPaymentState: Equatable { | ||
|
||
struct ApprovalResult: Decodable, Equatable { | ||
|
||
let id: String | ||
let status: String? | ||
} | ||
|
||
var createOrder: Order? | ||
var authorizedOrder: Order? | ||
var capturedOrder: Order? | ||
var intent: Intent = .authorize | ||
var approveResult: ApprovalResult? | ||
|
||
var createdOrderResponse: LoadingState<Order> = .idle { | ||
didSet { | ||
if case .loaded(let value) = createdOrderResponse { | ||
createOrder = value | ||
} | ||
} | ||
} | ||
|
||
var approveResultResponse: LoadingState<ApprovalResult> = .idle { | ||
didSet { | ||
if case .loaded(let value) = approveResultResponse { | ||
approveResult = value | ||
} | ||
} | ||
} | ||
|
||
var capturedOrderResponse: LoadingState<Order> = .idle { | ||
didSet { | ||
if case .loaded(let value) = capturedOrderResponse { | ||
capturedOrder = value | ||
} | ||
} | ||
} | ||
|
||
var authorizedOrderResponse: LoadingState<Order> = .idle { | ||
didSet { | ||
if case .loaded(let value) = authorizedOrderResponse { | ||
authorizedOrder = value | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.