payments
payments copied to clipboard
feat(payments): StoreKit v2 + Google Billing v8
Reworks the legacy payment setup to be simpler to use while also using all latest SDKs.
Example Usage
import { Payment, Product } from '@nativescript/payments'
const payment = new Payment();
payment.onPurchaseUpdate = (purchases, error) => {
if (error) {
console.error(`🛑 Purchase Update Error: ${error} 🛑`);
} else {
console.log(`🟢 Purchase Update: ${purchases.length} items 🟢`);
purchases.forEach((transaction) => {
switch (transaction.state) {
case 'pending':
transaction.finish();
break;
case 'purchased':
console.log(`🟢 Purchase Update: ${JSON.stringify(transaction.receiptToken)} 🟢`);
break;
}
});
}
};
payment.onReady = async () => {
try {
console.log('🟢 Payment System Ready 🟢');
const purchases = await payment.fetchPurchases();
console.log(`🟢 Fetched previous ${purchases.length} In App Purchase Items 🟢`);
const products = await payment.fetchProducts(['io.nstudio.iapdemo.coinsfive', 'io.nstudio.iapdemo.coinsone', 'io.nstudio.iapdemo.coinsonethousand'], 'inapp');
console.log("here's the products!", products)
} catch (error) {
console.error(`🛑 Error: ${error} 🛑`);
}
};
function buyItem(item: Product) {
payment.purchaseProduct(item);
}
These changes modernize the payments plugin, simplify its usage, and remove a significant amount of legacy and abstraction code in favor of a more direct and maintainable API.
I have some pending changes for billing 8 because it includes API changes. Let's chat about it this week.
Also I don't understand why move all the logic to native, as it's pretty straightforward in JS