Skip to content

Commit

Permalink
Created individual views for each step of order process
Browse files Browse the repository at this point in the history
  • Loading branch information
GMALKHA committed Dec 4, 2024
1 parent c3188c3 commit d60f6dd
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 14 deletions.
16 changes: 12 additions & 4 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
1001E2C12CFFC72E0023A03C /* PayPalPaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C02CFFC72E0023A03C /* PayPalPaymentState.swift */; };
1001E2C52CFFD2800023A03C /* PayPalApprovalResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */; };
1001E2C72CFFD2A30023A03C /* PayPalOrderCompletionResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */; };
3B20273D2A89E3F00007907E /* CreateSetupTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B20273C2A89E3F00007907E /* CreateSetupTokenView.swift */; };
3B20273F2A89F24E0007907E /* CardVaultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */; };
3B2027412A8A72050007907E /* VaultState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B2027402A8A72050007907E /* VaultState.swift */; };
Expand Down Expand Up @@ -68,7 +70,7 @@
BE1766B326F911A2007EF438 /* URLResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE1766B226F911A2007EF438 /* URLResponseError.swift */; };
BE1766D926FA7BC8007EF438 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BE1766D826FA7BC8007EF438 /* Settings.bundle */; };
BE5898952B2B91F800AA196E /* LabelViewText.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5898942B2B91F800AA196E /* LabelViewText.swift */; };
BE8117642B07E778009867B9 /* PayPalWebResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117632B07E778009867B9 /* PayPalWebResultView.swift */; };
BE8117642B07E778009867B9 /* PayPalOrderCreateResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */; };
BE8117682B080472009867B9 /* CurrentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE8117672B080472009867B9 /* CurrentState.swift */; };
BE9F36D82745490400AFC7DA /* FloatingLabelTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE9F36D72745490400AFC7DA /* FloatingLabelTextField.swift */; };
BECD84A027036DC2007CCAE4 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = BECD849F27036DC2007CCAE4 /* Environment.swift */; };
Expand Down Expand Up @@ -120,6 +122,8 @@

