Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android implementation updates #396

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jsconfig.json
.vscode/*
.idea
*.iml
.history

# project
#
Expand Down
72 changes: 37 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,19 @@ const METHOD_DATA = [{
supportedMethods: ['android-pay'],
data: {
supportedNetworks: ['visa', 'mastercard', 'amex'],
// https://developers.google.com/android/reference/com/google/android/gms/wallet/WalletConstants.html
// PAYMENT_METHOD_CARD and PAYMENT_METHOD_TOKENIZED_CARD.. or [1, 2]
allowedPaymentMethods: [1, 2],
currencyCode: 'USD',
environment: 'TEST', // defaults to production
paymentMethodTokenizationParameters: {
tokenizationType: 'NETWORK_TOKEN',
tokenizationType: 'PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT', // or PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY
parameters: {
publicKey: 'your-pubic-key'
publicKey: 'your-pubic-key' // https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#using-openssl
// if use PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY
// gateway: 'your gateway',
// gatewayMerchantId: 'your gatewayMerchantId',
// merchantName: 'your merchantName',
}
}
}
Expand Down Expand Up @@ -451,7 +458,7 @@ paymentRequest.addEventListener('shippingoptionchange', e => {

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)_.

🚨 _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._
🚨 _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`_

### Processing Payments
Now that we know how to initialize, display, and dismiss a Payment Request, let's take a look at how to process payments.
Expand Down Expand Up @@ -501,24 +508,19 @@ paymentRequest.show()
```es6
paymentRequest.show()
.then(paymentResponse => {
const { getPaymentToken } = paymentResponse.details;

return getPaymentToken()
.then(paymentToken => {
const { ephemeralPublicKey, encryptedMessage, tag } = paymentResponse.details;

return fetch('...', {
method: 'POST',
body: {
ephemeralPublicKey,
encryptedMessage,
tag
}
})
.then(res => res.json())
.then(successHandler)
.catch(errorHandler)
});
const { ephemeralPublicKey, encryptedMessage, tag } = paymentResponse.details.paymentToken;

return fetch('...', {
method: 'POST',
body: {
ephemeralPublicKey,
encryptedMessage,
tag
}
})
.then(res => res.json())
.then(successHandler)
.catch(errorHandler)
});
```

Expand All @@ -533,7 +535,7 @@ When using a payment processor, you'll receive a `paymentToken` field within the
```es6
paymentRequest.show()
.then(paymentResponse => {
const { paymentToken } = paymentResponse.details; // On Android, you need to invoke the `getPaymentToken` method to receive the `paymentToken`.
const { paymentToken } = paymentResponse.details;

return fetch('...', {
method: 'POST',
Expand All @@ -554,19 +556,17 @@ paymentRequest.show()
```es6
paymentRequest.show()
.then(paymentResponse => {
const { getPaymentToken } = paymentResponse.details;

return getPaymentToken()
.then(paymentToken => fetch('...', {
method: 'POST',
body: {
paymentToken
}
})
.then(res => res.json())
.then(successHandler)
.catch(errorHandler);
});
const { paymentToken } = paymentResponse.details;

return fetch('...', {
method: 'POST',
body: {
paymentToken
}
})
.then(res => res.json())
.then(successHandler)
.catch(errorHandler);
});
```

Expand Down Expand Up @@ -631,6 +631,8 @@ Here's a list of Payment Processors that you can enable via add-ons:
- [Brand Guidelines](https://developers.google.com/pay/api/android/guides/brand-guidelines)
- [Gateway Token Approach](https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/android-pay#gateway_token_approach)
- [Network Token Approach](https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/android-pay#network_token_approach)
- [WalletConstants](https://developers.google.com/android/reference/com/google/android/gms/wallet/WalletConstants)


# License
Licensed under the MIT License, Copyright © 2017, [Naoufal Kadhom](https://twitter.com/naoufal).
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion "28.0.3"

defaultConfig {
Expand All @@ -20,8 +20,8 @@ android {

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.android.gms:play-services-base:17.0.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-wallet:17.0.0'
implementation 'com.google.android.gms:play-services-base:18.0.0'
implementation 'com.google.android.gms:play-services-identity:18.0.0'
implementation 'com.google.android.gms:play-services-wallet:18.0.0'
implementation 'com.android.support:support-v4:23.0.1'
}
5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativepayments">

<application android:label="@string/app_name">
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
</application>
</manifest>
Loading