braintreePay

paypalOneTimePayment isWalletAppInstalled authorizeAccountWithProfileID

概述

Braintree 成立于 2007 年,在过去的几年里曾获得6900 万美元融资。成立后,Braintree发展速度迅猛,目前已有 4000 家商户在使用 Braintree 的支付系统,每年处理的交易额超过 100 亿美元之巨。Braintree通过向商户收取 2.9% 的佣金和 30 美分手续费获得盈利。Braintree能够为需要使用移动支付服务的公司提供一站式服务 Braintree

PayPal已经以8亿美元的现金收购了 Braintree。且 PayPal 已经将其移动端支付服务器全部转移到 Braintree 平台。

此模块封装了 Braintree 移动支付功能。

集成 Braintree 支付需要先在 PayPal 后台控制面板创建 App,详情参考 [Get Started] ()

附:PayPal 服务器接入文档

创建 App 之后,需要获取授权 token。如下: A client token is a signed data blob that includes configuration and authorization information required by the . These should not be reused; a new client token should be generated for each request that’s sent to Braintree. For security, we will revoke client tokens if they are reused excessively within a short time period.

Your server is responsible for generating the client token, which contains all of the necessary configuration information to set up the client SDKs. When your server provides a client token to your client, it authenticates the application to communicate directly to Braintree.

Your client is responsible for .

支付流程简介

1.Your app or web front-end requests a client token from your server in order to initialize the client SDK

2.Your server generates and sends a client token back to your client with the server SDK

3.Once the client SDK is initialized and the customer has submitted payment information, the SDK communicates that information to Braintree, which returns a payment method nonce

4.You then send the payment method nonce to your server

5.Your server code and then uses the server SDK to create a transaction or perform other functions.

1.配置 文件,配置完毕,需通过云端编译生效,配置方法如下:**

  • 名称:braintreePay
  • 参数:urlScheme
  • 配置示例:
  • 字段描述:

    urlScheme:(必须配置)用于实现应用间跳转及数据交换,This scheme must start with your app’s Bundle ID and be dedicated to Braintree app switch returns. For example, if the app bundle ID is com.your-company.Your-App, then your URL scheme could be com.your-company.Your-App.payments(e.g. com.your-company.Your-App.payments://test).详见 官方文档

2.必须添加白名单,如下:

关于白名单解释详情参考 APICloud 官方文档之——-

关于Venmo

关于 Venmo 参见Overview

开通 Venmo 详情参考

关于 Venmo profiles ,以及

Server-Side Implementation

paypalOneTimePayment

启动PayPal的单一支付

paypalOneTimePayment({params},callback(ret))

param

  • 类型:字符串类型
  • 描述:授权,通过服务器获取

amount:

  • 类型:字符串类型
  • 描述:金额,单位分

currencyCode:

  • 类型:字符串类型
  • 描述:(可选项)用于事务的有效ISO货币代码,当您首次创建PayPal业务帐户时,您将只能为与您的业务帐户关联的国家传递默认货币。如果希望以其他货币显示事务,请参阅。
  • 默认:商户货币代码。如果未指定,则根据客户端令牌中的活动商户帐户选择货币代码

displayName:

  • 类型:字符串类型
  • 描述:(可选项)paypal流中显示商户名称
  • 默认:您的Braintree帐户上的公司名称

endPage:

  • 类型:数字类型
  • 描述:(可选项)支付完成后返回页面
  • 内部字段:1/账单页面,2/登陆页面,仅支持Android端
  • 默认:1

intent:

  • 类型:字符串类型
  • 描述:(可选项)付款意图
  • 默认:‘authorize’
  • 取值范围:
    • authorize:授权 稍后捕获的付款
    • sale:立即付款
    • order:创建订单

submitText:

  • 类型:字符串类型
  • 描述:(可选项)确定按钮文本,仅支持Android端

offerCredit:

  • 类型:布尔类型
  • 描述:(可选项)支付流程中突出提供PayPal信用
  • 默认:false

address:

  • 类型:JSON 对象类型
  • 描述:(可选项)用于结帐流的自定义送货地址
  • 内部字段:

    1. {
    2. recipientName:'', //字符串类型;地址名称
    3. streetAddress:'', //字符串类型;街道地址
    4. extendedAddress:'', //字符串类型;扩展信息
    5. locality:'', //字符串类型;地点
    6. region:'', //字符串类型;区
    7. countryCodeAlpha2:'', //字符串类型;国家代码
    8. phoneNumber:'', //字符串类型;手机号码,仅支持Android端
    9. postalCode:'' //字符串类型;,仅支持iOS端。Zip code or equivalent is usually required for countries that have them. For a list of countries that do not have postal codes please refer to http://en.wikipedia.org/wiki/Postal_code.
    10. }

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. eventType:'success', //字符串类型;交互事件类型
  3. //success:成功
  4. //err:发生错误
  5. PayPalAccountNonce: { //JSON对象;eventType 为 success 时有值
  6. nonce: //字符串类型;
  7. localizedDescription: //字符串类型;
  8. type: //字符串类型;
  9. isDefault: //布尔类型;
  10. email: //字符串类型;
  11. firstName: //字符串类型;
  12. lastName: //字符串类型;
  13. phone: //字符串类型;
  14. clientMetadataId: //字符串类型;
  15. payerId: //字符串类型;
  16. }
  17. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. code:, //数字类型;错误码
  3. msg:, //字符串类型;错误信息
  4. }

示例代码

  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.paypalOneTimePayment({
  3. token:'',
  4. amount:'2.2',
  5. intent:'sale',
  6. }, function(ret, err) {
  7. if (ret.eventType == 'success'){
  8. alert(JSON.stringify(ret));
  9. } else if (ret.eventType == 'cancel') {
  10. } else {
  11. alert(JSON.stringify(err));
  12. }
  13. });

