-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* consolidate order states in PayPal Web views * add generic SuccessView * WIP - shared result view * WIP - start consolidating result views * WIP - continue refactoring state for PayPal Web * WIP - continued paypal web demo app refactor * WIP - start cleaning up file names; method signatures; etc for PayPal Web * cleanup how data is passed * add new state and general cleanup * cleanup funding source name, remove redundant types * cleanup views and remove order completion view * rename PayPalWebCompleteTransactionView to PayPalWebTransactionView; replace result view with status view so they do not dissapear on change for transaction view * update funding source * extract intent from view model directly * minor cleanup * sort paypal web files by name * cleanup authorize/capture order into singular method * add logic to reset state; combine loaded and success state; extract update logic into methods * merge main into demo-app-refactor * add ScrollView to PayPalWebTransactionView * PR feedback: rename Status enum to OrderStatus * PR feedback: rely on status instead or resetting state * update name of payPalViewModel to payPalWebViewModel * add scroll to bottom of PayPalWebTransactionView on vault with purchase * update order status from started to created to more accurately refect status * update PayPalWebDemoView to PayPalWebPaymentsView * add navigationViewStyle * update delegate to use updateState * move PayPalWebViewModel into PayPalWebPayments feature directory * remove OrderStatus and add cases to CurrentState * refactor current state; add back in OrderStatus; fix bug with ErrorView
- Loading branch information
1 parent
ae1adc3
commit a0ec619
Showing
21 changed files
with
386 additions
and
534 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Foundation | ||
|
||
enum CurrentState: Equatable { | ||
case idle | ||
case loading | ||
case success | ||
case error(message: String) | ||
} |
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
27 changes: 27 additions & 0 deletions
27
Demo/Demo/SwiftUIComponents/PayPalWebPayments/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import SwiftUI | ||
|
||
struct PayPalWebPaymentsView: View { | ||
|
||
@StateObject var payPalWebViewModel = PayPalWebViewModel() | ||
|
||
var body: some View { | ||
ScrollView { | ||
VStack(spacing: 16) { | ||
PayPalWebCreateOrderView(payPalWebViewModel: payPalWebViewModel) | ||
if payPalWebViewModel.createOrderResult != nil && payPalWebViewModel.state == .success { | ||
PayPalWebResultView(payPalWebViewModel: payPalWebViewModel, status: .created) | ||
NavigationLink { | ||
PayPalWebButtonsView(payPalWebViewModel: payPalWebViewModel) | ||
.navigationTitle("Checkout with PayPal") | ||
} label: { | ||
Text("Checkout with PayPal") | ||
} | ||
.buttonStyle(RoundedBlueButtonStyle()) | ||
.padding() | ||
} else if case .error = payPalWebViewModel.state { | ||
PayPalWebResultView(payPalWebViewModel: payPalWebViewModel, status: .error) | ||
} | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Demo/Demo/SwiftUIComponents/PayPalWebPayments/PayPalWebResultView.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,26 @@ | ||
import SwiftUI | ||
|
||
enum OrderStatus { | ||
case created | ||
case approved | ||
case completed | ||
case error | ||
} | ||
|
||
struct PayPalWebResultView: View { | ||
|
||
@ObservedObject var payPalWebViewModel: PayPalWebViewModel | ||
|
||
var status: OrderStatus | ||
|
||
var body: some View { | ||
switch payPalWebViewModel.state { | ||
case .idle, .loading: | ||
EmptyView() | ||
case .success: | ||
PayPalWebStatusView(status: status, payPalWebViewModel: payPalWebViewModel) | ||
case .error(let errorMessage): | ||
ErrorView(errorMessage: errorMessage) | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Demo/Demo/SwiftUIComponents/PayPalWebPayments/PayPalWebStatusView.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,76 @@ | ||
import SwiftUI | ||
|
||
struct PayPalWebStatusView: View { | ||
|
||
var status: OrderStatus | ||
var payPalWebViewModel: PayPalWebViewModel | ||
|
||
var body: some View { | ||
VStack(spacing: 16) { | ||
switch status { | ||
case .created: | ||
HStack { | ||
Text("Order Created") | ||
.font(.system(size: 20)) | ||
Spacer() | ||
} | ||
if let order = payPalWebViewModel.createOrderResult { | ||
LeadingText("Order ID", weight: .bold) | ||
LeadingText("\(order.id)") | ||
LeadingText("Status", weight: .bold) | ||
LeadingText("\(order.status)") | ||
} | ||
case .approved: | ||
HStack { | ||
Text("Order Approved") | ||
.font(.system(size: 20)) | ||
Spacer() | ||
} | ||
if let order = payPalWebViewModel.createOrderResult { | ||
LeadingText("Intent", weight: .bold) | ||
LeadingText("\(payPalWebViewModel.intent)") | ||
LeadingText("Order ID", weight: .bold) | ||
LeadingText("\(order.id)") | ||
LeadingText("Payer ID", weight: .bold) | ||
LeadingText("\(payPalWebViewModel.checkoutResult?.payerID ?? "")") | ||
} | ||
case .completed: | ||
if let order = payPalWebViewModel.transactionResult { | ||
HStack { | ||
Text("Order \(payPalWebViewModel.intent.rawValue.capitalized)d") | ||
.font(.system(size: 20)) | ||
Spacer() | ||
} | ||
LeadingText("Order ID", weight: .bold) | ||
LeadingText("\(order.id)") | ||
LeadingText("Status", weight: .bold) | ||
LeadingText("\(order.status)") | ||
|
||
if let emailAddress = order.paymentSource?.paypal?.emailAddress { | ||
LeadingText("Email", weight: .bold) | ||
LeadingText("\(emailAddress)") | ||
} | ||
|
||
if let vaultID = order.paymentSource?.paypal?.attributes?.vault.id { | ||
LeadingText("Vault ID / Payment Token", weight: .bold) | ||
LeadingText("\(vaultID)") | ||
} | ||
|
||
if let customerID = order.paymentSource?.paypal?.attributes?.vault.customer.id { | ||
LeadingText("Customer ID", weight: .bold) | ||
LeadingText("\(customerID)") | ||
} | ||
} | ||
default: | ||
Text("") | ||
} | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding() | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.gray, lineWidth: 2) | ||
.padding(5) | ||
) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Demo/Demo/SwiftUIComponents/PayPalWebPayments/PayPalWebTransactionView.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,46 @@ | ||
import SwiftUI | ||
|
||
struct PayPalWebTransactionView: View { | ||
|
||
@ObservedObject var payPalWebViewModel: PayPalWebViewModel | ||
|
||
var body: some View { | ||
ScrollView { | ||
ScrollViewReader { scrollView in | ||
VStack { | ||
PayPalWebStatusView(status: .approved, payPalWebViewModel: payPalWebViewModel) | ||
ZStack { | ||
Button("\(payPalWebViewModel.intent.rawValue.capitalized) Order") { | ||
Task { | ||
do { | ||
try await payPalWebViewModel.completeTransaction() | ||
} catch { | ||
print("Error capturing order: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
.buttonStyle(RoundedBlueButtonStyle()) | ||
.padding() | ||
|
||
if payPalWebViewModel.state == .loading { | ||
CircularProgressView() | ||
} | ||
} | ||
|
||
if payPalWebViewModel.transactionResult != nil && payPalWebViewModel.state == .success { | ||
PayPalWebResultView(payPalWebViewModel: payPalWebViewModel, status: .completed) | ||
.id("bottomView") | ||
} else if case .error = payPalWebViewModel.state { | ||
PayPalWebResultView(payPalWebViewModel: payPalWebViewModel, status: .error) | ||
} | ||
} | ||
.onChange(of: payPalWebViewModel.transactionResult) { _ in | ||
withAnimation { | ||
scrollView.scrollTo("bottomView") | ||
} | ||
} | ||
Spacer() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.