payment
Payment模块管理支付功能,用于提供网页安全支付能力,支持通过Web接口进行支付操作。通过plus.payment可获取支付管理对象。
方法:
- getChannels: 获取支付通道
- request: 请求支付操作
对象:
- PaymentChannel: 支付通道对象
- OrderStatementIAP: IAP订单数据对象
- PaymentResult: 支付操作结果对象
- IAPProduct: IAP商品对象
- IAPProductInfo: 购买IAP商品对象
- IAPTransaction: 购买IAP商品交易信息对象
回调方法:
- ChannelsSuccessCallback: 获取支付通道成功回调
- IapRequestOrderSuccessCallback: 请求支付商品列表回调方法
- IapRestoreComplateRequestCallback: 请求已经购买的非消耗性商品和订阅商品回调方法
- PaymentSuccessCallback: 支付操作成功回调
- PaymentErrorCallback: 支付操作失败回调
权限:
permissions
{
// ...
"permissions":{
// ...
"Payment": {
"description": "支付"
}
}
}
PaymentChannel
支付通道对象
interface plus.payment.PaymentChannel{
attribute String id;
attribute String description;
attribute Boolean serviceReady;
function void installService();
// iOS iAP
function void requestOrder(ids, successCB, errorCB);
function void restoreComplateRequest(options, successCB);
}
说明:
PaymentChannel对象表示特定的支付通道,用于向系统请求支付操作。
属性:
- id: 支付通道标识
- description: 支付通道描述
- serviceReady: 支付通道服务是否安装
方法:
- installService: 安装支付通道依赖的服务
- requestOrder: 向IAP服务器请求支付订单
- restoreComplateRequest: 向IAP服务器请求已经购买的非消耗性商品和订阅商品
OrderStatementIAP
IAP订单数据对象
interface plus.payment.OrderStatementIAP {
attribute String productid;
attribute String username;
attribute String quantity;
}
说明:
描述IAP商品订单信息,如标识、数量等。
属性:
- productid: (String
类型
)商品的标识
- username: (String
类型
)购买用户名称
- quantity: (String
类型
)商品数量
PaymentResult
支付操作结果对象
interface plus.payment.PaymentResult {
attribute PaymentChannel channel;
attribute String tradeno;
attribute String description;
attribute String url;
attribute String signature;
attribute String rawdata;
}
说明:
PaymentResult对象表示支付操作返回结果,用于确认支付操作成功。
属性:
- channel: (PaymentChannel
类型
)支付通道对象
用于发起支付操作的支付通道对象。
- tradeno: (String
类型
)交易编号信息
如果支付平台不支持此数据则返回undefined。
- description: (Boolean
类型
)交易描述信息
如果支付平台不支持此数据则返回undefined。
- url: (Boolean
类型
)查找支付交易信息地址
用于向支付平台查询交易信息,如果支付平台不支持此数据则返回undefined。
- signature: (String
类型
)支付操作指纹信息
用于向支付平台查询支付订单信息,如果支付平台不支持此数据则返回undefined。
- rawdata: (String
类型
)支付平台返回的原始数据
如果支付平台返回key-value类型字符串,则组合成符合JSON格式的字符串。
IAPProduct
IAP商品对象
interface plus.payment.IAPProduct {
attribute String productid;
attribute String price;
attribute String title;
attribute String description;
}
说明:
描述IAP商品详细信息,如标识、价格、标题、描述信息等。
属性:
- productid: (String
类型
)商品的标识
- price: (String
类型
)商品的价格
- title: (String
类型
)商品标题
- description: (String
类型
)商品的描述信息
IAPProductInfo
购买IAP商品对象
interface plus.payment.IAPProductInfo {
attribute String productIdentifier;
attribute String quantity;
}
说明:
描述购买的IAP商品详细信息,如标识、数量等。
属性:
- productIdentifier: (String
类型
)商品的标识
- quantity: (String
类型
)商品的数量
IAPTransaction
购买IAP商品交易信息对象
interface plus.payment.IAPTransaction {
attribute IAPProductInfo payment;
attribute String transactionDate;
attribute String transactionIdentifier;
attribute String transactionReceipt;
attribute String transactionState;
}
说明:
描述购买的IAP商品交易详细信息,如购买商品信息、交易日期、订单标识等。
属性:
- payment: (String
类型
)购买商品的信息
- transactionDate: (String
类型
)购买商品的交易日期
- transactionIdentifier: (String
类型
)购买商品的交易订单标识
- transactionReceipt: (String
类型
)购买商品的交易收据
base64编码格式字符串数据。
- transactionState: (String
类型
)购买商品的交易状态
可取值:"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
ChannelsSuccessCallback
获取支付通道成功回调
void ChannelsSuccessCallback( channels ) {
// Get payment channels success code
}
说明:
当获取支付通道列表成功时的回调函数,用于返回终端支持的支付通道列表。
参数:
- channels:
(
Array
)
必选 数组,系统支持的支付通道PaymentChannel列表
返回值:
void : 无IapRequestOrderSuccessCallback
请求支付商品列表回调方法
void onsuccess( results ) {
// Payment success code
}
说明:
获取IAP商品列表信息成功时的回调函数,返回商品详细信息。
参数:
- results:
(
Array[
IAPProduct
]
)
必选 商品信息数据
返回值:
void : 无IapRestoreComplateRequestCallback
请求已经购买的非消耗性商品和订阅商品回调方法
void onsuccess( results ) {
// Payment success code
}
说明:
获取IAP商品列表信息成功时的回调函数,返回商品详细信息。
参数:
- results:
(
Array[
IAPTransaction
]
)
必选 已购买的非消耗性商品和订阅商品交易信息
返回值:
void : 无PaymentSuccessCallback
支付操作成功回调
void PaymentSuccessCallback ( result ) {
// Payment success code
}
说明:
当支付操作成功时的回调函数,用于返回支付操作的成功信息。
参数:
- result :
(
PaymentResult
|
IAPTransaction
)
必选 支付操作成功的信息
iOS平台使用IAP支付返回的数据类型为IAPTransaction。
返回值:
void : 无PaymentErrorCallback
支付操作失败回调
void PaymentErrorCallback(error){
// Payment error code
}
说明:
当支付操作失败时的回调函数,用于返回支付操作失败的错误信息。
参数:
- error:
(
DOMException
)
必选 支付操作失败错误信息,可通过error.code获取错误代码,具体错误码有各支付通道定义
支付宝支付错误代码如下: 62000,客户端未安装支付通道依赖的服务; 62001,用户取消支付操作; 62002,此设备不支持支付; 62003,数据格式错误; 62004,支付账号状态错误; 62005,订单信息错误; 62006,支付操作内部错误; 62007,支付服务器错误; 62008,网络问题引起的错误; 62009,其它未定义的错误。 微信支付错误代码如下: -1,一般错误; -2,用户取消; -3,发送失败; -4,认证被否决; -5,不支持错误。