/* Begin PBXFileReference section */
1001E2C02CFFC72E0023A03C /* PayPalPaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalPaymentState.swift; sourceTree = "<group>"; };
1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalApprovalResultView.swift; sourceTree = "<group>"; };
1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalOrderCompletionResultView.swift; sourceTree = "<group>"; };
3B20273C2A89E3F00007907E /* CreateSetupTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateSetupTokenView.swift; sourceTree = "<group>"; };
3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardVaultViewModel.swift; sourceTree = "<group>"; };
3B2027402A8A72050007907E /* VaultState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -188,7 +192,7 @@
BE1766D826FA7BC8007EF438 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
BE420F3628189A7A00D8D66A /* PayPalUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PayPalUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BE5898942B2B91F800AA196E /* LabelViewText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewText.swift; sourceTree = "<group>"; };
BE8117632B07E778009867B9 /* PayPalWebResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalWebResultView.swift; sourceTree = "<group>"; };
BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayPalOrderCreateResultView.swift; sourceTree = "<group>"; };
BE8117672B080472009867B9 /* CurrentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentState.swift; sourceTree = "<group>"; };
BE9F36D72745490400AFC7DA /* FloatingLabelTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingLabelTextField.swift; sourceTree = "<group>"; };
BECD849F27036DC2007CCAE4 /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -359,8 +363,10 @@
3BA570062AA0DF330081D14F /* PayPalWebButtonsView.swift */,
3BA570022AA053AE0081D14F /* PayPalWebCreateOrderView.swift */,
3BA570002AA052E80081D14F /* PayPalWebPaymentsView.swift */,
BE8117632B07E778009867B9 /* PayPalWebResultView.swift */,
3B6472A62AFAEB3A004745C4 /* PayPalWebTransactionView.swift */,
BE8117632B07E778009867B9 /* PayPalOrderCreateResultView.swift */,
1001E2C42CFFD2800023A03C /* PayPalApprovalResultView.swift */,
1001E2C62CFFD2A20023A03C /* PayPalOrderCompletionResultView.swift */,
);
path = PayPalWebPaymentsView;
sourceTree = "<group>";
Expand Down Expand Up @@ -645,7 +651,7 @@
3B2027412A8A72050007907E /* VaultState.swift in Sources */,
80F33CED26F8E7A9006811B1 /* Order.swift in Sources */,
3B4DD9A02A892A7000F4A716 /* CardVaultView.swift in Sources */,
BE8117642B07E778009867B9 /* PayPalWebResultView.swift in Sources */,
BE8117642B07E778009867B9 /* PayPalOrderCreateResultView.swift in Sources */,
3BA56FF62A9E9AAB0081D14F /* CardOrderActionButton.swift in Sources */,
3BC622092A97198500251B85 /* LeadingText.swift in Sources */,
3B80D5102A291CB100D2EAC4 /* ClientIDResponse.swift in Sources */,
Expand All @@ -668,10 +674,12 @@
3B80D50E2A291C0800D2EAC4 /* ClientIDRequest.swift in Sources */,
3BA56FF02A9DCCFD0081D14F /* CardOrderApproveView.swift in Sources */,
BE8117682B080472009867B9 /* CurrentState.swift in Sources */,
1001E2C72CFFD2A30023A03C /* PayPalOrderCompletionResultView.swift in Sources */,
3BDB348E2A7CB02C008100D7 /* CreateSetupTokenParam.swift in Sources */,
3BA0A58B2B1E240300330681 /* VaultViewModel.swift in Sources */,
80F33CF326F8EA50006811B1 /* DemoSettings.swift in Sources */,
3BA56FE72A9DC9D70081D14F /* CardPaymentViewModel.swift in Sources */,
1001E2C52CFFD2800023A03C /* PayPalApprovalResultView.swift in Sources */,
3BA5700B2AA13C1C0081D14F /* CoreConfigManager.swift in Sources */,
80F33CE826F8DE29006811B1 /* DemoMerchantAPI.swift in Sources */,
80F33CEF26F8E7CC006811B1 /* CreateOrderParams.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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(spacing: 16) {
Text("Approval Result")
.font(.headline)
LeadingText("Approval ID", weight: .bold)

LeadingText(approvalResult.id)
if let status = approvalResult.status {
LeadingText("Status", weight: .bold)
LeadingText(status)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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(spacing: 16) {
Text("Order \(intent) Successfully")
.font(.headline)

LeadingText("Order ID", weight: .bold)
LeadingText(order.id)
LeadingText("Status", weight: .bold)
LeadingText(order.status)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

struct PayPalWebResultView: View {
struct PayPalOrderCreateResultView: View {

@ObservedObject var payPalWebViewModel: PayPalWebViewModel

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import SwiftUI

struct PayPalWebPaymentsView: View {

@StateObject var payPalWebViewModel = PayPalWebViewModel()

var body: some View {
ScrollView {
ScrollViewReader { scrollView in
VStack(spacing: 16) {

PayPalWebCreateOrderView(payPalWebViewModel: payPalWebViewModel)

if payPalWebViewModel.state.createOrder?.id != nil {

if case .loaded(let order) = payPalWebViewModel.state.createdOrderResponse {
PayPalOrderCreateResultView(payPalWebViewModel: payPalWebViewModel)

PayPalWebButtonsView(payPalWebViewModel: payPalWebViewModel)
}

PayPalWebResultView(payPalWebViewModel: payPalWebViewModel)

if payPalWebViewModel.checkoutResult != nil {
if case .loaded = payPalWebViewModel.state.approveResultResponse {
PayPalApprovalResultView(payPalWebViewModel: payPalWebViewModel)
PayPalWebTransactionView(payPalWebViewModel: payPalWebViewModel)
.padding(.bottom, 20)
.id("bottomView")
Expand All @@ -26,6 +29,12 @@ struct PayPalWebPaymentsView: View {
}
}
}

if case .loaded = payPalWebViewModel.state.capturedOrderResponse {
PayPalOrderCompletionResultView(payPalWebViewModel: payPalWebViewModel)
} else if case .loaded = payPalWebViewModel.state.authorizedOrderResponse {
PayPalOrderCreateResultView(payPalWebViewModel: payPalWebViewModel)
}
}
.onChange(of: payPalWebViewModel.state) { _ in
withAnimation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class PayPalWebViewModel: ObservableObject {
return
}

if let orderID {
if let orderID = state.createOrder?.id {
let payPalRequest = PayPalWebCheckoutRequest(orderID: orderID, fundingSource: funding)
payPalWebCheckoutClient.start(request: payPalRequest) { result, error in
if let error {
Expand Down

0 comments on commit d60f6dd

Please sign in to comment.