CdvPurchase.Store
Entry class of the plugin.
- checkSupport
- defaultPlatform
- error
- findInLocalReceipts
- findInVerifiedReceipts
- get
- getAdapter
- getApplicationUsername
- initialize
- manageBilling
- manageSubscriptions
- monitor
- off
- order
- owned
- ready
- refresh
- register
- requestPayment
- restorePurchases
- update
- when
• new Store(): Store
• Optional
applicationUsername: string
| () => undefined
| string
Return the identifier of the user for your application.
Note: Apple AppStore requires an UUIDv4 if you want it to appear as the "appAccountToken" in the transaction data.
• log: Logger
Logger
• minTimeBetweenUpdates: number
= 600000
Avoid invoking store.update() if the most recent call occurred within this specific number of milliseconds.
• validator: undefined
| string
| Function
| Target
URL or implementation of the receipt validation service
Example
Define the validator as a string
CdvPurchase.store.validator = "https://validator.iaptic.com/v1/validate?appName=test"
Example
Define the validator as a function
CdvPurchase.store.validator = (receipt, callback) => {
callback({
ok: true,
data: {
// see CdvPurchase.Validator.Response.Payload for details
}
})
}
See
CdvPurchase.Validator.Response.Payload
• validator_privacy_policy: undefined
| PrivacyPolicyItem
| PrivacyPolicyItem
[]
When adding information to receipt validation requests, those can serve different functions:
- handling support requests
- fraud detection
- analytics
- tracking
Make sure the value your select is in line with your application's privacy policy and your users' tracking preference.
Example
CdvPurchase.store.validator_privacy_policy = [
'fraud', 'support', 'analytics', 'tracking'
]
• verbosity: LogLevel
= LogLevel.ERROR
Verbosity level used by the plugin logger
Set to:
- LogLevel.QUIET or 0 to disable all logging (default)
- LogLevel.ERROR or 1 to show only error messages
- LogLevel.WARNING or 2 to show warnings and errors
- LogLevel.INFO or 3 to also show information messages
- LogLevel.DEBUG or 4 to enable internal debugging messages.
See
• version: string
= PLUGIN_VERSION
Version of the plugin currently installed.
• get
isReady(): boolean
true if the plugin is initialized and ready
boolean
• get
localReceipts(): Receipt
[]
List of all receipts present on the device.
Receipt
[]
• get
localTransactions(): Transaction
[]
List of all transaction from the local receipts.
• get
products(): Product
[]
List of all active products.
Products are active if their details have been successfully loaded from the store.
Product
[]
• get
verifiedPurchases(): VerifiedPurchase
[]
List of all purchases from the verified receipts.
• get
verifiedReceipts(): VerifiedReceipt
[]
List of receipts verified with the receipt validation service.
Those receipt contains more information and are generally more up-to-date than the local ones.
▸ checkSupport(platform
, functionality
): boolean
Returns true if a platform supports the requested functionality.
Name | Type |
---|---|
platform |
Platform |
functionality |
PlatformFunctionality |
boolean
Example
store.checkSupport(Platform.APPLE_APPSTORE, 'requestPayment');
// => false
▸ defaultPlatform(): Platform
The default payment platform to use depending on the OS.
- on iOS:
APPLE_APPSTORE
- on Android:
GOOGLE_PLAY
▸ error(error
): void
Register an error handler.
Name | Type | Description |
---|---|---|
error |
Callback <IError > |
An error callback that takes the error as an argument |
void
Example
store.error(function(error) {
console.error('CdvPurchase ERROR: ' + error.message);
});
▸ findInLocalReceipts(product
): undefined
| Transaction
Find the latest transaction for a given product, from those reported by the device.
Name | Type |
---|---|
product |
Product |
undefined
| Transaction
▸ findInVerifiedReceipts(product
): undefined
| VerifiedPurchase
Find the last verified purchase for a given product, from those verified by the receipt validator.
Name | Type |
---|---|
product |
Product |
undefined
| VerifiedPurchase
▸ get(productId
, platform?
): undefined
| Product
Find a product from its id and platform
Name | Type | Description |
---|---|---|
productId |
string |
Product identifier on the platform. |
platform? |
Platform |
The product the product exists in. Can be omitted if you're only using a single payment platform. |
undefined
| Product
▸ getAdapter(platform
): undefined
| Adapter
Retrieve a platform adapter.
The platform adapter has to have been initialized before.
Name | Type |
---|---|
platform |
Platform |
undefined
| Adapter
See
▸ getApplicationUsername(): undefined
| string
Get the application username as a string by either calling or returning Store.applicationUsername
undefined
| string
▸ initialize(platforms?
): Promise
<IError
[]>
Call to initialize the in-app purchase plugin.
Name | Type | Description |
---|---|---|
platforms |
(Platform | PlatformWithOptions )[] |
List of payment platforms to initialize, default to Store.defaultPlatform(). |
Promise
<IError
[]>
▸ manageBilling(platform?
): Promise
<undefined
| IError
>
Opens the billing methods page on AppStore, Play, Microsoft, ...
From this page, the user can update their payment methods.
If platform is not specified, the first available platform will be used.
Name | Type |
---|---|
platform? |
Platform |
Promise
<undefined
| IError
>
Example
if (purchase.isBillingRetryPeriod)
store.manageBilling(purchase.platform);
▸ manageSubscriptions(platform?
): Promise
<undefined
| IError
>
Open the subscription management interface for the selected platform.
If platform is not specified, the first available platform will be used.
Name | Type |
---|---|
platform? |
Platform |
Promise
<undefined
| IError
>
Example
const activeSubscription: Purchase = // ...
store.manageSubscriptions(activeSubscription.platform);
▸ monitor(transaction
, onChange
, callbackName
): TransactionMonitor
Setup a function to be notified of changes to a transaction state.
Name | Type | Description |
---|---|---|
transaction |
Transaction |
The transaction to monitor. |
onChange |
Callback <TransactionState > |
Function to be called when the transaction status changes. |
callbackName |
string |
- |
A monitor which can be stopped with monitor.stop()
Example
const monitor = store.monitor(transaction, state => {
console.log('new state: ' + state);
if (state === TransactionState.FINISHED)
monitor.stop();
});
▸ off<T
>(callback
): void
Remove a callback from any listener it might have been added to.
Name |
---|
T |
Name | Type |
---|---|
callback |
Callback <T > |
void
▸ order(offer
, additionalData?
): Promise
<undefined
| IError
>
Place an order for a given offer.
Name | Type |
---|---|
offer |
Offer |
additionalData? |
AdditionalData |
Promise
<undefined
| IError
>
▸ owned(product
): boolean
Return true if a product is owned
Important: The value will be false when the app starts and will only become true after purchase receipts have been loaded and validated. Without receipt validation, it might remain false depending on the platform, make sure to store the ownership status of non-consumable products in some way.
Name | Type | Description |
---|---|---|
product |
string | { id : string ; platform? : Platform } |
The product object or identifier of the product. |
boolean
▸ ready(cb
): void
Register a callback to be called when the plugin is ready.
This happens when all the platforms are initialized and their products loaded.
Name | Type |
---|---|
cb |
Callback <void > |
void
▸ refresh(): void
void
Deprecated
- use store.initialize(), store.update() or store.restorePurchases()
▸ register(product
): void
Register a product.
Name | Type |
---|---|
product |
IRegisterProduct | IRegisterProduct [] |
void
Example
store.register([{
id: 'subscription1',
type: ProductType.PAID_SUBSCRIPTION,
platform: Platform.APPLE_APPSTORE,
}, {
id: 'subscription1',
type: ProductType.PAID_SUBSCRIPTION,
platform: Platform.GOOGLE_PLAY,
}, {
id: 'consumable1',
type: ProductType.CONSUMABLE,
platform: Platform.BRAINTREE,
}]);
▸ requestPayment(paymentRequest
, additionalData?
): PaymentRequestPromise
Request a payment.
A payment is a custom amount to charge the user. Make sure the selected payment platform supports Payment Requests.
Name | Type | Description |
---|---|---|
paymentRequest |
PaymentRequest |
Parameters of the payment request |
additionalData? |
AdditionalData |
Additional parameters |
▸ restorePurchases(): Promise
<undefined
| IError
>
Replay the users transactions.
This method exists to cover an Apple AppStore requirement.
Promise
<undefined
| IError
>
▸ update(): Promise
<void
>
Call to refresh the price of products and status of purchases.
Promise
<void
>
▸ when(): When
Register event callbacks.
Events overview:
productUpdated
: Called when product metadata is loaded from the storereceiptUpdated
: Called when local receipt information changes (ownership status change, for example)verified
: Called after successful receipt validation (requires a receipt validator)
Example
// Monitor ownership with receipt validation
store.when()
.approved(transaction => transaction.verify())
.verified(receipt => {
if (store.owned("my-product")) {
// Product is owned and verified
}
});
Example
// Monitor ownership without receipt validation
store.when().receiptUpdated(receipt => {
if (store.owned("my-product")) {
// Product is owned according to local data
}
});