@hortemo/expo-billing-client
v1.0.0
Published
Expo module that wraps Google Play BillingClient APIs
Maintainers
Readme
@hortemo/expo-billing-client
Thin Android wrapper around the Google Play BillingClient for Expo / React Native apps.
Installation
npm install @hortemo/expo-billing-clientUsage
import BillingClient, {
BillingResponseCode,
ProductType,
} from "@hortemo/expo-billing-client";
BillingClient.addListener(
"purchasesUpdated",
async ({ billingResult, purchases }) => {
if (billingResult.responseCode === BillingResponseCode.OK) {
for (const purchase of purchases) {
if (!purchase.isAcknowledged) {
await BillingClient.acknowledgePurchase(purchase);
}
// Grant entitlements
}
}
}
);
const connectionResult = await BillingClient.startConnection();
if (connectionResult.responseCode !== BillingResponseCode.OK) {
throw new Error(connectionResult.debugMessage);
}
const { productDetailsList } = await BillingClient.queryProductDetails({
products: [
{ productId: "coins_100", productType: ProductType.INAPP },
{ productId: "pro_subscription", productType: ProductType.SUBS },
],
});
const subscription = productDetailsList.find(
(product) => product.productId === "pro_subscription"
);
await BillingClient.launchBillingFlow({
products: [
{
productId: subscription.productId,
productType: ProductType.SUBS,
offerToken: subscription.subscriptionOfferDetails[0].offerToken,
},
],
});