Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project are documented in this file.

### Added

- **ISO 3166-2 region codes in Google Pay addresses.** `CNPostalAddress` adds
`isoAdministrativeArea`, the region as an ISO 3166-2 code such as `'US-CA'`, for tax and shipping
systems that need a code rather than the free-text `state`. Android now requests full billing
addresses and shipping addresses in Google Pay's `FULL-ISO3166` format, which is `FULL` plus that
code. A `MIN` billing address, requested for a phone number alone, is unchanged. Apple Pay has no
such code, so it is always omitted on iOS
([#90](https://github.com/gmi-software/react-native-pay/issues/90)).
- **`pix` and `ewallet` Google Pay buttons.** `GooglePayButtonType` adds `'pix'` and `'ewallet'`,
Google's `PIX` and `EWALLET` button types. `'pix'` shows "Direct Pix payment"; Google Play
services draws `'ewallet'` like `'buy'` so far. They change only the button: the sheet still
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ interface CNPostalAddress {
postalCode?: string;
country?: string;
isoCountryCode?: string;
isoAdministrativeArea?: string; // Android only, ISO 3166-2, e.g. "US-CA"
}
```

Expand Down
3 changes: 2 additions & 1 deletion docs/docs/api/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ interface PaymentContact {
}
```

In `postalAddress`, `street` joins the address lines with `'\n'`, `isoCountryCode` is uppercase ISO 3166-1 alpha-2, and `country` (the country name) is iOS only.
In `postalAddress`, `street` joins the address lines with `'\n'`, `isoCountryCode` is uppercase ISO 3166-1 alpha-2, and `country` (the country name) is iOS only. `isoAdministrativeArea` is Android only: the region as an ISO 3166-2 code with the country prefix, such as `'US-CA'`, next to the free-text `state`.

---

Expand All @@ -680,6 +680,7 @@ interface CNPostalAddress {
postalCode?: string
country?: string
isoCountryCode?: string
isoAdministrativeArea?: string // Android only, ISO 3166-2, e.g. 'US-CA'
}

interface CNLabeledPhoneNumber {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/contact-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ With `HybridPaymentHandler`, set the same flags on the `PaymentRequest`; the det

- **name**: the full name, for example `'Jane Appleseed'`.
- **givenName**, **familyName**: iOS only. Google Pay returns the name as one string.
- **postalAddress**: `street` (address lines joined with `'\n'`), `city`, `state`, `postalCode`, `country` (iOS only) and `isoCountryCode` (uppercase ISO 3166-1 alpha-2, such as `'US'`).
- **postalAddress**: `street` (address lines joined with `'\n'`), `city`, `state`, `postalCode`, `country` (iOS only), `isoCountryCode` (uppercase ISO 3166-1 alpha-2, such as `'US'`) and `isoAdministrativeArea` (Android only: the ISO 3166-2 region code, such as `'US-CA'`). Use `isoAdministrativeArea` where a tax or shipping system needs a region code; on iOS, `state` is the only region you get.

`emailAddress` and `phoneNumber` are plain strings. The phone number is in the format the payer entered. Parts the payer left empty are omitted, not empty strings.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ object PaymentConstants {
const val AUTH_PAN_ONLY = "PAN_ONLY"
const val AUTH_CRYPTOGRAM_3DS = "CRYPTOGRAM_3DS"

// Billing address formats
// Address formats. MIN is for billing only.
const val BILLING_ADDRESS_FORMAT_MIN = "MIN"
const val BILLING_ADDRESS_FORMAT_FULL = "FULL"
// FULL plus `iso3166AdministrativeArea`, the region as an ISO 3166-2 code
const val ADDRESS_FORMAT_FULL_ISO3166 = "FULL-ISO3166"

// Tokenization
const val TOKENIZATION_PAYMENT_GATEWAY = "PAYMENT_GATEWAY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ object GooglePayRequestBuilder {
if (requested.shippingContact) {
put("shippingAddressRequired", true)
put("shippingAddressParameters", JSONObject().apply {
put("format", PaymentConstants.ADDRESS_FORMAT_FULL_ISO3166)
put("phoneNumberRequired", requested.phoneNumberOnShippingAddress)
})
}
Expand Down Expand Up @@ -190,7 +191,7 @@ object GooglePayRequestBuilder {
put(
"format",
if (requested.billingContact)
PaymentConstants.BILLING_ADDRESS_FORMAT_FULL
PaymentConstants.ADDRESS_FORMAT_FULL_ISO3166
else
PaymentConstants.BILLING_ADDRESS_FORMAT_MIN
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ object PaymentMapper {
state = address.optNonEmpty("administrativeArea"),
postalCode = address.optNonEmpty("postalCode"),
country = null,
isoCountryCode = address.optNonEmpty("countryCode")?.uppercase()
isoCountryCode = address.optNonEmpty("countryCode")?.uppercase(),
// Only with the FULL-ISO3166 format, which MIN billing addresses don't use
isoAdministrativeArea = address.optNonEmpty("iso3166AdministrativeArea")?.uppercase()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ class GooglePayRequestBuilderTest {
}

@Test
fun billingContact_requestsAFullBillingAddress() {
fun billingContact_requestsAFullBillingAddressWithTheIsoRegion() {
val json = build(paymentRequest(coffee, billingContactRequired = true))

val parameters = json.cardParameters()
assertTrue(parameters.getBoolean("billingAddressRequired"))
assertEquals("FULL", parameters.getJSONObject("billingAddressParameters").getString("format"))
assertEquals("FULL-ISO3166", parameters.getJSONObject("billingAddressParameters").getString("format"))
assertFalse(parameters.getJSONObject("billingAddressParameters").getBoolean("phoneNumberRequired"))
assertFalse(json.has("shippingAddressRequired"))
}
Expand All @@ -380,7 +380,9 @@ class GooglePayRequestBuilderTest {

assertTrue(json.getBoolean("emailRequired"))
assertTrue(json.getBoolean("shippingAddressRequired"))
assertTrue(json.getJSONObject("shippingAddressParameters").getBoolean("phoneNumberRequired"))
val shippingParameters = json.getJSONObject("shippingAddressParameters")
assertEquals("FULL-ISO3166", shippingParameters.getString("format"))
assertTrue(shippingParameters.getBoolean("phoneNumberRequired"))
assertFalse(json.cardParameters().has("billingAddressRequired"))
}

Expand All @@ -401,7 +403,7 @@ class GooglePayRequestBuilderTest {
val json = build(paymentRequest(coffee, billingContactRequired = true, phoneNumberRequired = true))

val billingParameters = json.cardParameters().getJSONObject("billingAddressParameters")
assertEquals("FULL", billingParameters.getString("format"))
assertEquals("FULL-ISO3166", billingParameters.getString("format"))
assertTrue(billingParameters.getBoolean("phoneNumberRequired"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PaymentMapperTest {
"address3": "",
"locality": "Springfield",
"administrativeArea": "IL",
"iso3166AdministrativeArea": "US-IL",
"countryCode": "us",
"postalCode": "62701",
"sortingCode": "",
Expand All @@ -57,6 +58,7 @@ class PaymentMapperTest {
"address1": "1 Billing St",
"locality": "Cupertino",
"administrativeArea": "CA",
"iso3166AdministrativeArea": " us-ca ",
"countryCode": "US",
"postalCode": "95014",
"phoneNumber": "+1 555 0100"
Expand Down Expand Up @@ -176,7 +178,8 @@ class PaymentMapperTest {
state = "CA",
postalCode = "95014",
country = null,
isoCountryCode = "US"
isoCountryCode = "US",
isoAdministrativeArea = "US-CA"
)
),
result.billingContact
Expand All @@ -192,7 +195,8 @@ class PaymentMapperTest {
state = "IL",
postalCode = "62701",
country = null,
isoCountryCode = "US"
isoCountryCode = "US",
isoAdministrativeArea = "US-IL"
)
),
result.shippingContact
Expand Down Expand Up @@ -253,7 +257,9 @@ class PaymentMapperTest {
state = null,
postalCode = null,
country = null,
isoCountryCode = "GB"
isoCountryCode = "GB",
// A MIN billing address has no ISO 3166-2 code.
isoAdministrativeArea = null
)
),
result.billingContact
Expand Down
7 changes: 5 additions & 2 deletions package/ios/PassKitTypeMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ enum PassKitTypeMapper {
state: nonEmpty(address.state),
postalCode: nonEmpty(address.postalCode),
country: nonEmpty(address.country),
isoCountryCode: nonEmpty(address.isoCountryCode)?.uppercased()
isoCountryCode: nonEmpty(address.isoCountryCode)?.uppercased(),
// Apple Pay has no ISO 3166-2 code, and `state` is free text.
isoAdministrativeArea: nil
)
}

Expand Down Expand Up @@ -366,7 +368,8 @@ enum PassKitTypeMapper {
state: contactsAddress.state,
postalCode: contactsAddress.postalCode,
country: contactsAddress.country,
isoCountryCode: contactsAddress.isoCountryCode
isoCountryCode: contactsAddress.isoCountryCode,
isoAdministrativeArea: nil
)

return CNLabeledPostalAddress.init(
Expand Down
10 changes: 7 additions & 3 deletions package/nitrogen/generated/android/c++/JCNPostalAddress.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion package/nitrogen/generated/ios/swift/CNPostalAddress.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package/nitrogen/generated/shared/c++/CNPostalAddress.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package/src/types/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export interface CNPostalAddress {
postalCode?: string
country?: string
isoCountryCode?: string
/**
* Android only: the region as an ISO 3166-2 code, such as `'US-CA'`, with
* the country prefix. Google Pay can return it for full billing and shipping
* addresses, and omits it when it has no code. On iOS it is always omitted.
*/
isoAdministrativeArea?: string
}

export interface CNLabeledPhoneNumber {
Expand Down
Loading