Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy between SDK Documentation and Micro Example #1596

Closed
selcukbeyhan opened this issue Sep 12, 2024 · 6 comments
Closed

Discrepancy between SDK Documentation and Micro Example #1596

selcukbeyhan opened this issue Sep 12, 2024 · 6 comments

Comments

@selcukbeyhan
Copy link

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:
/**
* Finish a transaction.
*
* When the application has delivered the product, it should finalizes the order.
* Only after that, money will be transferred to your account.
* This method ensures that no customers is charged for a product that couldn't be delivered.
*
* @example
* store.when()
* .approved(transaction => transaction.verify())
* .verified(receipt => receipt.finish())
/
finish(): Promise;
/
*
* Verify a transaction.
*
* This will trigger a call to the receipt validation service for the attached receipt.
* Once the receipt has been verified, you can finish the transaction.
*
* @example
* store.when()
* .approved(transaction => transaction.verify())
* .verified(receipt => receipt.finish())
*/
verify(): Promise;

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

Which one is correct?

Thank you.

@j3k0
Copy link
Owner

j3k0 commented Sep 12, 2024

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.

@j3k0 j3k0 closed this as completed Sep 12, 2024
@selcukbeyhan
Copy link
Author

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

@j3k0
Copy link
Owner

j3k0 commented Sep 12, 2024

In the verified callback,

store.when()
 .approved(transaction => transaction.verify())
 .verified(receipt => receipt.finish())

@selcukbeyhan
Copy link
Author

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
Copy link
Owner

j3k0 commented Sep 12, 2024

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

@selcukbeyhan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants