Last active
January 23, 2023 13:19
-
-
Save elkarrde/0a6dc5d3cb5bcbee58f96fcb49f7423d to your computer and use it in GitHub Desktop.
Fix for double "Add new card" button in NativeScript Stripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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