diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c1158..b2911de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Changelog +## 6.3.2 (2020, April 4) +### Fixes +- [(# 103)](https://github.com/triniwiz/nativescript-stripe/issues/103) Android PaymentSession with Prefilled Address crashes + ## 6.3.1 (2020, April 1) ### Fixes - [(# 101)](https://github.com/triniwiz/nativescript-stripe/issues/101) PaymentSession Doesn't Reread Config. Re-reads StripeConfig when a new PaymentSession is created. diff --git a/src/package.json b/src/package.json index 2a686e2..c9840fb 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-stripe", - "version": "6.3.1", + "version": "6.3.2", "description": "NativeScript Stripe sdk", "main": "stripe", "typings": "index.d.ts", diff --git a/src/standard/standard.android.ts b/src/standard/standard.android.ts index 39c9351..893ac39 100644 --- a/src/standard/standard.android.ts +++ b/src/standard/standard.android.ts @@ -15,6 +15,10 @@ export class StripeConfig extends StripeConfigCommon { private _paymentConfigurationInitiated: boolean = false; get native(): com.stripe.android.PaymentSessionConfig { // getter gives client a chance to set properties before using. + return this.nativeBuilder.build(); + } + + get nativeBuilder(): com.stripe.android.PaymentSessionConfig.Builder { this.initPaymentConfiguration(); let optionalFields = []; if (this.requiredShippingAddressFields.indexOf(StripeShippingAddressField.PostalAddress) < 0) { @@ -29,12 +33,10 @@ export class StripeConfig extends StripeConfigCommon { } const shippingRequired = this.requiredShippingAddressFields.length !== 0; - let config = new com.stripe.android.PaymentSessionConfig.Builder() + return new com.stripe.android.PaymentSessionConfig.Builder() .setShippingInfoRequired(shippingRequired) .setShippingMethodsRequired(shippingRequired) - .setOptionalShippingInfoFields(optionalFields) - .build(); - return config; + .setOptionalShippingInfoFields(optionalFields); } initPaymentConfiguration(): void { @@ -94,7 +96,7 @@ export class StripePaymentSession { public currency: string, public listener: StripePaymentListener, prefilledAddress?: StripeAddress) { - let config = StripeConfig.shared().native; + let builder = StripeConfig.shared().nativeBuilder; if (prefilledAddress) { const info = new com.stripe.android.model.ShippingInformation( new com.stripe.android.model.Address.Builder() @@ -108,17 +110,9 @@ export class StripePaymentSession { prefilledAddress.name, prefilledAddress.phone ); - config = new com.stripe.android.PaymentSessionConfig.Builder() - .setOptionalShippingInfoFields( - config.getOptionalShippingInfoFields() ? - config.getOptionalShippingInfoFields().toArray() : []) - .setShippingInfoRequired(config.isShippingInfoRequired()) - .setShippingMethodsRequired(config.isShippingMethodRequired()) - .setHiddenShippingInfoFields(config.getHiddenShippingInfoFields() ? - config.getHiddenShippingInfoFields().toArray() : []) - .setPrepopulatedShippingInfo(info) - .build(); + builder.setPrepopulatedShippingInfo(info); } + let config = builder.build(); this.native = new com.stripe.android.PaymentSession(this.patchActivity()); if (!this.native.init(createPaymentSessionListener(this, listener), config)) {