j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

Added items after store.refresh don't work correctly #1037

Closed ermite1408 closed 4 years ago

ermite1408 commented 4 years ago

System info

Cordova 9.0.1
Device: Android 8.0
Plugin Version: 10.0.1

Hello, I have the problem. In my game there are items for purchase. After buying one of them, it should be replaced by another. The application does not know in advance what the new item will be (this information comes from the backend).

What am I doing:

  1. User entry into the game
  2. I registration items and call store.refresh function
  3. User buying items
  4. Backend give new item
  5. Game call registration new item and store.refresh:
this.store.register(item);
this.store.refresh();

After store refreshing items have state = valid, but you can’t buy it or get some information A new item after refreshing has the form:

// called store.get('shopItemId');
additionalData: Object
alias: "shopItemId"
canPurchase: true
countryCode: null
currency: null
deferred: undefined
description: null
discounts: Array(0)
downloaded: false
downloading: false
group: ""
id: "shopItemId"
ineligibleForIntroPrice: null
introPrice: null
introPriceMicros: null
introPriceNumberOfPeriods: null
introPricePaymentMode: null
introPricePeriod: null
introPricePeriodUnit: null
introPriceSubscriptionPeriod: null
loaded: true
owned: false
price: null
priceMicros: null
state: "valid"
title: null
transaction: null
type: "consumable"
valid: true

I tried calling store.update(), but got an error:

successCb is not a function

at *path_to_folder*/www/plugins/cordova-plugin-purchase/www/store-android.js:2969:9
at *path_to_folder*/www/plugins/cordova-plugin-purchase/www/store-android.js:3570:31
at Object.callbackFromNative (*path_to_folder*/www/cordova.js:291:58)
at processMessage (*path_to_folder*/www/cordova.js:1114:17)
at processMessages (*path_to_folder*/www/cordova.js:1137:9

Please, help :)

j3k0 commented 4 years ago

Hey, the "successCb" bug has been fixed in latest release (10.2.0). I recommend you get the list of all possible purchase at startup, from a specific endpoint in your server... some purchases might have been made with the Google Play account but not linked to your application user (people switch accounts sometimes). Then the plugin wouldn't know what this purchase is about and you're in undefined- behavior-land ;)

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.