Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-zh
提交
cd714a98
unidocs-zh
项目概览
DCloud
/
unidocs-zh
通知
3593
Star
108
Fork
920
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
120
列表
看板
标记
里程碑
合并请求
108
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
unidocs-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
120
Issue
120
列表
看板
标记
里程碑
合并请求
108
合并请求
108
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cd714a98
编写于
1月 26, 2022
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update app-payment-stripe.md
上级
8b68bcf0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
114 addition
and
84 deletion
+114
-84
docs/app-payment-stripe.md
docs/app-payment-stripe.md
+114
-84
未找到文件。
docs/app-payment-stripe.md
浏览文件 @
cd714a98
###
# 开通
###
开通
*
[
登录stripe
](
https://dashboard.stripe.com/login
)
-
[
登录Stripe
](
https://dashboard.stripe.com/login
)
注册账号
*
完善公司信息
*
注册账号后可获取开发测试的API密钥(公钥、私钥),注意:需
[
激活账户
](
https://dashboard.stripe.com/account/onboarding
)
获取正式的API密钥
*
获取密钥等相关信息
*
设置
[
支付方式
](
https://dashboard.stripe.com/settings/payment_methods
)
更多信息详见
[
stripe开通文档
](
https://uniapp.dcloud.io/app-payment-stripe-open
)
更多信息详见
[
申请开通Stripe操作指南
](
https://uniapp.dcloud.io/app-payment-stripe-open
)
#### 配置
在manifest.json文件“App模块配置”项的“Payment(支付)”下,勾选“stripe支付”项并添加配置
### 配置
在manifest.json文件“App模块配置”项的“Payment(支付)”下,勾选“paypal支付”项并配置相关参数


