expo-alipay-sdk 0.0.1

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.
Files changed (41) hide show
  1. package/README.md +281 -0
  2. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  3. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  4. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  5. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/8.9/gc.properties +0 -0
  7. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  9. package/android/.gradle/vcs-1/gc.properties +0 -0
  10. package/android/build.gradle +22 -0
  11. package/android/src/main/AndroidManifest.xml +14 -0
  12. package/android/src/main/java/com/goldstar/alipay/AlipayModule.java +140 -0
  13. package/android/src/main/java/com/goldstar/alipay/AlipayPackage.java +26 -0
  14. package/android/src/main/java/com/goldstar/alipay/PayResult.java +46 -0
  15. package/app.plugin.js +53 -0
  16. package/expo-alipay.podspec +32 -0
  17. package/ios/Alipay.h +9 -0
  18. package/ios/Alipay.mm +143 -0
  19. package/ios/iOS_SDK/AlipaySDK.bundle/alipay_msp_back@2x.png +0 -0
  20. package/ios/iOS_SDK/AlipaySDK.bundle/alipay_msp_refresh@2x.png +0 -0
  21. package/ios/iOS_SDK/AlipaySDK.bundle/bar@2x.png +0 -0
  22. package/ios/iOS_SDK/AlipaySDK.bundle/bridge.js +1 -0
  23. package/ios/iOS_SDK/AlipaySDK.bundle/bridge_v2.js +79 -0
  24. package/ios/iOS_SDK/AlipaySDK.bundle/refresh@2x.png +0 -0
  25. package/ios/iOS_SDK/AlipaySDK.bundle/refresh_click@2x.png +0 -0
  26. package/ios/iOS_SDK/AlipaySDK.bundle/shutdown@2x.png +0 -0
  27. package/ios/iOS_SDK/AlipaySDK.bundle/shutdown_click@2x.png +0 -0
  28. package/ios/iOS_SDK/AlipaySDK.framework/AlipaySDK +0 -0
  29. package/ios/iOS_SDK/AlipaySDK.framework/AlipaySDK-inside-Info.plist +0 -0
  30. package/ios/iOS_SDK/AlipaySDK.framework/Headers/AFServiceCenter.h +68 -0
  31. package/ios/iOS_SDK/AlipaySDK.framework/Headers/AFServiceResponse.h +43 -0
  32. package/ios/iOS_SDK/AlipaySDK.framework/Headers/APCellularHTTPSClient.h +73 -0
  33. package/ios/iOS_SDK/AlipaySDK.framework/Headers/APDeductSDK.h +27 -0
  34. package/ios/iOS_SDK/AlipaySDK.framework/Headers/APayAuthInfo.h +33 -0
  35. package/ios/iOS_SDK/AlipaySDK.framework/Headers/AlipaySDK.h +253 -0
  36. package/ios/iOS_SDK/AlipaySDK.framework/Headers/AlipaySDKModule.h +18 -0
  37. package/ios/iOS_SDK/AlipaySDK.framework/Headers/MQPWebViewResourcesManager.h +37 -0
  38. package/ios/iOS_SDK/AlipaySDK.framework/Modules/module.modulemap +14 -0
  39. package/package.json +62 -0
  40. package/src/index.d.ts +69 -0
  41. package/src/index.js +164 -0
