Skip to content

Instantly share code, notes, and snippets.

@elkarrde
Last active January 23, 2023 13:19
Show Gist options
  • Save elkarrde/0a6dc5d3cb5bcbee58f96fcb49f7423d to your computer and use it in GitHub Desktop.
Save elkarrde/0a6dc5d3cb5bcbee58f96fcb49f7423d to your computer and use it in GitHub Desktop.
Fix for double "Add new card" button in NativeScript Stripe
export class StripeStandardPaymentSession {
// all the code...
constructor(_page: Page, public customerSession: StripeStandardCustomerSession, amount: number, public currency: string, public listener: StripeStandardPaymentListener, prefilledAddress?: Address) {
let builder = StripeStandardConfig.shared.nativeBuilder;
// ...
const allowPaymentMethodTypes = new java.util.ArrayList();
// Added HashSet, to keep the list unique
const allowPaymentMethodTypesSet = new java.util.HashSet();
StripeStandardConfig.shared.allowedPaymentMethodTypes.forEach((type) => {
switch (type) {
case StripeStandardPaymentMethodType.Card:
allowPaymentMethodTypes.add(com.stripe.android.model.PaymentMethod.Type.Card);
break;
case StripeStandardPaymentMethodType.Fpx:
allowPaymentMethodTypes.add(com.stripe.android.model.PaymentMethod.Type.Fpx);
break;
}
});
// HashSet needs to be converted to ArrayList to continue
allowPaymentMethodTypes.addAll(allowPaymentMethodTypesSet);
// ~~~ OR ~~~
// this next line can be removed, there is no equivalent in index.ios.ts, and it
// works just the same even without this call to setPaymentMethodTypes method.
builder.setPaymentMethodTypes(allowPaymentMethodTypes);
// ...
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment