Open pmosedale opened 6 months ago
My code:
import 'cordova-plugin-purchase'; var myProduct; const ANDROID: React.FC = () => { let history = useHistory(); document.body.classList.remove('web-app'); document.body.classList.add('ios-app'); document.addEventListener("deviceready", function(){ const { store, ProductType, Platform } = CdvPurchase; refreshUI(); const iaptic = new CdvPurchase.Iaptic({ appName: "com.app.app", apiKey: "XXX", }); store.register([{ type: ProductType.PAID_SUBSCRIPTION, id: "tpmonthly", platform: Platform.GOOGLE_PLAY, group: "default" }]); store.validator = iaptic.validator; store.when() .productUpdated(refreshUI) .approved(finishPurchase); store.initialize([Platform.GOOGLE_PLAY, ProductType.PAID_SUBSCRIPTION]); console.log(store); }); function finishPurchase(p) { p.finish(); refreshUI(); } function refreshUI() { const {store, ProductType, Platform} = CdvPurchase; const myProduct = store.get("tpmonthly", Platform.GOOGLE_PLAY, ProductType.PAID_SUBSCRIPTION); const myReceipt = store.findInLocalReceipts(myProduct); document.getElementsByTagName('body')[0].innerHTML = ` <div> <pre> Product.title: ${myProduct ? myProduct.title : ''}.descr: ${myProduct ? myProduct.description : ''}.price: ${myProduct ? myProduct.pricing.price : ''} </pre> </div>`; } function orderProduct() { const { store, ProductType, Platform } = CdvPurchase; const myProduct = store.get("tpmonthly", Platform.GOOGLE_PLAY, ProductType.PAID_SUBSCRIPTION); const myReceipt = store.findInLocalReceipts(myProduct); myReceipt.getOffer().order(); } return ( refreshUI(), orderProduct() ) }; export default ANDROID;
In Android, product is successfully retrieved: 2023-11-02 13:17:36.292 26855-27061 CdvPurchase com.app.app D getAvailableProducts() -> productDetails: ProductDetails{jsonString='{"productId":"tpmonthly","type":"subs","title":"Monthly Subscription","name":"Monthly Subscription","localizedIn":["en-AU"],"skuDetailsToken":"AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M","subscriptionOfferDetails":[{"offerIdToken":"AUj\/Yhh0wth1ytB5k5KgPugFHx3A6OYFj3ZeR2NZRq4s2HpfYWVdJab\/HivcyjHPHveMea\/KunkZyPWi8G6aRsdg7saDloB9AAh9pwHB7Cht\/d6INlpV","basePlanId":"tpmonthly","pricingPhases":[{"priceAmountMicros":6990000,"priceCurrencyCode":"AUD","formattedPrice":"$6.99","billingPeriod":"P1M","recurrenceMode":1}],"offerTags":[]}]}', parsedJson={"productId":"tpmonthly","type":"subs","title":"Monthly Subscription (Adventure Curated)","name":"Monthly Subscription","localizedIn":["en-AU"],"skuDetailsToken":"AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M","subscriptionOfferDetails":[{"offerIdToken":"AUj\/Yhh0wth1ytB5k5KgPugFHx3A6OYFj3ZeR2NZRq4s2HpfYWVdJab\/HivcyjHPHveMea\/KunkZyPWi8G6aRsdg7saDloB9AAh9pwHB7Cht\/d6INlpV","basePlanId":"tpmonthly","pricingPhases":[{"priceAmountMicros":6990000,"priceCurrencyCode":"AUD","formattedPrice":"$6.99","billingPeriod":"P1M","recurrenceMode":1}],"offerTags":[]}]}, productId='tpmonthly', productType='subs', title='Monthly Subscription (Adventure Curated)', productDetailsToken='AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M', subscriptionOfferDetails=[com.android.billingclient.api.ProductDetails$SubscriptionOfferDetails@d8a651]}
But upon calling orderProduct - Msg: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getOffer')
My code:
In Android, product is successfully retrieved: 2023-11-02 13:17:36.292 26855-27061 CdvPurchase com.app.app D getAvailableProducts() -> productDetails: ProductDetails{jsonString='{"productId":"tpmonthly","type":"subs","title":"Monthly Subscription","name":"Monthly Subscription","localizedIn":["en-AU"],"skuDetailsToken":"AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M","subscriptionOfferDetails":[{"offerIdToken":"AUj\/Yhh0wth1ytB5k5KgPugFHx3A6OYFj3ZeR2NZRq4s2HpfYWVdJab\/HivcyjHPHveMea\/KunkZyPWi8G6aRsdg7saDloB9AAh9pwHB7Cht\/d6INlpV","basePlanId":"tpmonthly","pricingPhases":[{"priceAmountMicros":6990000,"priceCurrencyCode":"AUD","formattedPrice":"$6.99","billingPeriod":"P1M","recurrenceMode":1}],"offerTags":[]}]}', parsedJson={"productId":"tpmonthly","type":"subs","title":"Monthly Subscription (Adventure Curated)","name":"Monthly Subscription","localizedIn":["en-AU"],"skuDetailsToken":"AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M","subscriptionOfferDetails":[{"offerIdToken":"AUj\/Yhh0wth1ytB5k5KgPugFHx3A6OYFj3ZeR2NZRq4s2HpfYWVdJab\/HivcyjHPHveMea\/KunkZyPWi8G6aRsdg7saDloB9AAh9pwHB7Cht\/d6INlpV","basePlanId":"tpmonthly","pricingPhases":[{"priceAmountMicros":6990000,"priceCurrencyCode":"AUD","formattedPrice":"$6.99","billingPeriod":"P1M","recurrenceMode":1}],"offerTags":[]}]}, productId='tpmonthly', productType='subs', title='Monthly Subscription (Adventure Curated)', productDetailsToken='AEuhp4KKoglE6YsiOk6U2aD8dZ83WcYiuakqKGHT2zwMOHJcvTan78L4WRdoHD59W80M', subscriptionOfferDetails=[com.android.billingclient.api.ProductDetails$SubscriptionOfferDetails@d8a651]}
But upon calling orderProduct - Msg: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getOffer')