Skip to content

Use your own store code

Documents @snap4id-sdk/app-embed 1.0.0

The built-in store (purchases: 'built-in') runs expo-iap for you. If your app already has store code, pass an object instead and the component calls it:

createSnap4IdClient({
partnerId: 'your-partner-id',
purchases: {
onPurchaseRequest, // buy, bound to the page's paymentRef
onConfirmPurchase, // finish the purchase, after the unlock only
getUnfinishedPurchases, // recovery after a kill
getPendingPurchases, // "Ask to Buy" / Play PENDING waiting for approval
getPrice, // the store price of the product the page names
},
onCompleted,
});

The page shows the store price of your product on its order button. It names the product (the id you gave Snap4ID for this store) and the component asks your getPrice(productId): resolve { display_price, amount_minor, currency } from your store, or null when it has no price (the page then shows none; onError gets the non-fatal price_unavailable). Without getPrice the page shows no price.

async getPrice(productId) {
const [product] = await fetchProducts({ skus: [productId], type: 'in-app' });
if (!product) return null;
return { display_price: product.displayPrice, amount_minor: toMinorUnits(product.price, product.currency), currency: product.currency };
},

onPurchaseRequest({ jobId, productId, paymentRef, storeBinding })

Section titled “onPurchaseRequest({ jobId, productId, paymentRef, storeBinding })”

Buy productId with storeBinding.appAccountToken (App Store) or storeBinding.obfuscatedProfileId (Google Play). Answer:

Answer When
{ status: 'succeeded', transactionId, receipt, price? } bought; receipt is { kind: 'app-store', jws } or { kind: 'play', originalJson, signature }; price = the store price ({ amount_minor, currency }) if you know it
{ status: 'pending', transactionId } waiting for approval
{ status: 'cancelled' } the user cancelled
{ status: 'failed', reason } the store failed

A throw counts as failed and is reported to onError as purchase_callback_failed.

onConfirmPurchase(receipt, { jobId, paymentRef, transactionId })

Section titled “onConfirmPurchase(receipt, { jobId, paymentRef, transactionId })”

Finish (acknowledge / consume) the purchase here and nowhere else. It is called only after Snap4ID unlocked the job, and again after every start until it resolves: make it idempotent.

  • getUnfinishedPurchases() lists purchases your store still holds unfinished. Without it, a purchase made right before a kill cannot be recovered.
  • getPendingPurchases() lists purchases awaiting approval. Without it, an attempt killed while the store sheet was open is kept pending for up to 24 h (it may still be approved; buying again could charge twice).
  • client.purchaseUpdated(purchase) reports a purchase that resolved later (an approved “Ask to Buy”); it follows the normal unlock path.

Confirm-after-unlock needs the transaction to stay unfinished until onConfirmPurchase. Libraries that finish transactions on their own (RevenueCat by default) break that: run RevenueCat in observer mode, or use the built-in store. A working expo-iap implementation is in the SDK repository: examples/partner-app/src/app-purchases.ts.