diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c60549..2059b81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ============================== +## 5.4.0 (2019, June 12) +### Fixes +- [(# 70)](https://github.com/triniwiz/nativescript-stripe/issues/70) Support prefilled shipping address in StripePaymentSession + ## 5.3.3 (2019, May 13) ### Fixes - [(# 63)](https://github.com/triniwiz/nativescript-stripe/issues/63) Properly handle no shipping method or address diff --git a/demo/app/App_Resources/Android/app.gradle b/demo/app/App_Resources/Android/app.gradle index c9d40ec..803b52f 100644 --- a/demo/app/App_Resources/Android/app.gradle +++ b/demo/app/App_Resources/Android/app.gradle @@ -5,12 +5,12 @@ // compile 'com.android.support:recyclerview-v7:+' //} -android { - defaultConfig { +android { + defaultConfig { generatedDensities = [] - applicationId = "org.nativescript.demo" - } - aaptOptions { - additionalParameters "--no-version-vectors" - } -} + applicationId = "org.nativescript.stripe.demo" + } + aaptOptions { + additionalParameters "--no-version-vectors" + } +} diff --git a/src/package.json b/src/package.json index cf7505a..16787cd 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-stripe", - "version": "5.3.3", + "version": "5.4.0", "description": "NativeScript Stripe sdk", "main": "stripe", "typings": "index.d.ts", diff --git a/src/standard/index.d.ts b/src/standard/index.d.ts index 3461a9d..c29712c 100644 --- a/src/standard/index.d.ts +++ b/src/standard/index.d.ts @@ -65,7 +65,8 @@ export declare class StripePaymentSession { customerSession: StripeCustomerSession, amount: number, currency: string, - listener: StripePaymentListener); + listener: StripePaymentListener, + prefilledAddress?: StripeAddress); /** Is the native component loading? */ readonly loading: boolean; /** Has user entered enough info that a charge can be made? */ @@ -100,15 +101,15 @@ export declare interface StripePaymentData { shippingInfo: StripeShippingMethod; } export declare interface StripeAddress { - name: string; - line1: string; - line2: string; - city: string; - state: string; - postalCode: string; - country: string; - phone: string; - email: string; + name?: string; + line1?: string; + line2?: string; + city?: string; + state?: string; + postalCode?: string; + country?: string; + phone?: string; + email?: string; } export declare interface StripeShippingMethods { /** Is shipping to the address valid? */ diff --git a/src/standard/standard.android.ts b/src/standard/standard.android.ts index 541ed62..cbe9abe 100644 --- a/src/standard/standard.android.ts +++ b/src/standard/standard.android.ts @@ -71,13 +71,39 @@ export class StripePaymentSession { paymentInProgress: boolean; private receiver: android.content.BroadcastReceiver; - constructor(private page: Page, + constructor(_page: Page, public customerSession: StripeCustomerSession, amount: number, public currency: string, - listener: StripePaymentListener) { + listener: StripePaymentListener, + prefilledAddress?: StripeAddress) { + let config = StripeConfig.shared().native; + if (prefilledAddress) { + const info = new com.stripe.android.model.ShippingInformation( + new com.stripe.android.model.Address.Builder() + .setLine1(prefilledAddress.line1) + .setLine2(prefilledAddress.line2) + .setCity(prefilledAddress.city) + .setState(prefilledAddress.state) + .setCountry(prefilledAddress.country) + .setPostalCode(prefilledAddress.postalCode) + .build(), + 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(); + } this.native = new com.stripe.android.PaymentSession(this.patchActivity()); - if (!this.native.init(createPaymentListener(this, listener), StripeConfig.shared().native)) { + if (!this.native.init(createPaymentListener(this, listener), config)) { throw new Error("CustomerSession not initialized"); } this.native.setCartTotal(amount); @@ -132,7 +158,7 @@ export class StripePaymentSession { function createPaymentListener(parent: StripePaymentSession, listener: StripePaymentListener): com.stripe.android.PaymentSession.PaymentSessionListener { return new com.stripe.android.PaymentSession.PaymentSessionListener({ - onPaymentSessionDataChanged: function(sessionData: com.stripe.android.PaymentSessionData): void { + onPaymentSessionDataChanged: function (sessionData: com.stripe.android.PaymentSessionData): void { if (parent.paymentInProgress) { if (sessionData.getPaymentResult() === com.stripe.android.PaymentResultListener.SUCCESS) { if (listener.onPaymentSuccess) listener.onPaymentSuccess(); @@ -160,11 +186,11 @@ function createPaymentListener(parent: StripePaymentSession, listener: StripePay } })); }, - onCommunicatingStateChanged: function(isCommunicating: boolean): void { + onCommunicatingStateChanged: function (isCommunicating: boolean): void { parent.loading = isCommunicating; listener.onCommunicatingStateChanged(isCommunicating); }, - onError: function(code: number, message: string): void { + onError: function (code: number, message: string): void { listener.onError(code, message); } }); diff --git a/src/standard/standard.common.ts b/src/standard/standard.common.ts index 83a4590..ab9d8f1 100644 --- a/src/standard/standard.common.ts +++ b/src/standard/standard.common.ts @@ -90,15 +90,15 @@ export interface StripeShippingMethods { } export interface StripeAddress { - name: string; - line1: string; - line2: string; - city: string; - state: string; - postalCode: string; - country: string; - phone: string; - email: string; + name?: string; + line1?: string; + line2?: string; + city?: string; + state?: string; + postalCode?: string; + country?: string; + phone?: string; + email?: string; } export const enum StripeBillingAddressFields { diff --git a/src/standard/standard.ios.ts b/src/standard/standard.ios.ts index d7e59f4..153dd12 100644 --- a/src/standard/standard.ios.ts +++ b/src/standard/standard.ios.ts @@ -80,13 +80,27 @@ export class StripePaymentSession { customerSession: StripeCustomerSession, amount: number, currency: string, - listener?: StripePaymentListener) { + listener?: StripePaymentListener, + prefilledAddress?: StripeAddress) { this.native = STPPaymentContext.alloc() .initWithCustomerContextConfigurationTheme( customerSession.native, StripeConfig.shared().native, STPTheme.defaultTheme()); this.native.prefilledInformation = STPUserInformation.alloc().init(); + if (prefilledAddress) { + const addr = STPAddress.alloc().init(); + addr.name = prefilledAddress.name; + addr.line1 = prefilledAddress.line1; + addr.line2 = prefilledAddress.line2; + addr.city = prefilledAddress.city; + addr.state = prefilledAddress.state; + addr.country = prefilledAddress.country; + addr.postalCode = prefilledAddress.postalCode; + addr.phone = prefilledAddress.phone; + addr.email = prefilledAddress.email; + this.native.prefilledInformation.shippingAddress = addr; + } this.native.paymentAmount = amount; this.native.paymentCurrency = currency; if (listener) {