Skip to content

Commit

Permalink
Make CoreSDKError Equatable
Browse files Browse the repository at this point in the history
  • Loading branch information
KunJeongPark committed Nov 22, 2024
1 parent 3488f9e commit 6ea02e4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PayPalWebViewModel: ObservableObject {
let payPalRequest = PayPalWebCheckoutRequest(orderID: orderID, fundingSource: funding)
payPalWebCheckoutClient.start(request: payPalRequest) { result, error in
if let error {
if PayPalError.isCheckoutCanceled(error) {
if error == PayPalError.checkoutCanceledError {
print("Canceled")
self.updateState(.idle)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/ViewModels/CardPaymentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CardPaymentViewModel: ObservableObject {
let cardRequest = CardRequest(orderID: orderID, card: card, sca: sca)
cardClient?.approveOrder(request: cardRequest) { result, error in
if let error {
if CardError.isThreeDSecureCanceled(error) {
if error == CardError.threeDSecureCanceledError {
self.setApprovalCancelResult()
} else {
self.setApprovalFailureResult(vaultError: error)
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/ViewModels/CardVaultViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CardVaultViewModel: VaultViewModel {
)
)
} else if let vaultError {
if CardError.isThreeDSecureCanceled(vaultError) {
if let error = vaultError as? CoreSDKError, error == CardError.threeDSecureCanceledError {
print("Canceled")
self.state.updateSetupTokenResponse = .idle
} else {
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/ViewModels/PayPalVaultViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PayPalVaultViewModel: VaultViewModel {
let vaultRequest = PayPalVaultRequest(setupTokenID: setupTokenID)
paypalClient.vault(vaultRequest) { result, error in
if let error {
if PayPalError.isVaultCanceled(error) {
if error == PayPalError.vaultCanceledError {
DispatchQueue.main.async {
print("Canceled")
self.state.paypalVaultTokenResponse = .idle
Expand Down
10 changes: 5 additions & 5 deletions Sources/CardPayments/CardError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ public enum CardError {
case threeDSecureCanceledError
}

static let unknownError = CoreSDKError(
public static let unknownError = CoreSDKError(
code: Code.unknown.rawValue,
domain: domain,
errorDescription: "An unknown error has occured. Contact developer.paypal.com/support."
)

static let encodingError = CoreSDKError(
public static let encodingError = CoreSDKError(
code: Code.encodingError.rawValue,
domain: domain,
errorDescription: "An error occured encoding HTTP request body data. Contact developer.paypal.com/support."
)

static let threeDSecureError: (Error) -> CoreSDKError = { error in
public static let threeDSecureError: (Error) -> CoreSDKError = { error in
CoreSDKError(
code: Code.threeDSecureError.rawValue,
domain: domain,
errorDescription: error.localizedDescription
)
}

static let threeDSecureURLError = CoreSDKError(
public static let threeDSecureURLError = CoreSDKError(
code: Code.threeDSecureURLError.rawValue,
domain: domain,
errorDescription: "An invalid 3DS URL was returned. Contact developer.paypal.com/support."
)

static let threeDSecureCanceledError = CoreSDKError(
public static let threeDSecureCanceledError = CoreSDKError(
code: Code.threeDSecureCanceledError.rawValue,
domain: domain,
errorDescription: "3DS verification has been canceled by the user."
Expand Down
2 changes: 1 addition & 1 deletion Sources/CorePayments/CoreSDKError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Error structure that SDK errors conform to
public struct CoreSDKError: Error, LocalizedError {
public struct CoreSDKError: Error, LocalizedError, Equatable {

/// The error code.
public let code: Int?
Expand Down
12 changes: 6 additions & 6 deletions Sources/PayPalWebPayments/PayPalError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,39 @@ public enum PayPalError {
case vaultCanceledError
}

static let webSessionError: (Error) -> CoreSDKError = { error in
public static let webSessionError: (Error) -> CoreSDKError = { error in
CoreSDKError(
code: Code.webSessionError.rawValue,
domain: domain,
errorDescription: error.localizedDescription
)
}

static let payPalURLError = CoreSDKError(
public static let payPalURLError = CoreSDKError(
code: Code.payPalURLError.rawValue,
domain: domain,
errorDescription: "Error constructing URL for PayPal request."
)

static let malformedResultError = CoreSDKError(
public static let malformedResultError = CoreSDKError(
code: Code.malformedResultError.rawValue,
domain: domain,
errorDescription: "Result did not contain the expected data."
)

static let payPalVaultResponseError = CoreSDKError(
public static let payPalVaultResponseError = CoreSDKError(
code: Code.payPalVaultResponseError.rawValue,
domain: domain,
errorDescription: "Error parsing PayPal vault response"
)

static let checkoutCanceledError = CoreSDKError(
public static let checkoutCanceledError = CoreSDKError(
code: Code.checkoutCanceledError.rawValue,
domain: domain,
errorDescription: "PayPal checkout has been canceled by the user"
)

static let vaultCanceledError = CoreSDKError(
public static let vaultCanceledError = CoreSDKError(
code: Code.vaultCanceledError.rawValue,
domain: domain,
errorDescription: "PayPal vault has been canceled by the user"
Expand Down

0 comments on commit 6ea02e4

Please sign in to comment.