Skip to content

Commit d60f6dd

Browse files
committed
Created individual views for each step of order process
1 parent c3188c3 commit d60f6dd

File tree

6 files changed

+89
-14
lines changed

6 files changed

+89
-14
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
1001E2C12CFFC72E0023A03C /* PayPalPaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C02CFFC72E0023A03C /* PayPalPaymentState.swift */; };
11+
1001E2C52CFFD2800023A03C /* PayPalApprovalResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */; };
12+
1001E2C72CFFD2A30023A03C /* PayPalOrderCompletionResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */; };
1113
3B20273D2A89E3F00007907E /* CreateSetupTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B20273C2A89E3F00007907E /* CreateSetupTokenView.swift */; };
1214
3B20273F2A89F24E0007907E /* CardVaultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */; };
1315
3B2027412A8A72050007907E /* VaultState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B2027402A8A72050007907E /* VaultState.swift */; };
@@ -68,7 +70,7 @@
6870
BE1766B326F911A2007EF438 /* URLResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE1766B226F911A2007EF438 /* URLResponseError.swift */; };
6971
BE1766D926FA7BC8007EF438 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BE1766D826FA7BC8007EF438 /* Settings.bundle */; };
7072
BE5898952B2B91F800AA196E /* LabelViewText.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5898942B2B91F800AA196E /* LabelViewText.swift */; };
71-
BE8117642B07E778009867B9 /* PayPalWebResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117632B07E778009867B9 /* PayPalWebResultView.swift */; };
73+
BE8117642B07E778009867B9 /* PayPalOrderCreateResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */; };
7274
BE8117682B080472009867B9 /* CurrentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117672B080472009867B9 /* CurrentState.swift */; };
7375
BE9F36D82745490400AFC7DA /* FloatingLabelTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE9F36D72745490400AFC7DA /* FloatingLabelTextField.swift */; };
7476
BECD84A027036DC2007CCAE4 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = BECD849F27036DC2007CCAE4 /* Environment.swift */; };
@@ -120,6 +122,8 @@
120122

