Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2fb986
commit e58f1fc
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
import PayPalCheckout | ||
|
||
@objc(Paypal) | ||
class Paypal: NSObject { | ||
|
||
@objc(multiply:withB:withResolver:withRejecter:) | ||
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { | ||
resolve(a*b) | ||
@objc func startWithOrderId( | ||
_ | ||
options: NSDictionary, | ||
resolver: @escaping RCTPromiseResolveBlock, | ||
rejecter: @escaping RCTPromiseRejectBlock | ||
) -> Void { | ||
let clientID = options["clientID"] as? String ?? "" | ||
let returnUrl = options["returnUrl"] as? String ?? "" | ||
let orderId = options["orderId"] as? String ?? "" | ||
let useSandbox = options["useSandbox"] as? Bool ?? true | ||
|
||
let environment = useSandbox ? Environment.sandbox : Environment.live | ||
let config = CheckoutConfig( | ||
clientID: clientID, | ||
returnUrl: returnUrl, | ||
environment: environment | ||
) | ||
|
||
Checkout.set(config: config) | ||
|
||
Checkout.setCreateOrderCallback { createOrderActions in | ||
createOrderActions.set(orderId: orderId) | ||
} | ||
|
||
Checkout.setOnApproveCallback { approval in | ||
resolver(approval.data) | ||
} | ||
|
||
Checkout.setOnCancelCallback { error in | ||
rejecter("PAYPAL_CANCELLED", "The user cancelled", nil) | ||
} | ||
|
||
Checkout.setOnErrorCallback { error in | ||
rejecter("PAYPAL_ERROR", error.reason, nil) | ||
} | ||
|
||
DispatchQueue.main.async { | ||
Checkout.start() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters