You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/prettier/prettier)
8
8
9
-
Accept Payments with Apple Pay using the [Payment Request API](https://paymentrequest.show).
9
+
Accept Payments with Apple Pay and Android Pay using the [Payment Request API](https://paymentrequest.show).
10
10
11
11
__Features__
12
12
-__Simple.__ No more checkout forms.
13
13
-__Effective__. Faster checkouts that increase conversion.
14
14
-__Future-proof__. Use a W3C Standards API, supported by companies like Google, Firefox and others.
15
-
-__Cross-platform__. Share payments code between your iOS and web apps.
15
+
-__Cross-platform__. Share payments code between your iOS, Android, and web apps.
16
16
-__Add-ons__. Easily enable support for Stripe or Braintree via add-ons.
@@ -50,7 +53,7 @@ $ react-native link react-native-payments
50
53
```
51
54
52
55
## Usage
53
-
-[Registering as a Merchant](#registering-as-a-merchant)
56
+
-[Setting up Apple Pay/Android Pay](#setting-up-apple-payandroid-pay)
54
57
-[Importing the Library](#importing-the-library)
55
58
-[Initializing the Payment Request](#initializing-the-payment-request)
56
59
-[Displaying the Payment Request](#displaying-the-payment-request)
@@ -61,17 +64,25 @@ $ react-native link react-native-payments
61
64
-[Dismissing the Payment Request](#dismissing-the-payment-request)
62
65
63
66
64
-
### Registering as a Merchant
65
-
Before you can start accepting payments with Apple Pay, there are a few steps you'll need to go through:
67
+
### Setting up Apple Pay/Android Pay
68
+
Before you can start accepting payments in your App, you'll need to setup Apple Pay and/or Android Pay.
66
69
70
+
#### Apple Pay
67
71
1. Register as an Apple Developer
68
72
1. Obtain a merchant ID
69
-
2. Enable Apple Pay in your app
73
+
1. Enable Apple Pay in your app
70
74
71
-
Apple has a documentation on how to do both of these in their _[Configuring your Environment](https://developer.apple.com/library/content/ApplePay_Guide/Configuration.html)_ guide.
75
+
Apple has a documentation on how to do this in their _[Configuring your Environment](https://developer.apple.com/library/content/ApplePay_Guide/Configuration.html)_ guide.
76
+
77
+
#### Android Pay
78
+
79
+
1. Add Android Pay and Google Play Services to your dependencies
80
+
1. Enable Android Pay in your Manifest
81
+
82
+
Google has documentation on how to do this in their _[Setup Android Pay](https://developers.google.com/android-pay/setup)_ guide.
72
83
73
84
### Importing the Library
74
-
Once Apple Pay is enabled in your app, jump into your app's entrypoint and make the `PaymentRequest` globally available to your app.
85
+
Once Apple Pay/Android Pay is enabled in your app, jump into your app's entrypoint and make the `PaymentRequest` globally available to your app.
🚨 _Note: On Android, display items are not displayed within the Android Pay view. Instead, the _[User Flows documentation](https://developers.google.com/android-pay/payment-flows)_ suggests showing users a confirmation view where you list the display items. When using React Native Payments, show this view after receiving the `PaymentResponse`._
161
+
126
162
### Displaying the Payment Request
127
163
Now that you've setup your Payment Request, displaying it is as simple as calling the `show` method.
@@ -144,6 +181,8 @@ You can abort the Payment Request at any point by calling the `abort` method.
144
181
paymentRequest.abort();
145
182
```
146
183
184
+
🚨 _Note: Not yet implemented on Android Pay_
185
+
147
186
### Requesting Contact Information
148
187
Some apps may require contact information from a user. You can do so by providing a [`PaymentOptions`]() as a third argument when initializing a Payment Request. Using Payment Options, you can request a contact name, phone number and/or email.
🚨 _Note: On Android, requesting a contact name will present the user with a shipping address selector. If you're not shipping anything to the user, consider capturing the contact name outside of Android Pay._
166
208
167
209
#### Requesting a Phone Number
168
210
Set `requestPayerPhone` to `true` to request a phone number.
🚨 _Note: On Android, requesting a phone number will present the user with a shipping address selector. If you're not shipping anything to the user, consider capturing the phone number outside of Android Pay._
182
228
183
229
#### Requesting an Email Address
184
230
Set `requestPayerEmail` to `true` to request an email address.
@@ -260,6 +307,8 @@ paymentRequest.addEventListener('shippingaddresschange', e => {
260
307
261
308
For a deeper dive on handling shipping in Payment Request, checkout Google's _[Shipping in Payment Request](https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/deep-dive-into-payment-request#shipping_in_payment_request_api)_.
262
309
310
+
🚨 _Note: On Android, there are no `shippingaddresschange` and `shippingoptionchange` events. To allow users to update their shipping address, you'll need to trigger a new `PaymentRequest`. Updating shipping options typically happens after the receiving the `PaymentResponse` and before calling its `getPaymentToken` method._
311
+
263
312
### Processing Payments
264
313
Now that we know how to initialize, display, and dismiss a Payment Request, let's take a look at how to process payments.
265
314
@@ -274,10 +323,10 @@ paymentRequest.show()
274
323
});
275
324
```
276
325
277
-
There are two ways to process Apple Pay payments -- on your server or using a payment processor.
326
+
There are two ways to process Apple Pay/Android Pay payments -- on your server or using a payment processor.
278
327
279
328
#### Processing Payments on Your Server
280
-
If you're equiped to Apple Paypayments on your server, all you have to do is send the Payment Response's `transactionIdentifier` and `paymentData` to your server.
329
+
If you're equiped to process Apple Pay/Android Pay payments on your server, all you have to do is send the Payment Response data to your server.
const { ephemeralPublicKey, encryptedMessage, tag } =paymentResponse.details;
363
+
364
+
returnfetch('...', {
365
+
method:'POST',
366
+
body: {
367
+
ephemeralPublicKey,
368
+
encryptedMessage,
369
+
tag
370
+
}
371
+
})
372
+
.then(res=>res.json())
373
+
.then(successHandler)
374
+
.catch(errorHandler)
375
+
});
376
+
});
377
+
```
378
+
379
+
</details>
380
+
<br/>
381
+
302
382
You can learn more about server-side decrypting of Payment Tokens on Apple's [Payment Token Format Reference](https://developer.apple.com/library/content/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html) documentation.
303
383
304
384
#### Processing Payments with a Payment Processor
@@ -307,7 +387,7 @@ When using a payment processor, you'll receive a `paymentToken` field within the
307
387
```es6
308
388
paymentRequest.show()
309
389
.then(paymentResponse=> {
310
-
const { paymentToken } =paymentResponse.details;
390
+
const { paymentToken } =paymentResponse.details;// On Android, you need to invoke the `getPaymentToken` method to receive the `paymentToken`.
- [Payment Token Format Reference](https://developer.apple.com/library/content/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html#//apple_ref/doc/uid/TP40014929)
0 commit comments