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

Discrepancy between SDK Documentation and Micro Example #1596

Closed selcukbeyhan closed 1 month ago

selcukbeyhan commented 1 month ago

Hi,

Observed behavior

In the Micro Example, there are these instructions: function onDeviceReady() { const {store, ProductType, Platform} = CdvPurchase; refreshUI(); store.register([{ type: ProductType.CONSUMABLE, id: 'my_product', platform: Platform.TEST, ]}); store.when() .productUpdated(refreshUI) .approved(finishPurchase); store.initialize([Platform.TEST]); }

function finishPurchase(transaction) { localStorage.goldCoins = (localStorage.goldCoins | 0) + 10; transaction.finish(); refreshUI(); }

These indicate to call the transaction.finish() function when the purchase is approved. However, in the SDK documentation, this is written different under the CdvPurchase.Transaction: /**

This indicates that transaction.verify() should be called when purchase is approved and not transaction.finish().

Which one is correct?

Thank you.

j3k0 commented 1 month ago

Generally your integration will include a receipt validation server (iaptic.com or your own). Calling "verify" will wait for confirmation that the receipt is legit (and store that purchase on the server) when confirmed the transaction can be finished. This is however optional and was omitted in the micro example.

selcukbeyhan commented 1 month ago

After the validation at the remote server is done, where should we call the transaction.finish() then or is it not necessary?

j3k0 commented 1 month ago

In the verified callback,

store.when()
 .approved(transaction => transaction.verify())
 .verified(receipt => receipt.finish())
selcukbeyhan commented 1 month ago

Thanks a lot.

Can you please help with the issue #1530 too?

I created this validator for simplicity but the interface contract seems is missing. let validator = (receipt:any, callback:any) => { callback({ ok: true, status: 'valid', data: { quantity: 1, transaction_id: receipt.transaction.id, purchase_date: receipt.transaction.purchaseDate, expiration_date: receipt.transaction.expirationDate, "is_canceled": false, "is_refunded": false, id: receipt.id, latest_receipt: true, transaction: {type: 'ios-appstore', data:null} } }); } CdvPurchase.store.validator = validator;

Thank you.

j3k0 commented 1 month ago

If that's all your validator does, you can skip the "verify" step and call finish right away.

selcukbeyhan commented 4 weeks ago

I had actually developed that validator just to test the validator. It is not the final version.