From f1988f67f53be0e4a32b046e1553131ca48c64c6 Mon Sep 17 00:00:00 2001 From: mhartington Date: Fri, 15 Jul 2016 17:33:55 -0400 Subject: [PATCH 1/2] feat(inAppPurchase): add inAppPurchase --- src/index.ts | 3 + src/plugins/inapppurchase.ts | 109 +++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/plugins/inapppurchase.ts diff --git a/src/index.ts b/src/index.ts index 3e18678308..b85cc9d522 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,6 +47,7 @@ import {Httpd} from './plugins/httpd'; import {IBeacon} from './plugins/ibeacon'; import {ImagePicker} from './plugins/imagepicker'; import {InAppBrowser} from './plugins/inappbrowser'; +import {InAppPurchase} from './plugins/inapppurchase'; import {Insomnia} from './plugins/insomnia'; import {Keyboard} from './plugins/keyboard'; import {LaunchNavigator} from './plugins/launchnavigator'; @@ -125,6 +126,7 @@ export { GooglePlus, GoogleAnalytics, Hotspot, + InAppPurchase, Insomnia, Keyboard, Network, @@ -187,6 +189,7 @@ window['IonicNative'] = { IBeacon: IBeacon, ImagePicker: ImagePicker, InAppBrowser: InAppBrowser, + InAppPurchase: InAppPurchase, Keyboard: Keyboard, LaunchNavigator: LaunchNavigator, LocalNotifications: LocalNotifications, diff --git a/src/plugins/inapppurchase.ts b/src/plugins/inapppurchase.ts new file mode 100644 index 0000000000..9dea2733db --- /dev/null +++ b/src/plugins/inapppurchase.ts @@ -0,0 +1,109 @@ +import {Plugin, Cordova} from './plugin'; + + +/** + * @name InAppPurchase + * @description + * A lightweight Cordova plugin for in app purchases on iOS/Android. + * + * For more info, please see the [InAppPurchase plugin docs](https://github.com/AlexDisler/cordova-plugin-inapppurchase). + * + * @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'] +}) +export class InAppPurchase { + + /** + * Retrieves a list of full product data from Apple/Google. This method must be called before making purchases. + * @param {array} productId an array of product ids. + * @returns {Promise} Returns a Promise that resolves with an array of objects. + */ + @Cordova() + static getProducts(productId: array): Promise { 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() + 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() + 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() + static consume(productType: string, receipt: string, signature: string): void { } + + /** + * Restore all purchases from the store + * @returns {Promise} Returns a promise with an array of purchases. + */ + @Cordova() + static restorePurchases(): Promise { return; } + + /** + * Get the receipt. + * @returns {Promise} Returns a promise that contains the string for the receipt + */ + @Cordova() + static getReceipt(): Promise { return; } + +} From 1e300ae35fcab018291236cba2215902875e3494 Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Mon, 15 Aug 2016 01:15:20 -0400 Subject: [PATCH 2/2] add otherPromise option to decorator --- src/plugins/inapppurchase.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/plugins/inapppurchase.ts b/src/plugins/inapppurchase.ts index 9dea2733db..ba68223a8f 100644 --- a/src/plugins/inapppurchase.ts +++ b/src/plugins/inapppurchase.ts @@ -6,8 +6,6 @@ import {Plugin, Cordova} from './plugin'; * @description * A lightweight Cordova plugin for in app purchases on iOS/Android. * - * For more info, please see the [InAppPurchase plugin docs](https://github.com/AlexDisler/cordova-plugin-inapppurchase). - * * @usage * ```ts * import {InAppPurchase} from 'ionic-native'; @@ -55,7 +53,8 @@ import {Plugin, Cordova} from './plugin'; @Plugin({ plugin: 'cordova-plugin-inapppurchase', pluginRef: 'inAppPurchase', - platforms: ['Android', 'iOS'] + platforms: ['Android', 'iOS'], + repo: 'https://github.com/AlexDisler/cordova-plugin-inapppurchase' }) export class InAppPurchase { @@ -64,15 +63,19 @@ export class InAppPurchase { * @param {array} productId an array of product ids. * @returns {Promise} Returns a Promise that resolves with an array of objects. */ - @Cordova() - static getProducts(productId: array): Promise { return; } + @Cordova({ + otherPromise: true + }) + static getProducts(productId: string[]): Promise { 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() + @Cordova({ + otherPromise: true + }) static buy(productId: string): Promise<{transactionId: string, receipt: string, signature: string, productType: string}> { return; } /** @@ -80,7 +83,9 @@ export class InAppPurchase { * @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() + @Cordova({ + otherPromise: true + }) static subscribe(productId: string): Promise<{transactionId: string, receipt: string, signature: string, productType: string}> { return; } /** @@ -89,21 +94,28 @@ export class InAppPurchase { * @param {string} receipt * @param {string} signature */ - @Cordova() - static consume(productType: string, receipt: string, signature: string): void { } + @Cordova({ + otherPromise: true + }) + static consume(productType: string, receipt: string, signature: string): Promise { return; } /** * Restore all purchases from the store * @returns {Promise} Returns a promise with an array of purchases. */ - @Cordova() + @Cordova({ + otherPromise: true + }) static restorePurchases(): Promise { return; } /** * Get the receipt. * @returns {Promise} Returns a promise that contains the string for the receipt */ - @Cordova() + @Cordova({ + otherPromise: true, + platforms: ['iOS'] + }) static getReceipt(): Promise { return; } }