expo-iap 2.0.0-rc.1 → 2.0.0
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.
- package/.prettierrc.js +1 -1
- package/README.md +2 -9
- package/app.plugin.js +1 -0
- package/build/ExpoIap.types.js +1 -1
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js.map +1 -1
- package/package.json +11 -4
- package/plugin/build/withIAP.d.ts +9 -0
- package/plugin/build/withIAP.js +83 -0
- package/plugin/jest.config.js +5 -0
- package/plugin/src/withIAP.ts +136 -0
- package/plugin/tsconfig.json +9 -0
- package/src/ExpoIap.types.ts +1 -1
- package/src/index.ts +6 -3
- package/src/modules/android.ts +8 -2
package/.prettierrc.js
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="https://github.com/user-attachments/assets/f51a4b1b-b257-47bf-afe7-5ef8692f0594" height="200"/>
|
|
2
2
|
|
|
3
3
|
In App Purchase module in Expo
|
|
4
4
|
|
|
@@ -23,17 +23,10 @@ npm install expo-iap
|
|
|
23
23
|
|
|
24
24
|
### Configure for iOS
|
|
25
25
|
|
|
26
|
-
Run `npx pod-install` after installing the npm package.
|
|
27
|
-
Sine we only support `StoreKit`, `deploymentTarget` should be `15.0`.
|
|
26
|
+
Run `npx pod-install` after installing the npm package. Sine we only support `StoreKit`, `deploymentTarget` should be `15.0`.
|
|
28
27
|
|
|
29
28
|
```json
|
|
30
29
|
"ios": {
|
|
31
30
|
"deploymentTarget": "15.0"
|
|
32
31
|
},
|
|
33
32
|
```
|
|
34
|
-
|
|
35
|
-
### Configure for Android
|
|
36
|
-
|
|
37
|
-
# Contributing
|
|
38
|
-
|
|
39
|
-
Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing).
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build/withIAP');
|
package/build/ExpoIap.types.js
CHANGED
|
@@ -48,7 +48,7 @@ export class PurchaseError {
|
|
|
48
48
|
this.debugMessage = debugMessage;
|
|
49
49
|
this.code = code;
|
|
50
50
|
this.productId = productId;
|
|
51
|
-
this.name = '[
|
|
51
|
+
this.name = '[expo-iap]: PurchaseError';
|
|
52
52
|
this.message = message;
|
|
53
53
|
this.responseCode = responseCode;
|
|
54
54
|
this.debugMessage = debugMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAUD,IAAK,oBAIJ;AAJD,WAAK,oBAAoB;IACvB,yFAAqB,CAAA;IACrB,yEAAa,CAAA;IACb,qEAAW,CAAA;AACb,CAAC,EAJI,oBAAoB,KAApB,oBAAoB,QAIxB;AA+BD,IAAK,iBAGJ;AAHD,WAAK,iBAAiB;IACpB,0CAAqB,CAAA;IACrB,wCAAmB,CAAA;AACrB,CAAC,EAHI,iBAAiB,KAAjB,iBAAiB,QAGrB;AAoBD,MAAM,CAAN,IAAY,SAkBX;AAlBD,WAAY,SAAS;IACnB,oCAAuB,CAAA;IACvB,kDAAqC,CAAA;IACrC,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;IACzC,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,gDAAmC,CAAA;IACnC,kDAAqC,CAAA;IACrC,oEAAuD,CAAA;IACvD,8CAAiC,CAAA;IACjC,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC,oDAAuC,CAAA;IACvC,wFAA2E,CAAA;IAC3E,sDAAyC,CAAA;IACz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AA;IACnC,oDAAuC,CAAA;IACvC,wFAA2E,CAAA;IAC3E,sDAAyC,CAAA;IACzC,4CAA+B,CAAA;IAC/B,wDAA2C,CAAA;AAC7C,CAAC,EAlBW,SAAS,KAAT,SAAS,QAkBpB;AAED,MAAM,OAAO,aAAa;IAEf;IACA;IACA;IACA;IACA;IACA;IANT,YACS,IAAY,EACZ,OAAe,EACf,YAAqB,EACrB,YAAqB,EACrB,IAAgB,EAChB,SAAkB;QALlB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAS;QACrB,iBAAY,GAAZ,YAAY,CAAS;QACrB,SAAI,GAAJ,IAAI,CAAY;QAChB,cAAS,GAAT,SAAS,CAAS;QAEzB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {\n ProductAndroid,\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n SubscriptionProductAndroid,\n} from './types/ExpoIapAndroid.types';\nimport {\n ProductIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n} from './types/ExpoIapIos.types';\nexport type ChangeEventPayload = {\n value: string;\n};\n\nexport type Product = ProductAndroid | ProductIos;\nexport enum ProductType {\n InAppPurchase = 'inapp',\n Subscription = 'subs',\n}\n\nexport type SubscriptionProduct =\n | SubscriptionProductAndroid\n | SubscriptionProductIos;\n\nexport type RequestPurchaseProps =\n | RequestPurchaseIosProps\n | RequestPurchaseAndroidProps;\n\nenum PurchaseStateAndroid {\n UNSPECIFIED_STATE = 0,\n PURCHASED = 1,\n PENDING = 2,\n}\n\nexport type ProductPurchase = {\n productId: string;\n transactionId?: string;\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string;\n //iOS\n quantityIOS?: number;\n originalTransactionDateIOS?: number;\n originalTransactionIdentifierIOS?: string;\n verificationResultIOS?: string;\n appAccountToken?: string;\n //Android\n productIds?: string[];\n dataAndroid?: string;\n signatureAndroid?: string;\n autoRenewingAndroid?: boolean;\n purchaseStateAndroid?: PurchaseStateAndroid;\n isAcknowledgedAndroid?: boolean;\n packageNameAndroid?: string;\n developerPayloadAndroid?: string;\n obfuscatedAccountIdAndroid?: string;\n obfuscatedProfileIdAndroid?: string;\n};\n\nexport type RequestSubscriptionProps =\n | RequestSubscriptionAndroidProps\n | RequestSubscriptionIosProps;\n\nenum TransactionReason {\n PURCHASE = 'PURCHASE',\n RENEWAL = 'RENEWAL',\n}\n\nexport type SubscriptionPurchase = {\n autoRenewingAndroid?: boolean;\n originalTransactionDateIOS?: number;\n originalTransactionIdentifierIOS?: string;\n verificationResultIOS?: string;\n transactionReasonIOS?: TransactionReason | string;\n} & ProductPurchase;\n\nexport type Purchase = ProductPurchase | SubscriptionPurchase;\n\nexport type PurchaseResult = {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseToken?: string;\n};\n\nexport enum ErrorCode {\n E_UNKNOWN = 'E_UNKNOWN',\n E_USER_CANCELLED = 'E_USER_CANCELLED',\n E_USER_ERROR = 'E_USER_ERROR',\n E_ITEM_UNAVAILABLE = 'E_ITEM_UNAVAILABLE',\n E_REMOTE_ERROR = 'E_REMOTE_ERROR',\n E_NETWORK_ERROR = 'E_NETWORK_ERROR',\n E_SERVICE_ERROR = 'E_SERVICE_ERROR',\n E_RECEIPT_FAILED = 'E_RECEIPT_FAILED',\n E_RECEIPT_FINISHED_FAILED = 'E_RECEIPT_FINISHED_FAILED',\n E_NOT_PREPARED = 'E_NOT_PREPARED',\n E_NOT_ENDED = 'E_NOT_ENDED',\n E_ALREADY_OWNED = 'E_ALREADY_OWNED',\n E_DEVELOPER_ERROR = 'E_DEVELOPER_ERROR',\n E_BILLING_RESPONSE_JSON_PARSE_ERROR = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n E_DEFERRED_PAYMENT = 'E_DEFERRED_PAYMENT',\n E_INTERRUPTED = 'E_INTERRUPTED',\n E_IAP_NOT_AVAILABLE = 'E_IAP_NOT_AVAILABLE',\n}\n\nexport class PurchaseError implements Error {\n constructor(\n public name: string,\n public message: string,\n public responseCode?: number,\n public debugMessage?: string,\n public code?: ErrorCode,\n public productId?: string,\n ) {\n this.name = '[expo-iap]: PurchaseError';\n this.message = message;\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n }\n}\n"]}
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EACL,OAAO,EACP,eAAe,EAEf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EACL,OAAO,EACP,eAAe,EAEf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,2BAA2B,EAE5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,uBAAuB,EAIxB,MAAM,0BAA0B,CAAC;AAGlC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAG9B,e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I,GAAG,IAAI,CA2DjE,CAAC;AAEN,eAAO,MAAM,iBAAiB,yDAI3B;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,KAAG,QAAQ,cAAc,GAAG,OAAO,CAiCnC,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -126,7 +126,7 @@ export const requestPurchase = (request) => (Platform.select({
|
|
|
126
126
|
}
|
|
127
127
|
const { sku, andDangerouslyFinishTransactionAutomaticallyIOS = false, appAccountToken, quantity, withOffer, } = request;
|
|
128
128
|
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
129
|
-
console.warn('You are dangerously allowing
|
|
129
|
+
console.warn('You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
130
130
|
}
|
|
131
131
|
const offer = offerToRecordIos(withOffer);
|
|
132
132
|
const result = await ExpoIapModule.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer);
|
|
@@ -157,7 +157,7 @@ export const requestSubscription = (request) => (Platform.select({
|
|
|
157
157
|
}
|
|
158
158
|
const { sku, andDangerouslyFinishTransactionAutomaticallyIOS = false, appAccountToken, quantity, withOffer, } = request;
|
|
159
159
|
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
160
|
-
console.warn('You are dangerously allowing
|
|
160
|
+
console.warn('You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
161
161
|
}
|
|
162
162
|
const offer = offerToRecordIos(withOffer);
|
|
163
163
|
const purchase = iosTransactionToPurchaseMap(await ExpoIapModule.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer));
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAGL,WAAW,GAOZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAU5C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAE3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAE9B,iCAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;AAEnC,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,gDAAoC,CAAA;IACpC,4CAAgC,CAAA;IAChC,6DAAiD,CAAA;AACnD,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAa;IAC/C,OAAO,MAAM,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,YAAY,CACrC,aAAa,IAAI,kBAAkB,CAAC,OAAO,CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,QAAmC,EACnC,EAAE;IACF,MAAM,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAC7C,QAAQ,CAAC,eAAe,EACxB,QAAQ,CACT,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAAwC,EACxC,EAAE;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AI,CAAC,CAAC,CACpC,EAAE,CAAC;AAEN,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,QAAQ,EACR,YAAY,EACZ,uBAAuB,GAKxB,EAAqC,EAAE;IACtC,OAAO,CACL,QAAQ,CAAC,MAAM,CAAC;QACd,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC;YAE7C,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAC9D,CAAC;YACJ,CAAC;YACD,MAAM,aAAa,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,QAAQ,EAAE,aAAa,EAAE,CAAC;gBAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;gBACJ,CAAC;gBAED,OAAO,aAAa,CAAC,cAAc,CACjC,QAAQ,CAAC,aAAa,EACtB,uBAAuB,CACxB,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;QACJ,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy, EventEmitter} from 'expo-modules-core';\nimport {Platform} from 'react-native';\n\nimport {\n Product,\n ProductPurchase,\n ProductType,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {RequestPurchaseAndroidProps, RequestSubscriptionAndroidProps} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n ProductIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n TransactionSk2,\n} from './types/ExpoIapIos.types';\nimport {isProductIos} from './modules/ios';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value.\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport async function setValueAsync(value: string) {\n return await ExpoIapModule.setValueAsync(value);\n}\n\nexport const emitter = new EventEmitter(\n ExpoIapModule ?? NativeModulesProxy.ExpoIap,\n);\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener<PurchaseError>(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const items = (await ExpoIapModule.getItems(skus)) as ProductIos[];\n return items.filter((item: ProductIos) => isProductIos(item));\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType(\n ProductType.InAppPurchase,\n skus,\n );\n\n return products;\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async (): Promise<SubscriptionProductIos[]> => {\n const items: SubscriptionProductIos[] = (\n (await ExpoIapModule.getItems(skus)) as SubscriptionProductIos[]\n ).filter((item: SubscriptionProductIos) => skus.includes(item.id));\n\n return items;\n },\n android: async () => {\n return ExpoIapModule.getItemsByType('subs', skus);\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = true,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getAvailableItemsByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\nconst iosTransactionToPurchaseMap = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n originalID,\n verificationResult,\n appAccountToken,\n jsonRepresentation,\n}: TransactionSk2): Purchase => {\n let transactionReasonIOS;\n\n try {\n if (jsonRepresentation) {\n const transactionData = JSON.parse(jsonRepresentation);\n transactionReasonIOS = transactionData.transactionReason;\n }\n } catch (e) {\n console.log('SK2 Error parsing jsonRepresentation', e);\n }\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not available\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: originalPurchaseDate,\n originalTransactionIdentifierIOS: originalID,\n verificationResultIOS: verificationResult ?? '',\n appAccountToken: appAccountToken ?? '',\n transactionReasonIOS: transactionReasonIOS ?? '',\n };\n return purchase;\n};\n\nexport const requestPurchase = (\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps,\n): Promise<ProductPurchase | ProductPurchase[] | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS purchase');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const result = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n const purchase = iosTransactionToPurchaseMap(result);\n return Promise.resolve(purchase);\n },\n android: async () => {\n if (!('skus' in request) || !request.skus.length) {\n throw new Error('skus is required for Android purchase');\n }\n\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.InAppPurchase,\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || Promise.resolve\n )();\n\nexport const requestSubscription = (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS subscriptions');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request as RequestSubscriptionIosProps;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const purchase = iosTransactionToPurchaseMap(\n await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n ),\n );\n return Promise.resolve(purchase);\n },\n android: async () => {\n console.log('requestSubscription', request);\n const {\n skus,\n isOfferPersonalized,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n subscriptionOffers,\n replacementModeAndroid,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.Subscription,\n skuArr: skus.map((so) => so),\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || (() => Promise.resolve(null))\n )();\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n if (purchase?.purchaseToken) {\n if (!isConsumable) {\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n }\n\n return ExpoIapModule.consumeProduct(\n purchase.purchaseToken,\n developerPayloadAndroid,\n );\n }\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAGL,WAAW,GAOZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAa5C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe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OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,QAAQ,EAAE,aAAa,EAAE,CAAC;gBAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;gBACJ,CAAC;gBAED,OAAO,aAAa,CAAC,cAAc,CACjC,QAAQ,CAAC,aAAa,EACtB,uBAAuB,CACxB,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,0CAA0C,CAAC,CACtD,CAAC;QACJ,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy, EventEmitter} from 'expo-modules-core';\nimport {Platform} from 'react-native';\n\nimport {\n Product,\n ProductPurchase,\n ProductType,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n ProductIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n TransactionSk2,\n} from './types/ExpoIapIos.types';\nimport {isProductIos} from './modules/ios';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value.\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport async function setValueAsync(value: string) {\n return await ExpoIapModule.setValueAsync(value);\n}\n\nexport const emitter = new EventEmitter(\n ExpoIapModule ?? NativeModulesProxy.ExpoIap,\n);\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener<PurchaseError>(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const items = (await ExpoIapModule.getItems(skus)) as ProductIos[];\n return items.filter((item: ProductIos) => isProductIos(item));\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType(\n ProductType.InAppPurchase,\n skus,\n );\n\n return products;\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async (): Promise<SubscriptionProductIos[]> => {\n const items: SubscriptionProductIos[] = (\n (await ExpoIapModule.getItems(skus)) as SubscriptionProductIos[]\n ).filter((item: SubscriptionProductIos) => skus.includes(item.id));\n\n return items;\n },\n android: async () => {\n return ExpoIapModule.getItemsByType('subs', skus);\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = true,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n automaticallyFinishRestoredTransactions = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n automaticallyFinishRestoredTransactions?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType(\n ProductType.InAppPurchase,\n );\n\n const subscriptions = await ExpoIapModule.getAvailableItemsByType(\n ProductType.Subscription,\n );\n\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\nconst iosTransactionToPurchaseMap = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n originalID,\n verificationResult,\n appAccountToken,\n jsonRepresentation,\n}: TransactionSk2): Purchase => {\n let transactionReasonIOS;\n\n try {\n if (jsonRepresentation) {\n const transactionData = JSON.parse(jsonRepresentation);\n transactionReasonIOS = transactionData.transactionReason;\n }\n } catch (e) {\n console.log('SK2 Error parsing jsonRepresentation', e);\n }\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not available\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: originalPurchaseDate,\n originalTransactionIdentifierIOS: originalID,\n verificationResultIOS: verificationResult ?? '',\n appAccountToken: appAccountToken ?? '',\n transactionReasonIOS: transactionReasonIOS ?? '',\n };\n return purchase;\n};\n\nexport const requestPurchase = (\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps,\n): Promise<ProductPurchase | ProductPurchase[] | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS purchase');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const result = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n const purchase = iosTransactionToPurchaseMap(result);\n return Promise.resolve(purchase);\n },\n android: async () => {\n if (!('skus' in request) || !request.skus.length) {\n throw new Error('skus is required for Android purchase');\n }\n\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.InAppPurchase,\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || Promise.resolve\n )();\n\nexport const requestSubscription = (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS subscriptions');\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request as RequestSubscriptionIosProps;\n\n if (andDangerouslyFinishTransactionAutomaticallyIOS) {\n console.warn(\n 'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',\n );\n }\n\n const offer = offerToRecordIos(withOffer);\n\n const purchase = iosTransactionToPurchaseMap(\n await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n ),\n );\n return Promise.resolve(purchase);\n },\n android: async () => {\n console.log('requestSubscription', request);\n const {\n skus,\n isOfferPersonalized,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n subscriptionOffers,\n replacementModeAndroid,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return ExpoIapModule.buyItemByType({\n type: ProductType.Subscription,\n skuArr: skus.map((so) => so),\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || (() => Promise.resolve(null))\n )();\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n if (purchase?.purchaseToken) {\n if (!isConsumable) {\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n }\n\n return ExpoIapModule.consumeProduct(\n purchase.purchaseToken,\n developerPayloadAndroid,\n );\n }\n return Promise.reject(\n new Error('purchase is not suitable to be purchased'),\n );\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAC9E,OAAO,
|
|
1
|
+
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,cAAc,EACd,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAGvC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,cAAc,CAE5E;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mBAAmB,GAC3B,OAAO,IAAI,0BAA0B,CAEvC;AAED;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,aAExC;IACD,GAAG,EAAE,MAAM,CAAC;CACb,KAAG,QAAQ,IAAI,CAIf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,kEAMhC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,KAAG,QAAQ,cAAc,CAsBzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,iCAGpC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,QAAQ,cAAc,GAAG,OAAO,GAAG,IAAI,CAE1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAOrC,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAQ,OAA0B,EAAE,KAAK,KAAK,SAAS,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,OAA4B;IAE5B,OAAQ,OAAsC,EAAE,KAAK,KAAK,SAAS,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EAAE,EACnD,GAAG,GAGJ,EAAiB,EAAE;IAClB,OAAO,OAAO,CAAC,OAAO,CACpB,+DAA+D,MAAM,aAAa,CAAC,cAAc,EAAE,QAAQ,GAAG,EAAE,CACjH,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,KAAK,GAON,EAA2B,EAAE;IAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC;IAElD,MAAM,GAAG,GACP,0EAA0E;QAC1E,IAAI,WAAW,cAAc,IAAI,IAAI,SAAS,EAAE;QAChD,WAAW,YAAY,iBAAiB,WAAW,EAAE,CAAC;IAExD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YAClD,UAAU,EAAE,QAAQ,CAAC,MAAM;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,EACzC,KAAK,EACL,gBAAgB,GAIjB,EAA4C,EAAE;IAC7C,OAAO,aAAa,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;AACpE,CAAC,CAAC","sourcesContent":["import {Linking} from 'react-native';\nimport {Product, PurchaseResult, SubscriptionProduct} from '../ExpoIap.types';\nimport {\n ProductAndroid,\n ReceiptAndroid,\n SubscriptionProductAndroid,\n} from '../types/ExpoIapAndroid.types';\nimport ExpoIapModule from '../ExpoIapModule';\n\nexport function isProductAndroid(product: Product): product is ProductAndroid {\n return (product as ProductAndroid)?.title !== undefined;\n}\n\nexport function isSubscriptionProductAndroid(\n product: SubscriptionProduct,\n): product is SubscriptionProductAndroid {\n return (product as SubscriptionProductAndroid)?.title !== undefined;\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {string} sku The product's SKU (on Android)\n * @returns {Promise<void>}\n */\nexport const deepLinkToSubscriptionsAndroid = async ({\n sku,\n}: {\n sku: string;\n}): Promise<void> => {\n return Linking.openURL(\n `https://play.google.com/store/account/subscriptions?package=${await ExpoIapModule.getPackageName()}&sku=${sku}`,\n );\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} packageName package name of your app.\n * @param {string} productId product id for your in app product.\n * @param {string} productToken token for your purchase.\n * @param {string} accessToken accessToken from googleApis.\n * @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<ReceiptAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}?access_token=${accessToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {string} token The product's token (on Android)\n * @returns {Promise<PurchaseResult | void>}\n */\nexport const acknowledgePurchaseAndroid = ({\n token,\n developerPayload,\n}: {\n token: string;\n developerPayload?: string;\n}): Promise<PurchaseResult | boolean | void> => {\n return ExpoIapModule.acknowledgePurchase(token, developerPayload);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-iap",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "In App Purchase module in Expo",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -8,13 +8,20 @@
|
|
|
8
8
|
"build": "expo-module build",
|
|
9
9
|
"clean": "expo-module clean",
|
|
10
10
|
"lint": "eslint --ext .ts,.tsx,.js,.jsx src",
|
|
11
|
+
"lint:eslint": "eslint --fix '**/*.{ts,tsx}'",
|
|
12
|
+
"lint:prettier": "prettier --write \"**/*.{md,js,jsx,ts,tsx}\"",
|
|
13
|
+
"lint:tsc": "tsc -p tsconfig.json --noEmit --skipLibCheck",
|
|
14
|
+
"lint:ci": "yarn lint:tsc && yarn lint:eslint && yarn lint:prettier",
|
|
11
15
|
"test": "expo-module test",
|
|
12
16
|
"prepare": "expo-module prepare",
|
|
13
17
|
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
18
|
"expo-module": "expo-module",
|
|
15
19
|
"open:ios": "xed example/ios",
|
|
16
20
|
"open:android": "open -a \"Android Studio\" example/android",
|
|
17
|
-
"lint:kotlin": "ktlint --format ./android"
|
|
21
|
+
"lint:kotlin": "ktlint --format ./android",
|
|
22
|
+
"build:plugin": "tsc --build plugin",
|
|
23
|
+
"clean:plugin": "expo-module clean plugin",
|
|
24
|
+
"lint:plugin": "eslint plugin/src/*"
|
|
18
25
|
},
|
|
19
26
|
"keywords": [
|
|
20
27
|
"react-native",
|
|
@@ -22,11 +29,11 @@
|
|
|
22
29
|
"expo-iap",
|
|
23
30
|
"ExpoIap"
|
|
24
31
|
],
|
|
25
|
-
"repository": "https://github.com/hyochan",
|
|
32
|
+
"repository": "https://github.com/hyochan/expo-iap",
|
|
26
33
|
"bugs": {
|
|
27
34
|
"url": "https://github.com/hyochan/issues"
|
|
28
35
|
},
|
|
29
|
-
"author": "hyochan <
|
|
36
|
+
"author": "hyochan <hyochan.dev@gmail.com> (https://github.com/hyochan)",
|
|
30
37
|
"license": "MIT",
|
|
31
38
|
"homepage": "https://github.com/hyochan#readme",
|
|
32
39
|
"dependencies": {},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigPlugin } from 'expo/config-plugins';
|
|
2
|
+
type PaymentProvider = 'Amazon AppStore' | 'both' | 'Play Store';
|
|
3
|
+
export declare const modifyAppBuildGradle: (buildGradle: string, paymentProvider: PaymentProvider) => string;
|
|
4
|
+
export declare const modifyProjectBuildGradle: (buildGradle: string) => string;
|
|
5
|
+
interface Props {
|
|
6
|
+
paymentProvider?: PaymentProvider;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: ConfigPlugin<Props | undefined>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modifyProjectBuildGradle = exports.modifyAppBuildGradle = void 0;
|
|
4
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
5
|
+
const config_plugins_2 = require("expo/config-plugins");
|
|
6
|
+
const pkg = require('../../package.json');
|
|
7
|
+
const hasPaymentProviderProperValue = (paymentProvider) => {
|
|
8
|
+
return ['Amazon AppStore', 'Play Store', 'both'].includes(paymentProvider);
|
|
9
|
+
};
|
|
10
|
+
const linesToAdd = {
|
|
11
|
+
['Amazon AppStore']: `missingDimensionStrategy "store", "amazon"`,
|
|
12
|
+
['Play Store']: `missingDimensionStrategy "store", "play"`,
|
|
13
|
+
['both']: `flavorDimensions "appstore"
|
|
14
|
+
|
|
15
|
+
productFlavors {
|
|
16
|
+
googlePlay {
|
|
17
|
+
dimension "appstore"
|
|
18
|
+
missingDimensionStrategy "store", "play"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
amazon {
|
|
22
|
+
dimension "appstore"
|
|
23
|
+
missingDimensionStrategy "store", "amazon"
|
|
24
|
+
}
|
|
25
|
+
}`,
|
|
26
|
+
};
|
|
27
|
+
const addToBuildGradle = (newLine, anchor, offset, buildGradle) => {
|
|
28
|
+
const lines = buildGradle.split('\n');
|
|
29
|
+
const lineIndex = lines.findIndex((line) => line.match(anchor));
|
|
30
|
+
// add after given line
|
|
31
|
+
lines.splice(lineIndex + offset, 0, newLine);
|
|
32
|
+
return lines.join('\n');
|
|
33
|
+
};
|
|
34
|
+
const modifyAppBuildGradle = (buildGradle, paymentProvider) => {
|
|
35
|
+
if (paymentProvider === 'both') {
|
|
36
|
+
if (buildGradle.includes(`flavorDimensions "appstore"`)) {
|
|
37
|
+
return buildGradle;
|
|
38
|
+
}
|
|
39
|
+
return addToBuildGradle(linesToAdd[paymentProvider], 'defaultConfig', -1, buildGradle);
|
|
40
|
+
}
|
|
41
|
+
const missingDimensionStrategy = linesToAdd[paymentProvider];
|
|
42
|
+
if (buildGradle.includes(missingDimensionStrategy)) {
|
|
43
|
+
return buildGradle;
|
|
44
|
+
}
|
|
45
|
+
return addToBuildGradle(missingDimensionStrategy, 'defaultConfig', 1, buildGradle);
|
|
46
|
+
};
|
|
47
|
+
exports.modifyAppBuildGradle = modifyAppBuildGradle;
|
|
48
|
+
const modifyProjectBuildGradle = (buildGradle) => {
|
|
49
|
+
const supportLibVersion = `supportLibVersion = "28.0.0"`;
|
|
50
|
+
if (buildGradle.includes(supportLibVersion)) {
|
|
51
|
+
return buildGradle;
|
|
52
|
+
}
|
|
53
|
+
return addToBuildGradle(supportLibVersion, 'ext', 1, buildGradle);
|
|
54
|
+
};
|
|
55
|
+
exports.modifyProjectBuildGradle = modifyProjectBuildGradle;
|
|
56
|
+
const withIAPAndroid = (config, { paymentProvider }) => {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
58
|
+
config = (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
|
|
59
|
+
config.modResults.contents = (0, exports.modifyAppBuildGradle)(config.modResults.contents, paymentProvider);
|
|
60
|
+
return config;
|
|
61
|
+
});
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
63
|
+
config = (0, config_plugins_1.withProjectBuildGradle)(config, (config) => {
|
|
64
|
+
config.modResults.contents = (0, exports.modifyProjectBuildGradle)(config.modResults.contents);
|
|
65
|
+
return config;
|
|
66
|
+
});
|
|
67
|
+
return config;
|
|
68
|
+
};
|
|
69
|
+
const withIAP = (config, props) => {
|
|
70
|
+
const paymentProvider = props?.paymentProvider ?? 'Play Store';
|
|
71
|
+
if (!hasPaymentProviderProperValue(paymentProvider)) {
|
|
72
|
+
config_plugins_1.WarningAggregator.addWarningAndroid('expo-iap', `The payment provider '${paymentProvider}' is not supported. Please update your app.json file with one of the following supported values: 'Play Store', 'Amazon AppStore', or 'both'.`);
|
|
73
|
+
return config;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
config = withIAPAndroid(config, { paymentProvider });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
config_plugins_1.WarningAggregator.addWarningAndroid('expo-iap', `There was a problem configuring expo-iap in your native Android project: ${error}`);
|
|
80
|
+
}
|
|
81
|
+
return config;
|
|
82
|
+
};
|
|
83
|
+
exports.default = (0, config_plugins_2.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WarningAggregator,
|
|
3
|
+
withAppBuildGradle,
|
|
4
|
+
withProjectBuildGradle,
|
|
5
|
+
} from 'expo/config-plugins';
|
|
6
|
+
import {ConfigPlugin, createRunOncePlugin} from 'expo/config-plugins';
|
|
7
|
+
|
|
8
|
+
const pkg = require('../../package.json');
|
|
9
|
+
|
|
10
|
+
type PaymentProvider = 'Amazon AppStore' | 'both' | 'Play Store';
|
|
11
|
+
|
|
12
|
+
const hasPaymentProviderProperValue = (
|
|
13
|
+
paymentProvider: string,
|
|
14
|
+
): paymentProvider is PaymentProvider => {
|
|
15
|
+
return ['Amazon AppStore', 'Play Store', 'both'].includes(paymentProvider);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const linesToAdd: {[key in PaymentProvider]: string} = {
|
|
19
|
+
['Amazon AppStore']: `missingDimensionStrategy "store", "amazon"`,
|
|
20
|
+
['Play Store']: `missingDimensionStrategy "store", "play"`,
|
|
21
|
+
['both']: `flavorDimensions "appstore"
|
|
22
|
+
|
|
23
|
+
productFlavors {
|
|
24
|
+
googlePlay {
|
|
25
|
+
dimension "appstore"
|
|
26
|
+
missingDimensionStrategy "store", "play"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
amazon {
|
|
30
|
+
dimension "appstore"
|
|
31
|
+
missingDimensionStrategy "store", "amazon"
|
|
32
|
+
}
|
|
33
|
+
}`,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const addToBuildGradle = (
|
|
37
|
+
newLine: string,
|
|
38
|
+
anchor: RegExp | string,
|
|
39
|
+
offset: number,
|
|
40
|
+
buildGradle: string,
|
|
41
|
+
) => {
|
|
42
|
+
const lines = buildGradle.split('\n');
|
|
43
|
+
const lineIndex = lines.findIndex((line) => line.match(anchor));
|
|
44
|
+
// add after given line
|
|
45
|
+
lines.splice(lineIndex + offset, 0, newLine);
|
|
46
|
+
return lines.join('\n');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const modifyAppBuildGradle = (
|
|
50
|
+
buildGradle: string,
|
|
51
|
+
paymentProvider: PaymentProvider,
|
|
52
|
+
) => {
|
|
53
|
+
if (paymentProvider === 'both') {
|
|
54
|
+
if (buildGradle.includes(`flavorDimensions "appstore"`)) {
|
|
55
|
+
return buildGradle;
|
|
56
|
+
}
|
|
57
|
+
return addToBuildGradle(
|
|
58
|
+
linesToAdd[paymentProvider],
|
|
59
|
+
'defaultConfig',
|
|
60
|
+
-1,
|
|
61
|
+
buildGradle,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const missingDimensionStrategy = linesToAdd[paymentProvider];
|
|
66
|
+
if (buildGradle.includes(missingDimensionStrategy)) {
|
|
67
|
+
return buildGradle;
|
|
68
|
+
}
|
|
69
|
+
return addToBuildGradle(
|
|
70
|
+
missingDimensionStrategy,
|
|
71
|
+
'defaultConfig',
|
|
72
|
+
1,
|
|
73
|
+
buildGradle,
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const modifyProjectBuildGradle = (buildGradle: string) => {
|
|
78
|
+
const supportLibVersion = `supportLibVersion = "28.0.0"`;
|
|
79
|
+
if (buildGradle.includes(supportLibVersion)) {
|
|
80
|
+
return buildGradle;
|
|
81
|
+
}
|
|
82
|
+
return addToBuildGradle(supportLibVersion, 'ext', 1, buildGradle);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const withIAPAndroid: ConfigPlugin<{paymentProvider: PaymentProvider}> = (
|
|
86
|
+
config,
|
|
87
|
+
{paymentProvider},
|
|
88
|
+
) => {
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
90
|
+
config = withAppBuildGradle(config, (config) => {
|
|
91
|
+
config.modResults.contents = modifyAppBuildGradle(
|
|
92
|
+
config.modResults.contents,
|
|
93
|
+
paymentProvider,
|
|
94
|
+
);
|
|
95
|
+
return config;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
99
|
+
config = withProjectBuildGradle(config, (config) => {
|
|
100
|
+
config.modResults.contents = modifyProjectBuildGradle(
|
|
101
|
+
config.modResults.contents,
|
|
102
|
+
);
|
|
103
|
+
return config;
|
|
104
|
+
});
|
|
105
|
+
return config;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
interface Props {
|
|
109
|
+
paymentProvider?: PaymentProvider;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const withIAP: ConfigPlugin<Props | undefined> = (config, props) => {
|
|
113
|
+
const paymentProvider = props?.paymentProvider ?? 'Play Store';
|
|
114
|
+
|
|
115
|
+
if (!hasPaymentProviderProperValue(paymentProvider)) {
|
|
116
|
+
WarningAggregator.addWarningAndroid(
|
|
117
|
+
'expo-iap',
|
|
118
|
+
|
|
119
|
+
`The payment provider '${paymentProvider}' is not supported. Please update your app.json file with one of the following supported values: 'Play Store', 'Amazon AppStore', or 'both'.`,
|
|
120
|
+
);
|
|
121
|
+
return config;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
config = withIAPAndroid(config, {paymentProvider});
|
|
125
|
+
} catch (error) {
|
|
126
|
+
WarningAggregator.addWarningAndroid(
|
|
127
|
+
'expo-iap',
|
|
128
|
+
|
|
129
|
+
`There was a problem configuring expo-iap in your native Android project: ${error}`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return config;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export default createRunOncePlugin(withIAP, pkg.name, pkg.version);
|
package/src/ExpoIap.types.ts
CHANGED
|
@@ -115,7 +115,7 @@ export class PurchaseError implements Error {
|
|
|
115
115
|
public code?: ErrorCode,
|
|
116
116
|
public productId?: string,
|
|
117
117
|
) {
|
|
118
|
-
this.name = '[
|
|
118
|
+
this.name = '[expo-iap]: PurchaseError';
|
|
119
119
|
this.message = message;
|
|
120
120
|
this.responseCode = responseCode;
|
|
121
121
|
this.debugMessage = debugMessage;
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
SubscriptionPurchase,
|
|
16
16
|
} from './ExpoIap.types';
|
|
17
17
|
import ExpoIapModule from './ExpoIapModule';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
RequestPurchaseAndroidProps,
|
|
20
|
+
RequestSubscriptionAndroidProps,
|
|
21
|
+
} from './types/ExpoIapAndroid.types';
|
|
19
22
|
import {
|
|
20
23
|
PaymentDiscount,
|
|
21
24
|
ProductIos,
|
|
@@ -247,7 +250,7 @@ export const requestPurchase = (
|
|
|
247
250
|
|
|
248
251
|
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
249
252
|
console.warn(
|
|
250
|
-
'You are dangerously allowing
|
|
253
|
+
'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',
|
|
251
254
|
);
|
|
252
255
|
}
|
|
253
256
|
|
|
@@ -310,7 +313,7 @@ export const requestSubscription = (
|
|
|
310
313
|
|
|
311
314
|
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
312
315
|
console.warn(
|
|
313
|
-
'You are dangerously allowing
|
|
316
|
+
'You are dangerously allowing expo-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',
|
|
314
317
|
);
|
|
315
318
|
}
|
|
316
319
|
|
package/src/modules/android.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {Linking} from 'react-native';
|
|
2
2
|
import {Product, PurchaseResult, SubscriptionProduct} from '../ExpoIap.types';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ProductAndroid,
|
|
5
|
+
ReceiptAndroid,
|
|
6
|
+
SubscriptionProductAndroid,
|
|
7
|
+
} from '../types/ExpoIapAndroid.types';
|
|
4
8
|
import ExpoIapModule from '../ExpoIapModule';
|
|
5
9
|
|
|
6
10
|
export function isProductAndroid(product: Product): product is ProductAndroid {
|
|
7
11
|
return (product as ProductAndroid)?.title !== undefined;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
|
-
export function isSubscriptionProductAndroid(
|
|
14
|
+
export function isSubscriptionProductAndroid(
|
|
15
|
+
product: SubscriptionProduct,
|
|
16
|
+
): product is SubscriptionProductAndroid {
|
|
11
17
|
return (product as SubscriptionProductAndroid)?.title !== undefined;
|
|
12
18
|
}
|
|
13
19
|
|