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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ All notable changes to this project are documented in this file.

### Added

- **`googlePayAssuranceDetailsRequired`** in `PaymentRequest` and the `usePaymentCheckout` config.
`true` sends Google Pay's `assuranceDetailsRequired` in the payment request, and the token's
`paymentMethod.assuranceDetails` (`GooglePayAssuranceDetails`: `accountVerified`,
`cardHolderAuthenticated`) reports whether Google verified the card and authenticated the
cardholder, in `onAuthorize` and the result. When both are `true`, Google says the payment
needs no 3-D Secure step-up. The details are not in the encrypted token, so your server gets
them only from your app, unsigned: treat them as a risk signal. Omitted or `false`, the request
and the result are unchanged. Android only
([#88](https://github.com/gmi-software/react-native-pay/issues/88)).
- **Google Pay `DIRECT` tokenization.** `PaymentRequest` and `usePaymentCheckout` add
`googlePayTokenization`. `{ type: 'direct', publicKey }` has Google encrypt the token with your
own EC public key (`protocolVersion: "ECv2"`), for a PCI DSS compliant server that decrypts it;
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ interface UsePaymentCheckoutConfig {
googlePayTokenization?: GooglePayTokenization; // Default: gateway. { type: "direct", publicKey } to decrypt yourself
googlePayAllowedAuthMethods?: GooglePayAuthMethod[]; // Default: ['PAN_ONLY', 'CRYPTOGRAM_3DS']
googlePayAllowPrepaidCards?: boolean; // false leaves prepaid cards out. Default: true
googlePayAssuranceDetailsRequired?: boolean; // true returns token.paymentMethod.assuranceDetails. Default: false
googlePayCheckoutOption?: GooglePayCheckoutOption; // Sheet button label. Default: Google Pay picks
// Contact details, returned in the result (see "Shipping and contact details")
billingContactRequired?: boolean;
Expand Down Expand Up @@ -811,6 +812,7 @@ interface PaymentRequest {
googlePayTokenization?: GooglePayTokenization; // who encrypts the token
googlePayAllowedAuthMethods?: string[]; // GooglePayAuthMethod values
googlePayAllowPrepaidCards?: boolean; // false leaves prepaid cards out
googlePayAssuranceDetailsRequired?: boolean; // ask whether Google verified the card
googlePayCheckoutOption?: GooglePayCheckoutOption; // the sheet's button label
}

Expand Down Expand Up @@ -847,6 +849,13 @@ interface PaymentMethod {
type: PaymentMethodType; // funding source; "store" is iOS only
secureElementPass?: PKSecureElementPass;
billingAddress?: CNContact;
assuranceDetails?: GooglePayAssuranceDetails; // Android, with googlePayAssuranceDetailsRequired
}

// What Google checked about the card (Android)
interface GooglePayAssuranceDetails {
accountVerified: boolean; // the payer possesses the card
cardHolderAuthenticated: boolean; // Google identified and verified the cardholder
}

// Payment Networks. Google Pay offers visa, mastercard, amex, discover, jcb
Expand Down
19 changes: 19 additions & 0 deletions docs/docs/api/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ interface PaymentRequest {
googlePayTokenization?: GooglePayTokenization // default: gateway
googlePayAllowedAuthMethods?: string[] // GooglePayAuthMethod values
googlePayAllowPrepaidCards?: boolean // default: true
googlePayAssuranceDetailsRequired?: boolean // default: false
googlePayCheckoutOption?: GooglePayCheckoutOption // the sheet's button label
}
```
Expand All @@ -115,6 +116,8 @@ Without `googlePayEnvironment`, Android uses `'TEST'`. When it is omitted, an An

`googlePayAllowPrepaidCards: false` leaves prepaid cards out of the Google Pay sheet, for a gateway or risk policy that refuses them. Sent as Google Pay's `allowPrepaidCards`. Omitted or `true`, prepaid cards are accepted. Android only: Apple Pay cannot leave prepaid cards out.

`googlePayAssuranceDetailsRequired: true` asks Google Pay whether it verified the card and authenticated the cardholder, returned as [`token.paymentMethod.assuranceDetails`](#googlepayassurancedetails). Sent as Google Pay's `assuranceDetailsRequired`. Omitted or `false`, the request and the result are unchanged. Android only.

`googlePayCheckoutOption` sets the label of the Google Pay sheet's button: see [`GooglePayCheckoutOption`](#googlepaycheckoutoption). Omitted, Google Pay picks "Continue" or "Pay". Android only.

`billingContactRequired`, `shippingContactRequired`, `emailRequired` and `phoneNumberRequired` ask the payer for contact details, which come back in the result as [`PaymentDetails`](#paymentdetails). On Android, a phone number is collected with an address. See [Shipping and contact details](/docs/guides/contact-details).
Expand Down Expand Up @@ -328,6 +331,7 @@ interface PaymentMethod {
type: PaymentMethodType
secureElementPass?: PKSecureElementPass // iOS
billingAddress?: CNContact // iOS
assuranceDetails?: GooglePayAssuranceDetails // Android
}

type PaymentMethodType = 'unknown' | 'debit' | 'credit' | 'prepaid' | 'store'
Expand All @@ -338,6 +342,21 @@ type PaymentMethodType = 'unknown' | 'debit' | 'credit' | 'prepaid' | 'store'
- **displayName** — Describes the card to the payer, as the wallet words it: `PKPaymentMethod.displayName` on iOS, `paymentMethodData.description` on Android (for example "Visa •••• 1234"). Show it as is; don't parse it.
- **network** — The card's [`PaymentNetwork`](#paymentnetwork), or `'unknown'` for a network the library cannot name. Use `network` rather than `displayName` for logic.
- **type** — How the card is funded: `PKPaymentMethod.type` on iOS, Google Pay's `cardFundingSource` on Android. Android reports `'credit'`, `'debit'` or `'prepaid'`, and `'unknown'` when Google Pay does not know; `'store'` (a store card) is iOS only.
- **assuranceDetails** — What Google checked about the card. Set only when `googlePayAssuranceDetailsRequired` asked for it and Google Pay returned it. Android only. See [GooglePayAssuranceDetails](#googlepayassurancedetails).

### GooglePayAssuranceDetails

```ts no-check
interface GooglePayAssuranceDetails {
accountVerified: boolean
cardHolderAuthenticated: boolean
}
```

- **accountVerified** — Google validated that the payer possesses the card.
- **cardHolderAuthenticated** — Google identified and verified the cardholder (ID&V). `false` leaves it to the risk checks you run for other card payments, such as a 3-D Secure step-up.

When both are `true`, Google says you don't need to step up the payment. A flag missing from Google Pay's response reads as `false`. The details are not part of the encrypted `paymentData`: they reach your server through your app, with nothing to prove Google sent them. Treat them as a risk signal, not as the only reason to skip 3-D Secure, and prefer your gateway's own report of them if it has one. See [Card authentication and 3-D Secure](/docs/setup/android-google-pay#card-authentication-and-3-d-secure) and Google's [AssuranceDetailsSpecifications](https://developers.google.com/pay/api/android/reference/response-objects#assurance-details-specifications).

---

Expand Down
2 changes: 2 additions & 0 deletions docs/docs/api/use-payment-checkout.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface UsePaymentCheckoutConfig {
googlePayTokenization?: GooglePayTokenization // default: gateway
googlePayAllowedAuthMethods?: GooglePayAuthMethod[] // default: both
googlePayAllowPrepaidCards?: boolean // default: true
googlePayAssuranceDetailsRequired?: boolean // default: false
googlePayCheckoutOption?: GooglePayCheckoutOption // the sheet's button label
// Contact details, returned in the result
billingContactRequired?: boolean
Expand All @@ -57,6 +58,7 @@ interface UsePaymentCheckoutConfig {
- **googlePayTokenization** — Android only. Who encrypts the Google Pay token. Omitted or `{ type: 'gateway' }`, your gateway does, from `googlePayGateway` and `googlePayGatewayMerchantId`. `{ type: 'direct', publicKey }` has Google encrypt it with your own key, for a PCI DSS compliant server that decrypts it; it needs Google's approval. A missing `publicKey` fails with a `'CONFIGURATION'` error. See [GooglePayTokenization](/docs/api/types#googlepaytokenization).
- **googlePayAllowedAuthMethods** — Android only. Which Google Pay cards to accept: `'PAN_ONLY'` (saved to the Google account), `'CRYPTOGRAM_3DS'` (tokenized on the device), or both, the default. See [GooglePayAuthMethod](/docs/api/types#googlepayauthmethod).
- **googlePayAllowPrepaidCards** — Android only. `false` leaves prepaid cards out of the Google Pay sheet, for a gateway or risk policy that refuses them; without it, the payer learns only when the charge fails. Defaults to `true`. Pass the same value to [`GooglePayButton`](/docs/api/components#googlepaybutton-android-only).
- **googlePayAssuranceDetailsRequired** — Android only. `true` asks Google Pay whether it verified the card and authenticated the cardholder, returned as `token.paymentMethod.assuranceDetails` in `onAuthorize` and the result, for example to skip a 3-D Secure step-up. Defaults to `false`. See [GooglePayAssuranceDetails](/docs/api/types#googlepayassurancedetails).
- **googlePayCheckoutOption** — Android only. The label of the Google Pay sheet's button: `'default'` ("Continue" or "Pay", as when it is omitted), `'completeImmediatePurchase'` ("Pay now") or `'continueToReview'` ("Review Order"). `'completeImmediatePurchase'` needs a final total: with a `'pending'` item, `startPayment()` fails with a `'CONFIGURATION'` error before the sheet opens. See [GooglePayCheckoutOption](/docs/api/types#googlepaycheckoutoption).
- **merchantCapabilities** — The card types to accept and, on iOS, the payment protocols. iOS adds `'3DS'` when neither `'3DS'` nor `'EMV'` is given. On Android only `'Debit'` without `'Credit'` has an effect: it leaves credit cards out. Google Pay cannot leave debit cards out, so `['3DS', 'Credit']` accepts every card type on Android. An unknown value fails the payment on both platforms. Pass the same list to [`GooglePayButton`](/docs/api/components#googlepaybutton-android-only). See [MerchantCapability](/docs/api/types#merchantcapability).
- **supportedNetworks**, **merchantCapabilities**, **googlePayAllowedAuthMethods**, **googlePayAllowPrepaidCards**, **googlePayEnvironment** — Also used for the availability check, which fails like the payment for a value the payment would refuse. Set `googlePayEnvironment: 'PRODUCTION'` in a live app: in `TEST`, Google Pay reports a card whether or not there is one. Omitted, it is `'TEST'`, and an Android release build logs a warning once per app run when `startPayment()` builds a payment. The availability check alone logs nothing.
Expand Down
25 changes: 24 additions & 1 deletion docs/docs/setup/android-google-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,30 @@ usePaymentCheckout({
})
```

Google can also report whether it has already verified the card and the cardholder ([`assuranceDetailsRequired`](https://developers.google.com/pay/api/android/reference/response-objects#assurance-details-specifications)), so you can skip the step-up when both checks pass. This library does not request it yet.
Google can also report whether it has already verified the card and authenticated the cardholder. Ask for it with `googlePayAssuranceDetailsRequired`, and read [`token.paymentMethod.assuranceDetails`](/docs/api/types#googlepayassurancedetails). When both `accountVerified` and `cardHolderAuthenticated` are `true`, Google says you don't need to step up the payment:

```ts
import { usePaymentCheckout } from '@gmisoftware/react-native-pay'

const order = { id: 'order_123' } // your order

usePaymentCheckout({
googlePayAssuranceDetailsRequired: true,
onAuthorize: async (token) => {
const assurance = token.paymentMethod.assuranceDetails
// Your server charges each order at most once, also when the app
// retries after a lost response.
const response = await fetch('https://api.yourserver.com/process-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token, orderId: order.id, assurance }),
})
return response.ok ? { status: 'success' } : { status: 'failure' }
},
})
```

The details are not part of the encrypted token: they reach your server through your app, as above, with nothing to prove Google sent them. Treat them as a risk signal, not as the only reason to skip 3-D Secure, and prefer your gateway's own report of them if it has one. See Google's [AssuranceDetailsSpecifications](https://developers.google.com/pay/api/android/reference/response-objects#assurance-details-specifications).

## The `donate` button

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ object GooglePayRequestBuilder {
})
}
}
if (request.googlePayAssuranceDetailsRequired == true) {
// Only the payment request: the readiness check and the button have no result to carry it.
baseMethod.getJSONObject("parameters").put("assuranceDetailsRequired", true)
}
baseMethod.put("tokenizationSpecification", createTokenizationSpec(request, environment))
return baseMethod
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ object PaymentMapper {
network = GooglePayNetworks.fromGooglePay(cardNetwork),
type = mapCardFundingSource(cardFundingSource),
secureElementPass = null,
billingAddress = null
billingAddress = null,
assuranceDetails = info.optJSONObject("assuranceDetails")?.let(::mapAssuranceDetails)
)

// Create payment token
Expand Down Expand Up @@ -125,6 +126,17 @@ object PaymentMapper {
)
}

/**
* Maps Google Pay's `assuranceDetails`, returned only when the request set
* `assuranceDetailsRequired`. A missing flag reads as `false`: not checked.
*/
private fun mapAssuranceDetails(details: JSONObject): GooglePayAssuranceDetails {
return GooglePayAssuranceDetails(
accountVerified = details.optBoolean("accountVerified", false),
cardHolderAuthenticated = details.optBoolean("cardHolderAuthenticated", false)
)
}

/**
* The trimmed string at [key], or null when it is missing, JSON null or blank
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class AuthorizationAttemptTest {
network = PaymentNetwork.VISA,
type = PaymentMethodType.CREDIT,
secureElementPass = null,
billingAddress = null
billingAddress = null,
assuranceDetails = null
),
transactionIdentifier = null,
paymentData = "gateway-token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,38 @@ class GooglePayRequestBuilderTest {
assertFalse(parameters.getBoolean("allowPrepaidCards"))
}

// Assurance details

@Test
fun assuranceDetailsRequired_asksForThemInThePaymentRequestOnly() {
val request = build(paymentRequest(coffee, googlePayAssuranceDetailsRequired = true))
val readiness = GooglePayRequestBuilder.createIsReadyToPayRequest(GooglePayCardParameters.DEFAULT)
val button = GooglePayRequestBuilder.createAllowedPaymentMethods(GooglePayCardParameters.DEFAULT)

assertTrue(request.cardParameters().getBoolean("assuranceDetailsRequired"))
assertFalse(readiness.cardParameters().has("assuranceDetailsRequired"))
assertFalse(button.getJSONObject(0).getJSONObject("parameters").has("assuranceDetailsRequired"))
}

@Test
fun assuranceDetailsOmittedOrFalse_sendsTheSameRequestAsBefore() {
val omitted = build(paymentRequest(coffee))
val notRequired = build(paymentRequest(coffee, googlePayAssuranceDetailsRequired = false))

assertFalse(omitted.cardParameters().has("assuranceDetailsRequired"))
assertEquals(omitted.toString(), notRequired.toString())
}

@Test
fun assuranceDetailsRequired_combinesWithABillingAddress() {
val parameters = build(
paymentRequest(coffee, billingContactRequired = true, googlePayAssuranceDetailsRequired = true)
).cardParameters()

assertTrue(parameters.getBoolean("assuranceDetailsRequired"))
assertTrue(parameters.getBoolean("billingAddressRequired"))
}

// Payment data callbacks

private fun buildWithCallbacks(request: PaymentRequest, callbacks: CallbackIntents): JSONObject =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,60 @@ class PaymentMapperTest {
assertNull(token.paymentMethod.billingAddress)
}

@Test
fun mapPaymentDataToResult_readsTheAssuranceDetails() {
// Google's sample response for a request with assuranceDetailsRequired
val result = PaymentMapper.mapPaymentDataToResult(
paymentData(
"""
{
"type": "CARD",
"description": "Visa •••• 1234",
"info": {
"cardNetwork": "VISA",
"cardDetails": "1234",
"assuranceDetails": {"accountVerified": true, "cardHolderAuthenticated": false}
},
"tokenizationData": {"type": "PAYMENT_GATEWAY", "token": "gateway-token"}
}
"""
)
)

assertEquals(
GooglePayAssuranceDetails(accountVerified = true, cardHolderAuthenticated = false),
result.token!!.paymentMethod.assuranceDetails
)
}

@Test
fun mapPaymentDataToResult_reportsAMissingAssuranceFlagAsNotChecked() {
val result = PaymentMapper.mapPaymentDataToResult(
paymentData(
"""
{
"info": {"cardNetwork": "VISA", "assuranceDetails": {"cardHolderAuthenticated": true}},
"tokenizationData": {"token": "gateway-token"}
}
"""
)
)

assertEquals(
GooglePayAssuranceDetails(accountVerified = false, cardHolderAuthenticated = true),
result.token!!.paymentMethod.assuranceDetails
)
}

@Test
fun mapPaymentDataToResult_reportsNoAssuranceDetailsWithoutThem() {
val result = PaymentMapper.mapPaymentDataToResult(
paymentData("""{"info": {"cardNetwork": "VISA"}, "tokenizationData": {"token": "gateway-token"}}""")
)

assertNull(result.token!!.paymentMethod.assuranceDetails)
}

@Test
fun mapPaymentDataToResult_fillsMissingCardInfo() {
val result = PaymentMapper.mapPaymentDataToResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class SheetAuthorizationTest {
network = PaymentNetwork.VISA,
type = PaymentMethodType.CREDIT,
secureElementPass = null,
billingAddress = null
billingAddress = null,
assuranceDetails = null
),
transactionIdentifier = null,
paymentData = token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal fun paymentRequest(
supportedNetworks: Array<String> = arrayOf("visa"),
googlePayAllowedAuthMethods: Array<String>? = null,
googlePayAllowPrepaidCards: Boolean? = null,
googlePayAssuranceDetailsRequired: Boolean? = null,
merchantCapabilities: Array<String> = arrayOf("3DS"),
recurring: RecurringPaymentRequest? = null,
deferred: DeferredPaymentRequest? = null,
Expand Down Expand Up @@ -68,6 +69,7 @@ internal fun paymentRequest(
googlePayTokenization = googlePayTokenization,
googlePayAllowedAuthMethods = googlePayAllowedAuthMethods,
googlePayAllowPrepaidCards = googlePayAllowPrepaidCards,
googlePayAssuranceDetailsRequired = googlePayAssuranceDetailsRequired,
googlePayCheckoutOption = googlePayCheckoutOption
)

Expand Down
4 changes: 3 additions & 1 deletion package/ios/HybridPaymentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ private struct PaymentTokenConverter {
network: pkMethod.network.map { PassKitTypeMapper.convert($0) },
type: PassKitTypeMapper.convert(pkMethod.type),
secureElementPass: convertSecureElementPass(pkMethod),
billingAddress: convertBillingAddress(pkMethod)
billingAddress: convertBillingAddress(pkMethod),
// Google Pay only
assuranceDetails: nil
)
}

Expand Down
Loading
Loading