Skip to content

Commit

Permalink
isReadyToPay always resolve boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey committed Jun 15, 2019
1 parent 61778e9 commit 5cd261c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
13 changes: 7 additions & 6 deletions Example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export default class App extends Component {
payWithGooglePay = () => {
// Check if Google Pay is available
GooglePay.isReadyToPay(allowedCardNetworks, allowedCardAuthMethods)
.then(() => {
// Request payment token
GooglePay.requestPayment(requestData)
.then(this.handleSuccess)
.catch(this.handleError)
.then((ready) => {
if (ready) {
// Request payment token
GooglePay.requestPayment(requestData)
.then(this.handleSuccess)
.catch(this.handleError)
}
})
.catch(this.handleError)
}

handleSuccess = (token: string) => {
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ GooglePay.setEnvironment(GooglePay.ENVIRONMENT_TEST);

// Check if Google Pay is available
GooglePay.isReadyToPay(allowedCardNetworks, allowedCardAuthMethods)
.then(() => {
// Request payment token
GooglePay.requestPayment(requestData)
.then((token: string) => {
// Send a token to your payment gateway
})
.catch((error) => console.log(error.code, error.message));
.then((ready) => {
if (ready) {
// Request payment token
GooglePay.requestPayment(requestData)
.then((token: string) => {
// Send a token to your payment gateway
})
.catch((error) => console.log(error.code, error.message));
}
})
.catch((error) => console.log(error.code, error.message));
```

## Demo
Expand Down
13 changes: 8 additions & 5 deletions android/src/main/java/com/busfor/RNGooglePayModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ public void setEnvironment(int environment) {
public void isReadyToPay(ReadableArray allowedCardNetworks, ReadableArray allowedCardAuthMethods, final Promise promise) {
final JSONObject isReadyToPayJson = PaymentsUtil.getIsReadyToPayRequest(allowedCardNetworks.toArrayList(), allowedCardAuthMethods.toArrayList());
if (isReadyToPayJson == null) {
promise.reject("NOT_READY_TO_PAY", "Not ready to pay");
Log.w(TAG, "[GooglePay] isReadyToPayJson == null");
promise.resolve(false);
return;
}
IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.toString());
if (request == null) {
promise.reject("NOT_READY_TO_PAY", "Not ready to pay");
Log.w(TAG, "[GooglePay] IsReadyToPayRequest == null");
promise.resolve(false);
return;
}

Expand All @@ -116,13 +118,14 @@ public void isReadyToPay(ReadableArray allowedCardNetworks, ReadableArray allowe
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
if (task.getResult()) {
promise.resolve(null);
promise.resolve(true);
} else {
promise.reject("NOT_AVAILABLE", "Not available");
Log.w(TAG, "[GooglePay] Not available");
promise.resolve(false);
}
} else {
Log.w(TAG, "[GooglePay] isReadyToPay failed");
promise.reject("IS_READY_TO_PAY_FAILED", "isReadyToPay failed");
promise.resolve(false);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "react-native-google-pay",
"version": "1.1.0",
"version": "1.2.0",
"description": "React Native bridge for Google Pay",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5cd261c

Please sign in to comment.