配置说明:returnURL(只需配置iOS),格式为'your-app://stripe'(示例 hbuilder://stripe),'your-app'为应用的自定义scheme,参考:
[
配置一个自定义页面内跳转协议 (URL Scheme)
](
https://ask.dcloud.net.cn/article/64
)
#### 服务器生成订单
**参数说明**
服务器生成支付订单
[
参考stripeAPI
](
https://stripe.com/docs/payments/accept-a-payment
)
-
returnURL
Android平台使用,格式为"your-app://stripe"(示例 io.dcloud.test://stripe),'your-app'为应用的bundle id或其它自定义scheme,参考:
[
配置一个自定义页面内跳转协议 (URL Scheme)
](
https://ask.dcloud.net.cn/article/64
)
### 服务器生成订单
在 App 端调用支付前,需在业务服务器生成
[
PaymentIntent
](
https://stripe.com/docs/api/payment_intents
)
,详情可参考Stripe官方文档:
[
Add an endpoint
](
https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=payment-sheet#add-server-endpoint
)
激活账户前可通过POST请求Stripe官方沙盒服务器
[
https://stripe.com/docs/payments/accept-a-payment
](
https://stripe.com/docs/payments/accept-a-payment
)
,生成测试PaymentIntent,示例如下:
```
js
```
js
uni
.
request
({
uni
.
request
({
url
:
'
https://stripe-mobile-payment-sheet.glitch.me/checkout
'
,
//仅为示例
url
:
'
https://stripe-mobile-payment-sheet.glitch.me/checkout
'
,
//仅为示例
method
:
"
POST
"
,
method
:
"
POST
"
,
success
:(
res
)
=>
{
success
:(
res
)
=>
{
console
.
log
(
"
订单信息
"
+
res
.
data
);
console
.
log
(
"
订单信息
"
+
res
.
data
);
var
publishKey
=
res
.
data
.
publishableKey
;
var
publishKey
=
res
.
data
.
publishableKey
;
var
paymentIntent
=
res
.
data
.
paymentIntent
;
var
paymentIntent
=
res
.
data
.
paymentIntent
;
var
customer
=
res
.
data
.
customer
;
var
customer
=
res
.
data
.
customer
;
var
ephemeralKey
=
res
.
data
.
ephemeralKey
;
var
ephemeralKey
=
res
.
data
.
ephemeralKey
;
}
}
})
});
```
```
#### 应用内发起支付
### 应用内发起支付
订单信息参数如下
-
uni-app项目
| 参数名称 | 参数说明 | 必须 |
调用
[
uni.requestPayment(OBJECT)
](
https://uniapp.dcloud.io/api/plugins/payment?id=requestpayment
)
发起支付,OBJECT参数中provider属性值固定为
`stripe`
、orderInfo属性值为订单对象
|-------------|-------|-----|
-
5+ App项目
| publishKey | 公钥(获取方式详见stripe开通文档) | 是 |
调用
[
plus.payment.request(channel, orderInfo, successCB, errorCB)
](
https://www.html5plus.org/doc/zh_cn/payment.html#plus.payment.request
)
发起支付, channel参数为stripe支付对象,orderInfo参数为订单对象
| paymentIntent | 订单信息 | 是 |
| merchantName | 商户名称 |是 |
| customer | 如果要设置支付方式供以后使用,则必须将它绑定到一个 Customer | 否 |
| ephemeralKey | EphemeralKey的作用是让 SDK 临时访问 Customer | 否 |
| isAllowDelay | 是否支持延迟支付,默认不支持(将 isAllowDelay 设置为 true 后可使用一些较慢的支付方式,例如 SEPA 借记和 Sofort 对于这些支付方式,只有当 PaymentSheet 完成后才能知道最终的付款状态是成功还是失败。如果您允许这样,则通知客户您已确认他们的订单,但收到付款后才能履行(例如,发货)订单。) | 否 |
注:customer与ephemeralKey必须成对出现,只传其一无效
#### 订单对象参数说明
*
uni-app项目示例(provider填写stripe)
Object对象类型
```
js
uni
.
getProvider
({
| 属性 | 类型 | 必填 | 说明 |
service
:
'
payment
'
,
| :--- | :--- | :--- | :--- |
success
:
function
(
res
)
{
| customer | String | 否 | Stripe的
[
Customer
](
https://stripe.com/docs/api/customers
)
对象,如为同一用户执行定期重复性收款,并跟踪多笔收款 |
console
.
log
(
res
);
| ephemeralKey | String | 否 | Stripe的Customer Ephemeral Key,用于临时访问Customer |
if
(
~
res
.
provider
.
indexOf
(
'
stripe
'
))
{
| isAllowDelay | String | 否 | 是否支持延迟支付,默认不支持(将 isAllowDelay 设置为 true 后可使用一些较慢的支付方式,例如 SEPA 借记和 Sofort 对于这些支付方式,只有当 PaymentSheet 完成后才能知道最终的付款状态是成功还是失败。如果您允许这样,则通知客户您已确认他们的订单,但收到付款后才能履行(例如,发货)订单。) |
| merchantName | String | 是 | 商户名称 |
uni
.
request
({
| paymentIntent | String | 是 | Stripe的
[
PaymentIntent
](
https://stripe.com/docs/api/payment_intents
)
对象,对应服务器生成的支付订单 |
url
:
'
https://stripe-mobile-payment-sheet.glitch.me/checkout
'
,
| publishKey | String | 是 | 公钥,在Stripe注册账号后可获取 |
method
:
"
POST
"
,
success
:
(
res
)
=>
{
> 注意:customer与ephemeralKey必须成对出现,只传其一无效
console
.
log
(
res
.
data
);
uni
.
requestPayment
({
#### 示例代码
-
uni-app项目
```
js
//订单对象
var
orderInfo
=
{
"
customer
"
:
"
Stripe的Customer
"
,
//Customer
"
ephemeralKey
"
:
"
Stripe的Customer Ephemeral Key
"
,
//临时访问Customer的Key
"
isAllowDelay
"
:
true
,
//是否支持延迟支付 默认false
"
merchantName
"
:
"
DCloud
"
,
//商户名
"
paymentIntent
"
:
"
Stripe的PaymentIntent
"
,
//订单信息
"
publishKey
"
:
"
Public Key
"
,
//公钥
};
// 从Stripe测试服务器获取订单数据
uni
.
request
({
url
:
'
https://stripe-mobile-payment-sheet.glitch.me/checkout
'
,
method
:
"
POST
"
,
success
:
(
res
)
=>
{
orderInfo
=
{
"
customer
"
:
res
.
data
.
customer
,
"
ephemeralKey
"
:
res
.
data
.
ephemeralKey
,
"
isAllowDelay
"
:
true
,
"
merchantName
"
:
"
DCloud
"
,
"
paymentIntent
"
:
res
.
data
.
paymentIntent
,
"
publishKey
"
:
res
.
data
.
publishableKey
,
};
}
});
//...
//发起支付
uni
.
getProvider
({
service
:
'
payment
'
,
success
:
function
(
res
)
{
if
(
~
res
.
provider
.
indexOf
(
'
stripe
'
))
{
uni
.
requestPayment
({
"
provider
"
:
"
stripe
"
,
"
provider
"
:
"
stripe
"
,
"
orderInfo
"
:
{
"
orderInfo
"
:
orderInfo
,
"
publishKey
"
:
res
.
data
.
publishableKey
,
//公钥
"
paymentIntent
"
:
res
.
data
.
paymentIntent
,
//订单信息
"
customer
"
:
res
.
data
.
customer
,
//支付方式等信息
"
ephemeralKey
"
:
res
.
data
.
ephemeralKey
,
//信息key
"
isAllowDelay
"
:
true
,
//是否支持延迟支付 默认false
"
merchantName
"
:
"
数字天堂
"
,
//商户名
},
success
(
res
)
{
success
(
res
)
{
console
.
log
(
res
);
console
.
log
(
"
requestPayment Success:
"
+
JSON
.
stringify
(
res
)
);
},
},
fail
(
e
)
{
fail
(
e
)
{
console
.
log
(
e
);
console
.
log
(
"
requestPayment failed:
"
+
JSON
.
stringify
(
e
)
);
}
}
});
});
}
}
});
}
}
});
}
```
});
```
*
5+App项目示例
-
5+ App项目
```
js
```
js
//获取渠道
//订单对象,从服务器获取
var
stripeSev
=
null
;
var
orderInfo
=
{
plus
.
payment
.
getChannels
(
function
(
channels
)
{
"
customer
"
:
"
Stripe的Customer
"
,
//Customer
for
(
var
i
in
channels
)
{
"
ephemeralKey
"
:
"
Stripe的Customer Ephemeral Key
"
,
//临时访问Customer的Key
var
channel
=
channels
[
i
];
"
isAllowDelay
"
:
true
,
//是否支持延迟支付 默认false
if
(
channel
.
id
===
'
stripe
'
)
{
"
merchantName
"
:
"
DCloud
"
,
//商户名
stripeSev
=
channel
;
"
paymentIntent
"
:
"
Stripe的PaymentIntent
"
,
//订单信息
}
"
publishKey
"
:
"
Public Key
"
,
//公钥
}
};
},
function
(
e
)
{
//获取支付渠道
console
.
log
(
"
获取支付渠道失败:
"
+
e
.
message
);
var
stripeSev
=
null
;
});
plus
.
payment
.
getChannels
(
function
(
channels
){
//发起支付
for
(
var
i
in
channels
)
{
var
statement
=
{
var
channel
=
channels
[
i
];
"
publishKey
"
:
publishKey
,
//公钥
if
(
channel
.
id
===
'
stripe
'
)
{
"
paymentIntent
"
:
paymentIntent
,
//订单加密信息
stripeSev
=
channel
;
"
merchantName
"
:
"
数字天堂
"
,
//
}
"
customer
"
:
customer
,
}
"
ephemeralKey
"
:
ephemeralKey
,
//
//发起支付
"
isAllowDelay
"
:
true
,
//
plus
.
payment
.
request
(
stripeSev
,
orderInfo
,
function
(
result
)
{
};
var
rawdata
=
JSON
.
parse
(
result
.
rawdata
);
plus
.
payment
.
request
(
stripeSev
,
statement
,
function
(
result
)
{
console
.
log
(
"
支付成功
"
);
console
.
log
(
"
支付成功
"
);
},
function
(
e
)
{
},
function
(
e
)
{
console
.
log
(
"
支付失败:
"
+
e
.
message
);
console
.
log
(
"
支付失败:
"
+
JSON
.
stringify
(
e
)
);
});
});
},
function
(
e
){
console
.
log
(
"
获取支付渠道失败:
"
+
JSON
.
stringify
(
e
));
});
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录