From dd29c8e4a94e485fd2a17f6546e2e45500612736 Mon Sep 17 00:00:00 2001 From: KhaledAlramam Date: Mon, 12 Sep 2022 13:14:27 +0200 Subject: [PATCH 1/9] Add tokenized payment --- .vscode/settings.json | 3 ++ android/build.gradle | 2 +- .../paymentsdk/RNPaymentManagerModule.java | 53 +++++++++++++++++-- example/App.js | 43 +++++++++++++++ example/package.json | 2 +- src/PaymentSDKSavedCardInfo.js | 6 +++ src/RNPaymentSDKLibrary.js | 35 ++++++++++++ 7 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/PaymentSDKSavedCardInfo.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index d8367d0..26c65af 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -164,6 +164,6 @@ repositories { dependencies { implementation 'com.facebook.react:react-native:+' - implementation 'com.paytabs:payment-sdk:6.2.12' + implementation 'com.paytabs:payment-sdk:6.3.2' } \ No newline at end of file diff --git a/android/src/main/java/com/paymentsdk/RNPaymentManagerModule.java b/android/src/main/java/com/paymentsdk/RNPaymentManagerModule.java index 2c9a227..0ffbc0e 100644 --- a/android/src/main/java/com/paymentsdk/RNPaymentManagerModule.java +++ b/android/src/main/java/com/paymentsdk/RNPaymentManagerModule.java @@ -87,6 +87,33 @@ public void startCardPayment(final String arguments,final Promise promise) { promise.reject("Error", e.getMessage(), new Throwable(e.getMessage())); } } + + + + @ReactMethod + public void startTokenizedCardPayment( + final String arguments, + final String token, + final String transactionRef, + final Promise promise) { + this.promise = promise; + try { + final JSONObject paymentDetails = new JSONObject(arguments); + final PaymentSdkConfigBuilder configBuilder = createConfiguration(paymentDetails); + if (!paymentDetails.isNull("theme")) { + if (!paymentDetails.optJSONObject("theme").isNull("merchantLogo")) { + String iconUri = paymentDetails.optJSONObject("theme").optJSONObject("merchantLogo").optString("uri"); + Log.d("LogoURL", iconUri); + configBuilder.setMerchantIcon(iconUri); + } + } + + startTokenizedPayment(paymentDetails, token, transactionRef, configBuilder); + + } catch (Exception e) { + promise.reject("Error", e.getMessage(), new Throwable(e.getMessage())); + } + } public static String optString(JSONObject json, String key) { if (json.isNull(key)) @@ -95,12 +122,28 @@ public static String optString(JSONObject json, String key) { return json.optString(key, null); } - private void startPayment(JSONObject paymentDetails, PaymentSdkConfigBuilder configBuilder) { + private void startPayment(JSONObject paymentDetails, PaymentSdkConfigBuilder configBuilder) { + String samsungToken = paymentDetails.optString("samsungToken"); + if (samsungToken != null && samsungToken.length() > 0) + PaymentSdkActivity.startSamsungPayment(reactContext.getCurrentActivity(), configBuilder.build(), samsungToken, this); + else + PaymentSdkActivity.startCardPayment(reactContext.getCurrentActivity(), configBuilder.build(), this); + } + + + + private void startTokenizedPayment( + JSONObject paymentDetails, + final String token, + final String transactionRef, + PaymentSdkConfigBuilder configBuilder) { String samsungToken = paymentDetails.optString("samsungToken"); - if (samsungToken != null && samsungToken.length() > 0) - PaymentSdkActivity.startSamsungPayment(reactContext.getCurrentActivity(), configBuilder.build(), samsungToken, this); - else - PaymentSdkActivity.startCardPayment(reactContext.getCurrentActivity(), configBuilder.build(), this); + PaymentSdkActivity.startTokenizedCardPayment( + reactContext.getCurrentActivity(), + configBuilder.build(), + token, + transactionRef, + this); } @ReactMethod diff --git a/example/App.js b/example/App.js index d66a8ef..a096c3c 100644 --- a/example/App.js +++ b/example/App.js @@ -82,6 +82,47 @@ export default class App extends Component { }); } + onPressTokenizedPayment() { + let configuration = new PaymentSDKConfiguration(); + configuration.profileID = '63904' + configuration.serverKey = 'STJNNNTDKB-JBKWMD9Z9R-LKLNZBJLG2' + configuration.clientKey = 'CHKMMD-6MQ962-KVNDP9-NVRM92' + configuration.cartID = "545454" + configuration.currency = "EGP" + configuration.cartDescription = "Flowers" + configuration.merchantCountryCode = "eg" + configuration.merchantName = "Flowers Store" + configuration.amount = 20 + configuration.screenTitle = "Pay with Card" + + let billingDetails = new PaymentSDKBillingDetails(name= "Jone Smith", + email= "email@domain.com", + phone= "97311111111", + addressLine= "Flat 1,Building 123, Road 2345", + city= "Dubai", + state= "Dubai", + countryCode= "EG", + zip= "1234") + configuration.billingDetails = billingDetails + let theme = new PaymentSDKTheme() + + RNPaymentSDKLibrary.startTokenizedCardPayment( + JSON.stringify(configuration), + "2C4652BF67A3EA33C6B590FE658078BD", + "TST2224201325593" + ).then( result => { + if(result["PaymentDetails"] != null) { + let paymentDetails = result["PaymentDetails"] + console.log(paymentDetails) + } else if(result["Event"] == "CancelPayment") { + console.log("Cancel Payment Event") + } + }, function(error) { + console.log(error) + }); + } + + onPressApplePay() { let configuration = new PaymentSDKConfiguration(); configuration.profileID = '*profile id*' @@ -163,6 +204,8 @@ export default class App extends Component { {this.state.message}