mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
feat(inAppPurchase): add inAppPurhcase plugin (#423)
* feat(inAppPurchase): add inAppPurchase * add otherPromise option to decorator
This commit is contained in:
parent
61716467df
commit
8526e89e12
@ -41,7 +41,7 @@ import { Facebook } from './plugins/facebook';
|
||||
import { File } from './plugins/file';
|
||||
import { Transfer } from './plugins/filetransfer';
|
||||
import { Flashlight } from './plugins/flashlight';
|
||||
import {Geofence} from './plugins/geofence';
|
||||
import { Geofence } from './plugins/geofence';
|
||||
import { Geolocation } from './plugins/geolocation';
|
||||
import { Globalization } from './plugins/globalization';
|
||||
import { GooglePlus } from './plugins/google-plus';
|
||||
@ -53,6 +53,7 @@ import { IBeacon } from './plugins/ibeacon';
|
||||
import { ImagePicker } from './plugins/imagepicker';
|
||||
import { ImageResizer } from './plugins/imageresizer';
|
||||
import { InAppBrowser } from './plugins/inappbrowser';
|
||||
import { InAppPurchase } from './plugins/inapppurchase';
|
||||
import { Insomnia } from './plugins/insomnia';
|
||||
import { Instagram } from './plugins/instagram';
|
||||
import { IsDebug } from './plugins/is-debug';
|
||||
@ -65,7 +66,6 @@ import { NativeStorage } from './plugins/nativestorage';
|
||||
import { MediaPlugin } from './plugins/media';
|
||||
import { Network } from './plugins/network';
|
||||
import { OneSignal } from './plugins/onesignal';
|
||||
|
||||
import { PhotoViewer } from './plugins/photo-viewer';
|
||||
import { ScreenOrientation } from './plugins/screen-orientation';
|
||||
import { PinDialog } from './plugins/pin-dialog';
|
||||
@ -158,6 +158,7 @@ export {
|
||||
GooglePlus,
|
||||
GoogleAnalytics,
|
||||
Hotspot,
|
||||
InAppPurchase,
|
||||
Insomnia,
|
||||
Instagram,
|
||||
Keyboard,
|
||||
@ -236,6 +237,7 @@ window['IonicNative'] = {
|
||||
ImagePicker: ImagePicker,
|
||||
ImageResizer: ImageResizer,
|
||||
InAppBrowser: InAppBrowser,
|
||||
InAppPurchase: InAppPurchase,
|
||||
Instagram: Instagram,
|
||||
IsDebug: IsDebug,
|
||||
Keyboard: Keyboard,
|
||||
|
121
src/plugins/inapppurchase.ts
Normal file
121
src/plugins/inapppurchase.ts
Normal file
@ -0,0 +1,121 @@
|
||||
import {Plugin, Cordova} from './plugin';
|
||||
|
||||
|
||||
/**
|
||||
* @name InAppPurchase
|
||||
* @description
|
||||
* A lightweight Cordova plugin for in app purchases on iOS/Android.
|
||||
*
|
||||
* @usage
|
||||
* ```ts
|
||||
* import {InAppPurchase} from 'ionic-native';
|
||||
*
|
||||
* InAppPurchase
|
||||
* .getProducts(['com.yourapp.prod1', 'com.yourapp.prod2', ...])
|
||||
* .then((products) => {
|
||||
* console.log(products);
|
||||
* // [{ productId: 'com.yourapp.prod1', 'title': '...', description: '...', price: '...' }, ...]
|
||||
* })
|
||||
* .catch((err) => {
|
||||
* console.log(err);
|
||||
* });
|
||||
*
|
||||
*
|
||||
* InAppPurchase
|
||||
* .buy('com.yourapp.prod1')
|
||||
* .then((data)=> {
|
||||
* console.log(data);
|
||||
* // {
|
||||
* // transactionId: ...
|
||||
* // receipt: ...
|
||||
* // signature: ...
|
||||
* // }
|
||||
* })
|
||||
* .catch((err)=> {
|
||||
* console.log(err);
|
||||
* });
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @advanced
|
||||
*
|
||||
* ```ts
|
||||
* // fist buy the product...
|
||||
* InAppPurchase
|
||||
* .buy('com.yourapp.consumable_prod1')
|
||||
* .then(data => InAppPurchase.consume(data.productType, data.receipt, data.signature))
|
||||
* .then(() => console.log('product was successfully consumed!'))
|
||||
* .catch( err=> console.log(err))
|
||||
* ```
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Plugin({
|
||||
plugin: 'cordova-plugin-inapppurchase',
|
||||
pluginRef: 'inAppPurchase',
|
||||
platforms: ['Android', 'iOS'],
|
||||
repo: 'https://github.com/AlexDisler/cordova-plugin-inapppurchase'
|
||||
})
|
||||
export class InAppPurchase {
|
||||
|
||||
/**
|
||||
* Retrieves a list of full product data from Apple/Google. This method must be called before making purchases.
|
||||
* @param {array<string>} productId an array of product ids.
|
||||
* @returns {Promise} Returns a Promise that resolves with an array of objects.
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true
|
||||
})
|
||||
static getProducts(productId: string[]): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Buy a product that matches the productId.
|
||||
* @param {string} productId A string that matches the product you want to buy.
|
||||
* @returns {Promise} Returns a Promise that resolves with the transaction details.
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true
|
||||
})
|
||||
static buy(productId: string): Promise<{transactionId: string, receipt: string, signature: string, productType: string}> { return; }
|
||||
|
||||
/**
|
||||
* Same as buy, but for subscription based products.
|
||||
* @param {string} productId A string that matches the product you want to subscribe to.
|
||||
* @returns {Promise} Returns a Promise that resolves with the transaction details.
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true
|
||||
})
|
||||
static subscribe(productId: string): Promise<{transactionId: string, receipt: string, signature: string, productType: string}> { return; }
|
||||
|
||||
/**
|
||||
* Call this function after purchasing a "consumable" product to mark it as consumed. On Android, you must consume products that you want to let the user purchase multiple times. If you will not consume the product after a purchase, the next time you will attempt to purchase it you will get the error message:
|
||||
* @param {string} productType
|
||||
* @param {string} receipt
|
||||
* @param {string} signature
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true
|
||||
})
|
||||
static consume(productType: string, receipt: string, signature: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Restore all purchases from the store
|
||||
* @returns {Promise} Returns a promise with an array of purchases.
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true
|
||||
})
|
||||
static restorePurchases(): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Get the receipt.
|
||||
* @returns {Promise<string>} Returns a promise that contains the string for the receipt
|
||||
*/
|
||||
@Cordova({
|
||||
otherPromise: true,
|
||||
platforms: ['iOS']
|
||||
})
|
||||
static getReceipt(): Promise<string> { return; }
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user