Skip to content

Commit

Permalink
fix: Update error type when canceling Paypal payment (#1060)
Browse files Browse the repository at this point in the history
Update error type when canceling Paypal payment

Co-authored-by: Boris Nikolic <[email protected]>
Co-authored-by: Niall Quinn <[email protected]>
  • Loading branch information
3 people authored Dec 16, 2024
1 parent a9fc040 commit b75b525
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
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 error != nil {
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 b75b525

Please sign in to comment.