Skip to content

Commit

Permalink
make changes to launch pp app for checkout flow
Browse files Browse the repository at this point in the history
  • Loading branch information
agedd committed Jan 17, 2025
1 parent daaebca commit 67e0b5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Sources/BraintreePayPal/BTPayPalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,14 @@ import BraintreeDataCollector

switch approvalURL.redirectType {
case .payPalApp(let url):
guard let baToken = approvalURL.baToken else {
self.notifyFailure(with: BTPayPalError.missingBAToken, completion: completion)
guard let token = approvalURL.baToken ?? approvalURL.ecToken else {
self.notifyFailure(
with: self.isVaultRequest ? BTPayPalError.missingBAToken : BTPayPalError.missingECToken,
completion: completion
)
return
}

self.launchPayPalApp(with: url, baToken: baToken, completion: completion)
self.launchPayPalApp(with: url, token: token, completion: completion)
case .webBrowser(let url):
self.handlePayPalRequest(with: url, paymentType: request.paymentType, completion: completion)
}
Expand All @@ -381,7 +383,7 @@ import BraintreeDataCollector

private func launchPayPalApp(
with payPalAppRedirectURL: URL,
baToken: String,
token: String? = nil,
completion: @escaping (BTPayPalAccountNonce?, Error?) -> Void
) {
apiClient.sendAnalyticsEvent(
Expand All @@ -393,7 +395,7 @@ import BraintreeDataCollector

var urlComponents = URLComponents(url: payPalAppRedirectURL, resolvingAgainstBaseURL: true)
urlComponents?.queryItems = [
URLQueryItem(name: "ba_token", value: baToken),
URLQueryItem(name: isVaultRequest ? "ba_token" : "token", value: token),
URLQueryItem(name: "source", value: "braintree_sdk"),
URLQueryItem(name: "switch_initiated_time", value: String(Int(round(Date().timeIntervalSince1970 * 1000))))
]
Expand Down
9 changes: 8 additions & 1 deletion Sources/BraintreePayPal/BTPayPalError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public enum BTPayPalError: Error, CustomNSError, LocalizedError, Equatable {

/// 12. Missing BA Token for App Switch
case missingBAToken

/// 13. Missing EC Token for App Switch
case missingECToken

/// 13. Missing PayPal Request
case missingPayPalRequest
Expand Down Expand Up @@ -77,8 +80,10 @@ public enum BTPayPalError: Error, CustomNSError, LocalizedError, Equatable {
return 11
case .missingBAToken:
return 12
case .missingPayPalRequest:
case .missingECToken:
return 13
case .missingPayPalRequest:
return 14
}
}

Expand Down Expand Up @@ -112,6 +117,8 @@ public enum BTPayPalError: Error, CustomNSError, LocalizedError, Equatable {
return "UIApplication failed to perform app switch to PayPal."
case .missingBAToken:
return "Missing BA Token for PayPal App Switch."
case .missingECToken:
return "Missing EC Token for PayPal App Switch."
case .missingPayPalRequest:
return "The PayPal Request was missing or invalid."
}
Expand Down

0 comments on commit 67e0b5d

Please sign in to comment.