Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadReusableCard and SetupIntent optional customerId support #119

Merged
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
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