可用性

iOS 系统

可提供的 1.0.0 及更高版本

paypalBillingAgreement

启动PayPal的账单协议支付

paypalBillingAgreement({params},callback(ret))

param

token:

  • 类型:字符串类型
  • 描述:授权,通过服务器获取

amount:

  • 类型:字符串类型
  • 描述:金额,单位分

currencyCode:

  • 类型:字符串类型
  • 描述:(可选项)用于事务的有效ISO货币代码,当您首次创建PayPal业务帐户时,您将只能为与您的业务帐户关联的国家传递默认货币。如果希望以其他货币显示事务,请参阅货币设置
  • 默认:商户货币代码。如果未指定,则根据客户端令牌中的活动商户帐户选择货币代码

displayName:

  • 类型:字符串类型
  • 描述:(可选项)paypal流中显示商户名称
  • 默认:您的Braintree帐户上的公司名称

endPage:

  • 类型:数字类型
  • 描述:(可选项)支付完成后返回页面,仅支持Android端
  • 默认:1
  • 取值范围:
    • 1:账单页面
    • 2:登陆页面

submitText:

  • 类型:字符串类型
  • 描述:(可选项)确定按钮文本,仅支持Android端

offerCredit:

  • 类型:布尔类型
  • 描述:(可选项)支付流程中突出提供PayPal信用
  • 默认:false

address:

  • 类型:JSON 对象类型
  • 描述:(可选项)用于结帐流的自定义送货地址
  • 内部字段:

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. eventType:'success', //字符串类型;交互事件类型
  3. //success:成功
  4. //cancel:取消
  5. //err:发生错误
  6. PayPalAccountNonce: { //JSON对象;eventType 为 success 时有值
  7. nonce: //字符串类型;
  8. localizedDescription: //字符串类型;
  9. type: //字符串类型;
  10. isDefault: //布尔类型;
  11. email: //字符串类型;
  12. firstName: //字符串类型;
  13. lastName: //字符串类型;
  14. phone: //字符串类型;
  15. clientMetadataId: //字符串类型;
  16. payerId: //字符串类型;
  17. }
  18. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. code:, //数字类型;错误码
  3. }
  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.paypalBillingAgreement({
  3. token:'',
  4. amount:'2.2',
  5. }, function(ret, err) {
  6. if (ret.eventType == 'success'){
  7. alert(JSON.stringify(ret));
  8. } else if (ret.eventType == 'cancel') {
  9. alert('取消');
  10. } else {
  11. alert(JSON.stringify(err));
  12. }
  13. });

可用性

可提供的 1.0.0 及更高版本

isWalletAppInstalled

当前设备是否安装 Venmo

isWalletAppInstalled(callback(ret))

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. status: //布尔类型;是否安装

示例代码

  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.isWalletAppInstalled(function(ret, err) {
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS 系统

可提供的 1.0.0 及更高版本

authorizeAccountAndVault

Initiates Venmo login via app switch, which returns a VenmoAccountNonce when successful.

authorizeAccountAndVault({params},callback(ret))

param

token:

  • 类型:字符串类型
  • 描述:授权,通过服务器获取

vault:

  • 类型:布尔
  • 默认:false
  • 描述: Whether to automatically vault the Venmo Account. Vaulting will only occur if a client token with a customer_id is being used.

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. code:, //数字类型;错误码
  3. msg:, //字符串类型;错误信息
  4. }
  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.authorizeAccountAndVault({
  3. token:'',
  4. vault:true
  5. }, function(ret, err) {
  6. alert(JSON.stringify(ret));
  7. });

可用性

iOS 系统

可提供的 1.0.0 及更高版本

authorizeAccountWithProfileID

Initiates Venmo login via app switch, which returns a VenmoAccountNonce when successful.

authorizeAccountWithProfileID({params},callback(ret))

param

token:

  • 类型:字符串类型
  • 描述:授权,通过服务器获取

vault:

  • 类型:布尔
  • 默认:false
  • 描述: Whether to automatically vault the Venmo Account. Vaulting will only occur if a client token with a customer_id is being used.

profileID:

  • 类型:字符串类型
  • 描述:The Venmo profile ID to be used during payment authorization. Customers will see the business name and logo associated with this Venmo profile, and it will show up in the Venmo app as a “Connected Merchant”. Venmo profile IDs can be found in the Braintree Control Panel. 不传则 use the default Venmo profile.

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. eventType:'success', //字符串类型;交互事件类型
  3. //success:成功
  4. //cancel:取消
  5. //err:发生错误
  6. VenmoAccountNonce: { //JSON对象;eventType 为 success 时有值
  7. nonce: //字符串类型;
  8. localizedDescription: //字符串类型;
  9. type: //字符串类型;
  10. isDefault: //布尔类型;
  11. }
  12. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. code:, //数字类型;错误码
  3. msg:, //字符串类型;错误信息
  4. }

示例代码

  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.authorizeAccountWithProfileID({
  3. token:'',
  4. profileID:'',
  5. }, function(ret, err) {
  6. alert(JSON.stringify(ret));
  7. });

可用性

iOS 系统

可提供的 1.0.0 及更高版本

collectDeviceData

获取设备信息,在服务器端进行 Venmo 扣款时需要

collectDeviceData({params},callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. var braintreePay = api.require('braintreePay');
  2. braintreePay.collectDeviceData(function(ret) {
  3. alert(JSON.stringify(ret));

可用性

可提供的 1.0.0 及更高版本