121123
/* Begin PBXFileReference section */
122124
1001E2C02CFFC72E0023A03C /* PayPalPaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalPaymentState.swift; sourceTree = "<group>"; };
125+
1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalApprovalResultView.swift; sourceTree = "<group>"; };
126+
1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalOrderCompletionResultView.swift; sourceTree = "<group>"; };
123127
3B20273C2A89E3F00007907E /* CreateSetupTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateSetupTokenView.swift; sourceTree = "<group>"; };
124128
3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardVaultViewModel.swift; sourceTree = "<group>"; };
125129
3B2027402A8A72050007907E /* VaultState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultState.swift; sourceTree = "<group>"; };
@@ -188,7 +192,7 @@
188192
BE1766D826FA7BC8007EF438 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
189193
BE420F3628189A7A00D8D66A /* PayPalUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PayPalUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
190194
BE5898942B2B91F800AA196E /* LabelViewText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewText.swift; sourceTree = "<group>"; };
191-
BE8117632B07E778009867B9 /* PayPalWebResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalWebResultView.swift; sourceTree = "<group>"; };
195+
BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalOrderCreateResultView.swift; sourceTree = "<group>"; };
192196
BE8117672B080472009867B9 /* CurrentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentState.swift; sourceTree = "<group>"; };
193197
BE9F36D72745490400AFC7DA /* FloatingLabelTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingLabelTextField.swift; sourceTree = "<group>"; };
194198
BECD849F27036DC2007CCAE4 /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
@@ -359,8 +363,10 @@
359363
3BA570062AA0DF330081D14F /* PayPalWebButtonsView.swift */,
360364
3BA570022AA053AE0081D14F /* PayPalWebCreateOrderView.swift */,
361365
3BA570002AA052E80081D14F /* PayPalWebPaymentsView.swift */,
362-
BE8117632B07E778009867B9 /* PayPalWebResultView.swift */,
363366
3B6472A62AFAEB3A004745C4 /* PayPalWebTransactionView.swift */,
367+
BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */,
368+
1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */,
369+
1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */,
364370
);
365371
path = PayPalWebPaymentsView;
366372
sourceTree = "<group>";
@@ -645,7 +651,7 @@
645651
3B2027412A8A72050007907E /* VaultState.swift in Sources */,
646652
80F33CED26F8E7A9006811B1 /* Order.swift in Sources */,
647653
3B4DD9A02A892A7000F4A716 /* CardVaultView.swift in Sources */,
648-
BE8117642B07E778009867B9 /* PayPalWebResultView.swift in Sources */,
654+
BE8117642B07E778009867B9 /* PayPalOrderCreateResultView.swift in Sources */,
649655
3BA56FF62A9E9AAB0081D14F /* CardOrderActionButton.swift in Sources */,
650656
3BC622092A97198500251B85 /* LeadingText.swift in Sources */,
651657
3B80D5102A291CB100D2EAC4 /* ClientIDResponse.swift in Sources */,
@@ -668,10 +674,12 @@
668674
3B80D50E2A291C0800D2EAC4 /* ClientIDRequest.swift in Sources */,
669675
3BA56FF02A9DCCFD0081D14F /* CardOrderApproveView.swift in Sources */,
670676
BE8117682B080472009867B9 /* CurrentState.swift in Sources */,
677+
1001E2C72CFFD2A30023A03C /* PayPalOrderCompletionResultView.swift in Sources */,
671678
3BDB348E2A7CB02C008100D7 /* CreateSetupTokenParam.swift in Sources */,
672679
3BA0A58B2B1E240300330681 /* VaultViewModel.swift in Sources */,
673680
80F33CF326F8EA50006811B1 /* DemoSettings.swift in Sources */,
674681
3BA56FE72A9DC9D70081D14F /* CardPaymentViewModel.swift in Sources */,
682+
1001E2C52CFFD2800023A03C /* PayPalApprovalResultView.swift in Sources */,
675683
3BA5700B2AA13C1C0081D14F /* CoreConfigManager.swift in Sources */,
676684
80F33CE826F8DE29006811B1 /* DemoMerchantAPI.swift in Sources */,
677685
80F33CEF26F8E7CC006811B1 /* CreateOrderParams.swift in Sources */,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import SwiftUI
2+
3+
struct PayPalApprovalResultView: View {
4+
@ObservedObject var payPalWebViewModel: PayPalWebViewModel
5+
6+
var body: some View {
7+
switch payPalWebViewModel.state.approveResultResponse {
8+
case .idle, .loading:
9+
EmptyView()
10+
case .error(let message):
11+
ErrorView(errorMessage: message)
12+
case .loaded(let approvalResult):
13+
getApprovalSuccessView(approvalResult: approvalResult)
14+
}
15+
}
16+
17+
func getApprovalSuccessView(approvalResult: PayPalPaymentState.ApprovalResult) -> some View {
18+
VStack(spacing: 16) {
19+
Text("Approval Result")
20+
.font(.headline)
21+
LeadingText("Approval ID", weight: .bold)
22+
23+
LeadingText(approvalResult.id)
24+
if let status = approvalResult.status {
25+
LeadingText("Status", weight: .bold)
26+
LeadingText(status)
27+
}
28+
}
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import SwiftUI
2+
3+
struct PayPalOrderCompletionResultView: View {
4+
@ObservedObject var payPalWebViewModel: PayPalWebViewModel
5+
6+
var body: some View {
7+
VStack {
8+
if case .loaded(let authorizedOrder) = payPalWebViewModel.state.authorizedOrderResponse {
9+
getCompletionSuccessView(order: authorizedOrder, intent: "Authorized")
10+
}
11+
if case .loaded(let capturedOrder) = payPalWebViewModel.state.capturedOrderResponse {
12+
getCompletionSuccessView(order: capturedOrder, intent: "Captured")
13+
}
14+
}
15+
}
16+
17+
func getCompletionSuccessView(order: Order, intent: String) -> some View {
18+
VStack(spacing: 16) {
19+
Text("Order \(intent) Successfully")
20+
.font(.headline)
21+
22+
LeadingText("Order ID", weight: .bold)
23+
LeadingText(order.id)
24+
LeadingText("Status", weight: .bold)
25+
LeadingText(order.status)
26+
}
27+
}
28+
}

Demo/Demo/PayPalWebPayments/PayPalWebPaymentsView/PayPalWebResultView.swift renamed to Demo/Demo/PayPalWebPayments/PayPalWebPaymentsView/PayPalOrderCreateResultView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
struct PayPalWebResultView: View {
3+
struct PayPalOrderCreateResultView: View {
44

55
@ObservedObject var payPalWebViewModel: PayPalWebViewModel
66

Demo/Demo/PayPalWebPayments/PayPalWebPaymentsView/PayPalWebPaymentsView.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import SwiftUI
22

33
struct PayPalWebPaymentsView: View {
4-
4+
55
@StateObject var payPalWebViewModel = PayPalWebViewModel()
6-
6+
77
var body: some View {
88
ScrollView {
99
ScrollViewReader { scrollView in
1010
VStack(spacing: 16) {
11+
1112
PayPalWebCreateOrderView(payPalWebViewModel: payPalWebViewModel)
12-
13-
if payPalWebViewModel.state.createOrder?.id != nil {
13+
14+
if case .loaded(let order) = payPalWebViewModel.state.createdOrderResponse {
15+
PayPalOrderCreateResultView(payPalWebViewModel: payPalWebViewModel)
16+
1417
PayPalWebButtonsView(payPalWebViewModel: payPalWebViewModel)
1518
}
16-
17-
PayPalWebResultView(payPalWebViewModel: payPalWebViewModel)
18-
19-
if payPalWebViewModel.checkoutResult != nil {
19+
20+
if case .loaded = payPalWebViewModel.state.approveResultResponse {
21+
PayPalApprovalResultView(payPalWebViewModel: payPalWebViewModel)
22+
2023
PayPalWebTransactionView(payPalWebViewModel: payPalWebViewModel)
2124
.padding(.bottom, 20)
2225
.id("bottomView")
@@ -26,6 +29,12 @@ struct PayPalWebPaymentsView: View {
2629
}
2730
}
2831
}
32+
33+
if case .loaded = payPalWebViewModel.state.capturedOrderResponse {
34+
PayPalOrderCompletionResultView(payPalWebViewModel: payPalWebViewModel)
35+
} else if case .loaded = payPalWebViewModel.state.authorizedOrderResponse {
36+
PayPalOrderCreateResultView(payPalWebViewModel: payPalWebViewModel)
37+
}
2938
}
3039
.onChange(of: payPalWebViewModel.state) { _ in
3140
withAnimation {

Demo/Demo/PayPalWebPayments/PayPalWebViewModel/PayPalWebViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class PayPalWebViewModel: ObservableObject {
117117
return
118118
}
119119

120-
if let orderID {
120+
if let orderID = state.createOrder?.id {
121121
let payPalRequest = PayPalWebCheckoutRequest(orderID: orderID, fundingSource: funding)
122122
payPalWebCheckoutClient.start(request: payPalRequest) { result, error in
123123
if let error {

0 commit comments

Comments
 (0)