Skip to content

Commit

Permalink
Update error type when canceling Paypal payment
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisNikolic committed Dec 9, 2024
1 parent 9c47a5e commit f5a3b5f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Debug App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ PODS:
- PrimerIPay88MYSDK (0.1.7)
- PrimerKlarnaSDK (1.1.1)
- PrimerNolPaySDK (1.0.1)
- PrimerSDK (2.32.0):
- PrimerSDK/Core (= 2.32.0)
- PrimerSDK/Core (2.32.0)
- PrimerSDK (2.32.1):
- PrimerSDK/Core (= 2.32.1)
- PrimerSDK/Core (2.32.1)
- PrimerStripeSDK (1.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -37,9 +37,9 @@ SPEC CHECKSUMS:
PrimerIPay88MYSDK: 436ee0be7e2c97e4e81456ccddee20175e9e3c4d
PrimerKlarnaSDK: 564105170cc7b467bf95c31851813ea41c468f8b
PrimerNolPaySDK: 08b140ed39b378a0b33b4f8746544a402175c0cc
PrimerSDK: db06e6553747bdadf8a8ca276d556745af38bba3
PrimerSDK: 41eb9f627fa189f3edafdb18ea2a671d4403b3e2
PrimerStripeSDK: c37d4e7c1b5256d67d4890c4cc4b38ddc9427489

PODFILE CHECKSUM: fa17ead44d40b0b09abc2f30a5cc3d8aefe389e1

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "Primer3DS",
"repositoryURL": "https://github.com/primer-io/primer-sdk-3ds-ios",
"state": {
"branch": null,
"revision": "7d2c9ac8825a4459034a1416012cae61761543fd",
"version": "2.4.1"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import SafariServices

protocol WebAuthenticationService {
var session: ASWebAuthenticationSession? { get }
func connect(url: URL, scheme: String, _ completion: @escaping (Result<URL, Error>) -> Void)
func connect(paymentMethodType: String, url: URL, scheme: String, _ completion: @escaping (Result<URL, Error>) -> Void)
}

class DefaultWebAuthenticationService: NSObject, WebAuthenticationService {

var session: ASWebAuthenticationSession?

func connect(url: URL, scheme: String, _ completion: @escaping (Result<URL, Error>) -> Void) {
func connect(paymentMethodType: String, url: URL, scheme: String, _ completion: @escaping (Result<URL, Error>) -> Void) {
let webAuthSession = ASWebAuthenticationSession(
url: url,
callbackURLScheme: scheme,
completionHandler: { (url, error) in
if let url = url {
completion(.success(url))
} else if let error = error {
completion(.failure(PrimerError.underlyingErrors(errors: [error],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)))
} else if let _ = error {
completion(.failure(PrimerError.cancelled(paymentMethodType: paymentMethodType,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)))
} else {
let additionalInfo: [String: String] = [ "message": "Failed to create web authentication session" ]
completion(.failure(PrimerError.unknown(userInfo: .errorUserInfoDictionary(additionalInfo: additionalInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class NolPayTokenizationViewModel: PaymentMethodTokenizationViewModel {

firstly { () -> Promise<String> in
if self.isCancelled {
let err = PrimerError.cancelled(paymentMethodType: self.config.type, userInfo: .errorUserInfoDictionary(),
let err = PrimerError.cancelled(paymentMethodType: self.config.type,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
throw err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class PayPalTokenizationViewModel: PaymentMethodTokenizationViewModel {
return
}

webAuthenticationService.connect(url: url, scheme: scheme) { [weak self] result in
webAuthenticationService.connect(paymentMethodType: self.config.type, url: url, scheme: scheme) { [weak self] result in
switch result {
case .success(let url):
seal.fulfill(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class PaymentMethodTokenizationViewModel: NSObject, PaymentMethodTokenizationVie
var cancelledError: PrimerError?
self.didCancel = {
self.isCancelled = true
cancelledError = PrimerError.cancelled(paymentMethodType: self.config.type, userInfo: .errorUserInfoDictionary(),
cancelledError = PrimerError.cancelled(paymentMethodType: self.config.type,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: cancelledError!)
seal.reject(cancelledError!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi

firstly { () -> Promise<String> in
if self.isCancelled {
let err = PrimerError.cancelled(paymentMethodType: self.config.type, userInfo: .errorUserInfoDictionary(),
let err = PrimerError.cancelled(paymentMethodType: self.config.type,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
throw err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class MockWebAuthenticationService: WebAuthenticationService {

var onConnect: ((URL, String) -> URL)?

func connect(url: URL, scheme: String, _ completion: @escaping (Result<URL, any Error>) -> Void) {
func connect(paymentMethodType: String, url: URL, scheme: String, _ completion: @escaping (Result<URL, any Error>) -> Void) {
if let onConnect = onConnect {
completion(.success(onConnect(url, scheme)))
} else {
Expand Down

0 comments on commit f5a3b5f

Please sign in to comment.