Skip to content

Commit

Permalink
Merge pull request #30 from paytabscom/feature/add-3ds
Browse files Browse the repository at this point in the history
Feature/add 3ds
  • Loading branch information
KhaledAlramam authored Sep 14, 2022
2 parents 91f40d7 + 1cf4785 commit ddcb3d6
Show file tree
Hide file tree
Showing 17 changed files with 3,388 additions and 2,918 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# react-native-paytabs
![Version](https://img.shields.io/badge/React%20Native%20Paytabs-v2.3.11-green)
![Version](https://img.shields.io/badge/React%20Native%20Paytabs-v2.4.0-green)

React native paytabs library is a wrapper for the native PayTabs Android and iOS SDKs, It helps you integrate with PayTabs seamlessly.

Expand All @@ -12,7 +12,7 @@ Library Support:
# Installation

```sh
$ npm install @paytabs/react-native-paytabs@2.3.11 --save --force
$ npm install @paytabs/react-native-paytabs@2.4.0 --save --force
```

### Expo
Expand Down Expand Up @@ -48,7 +48,7 @@ expo install @paytabs/react-native-paytabs
Import `@paytabs/react-native-paytabs`

```javascript
import {RNPaymentSDKLibrary, PaymentSDKConfiguration, PaymentSDKBillingDetails, PaymentSDKTheme, PaymentSDKConstants} from '@paytabs/react-native-paytabs';
import {RNPaymentSDKLibrary, PaymentSDKConfiguration, PaymentSDKBillingDetails, PaymentSDKTheme, PaymentSDKConstants, PaymentSDKSavedCardInfo} from '@paytabs/react-native-paytabs';
```

### Pay with Card
Expand Down Expand Up @@ -104,7 +104,8 @@ Options to show billing and shipping ifno

```

3. Start payment by calling `startCardPayment` method and handle the transaction details
# 1- Pay with card
Start payment by calling `startCardPayment` method and handle the transaction details

```javascript

Expand All @@ -120,6 +121,74 @@ RNPaymentSDKLibrary.startCardPayment(JSON.stringify(configuration)).then( result
});

```
<img width="191" alt="card" src="https://user-images.githubusercontent.com/17829232/188835902-c50f41d1-5e3d-4d4c-a49a-e75b81480b75.png">


# 2- Pay with Token
Start payment by calling `startTokenizedCardPayment` method and handle the transaction details

```javascript

RNPaymentSDKLibrary.startTokenizedCardPayment(JSON.stringify(configuration),
"Token",
"TransactionReference"
).then( result => {
if(result["PaymentDetails"] != null) { // Handle transaction details
let paymentDetails = result["PaymentDetails"]
console.log(paymentDetails)
} else if(result["Event"] == "CancelPayment") { // Handle events
console.log("Cancel Payment Event")
}
}, function(error) { // Handle error
console.log(error)
});

```

# 3- Pay with 3DS Secured Token
Start payment by calling `start3DSecureTokenizedCardPayment` method and handle the transaction details

```javascript
let cardInfo = new PaymentSDKSavedCardInfo("Card mask", "cardType")
RNPaymentSDKLibrary.start3DSecureTokenizedCardPayment(
JSON.stringify(configuration),
JSON.stringify(cardInfo),
"Token"
).then( result => {
if(result["PaymentDetails"] != null) { // Handle transaction details
let paymentDetails = result["PaymentDetails"]
console.log(paymentDetails)
} else if(result["Event"] == "CancelPayment") { // Handle events
console.log("Cancel Payment Event")
}
}, function(error) { // Handle error
console.log(error)
});

```
<img width="197" alt="rec 3ds" src="https://user-images.githubusercontent.com/17829232/188836295-d8d48978-a80f-40d3-bda3-439423fcdec0.png">


# 4- Pay with saved card
Start payment by calling `startPaymentWithSavedCards` method and handle the transaction details

```javascript

RNPaymentSDKLibrary.startPaymentWithSavedCards(JSON.stringify(configuration),
support3DsBool).then( result => {
if(result["PaymentDetails"] != null) { // Handle transaction details
let paymentDetails = result["PaymentDetails"]
console.log(paymentDetails)
} else if(result["Event"] == "CancelPayment") { // Handle events
console.log("Cancel Payment Event")
}
}, function(error) { // Handle error
console.log(error)
});

```
<img width="197" alt="rec 3ds" src="https://user-images.githubusercontent.com/17829232/190152848-bfc83f8c-1a4b-4a55-99ec-af3c22a3de66.png">


### Pay with Apple Pay

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

146 changes: 141 additions & 5 deletions android/src/main/java/com/paymentsdk/RNPaymentManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionDetails;
import com.payment.paymentsdk.integrationmodels.PaymentSdkTransactionType;
import com.payment.paymentsdk.sharedclasses.interfaces.CallbackPaymentInterface;
import com.payment.paymentsdk.save_cards.entities.PaymentSDKSavedCardInfo;

import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
Expand Down Expand Up @@ -87,20 +88,145 @@ 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()));
}
}


@ReactMethod
public void start3DSecureTokenizedCardPayment(
final String arguments,
final String savedCardInfo,
final String token,
final Promise promise) {
this.promise = promise;
try {
final JSONObject paymentDetails = new JSONObject(arguments);
final PaymentSdkConfigBuilder configBuilder = createConfiguration(paymentDetails);

final JSONObject savedCardObject = new JSONObject(savedCardInfo);
final PaymentSDKSavedCardInfo paymentSDKSavedCardInfo = createSavedCardInfo(savedCardObject);
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);
}
}

start3DsPayment(paymentDetails, paymentSDKSavedCardInfo, token, configBuilder);

} catch (Exception e) {
promise.reject("Error", e.getMessage(), new Throwable(e.getMessage()));
}
}


@ReactMethod
public void startPaymentWithSavedCards(
final String arguments,
final Boolean support3DS,
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);
}
}

startSavedCardPayment(paymentDetails, support3DS, 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))
return "";
else
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);
}


private void start3DsPayment(
JSONObject paymentDetails,
final PaymentSDKSavedCardInfo savedCardInfo,
final String token,
PaymentSdkConfigBuilder configBuilder) {
String samsungToken = paymentDetails.optString("samsungToken");
PaymentSdkActivity.start3DSecureTokenizedCardPayment(
reactContext.getCurrentActivity(),
configBuilder.build(),
savedCardInfo,
token,
this);
}


private void startSavedCardPayment(
JSONObject paymentDetails,
final Boolean support3DS,
PaymentSdkConfigBuilder configBuilder) {
String samsungToken = paymentDetails.optString("samsungToken");
PaymentSdkActivity.startPaymentWithSavedCards(
reactContext.getCurrentActivity(),
configBuilder.build(),
support3DS,
this);
}

@ReactMethod
Expand Down Expand Up @@ -181,6 +307,16 @@ private PaymentSdkConfigBuilder createConfiguration(JSONObject paymentDetails) {
return configData;
}

private PaymentSDKSavedCardInfo createSavedCardInfo(JSONObject jsonCardInfo) {
String maskedCard = jsonCardInfo.optString("maskedCard");
String cardType = jsonCardInfo.optString("cardType");


PaymentSDKSavedCardInfo cardInfo = new PaymentSDKSavedCardInfo(
maskedCard, cardType);
return cardInfo;
}

private void getDrawableFromUri(final String path, final RetrieveDrawableListener listener) {
try {
new AsyncTask<String, Integer, BitmapDrawable>() {
Expand Down
Loading

0 comments on commit ddcb3d6

Please sign in to comment.