Skip to content

Commit

Permalink
ReadReusableCard and SetupIntent optional customerId support (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenry-stripe authored Mar 3, 2022
1 parent dbd4bd0 commit 52ba89c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,9 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :

@ReactMethod
fun createSetupIntent(params: ReadableMap, promise: Promise) {
val customerId = getStringOr(params, "customerId") ?: ""

val intentParams = SetupIntentParameters.Builder()
.setCustomer(customerId)
.build()
val intentParams = getStringOr(params, "customer")?.let { customerId ->
SetupIntentParameters.Builder().setCustomer(customerId).build()
} ?: SetupIntentParameters.NULL

Terminal.getInstance().createSetupIntent(intentParams, object : SetupIntentCallback {
override fun onSuccess(setupIntent: SetupIntent) {
Expand Down Expand Up @@ -691,14 +689,9 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) :

@ReactMethod
fun readReusableCard(params: ReadableMap, promise: Promise) {
validateRequiredParameters(params, listOf("customer"))?.let {
promise.resolve(createError(CommonErrorType.Failed.toString(), "You must provide $it parameters."))
return
}

val customer = getStringOr(params, "customer")?: ""

var reusableCardParams = ReadReusableCardParameters.Builder().setCustomer(customer).build();
val reusableCardParams = getStringOr(params, "customer")?.let { customerId ->
ReadReusableCardParameters.Builder().setCustomer(customerId).build()
} ?: ReadReusableCardParameters.NULL

readReusableCardCancelable = Terminal.getInstance().readReusableCard(reusableCardParams, object : PaymentMethodCallback {
override fun onSuccess(paymentMethod: PaymentMethod) {
Expand Down
1 change: 0 additions & 1 deletion example/src/screens/ReadReusableCardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function ReadReusableCardScreen() {

if (customerError) {
console.error(customerError);
return;
}

const { paymentMethod, error } = await readReusableCard({
Expand Down
1 change: 0 additions & 1 deletion example/src/screens/SetupIntentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export default function SetupIntentScreen() {

if (customerError) {
console.error(customerError);
return;
}

const response = await createSetupIntent({
Expand Down
2 changes: 1 addition & 1 deletion example/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const fetchCustomerId = async () => {
const { customers } = await response.json();

if (customers.length === 0) {
return { error: 'There is no any customer created yet.' };
return { error: 'No customers available.' };
}
const { id } = customers[0] as { id: string };

Expand Down

0 comments on commit 52ba89c

Please sign in to comment.