Skip to content
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

fix: Update error type when canceling Paypal payment #1060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading