Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The options passed to `showPaymentSheet` via the configuration object are as fol
| `connectionOptions` | `null` | An optional set of values passed to a connection when processing a transaction (see https://docs.gr4vy.com/reference/transactions/new-transaction) |
| `buyer` | `null` | An optional object to represent the buyer (personal details, billing details, and shipping information). This cannot be used in conjunction with `buyerId` or `buyerExternalIdentifier`. |
| `installmentCount` | `number` | An optional value that indicates the number of installments a buyer is required to make. |
| `excludedMethods` | `null` | An optional list of payment methods to exclude. |
| `debugMode` | `false` | `true`, `false` - Prints useful debug information to the console. |

### Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.ArrayList;

@ReactModule(name = EmbedReactNativeModule.NAME)
public class EmbedReactNativeModule extends ReactContextBaseJavaModule {
public static ReactApplicationContext reactContext;
Expand Down Expand Up @@ -57,6 +59,7 @@ public class EmbedReactNativeModule extends ReactContextBaseJavaModule {
static final String EXTRA_BUYER = "EXTRA_BUYER";
static final String EXTRA_INSTALLMENT_COUNT = "EXTRA_INSTALLMENT_COUNT";
static final String EXTRA_DEBUG_MODE = "EXTRA_DEBUG_MODE";
static final String EXTRA_EXCLUDED_METHODS = "EXTRA_EXCLUDED_METHODS";
private static final int GR4VY_PAYMENT_SHEET_REQUEST = 1;

public static <T> T coalesce(T... items) {
Expand Down Expand Up @@ -220,6 +223,15 @@ public void showPaymentSheet(ReadableMap config) {
Integer installmentCount = config.hasKey("installmentCount") ? config.getInt("installmentCount") : null;
Boolean debugMode = config.hasKey("debugMode") ? config.getBoolean("debugMode") : false;

ArrayList<String> excludedMethods = null;
if (config.hasKey("excludedMethods") && !config.isNull("excludedMethods")) {
ReadableArray rawArr = config.getArray("excludedMethods");
excludedMethods = new ArrayList<>();
for (int i = 0; i < rawArr.size(); i++) {
excludedMethods.add(rawArr.getString(i));
}
}

ReactApplicationContext context = getReactApplicationContext();
Intent androidIntent = new Intent(context, Gr4vyActivity.class);

Expand Down Expand Up @@ -283,6 +295,8 @@ public void showPaymentSheet(ReadableMap config) {
androidIntent.putExtra(EXTRA_INSTALLMENT_COUNT, installmentCount);
}

androidIntent.putStringArrayListExtra(EXTRA_EXCLUDED_METHODS, excludedMethods);

context.startActivityForResult(androidIntent, GR4VY_PAYMENT_SHEET_REQUEST, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static com.gr4vy.embedreactnative.EmbedReactNativeModule.EXTRA_CONNECTION_OPTIONS_STRING;
import static com.gr4vy.embedreactnative.EmbedReactNativeModule.EXTRA_BUYER;
import static com.gr4vy.embedreactnative.EmbedReactNativeModule.EXTRA_INSTALLMENT_COUNT;
import static com.gr4vy.embedreactnative.EmbedReactNativeModule.EXTRA_EXCLUDED_METHODS;

public class Gr4vyActivity extends ComponentActivity implements Gr4vyResultHandler {
private Gr4vySDK gr4vySDK;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class Gr4vyActivity extends ComponentActivity implements Gr4vyResultHandl
String connectionOptionsString;
Gr4vyBuyer buyer;
Integer installmentCount;
List<String> excludedMethods;
Boolean debugMode;

Boolean sdkLaunched = false;
Expand Down Expand Up @@ -289,6 +291,7 @@ protected void onCreate(Bundle savedInstanceState) {
this.locale = intent.getStringExtra(EXTRA_LOCALE);
this.connectionOptionsString = intent.getStringExtra(EXTRA_CONNECTION_OPTIONS_STRING);
this.installmentCount = intent.hasExtra(EXTRA_INSTALLMENT_COUNT) ? intent.getIntExtra(EXTRA_INSTALLMENT_COUNT, 0) : null;
this.excludedMethods = intent.getStringArrayListExtra(EXTRA_EXCLUDED_METHODS);
this.debugMode = intent.getExtras().getBoolean(EXTRA_DEBUG_MODE);

// Convert the cartItems JSON string to List<CartItem>
Expand Down Expand Up @@ -361,7 +364,8 @@ public void onStart() {
connectionOptionsString,
buyer,
debugMode,
installmentCount);
installmentCount,
excludedMethods);

sdkLaunched = true;
}
Expand Down
10 changes: 7 additions & 3 deletions ios/EmbedReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EmbedReactNative: NSObject {
buyer: Gr4vyBuyer?,
debugMode: Bool = false,
installmentCount: Int?,
excludedMethods: [String]?,
completion: @escaping(_ gr4vy: Gr4vy?) -> Void) {
var paymentSourceConverted: Gr4vyPaymentSource?
if paymentSource != nil {
Expand Down Expand Up @@ -65,7 +66,8 @@ class EmbedReactNative: NSObject {
connectionOptionsString: connectionOptions,
buyer: buyer,
debugMode: debugMode,
installmentCount: installmentCount) else {
installmentCount: installmentCount,
excludedMethods: excludedMethods) else {
completion(nil)
return
}
Expand Down Expand Up @@ -312,7 +314,8 @@ class EmbedReactNative: NSObject {
let connectionOptions = config["connectionOptions"] as? [String: [String: Any]?]?,
let buyer = config["buyer"] as? [String: Any?]?,
let debugMode = config["debugMode"] as? Bool?,
let installmentCount = config["installmentCount"] as? Int?
let installmentCount = config["installmentCount"] as? Int?,
let excludedMethods = config["excludedMethods"] as? [String]?
else {
EmbedReactNativeEvents.emitter.sendEvent(
withName: "onEvent",
Expand Down Expand Up @@ -351,7 +354,8 @@ class EmbedReactNative: NSObject {
connectionOptions: convertObjectToJsonString(connectionOptions),
buyer: convertBuyer(buyer),
debugMode: debugMode ?? false,
installmentCount: installmentCount) { (gr4vy) in
installmentCount: installmentCount,
excludedMethods: excludedMethods) { (gr4vy) in
if gr4vy == nil {
EmbedReactNativeEvents.emitter.sendEvent(
withName: "onEvent",
Expand Down
1 change: 1 addition & 0 deletions src/EmbedReactNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export type Gr4vyConfig = {
shippingDetails?: Gr4vyShippingDetails
}
installmentCount?: number
excludedMethods?: string[]
debugMode?: boolean
}

Expand Down
Loading