j3k0 / cordova-plugin-purchase

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

[ANDROID] Transactions do not finish after consuming a product #1380

Closed geshub closed 1 year ago

geshub commented 1 year ago

This problem is already described in https://github.com/j3k0/cordova-plugin-purchase/issues/1364 and on this pull request https://github.com/j3k0/cordova-plugin-purchase/pull/1372 but it's better to separate it from the other thread that also describe another issue. Just tried with the last code [v13.3.2] and problem persists.

Observed behavior

I can't get the finished event to get called on Android (v12) consumable. The same code is calling this event correctly on IOS.

I can see those in my logs:

[CdvPurchase.Validator] DEBUG: Register a new verified receipt. [CdvPurchase] INFO: finish(VerifiedReceipt) [CdvPurchase.GooglePlay.Bridge] INFO: consumePurchase() [CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"purchaseConsumed","data":{"purchase":{"orderId":"GPA.3323-0342-9288-38202","packageName":"... [CdvPurchase.GooglePlay] DEBUG: onPurchaseConsumed: GPA.3323-0342-9288-38202

but it's never calling the finished event.

Expected behavior

Calling the finished event after product is consumed to I can refresh UI.

System Info

Cordova CLI : 11.1.0 Cordova Platforms : android 11.0.0, ios 6.2.0 Cordova Plugins : cordova-plugin-purchase: 13.3.2, cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 24 other plugins)

j3k0 commented 1 year ago

Can you share your code and the full logs?

In the other issues, one problem was that the event handlers where added inside the "store.ready" event, which wasn't correct.

geshub commented 1 year ago

Thanks for checking,

I'm using this code to initialize the plugin:

    var store = CdvPurchase.store;
    var ProductType = CdvPurchase.ProductType;
    var Platform = CdvPurchase.Platform;
    var LogLevel = CdvPurchase.LogLevel;

    // LogLevel.QUIET, LogLevel.ERROR, LogLevel.WARNING, LogLevel.INFO, LogLevel.DEBUG
    store.verbosity = config.env_node === 'release' ? LogLevel.QUIET : LogLevel.DEBUG;

    // Set Username id if member
    if (authService.isUserLogged()) {
      var userid = userdataService.getUserID().toString();
      store.applicationUsername = function() {
        return 'userid_' + userid;
      };
    }

    // Register products
    store.register([{
      id: config.productId,
      type: ProductType.NON_RENEWING_SUBSCRIPTION,
      platform: Platform.APPLE_APPSTORE
    },
      {
        id: config.productId,
        type: ProductType.CONSUMABLE,
        platform: Platform.GOOGLE_PLAY
      }]);

    store.when()
      .approved(function (t) {
        return productApproved(t);
      })
      .verified(function (receipt) {
        console.log('************* Product verified from server-side, finishing product *************');
        return receipt.finish();
      })
      .finished(function (t) {
        return productFinished(t);
      })
      .receiptUpdated(function (r) {
        return updatePurchases(r);
      })
      .productUpdated(function (p) {
        return updateUI(p);
      });

store.ready(function () { console.log('Store is ready!'); });

store.initialize([ { platform: Platform.APPLE_APPSTORE, options: { needAppReceipt: false // Set to false if you don't need to verify the application receipt } }, Platform.GOOGLE_PLAY ]) .then(function () { console.log('Store is initialized!'); });

My productFinished function is called on IOS but not on Android 12 device (Xioami)

Some edited logs:

I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: Ready", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.Adapters] INFO: GooglePlay initialized. ", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.Adapters] INFO: GooglePlay products: [{"id":"*...***","type":"consumable","platform":"android-playstore"}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: Load: [{"id":"...**","type":"consumable","platform":"android-playstore"}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getAvailableProducts: ["*.**.."] | []", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: getAvailableProducts()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: getAvailableProducts() D/CdvPurchase: queryAllProductDetails() D/CdvPurchase: queryAllProductDetails() -> Query INAPP. D/CdvPurchase: queryProductDetailsAsync() D/CdvPurchase: executeServiceRequest() -> OK D/CdvPurchase: queryProductDetailsAsync() -> Success D/CdvPurchase: queryAllProductDetails() -> ProductDetails: Title: **** D/CdvPurchase: queryAllProductDetails() -> Calling listener. D/CdvPurchase: getAvailableProducts() -> productDetails: ProductDetails{jsonString='{"productId":"*...","type":"inapp","title":"****","name":"****","description":"****","localizedIn":["fr-FR"],"skuDetailsToken":"AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva","oneTimePurchaseOfferDetails":{"priceAmountMicros":19990000,"priceCurrencyCode":"EUR","formattedPrice":"€19.99"}}', parsedJson={"productId":"*...","type":"inapp","title":"****","name":"****","description":"****","localizedIn":["fr-FR"],"skuDetailsToken":"AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva","oneTimePurchaseOfferDetails":{"priceAmountMicros":19990000,"priceCurrencyCode":"EUR","formattedPrice":"€19.99"}}, productId='*...', productType='inapp', title='****', productDetailsToken='AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva', subscriptionOfferDetails=null} D/CdvPurchase: getAvailableProducts() -> Success D/CdvPurchase: getPurchases() D/CdvPurchase: queryPurchases() D/CdvPurchase: executeServiceRequest() -> OK I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: Loaded: [{"productId":"*...","title":"****","name":"****","description":"****","product_type":"inapp","product_format":"v11.0","formatted_price":"€19.99","price_amount_micros":19990000,"price_currency_code":"EUR"}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getPurchases", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: getPurchases()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.Adapters] INFO: GooglePlay loaded: [{"className":"Product","title":"****","description":"****","platform":"android-playstore","type":"consumable","id":"*...**","offers":[{"className":"Offer","id":"*.**..","pricingPhases":[{"price":"€19.99","priceMicros":19990000,"currency":"EUR","recurrenceMode":"NON_RECURRING"}],"productId":"*...**","productType":"consumable","platform":"android-playstore","type":"inapp"}]}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/CdvPurchase: queryPurchases(SUBS) -> Elapsed time: 9ms I/CdvPurchase: queryPurchases(INAPP) -> Elapsed time: 12ms D/CdvPurchase: sendToListener() -> setPurchases D/CdvPurchase: data -> {"purchases":[]} I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"setPurchases","data":{"purchases":[]}}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onSetPurchases: []", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onPurchaseUpdated: ", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getPurchases success", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase] INFO: update()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: Load: [{"id":"*.**..","type":"consumable","platform":"android-playstore"}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getAvailableProducts: ["*..."] | []", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: getAvailableProducts() I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: getAvailableProducts()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: queryAllProductDetails() D/CdvPurchase: queryAllProductDetails() -> Query INAPP. D/CdvPurchase: queryProductDetailsAsync() D/CdvPurchase: executeServiceRequest() -> OK D/CdvPurchase: queryProductDetailsAsync() -> Success D/CdvPurchase: queryAllProductDetails() -> ProductDetails: Title: **** D/CdvPurchase: queryAllProductDetails() -> Calling listener. D/CdvPurchase: getAvailableProducts() -> productDetails: ProductDetails{jsonString='{"productId":"*...","type":"inapp","title":"****","name":"****","description":"****","localizedIn":["fr-FR"],"skuDetailsToken":"AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva","oneTimePurchaseOfferDetails":{"priceAmountMicros":19990000,"priceCurrencyCode":"EUR","formattedPrice":"€19.99"}}', parsedJson={"productId":"*...","type":"inapp","title":"****","name":"****","description":"****","localizedIn":["fr-FR"],"skuDetailsToken":"AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva","oneTimePurchaseOfferDetails":{"priceAmountMicros":19990000,"priceCurrencyCode":"EUR","formattedPrice":"€19.99"}}, productId='*...', productType='inapp', title='****', productDetailsToken='AEuhp4IaJIWTVRI8fa3t912E17czbFspeMWVP4CS9CFsVH_c7y8f6CEbXjkxwpsc0Rva', subscriptionOfferDetails=null} D/CdvPurchase: getAvailableProducts() -> Success I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: Loaded: [{"productId":"*...","title":"****","name":"****","description":"****","product_type":"inapp","product_format":"v11.0","formatted_price":"€19.99","price_amount_micros":19990000,"price_currency_code":"EUR"}]", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getPurchases", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: getPurchases()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: getPurchases() D/CdvPurchase: queryPurchases() D/CdvPurchase: executeServiceRequest() -> OK I/CdvPurchase: queryPurchases(INAPP) -> Elapsed time: 3ms I/CdvPurchase: queryPurchases(SUBS) -> Elapsed time: 3ms D/CdvPurchase: sendToListener() -> setPurchases D/CdvPurchase: sendToListener() -> setPurchases D/CdvPurchase: data -> {"purchases":[]} D/CdvPurchase: data -> {"purchases":[]} I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"setPurchases","data":{"purchases":[]}}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onSetPurchases: []", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onPurchaseUpdated: ", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: getPurchases success", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"setPurchases","data":{"purchases":[]}}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onSetPurchases: []", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onPurchaseUpdated: ", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase] INFO: order(*...***)", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] INFO: Order - {"className":"Offer","id":"...**","pricingPhases":[{"price":"€19.99","priceMicros":19990000,"currency":"EUR","recurrenceMode":"NON_RECURRING"}],"productId":"*.**..","productType":"consumable","platform":"android-playstore","type":"inapp"}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: buy() I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: buy()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: buy() -> setProductDetailsParamsList D/CdvPurchase: initiatePurchaseFlow() D/CdvPurchase: executeServiceRequest() -> OK D/CdvPurchase: initiatePurchaseFlow() -> launchBillingFlow. D/CdvPurchase: onPurchasesUpdated() -> Success D/CdvPurchase: sendToListener() -> purchasesUpdated D/CdvPurchase: data -> {"purchases":[{"orderId":"GPA.3314-9744-6390-89331","packageName":"*...**","productId":"*.**..","purchaseTime":1676971165640,"purchaseState":0,"purchaseToken":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","quantity":1,"acknowledged":false,"productIds":["*...**"],"getPurchaseState":1,"developerPayload":"","autoRenewing":false,"accountId":"","profileId":"","signature":"JZLuFqN0L635ILr+QKQiaNmAV8TSJxOfK70\/VBlH0\/ql+qN35zFuLhye7WZBSQkCuIr7VZQ14tqFp+aLGFXRDlw7LxTMVORwaGPMqGa0Ds5X\/2tjdqbhWT0\/g31oyuuTu8rGSnJcu5rwTIASDTXyxs2FIQpgC8qrnzx8DnSDKjFNMQAj6AZQGqmm4warcAIdSCol3MnJoqDeM9EjoAhiS+1q2n+IcXymE9T6Z632iX0YCXwZLON66+rH3iW8+BhWbCIbZ+0qyze6BAEv1cb0MdGzEogPq8ue9Qjv8FKfHAMKsmIkR3eJ0kgZPg26zkxP1TOKB1a4prNrfRSYFIXk+w==","receipt":"{\"orderId\":\"GPA.3314-9744-6390-89331\",\"packageName\":\"*.**..\",\"productId\":\"*...**\",\"purchaseTime\":1676971165640,\"purchaseState\":0,\"purchaseToken\":\"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow\",\"quantity\":1,\"acknowledged\":false}"}]} I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"purchasesUpdated","data":{"purchases":[{"orderId":"GPA.3314-9744-6390-89331","packageName":"*.**..","productId":"*...**","purchaseTime":1676971165640,"purchaseState":0,"purchaseToken":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","quantity":1,"acknowledged":false,"productIds":["*.**.."],"getPurchaseState":1,"developerPayload":"","autoRenewing":false,"accountId":"","profileId":"","signature":"JZLuFqN0L635ILr+QKQiaNmAV8TSJxOfK70/VBlH0/ql+qN35zFuLhye7WZBSQkCuIr7VZQ14tqFp+aLGFXRDlw7LxTMVORwaGPMqGa0Ds5X/2tjdqbhWT0/g31oyuuTu8rGSnJcu5rwTIASDTXyxs2FIQpgC8qrnzx8DnSDKjFNMQAj6AZQGqmm4warcAIdSCol3MnJoqDeM9EjoAhiS+1q2n+IcXymE9T6Z632iX0YCXwZLON66+rH3iW8+BhWbCIbZ+0qyze6BAEv1cb0MdGzEogPq8ue9Qjv8FKfHAMKsmIkR3eJ0kgZPg26zkxP1TOKB1a4prNrfRSYFIXk+w==","receipt":"{\"orderId\":\"GPA.3314-9744-6390-89331\",\"packageName\":\"*...**\",\"productId\":\"*.**..\",\"purchaseTime\":1676971165640,\"purchaseState\":0,\"purchaseToken\":\"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow\",\"quantity\":1,\"acknowledged\":false}"}]}}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onPurchaseUpdated: GPA.3314-9744-6390-89331", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase] INFO: verify(Transaction)", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.Validator] DEBUG: Schedule validation: {"className":"Transaction","transactionId":"GPA.3314-9744-6390-89331","state":"approved","products":[{"id":"*...**"}],"platform":"android-playstore","nativePurchase":{"orderId":"GPA.3314-9744-6390-89331","packageName":"*.**..","productId":"*...**","purchaseTime":1676971165640,"purchaseState":0,"purchaseToken":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","quantity":1,"acknowledged":false,"productIds":["*.**.."],"getPurchaseState":1,"developerPayload":"","autoRenewing":false,"accountId":"","profileId":"","signature":"JZLuFqN0L635ILr+QKQiaNmAV8TSJxOfK70/VBlH0/ql+qN35zFuLhye7WZBSQkCuIr7VZQ14tqFp+aLGFXRDlw7LxTMVORwaGPMqGa0Ds5X/2tjdqbhWT0/g31oyuuTu8rGSnJcu5rwTIASDTXyxs2FIQpgC8qrnzx8DnSDKjFNMQAj6AZQGqmm4warcAIdSCol3MnJoqDeM9EjoAhiS+1q2n+IcXymE9T6Z632iX0YCXwZLON66+rH3iW8+BhWbCIbZ+0qyze6BAEv1cb0MdGzEogPq8ue9Qjv8FKfHAMKsmIkR3eJ0kgZPg26zkxP1TOKB1a4prNrfRSYFIXk+w==","receipt":"{\"orderId\":\"GPA.3314-9744-6390-89331\",\"packageName\":\"*...**\",\"productId\":\"*.**..\",\"purchaseTime\":1676971165640,\"purchaseState\":0,\"purchaseToken\":\"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow\",\"quantity\":1,\"acknowledged\":false}"},"purchaseId":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","purchaseDate":"2023-02-21T09:19:25.640Z","isPending":false,"isAcknowledged":false,"renewalIntent":"Lapse"}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.Validator] DEBUG: Register a new verified receipt.", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase] INFO: finish(VerifiedReceipt)", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: consumePurchase()", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) D/CdvPurchase: consumePurchase(ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow) D/CdvPurchase: executeServiceRequest() -> OK D/CdvPurchase: onConsumeResponse() D/CdvPurchase: onConsumeResponse() -> Success D/CdvPurchase: sendToListener() -> purchaseConsumed D/CdvPurchase: data -> {"purchase":{"orderId":"GPA.3314-9744-6390-89331","packageName":"*...**","productId":"*.**..","purchaseTime":1676971165640,"purchaseState":0,"purchaseToken":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","quantity":1,"acknowledged":false,"productIds":["*...**"],"getPurchaseState":1,"developerPayload":"","autoRenewing":false,"accountId":"","profileId":"","signature":"JZLuFqN0L635ILr+QKQiaNmAV8TSJxOfK70\/VBlH0\/ql+qN35zFuLhye7WZBSQkCuIr7VZQ14tqFp+aLGFXRDlw7LxTMVORwaGPMqGa0Ds5X\/2tjdqbhWT0\/g31oyuuTu8rGSnJcu5rwTIASDTXyxs2FIQpgC8qrnzx8DnSDKjFNMQAj6AZQGqmm4warcAIdSCol3MnJoqDeM9EjoAhiS+1q2n+IcXymE9T6Z632iX0YCXwZLON66+rH3iW8+BhWbCIbZ+0qyze6BAEv1cb0MdGzEogPq8ue9Qjv8FKfHAMKsmIkR3eJ0kgZPg26zkxP1TOKB1a4prNrfRSYFIXk+w==","receipt":"{\"orderId\":\"GPA.3314-9744-6390-89331\",\"packageName\":\"*.**..\",\"productId\":\"*...**\",\"purchaseTime\":1676971165640,\"purchaseState\":0,\"purchaseToken\":\"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow\",\"quantity\":1,\"acknowledged\":false}"}} I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"purchaseConsumed","data":{"purchase":{"orderId":"GPA.3314-9744-6390-89331","packageName":"*.**..","productId":"*...**","purchaseTime":1676971165640,"purchaseState":0,"purchaseToken":"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow","quantity":1,"acknowledged":false,"productIds":["*.**.."],"getPurchaseState":1,"developerPayload":"","autoRenewing":false,"accountId":"","profileId":"","signature":"JZLuFqN0L635ILr+QKQiaNmAV8TSJxOfK70/VBlH0/ql+qN35zFuLhye7WZBSQkCuIr7VZQ14tqFp+aLGFXRDlw7LxTMVORwaGPMqGa0Ds5X/2tjdqbhWT0/g31oyuuTu8rGSnJcu5rwTIASDTXyxs2FIQpgC8qrnzx8DnSDKjFNMQAj6AZQGqmm4warcAIdSCol3MnJoqDeM9EjoAhiS+1q2n+IcXymE9T6Z632iX0YCXwZLON66+rH3iW8+BhWbCIbZ+0qyze6BAEv1cb0MdGzEogPq8ue9Qjv8FKfHAMKsmIkR3eJ0kgZPg26zkxP1TOKB1a4prNrfRSYFIXk+w==","receipt":"{\"orderId\":\"GPA.3314-9744-6390-89331\",\"packageName\":\"*...*\",\"productId\":\"...****\",\"purchaseTime\":1676971165640,\"purchaseState\":0,\"purchaseToken\":\"ipofegnpkbhkkcnkhdgecokj.AO-J1OwxNJPv0Fm83DmNULy9cJQjZDckRsgFQa6V-3ekAHBP_PuQFs9SrzyOTVHMqzO1qYbz3b8bHSpxzOaEB4POVNCoqaYi9MqAfWvoU72a4-7bybMGrow\",\"quantity\":1,\"acknowledged\":false}"}}}", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319) I/chromium: [INFO:CONSOLE(319)] "[CdvPurchase.GooglePlay] DEBUG: onPurchaseConsumed: GPA.3314-9744-6390-89331", source: https://localhost/plugins/cordova-plugin-purchase/www/store.js (319)

HernanZh commented 1 year ago

As far as I could see, the root cause is a simple oversight on the native side: it never calls the Cordova success callback after consuming the purchase and the flow never returns to the JS side.

See https://github.com/j3k0/cordova-plugin-purchase/pull/1372/files#diff-044c5ff72b6419df529943519b45918fcc7a4c4847ede79c7255da0fbd64b84fR1059

j3k0 commented 1 year ago

First I recommend you do this:

store.applicationUsername = function() {
  // Set Username id if member
  if (authService.isUserLogged()) {
    var userid = userdataService.getUserID().toString();
    return 'userid_' + userid;
  };
}

This way, it works even if the user logs in after you initialize the plugin.

I'm on a fix for the report of consumed purchases.

j3k0 commented 1 year ago

Installing the plugin from the git repository should fix the issue. I'll prepare a proper patch release after the week-end

geshub commented 1 year ago
store.applicationUsername = function() {
  // Set Username id if member
  if (authService.isUserLogged()) {
    var userid = userdataService.getUserID().toString();
    return 'userid_' + userid;
  };
}

Thank you @j3k0

geshub commented 1 year ago

Installing the plugin from the git repository should fix the issue. I'll prepare a proper patch release after the week-end

@j3k0 I Did try installing from the git repository but I still can't get to the finished event on Android device, and it also seems to call my store.validator function twice now, causing duplicates (Android only).

I did try to install this pull request https://github.com/j3k0/cordova-plugin-purchase/pull/1372/files and It's calling the finished event normally after a product is consumed, but I don't know if it might be causing other issues.

j3k0 commented 1 year ago

I tested and merged the fix (improved a little bit to ensure receiptUpdated isn't called twice in that case). Available as cordova-plugin-purchase@13.3.5