@burdenoff/microfe-billing 2026.625.3 → 2026.625.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function t() {
|
|
4
|
-
return e.isNativePlatform();
|
|
5
|
-
}
|
|
6
|
-
async function n() {
|
|
7
|
-
if (!e.isNativePlatform()) return null;
|
|
8
|
-
try {
|
|
9
|
-
let e = await import(
|
|
10
|
-
/* @vite-ignore */
|
|
11
|
-
"@capgo/native-purchases"
|
|
12
|
-
);
|
|
13
|
-
return e.NativePurchases ?? e.default ?? null;
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function r(e, t) {
|
|
19
|
-
let r = await n();
|
|
20
|
-
return !r || e.length === 0 ? [] : (await r.getProducts({
|
|
21
|
-
productIdentifiers: e,
|
|
22
|
-
productType: t
|
|
23
|
-
})).products ?? [];
|
|
24
|
-
}
|
|
25
|
-
async function i(e, t) {
|
|
26
|
-
let r = await n();
|
|
27
|
-
if (!r) throw Error("Native purchases not available on this platform");
|
|
28
|
-
return r.purchaseProduct({
|
|
29
|
-
productIdentifier: e,
|
|
30
|
-
...t
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
async function a(e) {
|
|
34
|
-
let t = await n();
|
|
35
|
-
t && await t.acknowledgePurchase({ purchaseToken: e });
|
|
36
|
-
}
|
|
37
|
-
async function o() {
|
|
38
|
-
let e = await n();
|
|
39
|
-
e && await e.restorePurchases();
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { a as acknowledgeNativePurchase, r as getNativeProducts, t as isNativeIAPAvailable, i as purchaseNativeProduct, o as restoreNativePurchases };
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=native-purchases.js.map
|
|
1
|
+
import { acknowledgeNativePurchase as e, getNativeProducts as t, isNativeIAPAvailable as n, purchaseNativeProduct as r, restoreNativePurchases as i } from "@burdenoff/fe-libs/shared/native/purchases";
|
|
2
|
+
export { e as acknowledgeNativePurchase, t as getNativeProducts, n as isNativeIAPAvailable, r as purchaseNativeProduct, i as restoreNativePurchases };
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native-purchases.js","names":[],"sources":["../../../src/billing/lib/native-purchases.ts"],"sourcesContent":["/**\n * Native in-app purchase bridge for Apple StoreKit and Google Play Billing.\n *\n * Uses @capgo/native-purchases (direct StoreKit 2 / Play Billing Library integration)\n * when running inside a Capacitor native app. Falls back to null on web so callers\n * can route to the normal Stripe/Razorpay checkout instead.\n *\n * After a successful purchase the frontend sends the receipt / JWS / purchase token\n * to the backend via POST /rest/billing/iap/validate, which validates with Apple/Google\n * servers and activates the subscription or credits — no RevenueCat account required.\n */\n\nimport { Capacitor } from '@capacitor/core';\nimport type { PURCHASE_TYPE, Product, Transaction } from '@capgo/native-purchases';\n\n// Re-export plugin types with billing-domain-friendly aliases\nexport type { Product as NativeProduct, Transaction as NativeTransaction };\nexport type { PURCHASE_TYPE as NativePurchaseType };\n\n// ─── Platform check ───────────────────────────────────────────────────────────\n\n/** True when running inside a Capacitor iOS or Android app. */\nexport function isNativeIAPAvailable(): boolean {\n return Capacitor.isNativePlatform();\n}\n\n// ─── Plugin loader ────────────────────────────────────────────────────────────\n\n// Dynamically imported so the web bundle doesn't fail when the native plugin\n// is absent.\nasync function getPlugin() {\n if (!Capacitor.isNativePlatform()) return null;\n try {\n const mod = await import(/* @vite-ignore */ '@capgo/native-purchases');\n return mod.NativePurchases ?? mod.default ?? null;\n } catch {\n return null;\n }\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\n/**\n * Fetch product info from the App Store / Play Store for the given identifiers.\n * Returns an empty array on web or if the store lookup fails.\n */\nexport async function getNativeProducts(\n productIdentifiers: string[],\n productType?: PURCHASE_TYPE\n): Promise<Product[]> {\n const plugin = await getPlugin();\n if (!plugin || productIdentifiers.length === 0) return [];\n const result = await plugin.getProducts({ productIdentifiers, productType });\n return result.products ?? [];\n}\n\n/**\n * Initiate a native purchase for the given product identifier.\n *\n * The returned Transaction contains the receipt (iOS legacy), jwsRepresentation\n * (iOS StoreKit 2), or purchaseToken (Android) — send these to the backend for\n * server-side validation before granting entitlements.\n *\n * Throws if the user cancels or the purchase fails.\n */\nexport async function purchaseNativeProduct(\n productIdentifier: string,\n options?: {\n planIdentifier?: string;\n productType?: PURCHASE_TYPE;\n quantity?: number;\n appAccountToken?: string;\n isConsumable?: boolean;\n /** Set false to defer acknowledgment until backend validation completes. */\n autoAcknowledgePurchases?: boolean;\n }\n): Promise<Transaction> {\n const plugin = await getPlugin();\n if (!plugin) throw new Error('Native purchases not available on this platform');\n return plugin.purchaseProduct({ productIdentifier, ...options });\n}\n\n/**\n * Manually acknowledge/finish a transaction after server-side validation.\n * Only needed when purchaseNativeProduct was called with autoAcknowledgePurchases: false.\n *\n * @param purchaseToken - purchaseToken (Android) or transactionId (iOS)\n */\nexport async function acknowledgeNativePurchase(purchaseToken: string): Promise<void> {\n const plugin = await getPlugin();\n if (!plugin) return;\n await plugin.acknowledgePurchase({ purchaseToken });\n}\n\n/**\n * Restore previously completed purchases.\n * Required by App Store guidelines to be accessible in the UI.\n */\nexport async function restoreNativePurchases(): Promise<void> {\n const plugin = await getPlugin();\n if (!plugin) return;\n await plugin.restorePurchases();\n}\n\n/**\n * Return all purchases recorded for the current user on this device.\n * Useful for checking active entitlements without a backend call.\n */\nexport async function getNativePurchases(options?: {\n productType?: PURCHASE_TYPE;\n appAccountToken?: string;\n onlyCurrentEntitlements?: boolean;\n}): Promise<Transaction[]> {\n const plugin = await getPlugin();\n if (!plugin) return [];\n const result = await plugin.getPurchases(options);\n return result.purchases ?? [];\n}\n"],"mappings":";;AAsBA,SAAgB,IAAgC;AAC9C,QAAO,EAAU,kBAAkB;;AAOrC,eAAe,IAAY;AACzB,KAAI,CAAC,EAAU,kBAAkB,CAAE,QAAO;AAC1C,KAAI;EACF,IAAM,IAAM,MAAM;;GAA0B;;AAC5C,SAAO,EAAI,mBAAmB,EAAI,WAAW;SACvC;AACN,SAAO;;;AAUX,eAAsB,EACpB,GACA,GACoB;CACpB,IAAM,IAAS,MAAM,GAAW;AAGhC,QAFI,CAAC,KAAU,EAAmB,WAAW,IAAU,EAAE,IAC1C,MAAM,EAAO,YAAY;EAAE;EAAoB;EAAa,CAAC,EAC9D,YAAY,EAAE;;AAY9B,eAAsB,EACpB,GACA,GASsB;CACtB,IAAM,IAAS,MAAM,GAAW;AAChC,KAAI,CAAC,EAAQ,OAAU,MAAM,kDAAkD;AAC/E,QAAO,EAAO,gBAAgB;EAAE;EAAmB,GAAG;EAAS,CAAC;;AASlE,eAAsB,EAA0B,GAAsC;CACpF,IAAM,IAAS,MAAM,GAAW;AAC3B,MACL,MAAM,EAAO,oBAAoB,EAAE,kBAAe,CAAC;;AAOrD,eAAsB,IAAwC;CAC5D,IAAM,IAAS,MAAM,GAAW;AAC3B,MACL,MAAM,EAAO,kBAAkB"}
|