Skip to content

Commit

Permalink
fix(prefilled-address): PaymentSession with prefilledAddress crashes …
Browse files Browse the repository at this point in the history
…on Android (#104)

* Android: set prefilledAddress properly. #103

* Bump version
  • Loading branch information
RobertGardner authored Apr 5, 2020
1 parent abba940 commit 373e614
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 9 additions & 15 deletions src/standard/standard.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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)) {
Expand Down

0 comments on commit 373e614

Please sign in to comment.