-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Delegation Pattern to Completion Handler #293
Changes from all commits
b7c84d9
24ff08c
19cb340
da4c711
fa66cbb
c2178bc
a8c73fc
6b0c55e
817fbbc
d177350
e247cf0
fd14adc
c87d36a
6a29bdd
3217c25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import CardPayments | |
import CorePayments | ||
import FraudProtection | ||
|
||
class CardPaymentViewModel: ObservableObject, CardDelegate { | ||
class CardPaymentViewModel: ObservableObject { | ||
|
||
@Published var state = CardPaymentState() | ||
private var payPalDataCollector: PayPalDataCollector? | ||
|
@@ -117,11 +117,22 @@ class CardPaymentViewModel: ObservableObject, CardDelegate { | |
let config = try await configManager.getCoreConfig() | ||
cardClient = CardClient(config: config) | ||
payPalDataCollector = PayPalDataCollector(config: config) | ||
cardClient?.delegate = self | ||
let cardRequest = CardRequest(orderID: orderID, card: card, sca: sca) | ||
cardClient?.approveOrder(request: cardRequest) | ||
cardClient?.approveOrder(request: cardRequest) { result, error in | ||
if let error { | ||
self.setUpdateSetupTokenFailureResult(vaultError: error) | ||
} else if let result { | ||
self.approveResultSuccessResult( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qq: should this method be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good call. There are many changes I want to make on the demo app, but I stuck to ones relevant to the conversion. |
||
approveResult: CardPaymentState.CardResult( | ||
id: result.orderID, | ||
status: result.status, | ||
didAttemptThreeDSecureAuthentication: result.didAttemptThreeDSecureAuthentication | ||
) | ||
) | ||
} | ||
} | ||
} catch { | ||
self.state.approveResultResponse = .error(message: error.localizedDescription) | ||
setUpdateSetupTokenFailureResult(vaultError: error) | ||
print("failed in checkout with card. \(error.localizedDescription)") | ||
} | ||
} | ||
|
@@ -134,7 +145,7 @@ class CardPaymentViewModel: ObservableObject, CardDelegate { | |
} | ||
} | ||
|
||
func setUpdateSetupTokenFailureResult(vaultError: CorePayments.CoreSDKError) { | ||
func setUpdateSetupTokenFailureResult(vaultError: Error) { | ||
DispatchQueue.main.async { | ||
self.state.approveResultResponse = .error(message: vaultError.localizedDescription) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random q: would it be cleaner if we created the
Task
within thepaypalVaultViewModel.vault()
method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Button actions are synchronous contexts, so I need to create a Task block there to call an async/await function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense what you are saying, make the views look cleaner. Let me add that to demo app refactor ticket.