diff --git a/android/src/main/java/com/gettipsi/stripe/util/Converters.java b/android/src/main/java/com/gettipsi/stripe/util/Converters.java index fb2572da..e3429be8 100644 --- a/android/src/main/java/com/gettipsi/stripe/util/Converters.java +++ b/android/src/main/java/com/gettipsi/stripe/util/Converters.java @@ -67,8 +67,10 @@ public static WritableMap putExtraToTokenMap(final WritableMap tokenMap, UserAdd WritableMap billingContactMap = convertAddressToWritableMap(billingAddress); WritableMap shippingContactMap = convertAddressToWritableMap(shippingAddress); - billingContactMap.putString("emailAddress", emailAddress); - shippingContactMap.putString("emailAddress", emailAddress); + if (emailAddress != null && emailAddress.length() > 0) { + billingContactMap.putString("emailAddress", emailAddress); + shippingContactMap.putString("emailAddress", emailAddress); + } extra.putMap("billingContact", billingContactMap); diff --git a/ios/Classes/TPSStripeManager.m b/ios/Classes/TPSStripeManager.m index 3d699a56..3fd928a2 100644 --- a/ios/Classes/TPSStripeManager.m +++ b/ios/Classes/TPSStripeManager.m @@ -1646,7 +1646,7 @@ - (NSDictionary *)contactDetails:(PKContact*)inputContact { [contactDetails setValue:inputContact.supplementarySubLocality forKey:@"supplementarySubLocality"]; } - for (NSString *elem in @[@"street", @"city", @"state", @"country", @"ISOCountryCode", @"postalCode"]) { + for (NSString *elem in @[@"street", @"city", @"state", @"country", @"ISOCountryCode", @"postalCode", @"subAdministrativeArea", @"subLocality", @"formattedAddress"]) { if ([inputContact.postalAddress respondsToSelector:NSSelectorFromString(elem)]) { [contactDetails setValue:[inputContact.postalAddress valueForKey:elem] forKey:elem]; } diff --git a/lib/src/stripe_payment.dart b/lib/src/stripe_payment.dart index 6d1dec83..a37205a9 100644 --- a/lib/src/stripe_payment.dart +++ b/lib/src/stripe_payment.dart @@ -19,7 +19,12 @@ class StripePayment { /// https://tipsi.github.io/tipsi-stripe/docs/usage.html static void setOptions(StripeOptions settings) { - _channel.invokeMethod('setOptions', {"options": settings.toJson(), "errorCodes": Errors.mapping}); + try { + _channel.invokeMethod('setOptions', + {"options": settings.toJson(), "errorCodes": Errors.mapping}); + } catch(e) { + print(e); + } } /// https://tipsi.github.io/tipsi-stripe/docs/usage.html @@ -174,6 +179,10 @@ class StripePayment { final result = await _channel.invokeMethod('confirmSetupIntent', intent.toJson()); return SetupIntentResult.fromJson(result); } + + static openApplePaySetup() async { + _channel.invokeMapMethod('openApplePaySetup'); + } } class StripeOptions { diff --git a/lib/src/token.dart b/lib/src/token.dart index 9787ded5..1c7cf03b 100644 --- a/lib/src/token.dart +++ b/lib/src/token.dart @@ -4,8 +4,9 @@ class Token { double created; bool livemode; String tokenId; + Extra extra; - Token({this.bankAccount, this.card, this.created, this.livemode, this.tokenId}); + Token({this.bankAccount, this.card, this.created, this.livemode, this.tokenId, this.extra}); factory Token.fromJson(Map json) { return Token( @@ -14,6 +15,7 @@ class Token { created: json['created'] is int ? (json['created'] as int).toDouble() : json['created'], livemode: json['livemode'], tokenId: json['tokenId'], + extra: json['extra'] != null ? Extra.fromJson(json['extra']) : null, ); } @@ -28,6 +30,9 @@ class Token { if (this.card != null) { data['card'] = this.card.toJson(); } + if (this.extra != null) { + data['extra'] = this.extra.toJson(); + } return data; } } @@ -164,3 +169,91 @@ class CreditCard { return data; } } + +class Extra { + Contact shippingContact; + Contact billingContact; + + Extra( + {this.shippingContact, + this.billingContact}); + + factory Extra.fromJson(Map json) { + return Extra( + shippingContact: Contact.fromJson(json['shippingContact']), + billingContact: Contact.fromJson(json['billingContact']), + ); + } + + Map toJson() { + final Map data = new Map(); + if (this.shippingContact != null) data['shippingContact'] = this.shippingContact.toJson(); + if (this.billingContact != null) data['billingContact'] = this.billingContact.toJson(); + return data; + } +} + +class Contact { + String name; + String emailAddress; + String phoneNumber; + String country; + String postalCode; + String state; + String city; + String street; + String isoCountryCode; + String subAdministrativeArea; + String subLocality; + String supplementarySubLocality; + + Contact ( + {this.name, + this.emailAddress, + this.phoneNumber, + this.country, + this.postalCode, + this.state, + this.city, + this.street, + this.isoCountryCode, + this.subAdministrativeArea, + this.subLocality, + this.supplementarySubLocality + }); + + factory Contact.fromJson(Map json) { + print(json); + return Contact( + name: json['name'] ?? "", + emailAddress: json['emailAddress'] ?? "", + phoneNumber: json['phoneNumber'] ?? "", + country: json['country'] ?? "", + postalCode: json['postalCode'] ?? "", + state: json['state'] ?? json['administrativeArea'] ?? "", + city: json['city'] ?? json['locality'] ?? "", + street: json['street'] ?? json['address1'] != null ? json['address1'] + json['address2'] : "", + isoCountryCode: json['ISOCountryCode'] ?? json['countryCode'] ?? "", + subAdministrativeArea: json['subAdministrativeArea'] ?? "", + subLocality: json['subLocality'] ?? json['locality'] ?? "", + supplementarySubLocality: json['supplementarySubLocality'] ?? "", + ); + } + + Map toJson() { + final Map data = new Map(); + if (this.name != null) data['name'] = this.name; + if (this.emailAddress != null) data['emailAddress'] = this.emailAddress; + if (this.phoneNumber != null) data['phoneNumber'] = this.phoneNumber; + if (this.country != null) data['country'] = this.country; + if (this.postalCode != null) data['postalCode'] = this.postalCode; + if (this.state != null) data['state'] = this.state; + if (this.city != null) data['city'] = this.city; + if (this.street != null) data['street'] = this.street; + if (this.isoCountryCode != null) data['ISOCountryCode'] = this.isoCountryCode; + if (this.subAdministrativeArea != null) data['subAdministrativeArea'] = this.subAdministrativeArea; + if (this.subLocality != null) data['subLocality'] = this.subLocality; + if (this.supplementarySubLocality != null) data['supplementarySubLocality'] = this.supplementarySubLocality; + return data; + } +} \ No newline at end of file