Skip to content

Commit

Permalink
add sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
zakzheng committed Aug 5, 2019
1 parent 8ecc63d commit 36a7347
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -88,6 +88,10 @@ try {
}
```

### Alipay.setAlipaySandbox(isSandbox)

- `isSandbox` {boolean} Whether to open sandbox. Must be payed before use. See [使用沙箱环境](https://docs.open.alipay.com/200/105311)

### Alipay.pay(orderStr)

- `orderStr` {String} Order info in query string format. Must be signed before use. See [App payment request params description](https://docs.open.alipay.com/204/105465/).
Expand Down Expand Up @@ -121,6 +125,8 @@ import Alipay from '@0x5e/react-native-alipay';

// APP支付
try {
// 打开沙箱
Alipay.setAlipaySandbox(true)
let orderStr = 'app_id=xxxx&method=alipay.trade.app.pay&charset=utf-8&timestamp=2014-07-24 03:07:50&version=1.0&notify_url=https%3A%2F%2Fapi.xxx.com%2Fnotify&biz_content=%7B%22subject%22%3A%22%E5%A4%A7%E4%B9%90%E9%80%8F%22%2C%22out_trade_no%22%3A%22xxxx%22%2C%22total_amount%22%3A%229.00%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&sign_type=RSA2&sign=xxxx'; // get from server, signed
let response = await Alipay.pay(orderStr);
console.info(response);
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/java/com/reactlibrary/AlipayModule.java
@@ -1,6 +1,7 @@

package com.reactlibrary;

import com.alipay.sdk.app.EnvUtils;
import com.alipay.sdk.app.H5PayCallback;
import com.alipay.sdk.util.H5PayResultModel;
import com.alipay.sdk.app.AuthTask;
Expand Down Expand Up @@ -42,6 +43,16 @@ public void run() {
thread.start();
}

// 添加沙箱模式
@ReactMethod
public void setAlipaySandbox(Boolean isSandbox) {
if(isSandbox){
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
}else {
EnvUtils.setEnv(EnvUtils.EnvEnum.ONLINE);
}
}

@ReactMethod
public void pay(final String orderInfo, final Promise promise) {
Runnable runnable = new Runnable() {
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Expand Up @@ -10,6 +10,9 @@ declare namespace Alipay {

function authWithInfo(infoStr: string): IResult;

// 设置沙箱模式
function setAlipaySandbox(isSandbox: boolean): void

function pay(infoStr: string): IResult;

function payInterceptorWithUrl(infoStr: string): {
Expand Down

0 comments on commit 36a7347

Please sign in to comment.