Skip to content

Commit

Permalink
wrap paypal functions in async await
Browse files Browse the repository at this point in the history
  • Loading branch information
KunJeongPark committed Oct 23, 2024
1 parent 6b0c55e commit 817fbbc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Sources/PayPalWebPayments/PayPalWebCheckoutClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ public class PayPalWebCheckoutClient: NSObject {
)
}

/// Launch the PayPal web flow
/// - Parameters:
/// - request: the PayPalRequest for the transaction
/// - Returns: A `PayPalWebCheckoutResult` if successful
/// - Throws: An `Error` describing the failure
public func start(request: PayPalWebCheckoutRequest) async throws -> PayPalWebCheckoutResult {
try await withCheckedThrowingContinuation { continuation in
start(request: request) { result, error in
if let error {
continuation.resume(throwing: error)
} else if let result {
continuation.resume(returning: result)
}
}
}
}

func payPalCheckoutReturnURL(payPalCheckoutURL: URL) -> URL? {
let bundleID = PayPalCoreConstants.callbackURLScheme
let redirectURLString = "\(bundleID)://x-callback-url/paypal-sdk/paypal-checkout"
Expand Down Expand Up @@ -162,6 +179,24 @@ public class PayPalWebCheckoutClient: NSObject {
)
}

/// Starts a web session for vaulting PayPal Payment Method
/// After setupToken successfullly attaches a payment method, you will need to create a payment token with the setup token
/// - Parameters:
/// - vaultRequest: Request created with url for vault approval and setupTokenID
/// - Returns: `PayPalVaultResult`if successful
/// - Throws: `An `Error` describing failure
public func vault(_ vaultRequest: PayPalVaultRequest) async throws -> PayPalVaultResult {
try await withCheckedThrowingContinuation { continuation in
vault(vaultRequest) { result, error in
if let error {
continuation.resume(throwing: error)
} else if let result {
continuation.resume(returning: result)
}
}
}
}

private func getQueryStringParameter(url: String, param: String) -> String? {
guard let url = URLComponents(string: url) else { return nil }
return url.queryItems?.first { $0.name == param }?.value
Expand Down

0 comments on commit 817fbbc

Please sign in to comment.