Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Support developer payload #108

Open
wants to merge 1 commit 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
9 changes: 6 additions & 3 deletions src/android/InAppBillingV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ public void onIabSetupFinished(IabResult result) {

protected boolean runPayment(final JSONArray args, final CallbackContext callbackContext, boolean subscribe) {
final String sku;
String developerPayload = "";
try {
sku = args.getString(0);
if (args.length > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be args.length() for everyone running in the error.

developerPayload = args.getString(1);
}
} catch (JSONException e) {
callbackContext.error(makeError("Invalid SKU", INVALID_ARGUMENTS));
return false;
Expand All @@ -211,7 +215,6 @@ protected boolean runPayment(final JSONArray args, final CallbackContext callbac
final Activity cordovaActivity = this.cordova.getActivity();
int newOrder = orderSerial.getAndIncrement();
this.cordova.setActivityResultCallback(this);

IabHelper.OnIabPurchaseFinishedListener oipfl = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Expand Down Expand Up @@ -247,9 +250,9 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
}
};
if(subscribe){
iabHelper.launchSubscriptionPurchaseFlow(cordovaActivity, sku, newOrder, oipfl, "");
iabHelper.launchSubscriptionPurchaseFlow(cordovaActivity, sku, newOrder, oipfl, developerPayload);
} else {
iabHelper.launchPurchaseFlow(cordovaActivity, sku, newOrder, oipfl, "");
iabHelper.launchPurchaseFlow(cordovaActivity, sku, newOrder, oipfl, developerPayload);
}
return true;
}
Expand Down
15 changes: 8 additions & 7 deletions src/js/index-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ inAppPurchase.getProducts = (productIds) => {
});
};

const executePaymentOfType = (type, productId) => {
const executePaymentOfType = (type, productId, developerPayload) => {
developerPayload = developerPayload || "";
return new Promise((resolve, reject) => {
if (!inAppPurchase.utils.validString(productId)) {
if (!inAppPurchase.utils.validString(productId, developerPayload)) {
reject(new Error(inAppPurchase.utils.errors[102]));
} else {
nativeCall(type, [productId]).then((res) => {
nativeCall(type, [productId, developerPayload]).then((res) => {
resolve({
signature: res.signature,
productId: res.productId,
Expand All @@ -75,12 +76,12 @@ const executePaymentOfType = (type, productId) => {
});
};

inAppPurchase.buy = (productId) => {
return executePaymentOfType('buy', productId);
inAppPurchase.buy = (productId, developerPayload) => {
return executePaymentOfType('buy', productId, developerPayload);
};

inAppPurchase.subscribe = (productId) => {
return executePaymentOfType('subscribe', productId);
inAppPurchase.subscribe = (productId, developerPayload) => {
return executePaymentOfType('subscribe', productId, developerPayload);
};

inAppPurchase.consume = (type, receipt, signature) => {
Expand Down