cordova-plugin-inapppurchase
cordova-plugin-inapppurchase copied to clipboard
When running the method InAppPurchase.restorePurchase() I get a value of undefined on Android from the state and date properties.
Please include:
Your code / steps to reproduce
return new Promise((resolve, reject) => {
inAppPurchase.restorePurchases()
.then(purchased => resolve(purchased))
.catch(err => {
const message = this.handleError(err);
reject(message);
});
});
// on the display on screen method
inAppPurchase.restore()
.then((products) => {
products.forEach(product => {
const receipt = JSON.parse(product.receipt)
////////testing///////
alert(receipt.purchaseState)
////////////
if (product.productId == 'master.key' && stateAndroid[receipt.purchaseState] == ('ACTIVE' || 0)) {
bought = true;
}
})
})
.catch(err => handleError(err));
// Before I had it written this way
inAppPurchase.restore()
.then((products) => {
products.forEach(product => {
if (product.productId == 'master.key' && stateAndroid[product.state] == ('ACTIVE' || 0)) {
bought = true;
}
})
})
.catch(err => handleError(err));
Console output
undefined
but no errors.
Type of product you are working with consumable/non-consumable/subscription
non-consumable
Version of cordova
cordova 8.0
Version of iOS/Android
Android 7.1
Same thing here, But.... I receive a purchasedState :0, if the purchased was effective... Any other case : no connection, item no purchase, etc..., I get a success but with an empty array...
Really? How weird...
@Bandito11 - any luck in getting date of purchase on Android? Works well for me on iOS.
I never did :(
Esteban Morales
From: Sylwester [email protected] Sent: Tuesday, July 24, 2018 4:26:05 PM To: AlexDisler/cordova-plugin-inapppurchase Cc: Esteban Morales; Mention Subject: Re: [AlexDisler/cordova-plugin-inapppurchase] When running the method InAppPurchase.restorePurchase() I get a value of undefined on Android from the state and date properties. (#222)
@Bandito11https://github.com/Bandito11 - any luck in getting date of purchase on Android? Works well for me on iOS.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/AlexDisler/cordova-plugin-inapppurchase/issues/222#issuecomment-407540393, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJWmySL6DN7JN7Rga8TVgPnIFs6kmJulks5uJ4LdgaJpZM4StLgS.
until PR is accepted you need to edit platforms/android/platform_www/plugins/cordova-plugin-inapppurchase/www/index-android.js
change state and date to what i below. Hope it helps
inAppPurchase.restorePurchases = function () { return nativeCall('init', []).then(function () { return nativeCall('restorePurchases', []); }).then(function (purchases) { var arr = []; if (purchases) { arr = purchases.map(function (val) { return { productId: val.productId, state: val.purchaseState, date: val.purchaseTime, transactionId: val.orderId, type: val.type, productType: val.type, signature: val.signature, receipt: val.receipt }; }); } return Promise.resolve(arr); }); };
I'm using cordova-plugin-inapppurchase 1.2.0 and when I tried restoring purchases on Android, state
and date
were both undefined
. The solution given by @sylwester- (changing state: val.state
to state: val.purchaseState
and date: val.date
to date: val.purchaseTime
) worked.