From 943be7980287d92f7daac8bea1ac9edac204a465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=AA=E8=BF=B0=E8=8D=A3?= Date: Thu, 22 Dec 2016 11:47:14 +0800 Subject: [PATCH 1/3] add cordova-alipay-base plugin. to support Alipay payment --- src/index.ts | 4 +- src/plugins/alipay.ts | 111 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/plugins/alipay.ts diff --git a/src/index.ts b/src/index.ts index 470cca1814..08ea06e19c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,9 +3,9 @@ import { initAngular1 } from './ng1'; const DEVICE_READY_TIMEOUT = 5000; declare var window; - import { ActionSheet } from './plugins/actionsheet'; import { AdMob } from './plugins/admob'; +import { Alipay } from './plugins/alipay'; import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth'; import { AppAvailability } from './plugins/appavailability'; import { AppRate } from './plugins/apprate'; @@ -128,6 +128,7 @@ import { Zip } from './plugins/zip'; export * from './plugins/3dtouch'; export * from './plugins/actionsheet'; export * from './plugins/admob'; +export * from './plugins/alipay'; export * from './plugins/android-fingerprint-auth'; export * from './plugins/appavailability'; export * from './plugins/apprate'; @@ -252,6 +253,7 @@ export * from './plugins/zip'; window['IonicNative'] = { ActionSheet, AdMob, + Alipay, AndroidFingerprintAuth, AppAvailability, AppRate, diff --git a/src/plugins/alipay.ts b/src/plugins/alipay.ts new file mode 100644 index 0000000000..df32b4e7ef --- /dev/null +++ b/src/plugins/alipay.ts @@ -0,0 +1,111 @@ +import { Plugin, Cordova } from './plugin'; +/** + * @link https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.wlOhAE&treeId=193&articleId=105465&docType=1 + * 所有value都需要经过urlencode。 + */ +export interface AlipayOrder { + /** + * 支付宝分配给开发者的应用ID + */ + app_id: string; + + /** + * 接口名称 + * Should be: alipay.trade.app.pay + */ + method: string; + + /** + * 数据格式 + * Default: "JSON" + */ + format?: string; + + /** + * 请求使用的编码格式 + * Possible values: "UTF-8", "GBK" + * Default: "UTF-8" + */ + charset: string; + + /** + * 签名算法 + * Default: 'RSA' + */ + sign_type: string; + + /** + * 签名,这个很重要,需要从服务器端签名后传过来。APP上不应该存有签名用的任何密钥。 + * Default: 'RSA' + */ + sign: string; + + /** + * 发送请求的时间戳。"yyyy-MM-dd HH:mm:ss"格式,比如:2014-07-24 03:07:50 + */ + timestamp: string; + + /** + * 接口版本,固定 '1.0' + */ + version: string; + + /** + * 通知地址, 用来接收结果的地址。 + */ + notify_url: string; + + /** + * 业务请求参数集合,详见接口文档。这里是一个JSON格式的字符串。 + */ + biz_content: string; +} + +/** + * @name Alipay + * @description + * 支付宝APP支付插件,支持最新版本的支付宝SDK。 + * This plugin is used for Alipay APP support. Integrated with the latest SDK. + * + * Requires Cordova plugin: `cordova-alipay-base`. For more info, please see the [Alipay plugin docs](https://github.com/xueron/cordova-alipay-base). + * + * @usage + * ``` + * import { Alipay } from 'ionic-native'; + * + * // Should get from server side with sign. + * let alipayOrder = { + ... + * }; + * + * Alipay.pay(alipayOrder) + * .then(result => { + * console.log(result); // Success + * }) + * .catch(error => { + * console.log(error); // Failed + * }); + * + * ``` + * + * @interfaces + * AlipayOrder + */ +@Plugin({ + pluginName: 'Alipay', + plugin: 'cordova-alipay-base', + pluginRef: 'Alipay.Base', + repo: 'https://github.com/xueron/cordova-alipay-base', + platforms: ['Android', 'iOS'], + install: 'ionic plugin add https://github.com/xueron/cordova-alipay-base --variable ALI_PID=your_app_id' +}) +export class Alipay { + /** + * Open Alipay to perform App pay + * @param order { AlipayOrder } alipay options + * @returns {Promise} Returns a Promise that resolves with the success return, or rejects with an error. + */ + @Cordova() + static pay(order: AlipayOrder): Promise { return; } +} + From bb579062339f9d247b7dba47e29cc346d819cfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=AA=E8=BF=B0=E8=8D=A3?= Date: Thu, 22 Dec 2016 15:23:54 +0800 Subject: [PATCH 2/3] change ALI_PID to APP_ID, make it same with the latest SDK --- src/plugins/alipay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/alipay.ts b/src/plugins/alipay.ts index df32b4e7ef..ef8e1a5087 100644 --- a/src/plugins/alipay.ts +++ b/src/plugins/alipay.ts @@ -97,7 +97,7 @@ export interface AlipayOrder { pluginRef: 'Alipay.Base', repo: 'https://github.com/xueron/cordova-alipay-base', platforms: ['Android', 'iOS'], - install: 'ionic plugin add https://github.com/xueron/cordova-alipay-base --variable ALI_PID=your_app_id' + install: 'ionic plugin add https://github.com/xueron/cordova-alipay-base --variable APP_ID=your_app_id' }) export class Alipay { /** From 052a065fdf685ffc820f31ff4c859ec71aa42fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=AA=E8=BF=B0=E8=8D=A3?= Date: Mon, 20 Feb 2017 14:38:45 +0800 Subject: [PATCH 3/3] rewrite comments --- src/plugins/alipay.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/plugins/alipay.ts b/src/plugins/alipay.ts index ef8e1a5087..f81800f63e 100644 --- a/src/plugins/alipay.ts +++ b/src/plugins/alipay.ts @@ -1,62 +1,63 @@ import { Plugin, Cordova } from './plugin'; /** * @link https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.wlOhAE&treeId=193&articleId=105465&docType=1 - * 所有value都需要经过urlencode。 + * + * All values need be urlencoded. */ export interface AlipayOrder { /** - * 支付宝分配给开发者的应用ID + * appId assigned by Alipay */ app_id: string; /** - * 接口名称 + * Api name. * Should be: alipay.trade.app.pay */ method: string; /** - * 数据格式 + * Data format * Default: "JSON" */ format?: string; /** - * 请求使用的编码格式 + * Charset * Possible values: "UTF-8", "GBK" * Default: "UTF-8" */ charset: string; /** - * 签名算法 + * Sign method * Default: 'RSA' */ sign_type: string; /** - * 签名,这个很重要,需要从服务器端签名后传过来。APP上不应该存有签名用的任何密钥。 + * Sign value. Should be got from server side. * Default: 'RSA' */ sign: string; /** - * 发送请求的时间戳。"yyyy-MM-dd HH:mm:ss"格式,比如:2014-07-24 03:07:50 + * Timestamp, formated like "yyyy-MM-dd HH:mm:ss", e.g. 2014-07-24 03:07:50 */ timestamp: string; /** - * 接口版本,固定 '1.0' + * Api version. Fixed value '1.0' */ version: string; /** - * 通知地址, 用来接收结果的地址。 + * Notify url. */ notify_url: string; /** - * 业务请求参数集合,详见接口文档。这里是一个JSON格式的字符串。 + * biz content. formated in json. see alipay doc for detail. */ biz_content: string; } @@ -64,7 +65,6 @@ export interface AlipayOrder { /** * @name Alipay * @description - * 支付宝APP支付插件,支持最新版本的支付宝SDK。 * This plugin is used for Alipay APP support. Integrated with the latest SDK. * * Requires Cordova plugin: `cordova-alipay-base`. For more info, please see the [Alipay plugin docs](https://github.com/xueron/cordova-alipay-base).