Skip to content

Commit

Permalink
Resolve #101
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Sep 30, 2019
1 parent 583f389 commit bdcf522
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.0+9
* Resolve [#101](https://github.com/dooboolab/flutter_inapp_purchase/issues/101).
## 2.0.0+8
* Resolve [#100](https://github.com/dooboolab/flutter_inapp_purchase/issues/100).
## 2.0.0+7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,35 +390,44 @@ else if (call.method.equals("buyItemByType")) {
else if (call.method.equals("acknowledgePurchase")) {
final String token = call.argument("token");
final String developerPayload = call.argument("developerPayload");

if (billingClient == null || !billingClient.isReady()) {
AcknowledgePurchaseParams acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(token)
.setDeveloperPayload(developerPayload)
.build();
billingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {
@Override
public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
if (billingClient == null || !billingClient.isReady()) {
result.error(call.method,
"IAP not prepared. Check if Google Play service is available.",
DoobooUtils.getInstance().getBillingResponseData(billingResult.getResponseCode()));
return;
}
try {
JSONObject item = new JSONObject();
item.put("responseCode", billingResult.getResponseCode());
item.put("debugMessage", billingResult.getDebugMessage());
String[] errorData = DoobooUtils.getInstance().getBillingResponseData(billingResult.getResponseCode());
item.put("code", errorData[0]);
item.put("message", errorData[1]);
result.success(item.toString());
} catch (JSONException je) {
result.error(TAG, "E_BILLING_RESPONSE_JSON_PARSE_ERROR", je.getMessage());
}
}
});
result.error(call.method,
"IAP not prepared. Check if Google Play service is available.",
DoobooUtils.getInstance().getBillingResponseData(billingResult.getResponseCode()),
);
return;
}

AcknowledgePurchaseParams acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(token)
.setDeveloperPayload(developerPayload)
.build();
billingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {
@Override
public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
result.error(
call.method,
"The response code is not OK when requested acknowledge.",
DoobooUtils.getInstance().getBillingResponseData(billingResult.getResponseCode()),
);
return;
}
try {
JSONObject item = new JSONObject();
item.put("responseCode", billingResult.getResponseCode());
item.put("debugMessage", billingResult.getDebugMessage());
String[] errorData = DoobooUtils.getInstance().getBillingResponseData(billingResult.getResponseCode());
item.put("code", errorData[0]);
item.put("message", errorData[1]);
result.success(item.toString());
} catch (JSONException je) {
result.error(TAG, "E_BILLING_RESPONSE_JSON_PARSE_ERROR", je.getMessage());
}
}
});
}

/*
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_inapp_purchase
description: In App Purchase plugin for flutter. This project has been forked by react-native-iap and we are willing to share same experience with that on react-native.
version: 2.0.0+8
version: 2.0.0+9
author: dooboolab<dooboolab@gmail.com>
homepage: https://github.com/dooboolab/flutter_inapp_purchase/blob/master/pubspec.yaml
environment:
Expand Down

0 comments on commit bdcf522

Please sign in to comment.