@@ -0,0 +1,253 @@
1
+ //
2
+ // AlipaySDK.h
3
+ // AlipaySDK
4
+ //
5
+ // Created by antfin on 17-10-24.
6
+ // Copyright (c) 2017年 AntFin. All rights reserved.
7
+ //
8
+
9
+
10
+ ////////////////////////////////////////////////////////
11
+ ///////////////// 支付宝标准版本支付SDK ///////////////////
12
+ ///////// version:15.8.40 modify:2025.11.17///////////
13
+ ////////////////////////////////////////////////////////
14
+
15
+ #import <UIKit/UIKit.h>
16
+ #import "APayAuthInfo.h"
17
+ #import "AFServiceCenter.h"
18
+ #import "AFServiceResponse.h"
19
+
20
+ typedef void(^CompletionBlock)(NSDictionary *resultDic);
21
+
22
+ typedef enum {
23
+ ALIPAY_TIDFACTOR_IMEI,
24
+ ALIPAY_TIDFACTOR_IMSI,
25
+ ALIPAY_TIDFACTOR_TID,
26
+ ALIPAY_TIDFACTOR_CLIENTKEY,
27
+ ALIPAY_TIDFACTOR_VIMEI,
28
+ ALIPAY_TIDFACTOR_VIMSI,
29
+ ALIPAY_TIDFACTOR_CLIENTID,
30
+ ALIPAY_TIDFACTOR_APDID,
31
+ ALIPAY_TIDFACTOR_MAX
32
+ } AlipayTidFactor;
33
+
34
+ @interface AlipaySDK : NSObject
35
+
36
+ /**
37
+ * 创建支付单例服务
38
+ *
39
+ * @return 返回单例对象
40
+ */
41
+ + (AlipaySDK *)defaultService;
42
+
43
+ /**
44
+ * 用于设置SDK使用的window,如果没有自行创建window无需设置此接口
45
+ */
46
+ @property (nonatomic, weak) UIWindow *targetWindow;
47
+
48
+ //////////////////////////////////////////////////////////////////////////////////////////////
49
+ //////////////////////////支付宝支付相关接口/////////////////////////////////////////////////////
50
+ //////////////////////////////////////////////////////////////////////////////////////////////
51
+
52
+ /**
53
+ * 注册接口
54
+ *
55
+ * @param appId 商户appId
56
+ * @param universalLink 商户app关联的universalLink与开放平台配置一直
57
+ */
58
+ - (void)registerApp:(NSString *)appId universalLink:(NSString *)universalLink;
59
+
60
+ /**
61
+ * 支付接口
62
+ *
63
+ * @param orderStr 支付订单信息字串
64
+ * @param schemeStr 调用支付的app注册在info.plist中的scheme
65
+ * @param completionBlock 支付结果回调Block,用于wap支付结果回调,跳转支付宝支付时只有当processOrderWithPaymentResult接口的completionBlock为nil时会使用这个bolock
66
+ */
67
+ - (void)payOrder:(NSString *)orderStr
68
+ fromScheme:(NSString *)schemeStr
69
+ callback:(CompletionBlock)completionBlock;
70
+
71
+ /**
72
+ * 支付接口 v2
73
+ *
74
+ * @param orderStr 支付订单信息字串
75
+ * @param dynamicLaunch 是否使用动态配置策略跳转支付宝支付
76
+ * @param schemeStr 调用支付的app注册在info.plist中的scheme
77
+ * @param completionBlock 支付结果回调Block,用于wap支付结果回调
78
+ 跳转支付宝支付时只有当processOrderWithPaymentResult接口的completionBlock为nil时会使用这个bolock
79
+ */
80
+ - (void)payOrder:(NSString *)orderStr
81
+ dynamicLaunch:(BOOL)dynamicLaunch
82
+ fromScheme:(NSString *)schemeStr
83
+ callback:(CompletionBlock)completionBlock;
84
+
85
+ /**
86
+ * 处理支付宝app支付后跳回商户app携带的支付结果Url
87
+ *
88
+ * @param resultUrl 支付宝app返回的支付结果url
89
+ * @param completionBlock 支付结果回调 为nil时默认使用支付接口的completionBlock
90
+ */
91
+ - (void)processOrderWithPaymentResult:(NSURL *)resultUrl
92
+ standbyCallback:(CompletionBlock)completionBlock;
93
+
94
+
95
+ /**
96
+ * 商户接入UniversalLink支付接口使用该接口
97
+ *
98
+ * @param orderStr 支付订单信息字串
99
+ * @param schemeStr 调用支付的app注册在info.plist中的scheme
100
+ * @param universalLink 调用支付的app关联的universalLink,如'https://render.alipay.com/'
101
+ * @param completionBlock 支付结果回调Block,用于wap支付结果回调,跳转支付宝支付时只有当processOrderWithPaymentResult接口的completionBlock为nil时会使用这个bolock
102
+ */
103
+ - (void) payOrder:(NSString *)orderStr
104
+ fromScheme:(NSString *)schemeStr
105
+ fromUniversalLink:(NSString *)universalLink
106
+ callback:(CompletionBlock)completionBlock;
107
+
108
+
109
+ /**
110
+ * 处理支付宝app支付后通过universalLink跳回商户app携带的支付结果处理
111
+ *
112
+ * @param userActivity 系统接口传入的userActivity
113
+ * @param completionBlock 支付结果回调 为nil时默认使用支付接口的completionBlock
114
+ */
115
+ - (void)handleOpenUniversalLink:(NSUserActivity *)userActivity standbyCallback:(CompletionBlock)completionBlock;
116
+
117
+
118
+ /**
119
+ * 获取交易token。
120
+ *
121
+ * @return 交易token,若无则为空。
122
+ */
123
+ - (NSString *)fetchTradeToken;
124
+
125
+
126
+ //////////////////////////////////////////////////////////////////////////////////////////////
127
+ //////////////////////////支付宝授权 2.0 相关接口////////////////////////////////////////////////
128
+ //////////////////////////////////////////////////////////////////////////////////////////////
129
+
130
+ /**
131
+ * 快登授权2.0
132
+ *
133
+ * @param infoStr 授权请求信息字串
134
+ * @param schemeStr 调用授权的app注册在info.plist中的scheme
135
+ * @param completionBlock 授权结果回调,需要调用方在appDelegate中调用processAuth_V2Result:standbyCallback:方法获取授权结果
136
+ * 若在授权过程中,调用方应用被系统终止则此block无效(此时会调用'processAuth_V2Result:standbyCallback:'传入的standbyCallback)
137
+ */
138
+ - (void)auth_V2WithInfo:(NSString *)infoStr
139
+ fromScheme:(NSString *)schemeStr
140
+ callback:(CompletionBlock)completionBlock;
141
+
142
+ /**
143
+ * 处理支付宝app授权后跳回商户app携带的授权结果Url
144
+ *
145
+ * @param resultUrl 支付宝app返回的授权结果url
146
+ * @param completionBlock 授权结果回调,用于处理跳转支付宝授权过程中商户APP被系统终止的情况
147
+ */
148
+ - (void)processAuth_V2Result:(NSURL *)resultUrl
149
+ standbyCallback:(CompletionBlock)completionBlock;
150
+
151
+
152
+ //////////////////////////////////////////////////////////////////////////////////////////////
153
+ //////////////////////////支付宝授权 1.0 相关接口////////////////////////////////////////////////
154
+ //////////////////////////////////////////////////////////////////////////////////////////////
155
+
156
+
157
+ /**
158
+ * 快登授权
159
+ * @param authInfo 授权相关信息
160
+ * @param completionBlock 授权结果回调,若在授权过程中,调用方应用被系统终止,则此block无效,
161
+ 需要调用方在appDelegate中调用processAuth_V2Result:standbyCallback:方法获取授权结果
162
+ */
163
+ - (void)authWithInfo:(APayAuthInfo *)authInfo
164
+ callback:(CompletionBlock)completionBlock;
165
+
166
+ /**
167
+ * 处理支付宝app授权后跳回商户app携带的授权结果Url
168
+ *
169
+ * @param resultUrl 支付宝app返回的授权结果url
170
+ * @param completionBlock 授权结果回调
171
+ */
172
+ - (void)processAuthResult:(NSURL *)resultUrl
173
+ standbyCallback:(CompletionBlock)completionBlock;
174
+
175
+
176
+ //////////////////////////////////////////////////////////////////////////////////////////////
177
+ //////////////////////////支付宝 h5 支付转 native 支付接口////////////////////////////////////////
178
+ //////////////////////////////////////////////////////////////////////////////////////////////
179
+ /**
180
+ * 从h5链接中获取订单串并支付接口(自版本15.4.0起,推荐使用该接口)
181
+ *
182
+ * @param urlStr 拦截的 url string
183
+ *
184
+ * @return YES为成功获取订单信息并发起支付流程;NO为无法获取订单信息,输入url是普通url
185
+ */
186
+ - (BOOL)payInterceptorWithUrl:(NSString *)urlStr
187
+ fromScheme:(NSString *)schemeStr
188
+ callback:(CompletionBlock)completionBlock;
189
+
190
+
191
+
192
+ //////////////////////////////////////////////////////////////////////////////////////////////
193
+ //////////////////////////支付宝 tid 相关信息获取接口/////////////////////////////////////////////
194
+ //////////////////////////////////////////////////////////////////////////////////////////////
195
+
196
+ /**
197
+ * 获取当前tid相关信息
198
+ *
199
+ * @return tid相关信息
200
+ */
201
+ - (NSString*)queryTidFactor:(AlipayTidFactor)factor;
202
+
203
+
204
+
205
+ //////////////////////////////////////////////////////////////////////////////////////////////
206
+ //////////////////////////支付宝支付环境相关信息接口//////////////////////////////////////////////
207
+ //////////////////////////////////////////////////////////////////////////////////////////////
208
+
209
+ /**
210
+ * 是否已经使用过
211
+ *
212
+ * @return YES为已经使用过,NO反之
213
+ */
214
+ - (BOOL)isLogined;
215
+
216
+ /**
217
+ * 获取当前版本号
218
+ *
219
+ * @return 当前版本字符串
220
+ */
221
+ - (NSString *)currentVersion;
222
+
223
+ /**
224
+ * 測試所用,realse包无效
225
+ *
226
+ * @param url 测试环境
227
+ */
228
+ - (void)setUrl:(NSString *)url;
229
+
230
+ /**
231
+ * 支付前主动更新本地配置
232
+ *
233
+ * @param block 更新请求结果回调
234
+ */
235
+ - (void)fetchSdkConfigWithBlock:(void(^)(BOOL success))block;
236
+
237
+ typedef void(^APLogBlock)(NSString *log);
238
+
239
+ /**
240
+ * 接收AlipaySDK的log信息
241
+ *
242
+ * @param logBlock 打印log的回调block
243
+ */
244
+ + (void)startLogWithBlock:(APLogBlock)logBlock;
245
+
246
+ /**
247
+ * 停止输出log,会释放logBlock
248
+ *
249
+ *
250
+ */
251
+ + (void)stopLog;
252
+
253
+ @end
@@ -0,0 +1,18 @@
1
+ //
2
+ // AlipaySDKModule.h
3
+ // AlipaySDK
4
+ //
5
+ // Created by mingsheng on 2023/11/14.
6
+ // Copyright © 2023 Alipay. All rights reserved.
7
+ //
8
+
9
+ #ifndef AlipaySDKModule_h
10
+ #define AlipaySDKModule_h
11
+
12
+ #import "AlipaySDK.h"
13
+ #import "APDeductSDK.h"
14
+ #import "APayAuthInfo.h"
15
+ #import "AFServiceCenter.h"
16
+ #import "AFServiceResponse.h"
17
+
18
+ #endif /* AlipaySDKModule_h */
@@ -0,0 +1,37 @@
1
+ //
2
+ // MQPWebViewPreManager.h
3
+ // AlipaySDK
4
+ //
5
+ // Created by intfre on 2025/3/5.
6
+ // Copyright © 2025 Alipay. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+
11
+ @interface MQPWebViewResourcesManager : NSObject
12
+ @property (assign, nonatomic) BOOL isEnable;
13
+ @property (nonatomic, strong) NSDictionary *nextH5ResourceInfo;
14
+
15
+ /// H5收银台提速相关,H5资源缓存,更新等
16
+ + (MQPWebViewResourcesManager *)shared;
17
+
18
+
19
+
20
+ /// 当前资源版本
21
+ - (NSString *)resourcesVersion;
22
+
23
+
24
+
25
+ /// 返回当前本地的homeHtmlw文件路径
26
+ - (NSString *)localDocumentPath;
27
+
28
+
29
+ /// 从H5资源信息中更新本地H5资源
30
+ /// - Parameters:
31
+ /// - h5ResourceInfo: H5资源信息
32
+ /// - callback: 结果回调
33
+ - (void)updateResourcesFileWithH5ResourceInfo:(NSDictionary *)h5ResourceInfo callback:(void(^)(BOOL success,NSString *errCode)) callback;
34
+
35
+
36
+ @end
37
+
@@ -0,0 +1,14 @@
1
+ //
2
+ // AlipaySDK.modulemap
3
+ // AlipaySDK
4
+ //
5
+ // Created by mingsheng on 2023/11/14.
6
+ // Copyright © 2023 Alipay. All rights reserved.
7
+ //
8
+
9
+ framework module AlipaySDK {
10
+ umbrella header "AlipaySDKModule.h"
11
+
12
+ export *
13
+ module * { export * }
14
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "expo-alipay-sdk",
3
+ "title": "Expo Alipay SDK",
4
+ "version": "0.0.1",
5
+ "description": "Alipay SDK for Expo and React Native - Payment integration. Official Alipay payment solution with iOS & Android support. 支付宝支付功能集成",
6
+ "main": "src/index",
7
+ "files": [
8
+ "src",
9
+ "ios",
10
+ "android",
11
+ "expo-alipay.podspec",
12
+ "app.plugin.js",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1",
17
+ "build": "echo \"Build completed successfully\" && exit 0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/your-username/expo-alipay.git",
22
+ "baseUrl": "https://github.com/your-username/expo-alipay"
23
+ },
24
+ "keywords": [
25
+ "alipay",
26
+ "支付宝",
27
+ "expo",
28
+ "expo-plugin",
29
+ "react-native",
30
+ "react-native-alipay",
31
+ "alipay-sdk",
32
+ "alipay-pay",
33
+ "支付宝支付",
34
+ "mobile-payment",
35
+ "ios",
36
+ "android",
37
+ "native-module",
38
+ "typescript"
39
+ ],
40
+ "author": "Your Name <your.email@example.com>",
41
+ "license": "MIT",
42
+ "dependencies": {
43
+ "events": "^3.3.0"
44
+ },
45
+ "types": "./src/index.d.ts",
46
+ "expo": {
47
+ "name": "expo-alipay",
48
+ "slug": "expo-alipay",
49
+ "version": "1.0.0",
50
+ "description": "为 Expo 和 React Native 提供支付宝支付功能的原生模块",
51
+ "platforms": [
52
+ "ios",
53
+ "android"
54
+ ],
55
+ "plugin": "./app.plugin.js"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/your-username/expo-alipay/issues"
59
+ },
60
+ "homepage": "https://github.com/your-username/expo-alipay#readme"
61
+ }
62
+
package/src/index.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ declare module 'expo-alipay-sdk' {
2
+ /**
3
+ * 注册支付宝应用
4
+ * @param appId 支付宝应用ID
5
+ * @param universalLink iOS Universal Link(可选,仅 iOS 需要)
6
+ */
7
+ export function registerApp(
8
+ appId: string,
9
+ universalLink?: string
10
+ ): Promise<boolean>;
11
+
12
+ /**
13
+ * 发起支付
14
+ * @param orderInfo 支付订单信息字符串(由服务端生成并签名)
15
+ */
16
+ export function pay(
17
+ orderInfo: string
18
+ ): Promise<PayResult>;
19
+
20
+ /**
21
+ * 获取 SDK 版本号
22
+ */
23
+ export function getVersion(): Promise<string>;
24
+
25
+ /**
26
+ * 判断支付宝是否已安装
27
+ */
28
+ export function isAlipayInstalled(): Promise<boolean>;
29
+
30
+ /**
31
+ * 支付结果
32
+ */
33
+ export interface PayResult {
34
+ resultStatus: string;
35
+ result: string;
36
+ memo: string;
37
+ }
38
+
39
+ /**
40
+ * 支付宝错误
41
+ */
42
+ export class AlipayError extends Error {
43
+ code: string;
44
+ result: string;
45
+ memo: string;
46
+ }
47
+
48
+ /**
49
+ * 添加事件监听器
50
+ */
51
+ export function addListener(
52
+ eventName: string,
53
+ listener: (...args: any[]) => void
54
+ ): void;
55
+
56
+ /**
57
+ * 一次性事件监听器
58
+ */
59
+ export function once(
60
+ eventName: string,
61
+ listener: (...args: any[]) => void
62
+ ): void;
63
+
64
+ /**
65
+ * 移除所有监听器
66
+ */
67
+ export function removeAllListeners(eventName?: string): void;
68
+ }
69
+
package/src/index.js ADDED
@@ -0,0 +1,164 @@
1
+ // main index.js
2
+ 'use strict';
3
+
4
+ import { DeviceEventEmitter, NativeModules, Platform } from 'react-native';
5
+ import { EventEmitter } from 'events';
6
+
7
+ let isAppRegistered = false;
8
+ const { Alipay } = NativeModules;
9
+
10
+ // Event emitter to dispatch request and response from Alipay.
11
+ const emitter = new EventEmitter();
12
+
13
+ DeviceEventEmitter.addListener('Alipay_Resp', (resp) => {
14
+ emitter.emit(resp.type, resp);
15
+ });
16
+
17
+ DeviceEventEmitter.addListener('Alipay_Req', (resp) => {
18
+ emitter.emit(resp.type, resp);
19
+ });
20
+
21
+ function wrapRegisterApp(nativeFunc) {
22
+ if (!nativeFunc) {
23
+ return undefined;
24
+ }
25
+ return (...args) => {
26
+ if (isAppRegistered) {
27
+ return Promise.resolve(true);
28
+ }
29
+ isAppRegistered = true;
30
+ return new Promise((resolve, reject) => {
31
+ nativeFunc.apply(null, [
32
+ ...args,
33
+ (error, result) => {
34
+ if (!error) {
35
+ return resolve(result);
36
+ }
37
+ if (typeof error === 'string') {
38
+ return reject(new Error(error));
39
+ }
40
+ reject(error);
41
+ },
42
+ ]);
43
+ });
44
+ };
45
+ }
46
+
47
+ function wrapApi(nativeFunc) {
48
+ if (!nativeFunc) {
49
+ return undefined;
50
+ }
51
+ return (...args) => {
52
+ if (!isAppRegistered) {
53
+ return Promise.reject(new Error('registerApp required.'));
54
+ }
55
+ return new Promise((resolve, reject) => {
56
+ nativeFunc.apply(null, [
57
+ ...args,
58
+ (error, result) => {
59
+ if (!error) {
60
+ return resolve(result);
61
+ }
62
+ if (typeof error === 'string') {
63
+ return reject(new Error(error));
64
+ }
65
+ reject(error);
66
+ },
67
+ ]);
68
+ });
69
+ };
70
+ }
71
+
72
+ /**
73
+ * `addListener` inherits from `events` module
74
+ * @method addListener
75
+ * @param {String} eventName - the event name
76
+ * @param {Function} trigger - the function when event is fired
77
+ */
78
+ export const addListener = emitter.addListener.bind(emitter);
79
+
80
+ /**
81
+ * `once` inherits from `events` module
82
+ * @method once
83
+ * @param {String} eventName - the event name
84
+ * @param {Function} trigger - the function when event is fired
85
+ */
86
+ export const once = emitter.once.bind(emitter);
87
+
88
+ /**
89
+ * `removeAllListeners` inherits from `events` module
90
+ * @method removeAllListeners
91
+ * @param {String} eventName - the event name
92
+ */
93
+ export const removeAllListeners = emitter.removeAllListeners.bind(emitter);
94
+
95
+ /**
96
+ * @method registerApp
97
+ * @param {String} appId - the app id
98
+ * @param {String} universalLink - universal link (iOS only)
99
+ * @return {Promise}
100
+ */
101
+ export const registerApp = wrapRegisterApp(Alipay.registerApp);
102
+
103
+ /**
104
+ * 支付
105
+ * @method pay
106
+ * @param {String} orderInfo - 支付订单信息字符串(由服务端生成)
107
+ * @return {Promise}
108
+ */
109
+ export function pay(orderInfo) {
110
+ return new Promise((resolve, reject) => {
111
+ if (!isAppRegistered) {
112
+ return reject(new Error('registerApp required.'));
113
+ }
114
+ Alipay.pay(orderInfo, (error) => {
115
+ if (error) {
116
+ return reject(new Error(error));
117
+ }
118
+ });
119
+ emitter.once('PayResult.Resp', (resp) => {
120
+ if (resp.resultStatus === '9000') {
121
+ resolve(resp);
122
+ } else {
123
+ reject(new AlipayError(resp));
124
+ }
125
+ });
126
+ });
127
+ }
128
+
129
+ /**
130
+ * 获取 SDK 版本号
131
+ * @method getVersion
132
+ * @return {Promise<String>}
133
+ */
134
+ export const getVersion = wrapApi(Alipay.getVersion);
135
+
136
+ /**
137
+ * 判断支付宝是否已安装
138
+ * @method isAlipayInstalled
139
+ * @return {Promise<Boolean>}
140
+ */
141
+ export const isAlipayInstalled = wrapApi(Alipay.isAlipayInstalled);
142
+
143
+ /**
144
+ * promises will reject with this error when API call finish with an error.
145
+ */
146
+ export class AlipayError extends Error {
147
+ constructor(resp) {
148
+ const message = resp.memo || resp.resultStatus || 'Unknown error';
149
+ super(message);
150
+ this.name = 'AlipayError';
151
+ this.code = resp.resultStatus;
152
+ this.result = resp.result;
153
+ this.memo = resp.memo;
154
+
155
+ // avoid babel's limition about extending Error class
156
+ // https://github.com/babel/babel/issues/3083
157
+ if (typeof Object.setPrototypeOf === 'function') {
158
+ Object.setPrototypeOf(this, AlipayError.prototype);
159
+ } else {
160
+ this.__proto__ = AlipayError.prototype;
161
+ }
162
+ }
163
+ }
164
+