braintreeApplePayPlus

概述

Apple Pay 是苹果公司在2014苹果秋季新品发布会上发布的一种基于 NFC 的手机支付功能,于2014年10月20日在美国正式上线。2016年2月18日凌晨5:00, Apple Pay 业务在中国上线。

Apple Pay 系统要求

iOS 需升级到12.0及以上,WatchOS 需要2.1或更高版本。

Apple Pay 使用方法

使用 Apple Pay 需要在苹果系统自带的 Wallet 程序里添加银行卡。iPhone 用户点击进入 Wallet 后,点击屏幕右上方的+号,再点击“下一步”就可进入申请页面,然后将银行卡正面放置在iPhone摄像头前,使卡面出现在屏幕的提示框内,系统会自动识别卡号,当然也可以手工输入卡号,接下来需要手工输入姓名、卡片有效期与安全码,还要阅读业务须知并选择接受。添加卡片成功后需激活才能使用,客户要确认手机号,并接收和输入验证码,才能成功激活。

如果需要在 Apple Watch 上添加,只要在相关联的 iPhone 上打开 Watch APP,轻点“Wallet 与 Apple Pay”,再轻点“添加信用卡或借记卡”,也可同样进行设置。需要注意的是,只有iOS9.2以上的版本才支持 Apple Pay。

同一台设备可以添加多张银行卡。工行表示,同一台苹果设备可添加5张信用卡,首张添加卡即为默认卡。客户可以在 “Wallet” APP 中通过长按卡片并将该卡排列为首位的方式将该卡设为默认付款卡,也可在“设置- Wallet 与 Apple Pay”功能中设置默认付款卡。

Apple Pay 分为线上支付和线下支付。线下支付不需要手机接入互联网,也不需要点击进入APP,甚至无须唤醒显示屏,只要将iPhone 靠近有银联闪付标志的读卡器,并将手指放在HOME键上验证指纹,即可进行支付。也可以在iPhone 处于黑屏锁定状态时,轻点两下主屏幕按钮进入 Wallet,快速进行购买。如果交易终端显示需要输入密码,还需要输入银行卡的交易密码。只需一两秒钟就可以完成Apple Pay 支付。

本原生插件封装了 Apple Pay 的线上支付功能,开发者只需几行代码,即可把苹果支付功能集成至自己的app内。用户使用自己的 app 购买商品时,可选择使用 Apple Pay 支付方式进行支付自己所购买的商品。

提醒:如果你在你的 APP 中销售的是电子产品或者虚拟货币,你应该使用内购方式(iap)而不是 App Pay 去销售你的东西。你可以使用 Apple Pay 销售你的实体商品和服务。

Apple Pay 上线国家

  • 美国
  • 英国
  • 加拿大
  • 澳大利亚
  • 中国

Apple Pay 支付供应商

苹果公司强烈建议开发者选择支持 Apple Pay 并提供 SDK 的支付供应商。当然您也可以提供自己的服务器端解决方案,以用于从您的 App 接收付款、解密付款令牌并与支付供应商进行互动。信用卡和借记卡付款的处理可能非常复杂。如果您不具备相应的专业知识和系统,又希望您的 App 支持 Apple Pay,使用支付供应商提供的 SDK 是最为便捷可靠的一种方式。本原生插件即是封装了 Braintree 的 Apple Pay 支付 SDK。其支付的付款流程参考 Braintree 官网文档

Step 1 Your front-end requests a client token from your server and initializes the client SDK.

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

Step 3 The customer submits payment information, the client SDK communicates that information to Braintree and returns a payment method nonce.

Step 4 Your front-end sends the payment method nonce to your server.

Step 5 Your server code receives the payment method nonce and then uses the server SDK to create a transaction.

Availability

braintreeApplePayPlus 原生插件使用攻略

步骤一、成为Braintree支付入网商户

详情参考Apple Pay certificate request and provisioning

步骤二 、登录 Braintree 服务平台,通过服务平台申请 CSR

a、关于商户 CSR

接 Apple Pay 在线支付的商户,须生成 Apple Pay 专用的 CSR 文件并提及至苹果开发者网站进行签名,以签署证书,取得 Apple Pay 的访问权限。获取 CSR 方法:

Download your CSR (certificate signing request) from the Control Panel

    1. Click the gear icon in the top right corner, select Processing from the drop-down menu
    1. Scroll to Apple Pay, and click the toggle to enable this payment method
    1. Select the Options link and click the +Add link to download the CSR from the certificate management page
  • Note: If you are unable to access this information, contact your Control Panel admin. You may need a different Control Panel role.

步骤三、苹果证书及描述文件

  • 1.前往苹果开发者中心的Certificates, Identifiers, and Profiles部分并且创建一个新的商家ID,然后编辑此ID,编辑时需上传从 Braintree 下载的 CSR 文件(braintree_apple_pay.certSigningRequest)。注意此 ID 需要在支付时作为 mID 传给原生插件,其一般格式为:merchant.com.app名。创建完成后下载到 Mac 电脑,然后上传到 Braintree。

  • 2.接下来创建苹果证书,并创建一个新的苹果打包证书。这需要向苹果公司上传自己本地生成的CSR文件(CertificateSigningRequest.certSigningRequest)。创建成功后下载到本地,然后双击安装,在钥匙串导出为p12证书,留作上传YonBuilder移动开发平台用。

  • 3.创建App ID(包名,既bundle ID),注意创建时勾选 Apple Pay 功能。App ID 即是我们平台上称之为包名的 id,其一般格式为:com.公司名.app名。App ID 创建完成后要编辑其 Apple Pay 功能,此编辑过程需要勾选1过程创建的mID。创建完成后,点击该App ID,然后编辑它,使之与步骤1创建的 merchant ID关联。

  • 4.创建描述文件(Provisioning Profiles),此描述文件(mobileprovision文件)需要上传 Yonbuilder 移动开发平台编译服务器。此过程需要勾选3过程创建的App ID,以及2过程创建好的苹果证书(需安装mac电脑上后在钥匙串中导出为p12文件,然后上传 YonBuilder移动开发平台 编译服务器)。

  • 5.创建 entitlements 文件,Yonbuilder 移动开发平台上的开发者,可通过此文件告诉编译服务器开通苹果支付功能。配置方法参考论坛帖子。配置示例如下:

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
            <key>com.apple.developer.healthkit</key>
            <true/>
            <key>com.apple.developer.in-app-payments</key>
            <array>
                <string>merchant.com.builder</string>
            </array>
        </dict>
        </plist>
    

    其中 merchant.com.builder 为第一步申请的商家ID。<key>com.apple.developer.healthkit</key>

    <true/> 是开通健康功能,与本原生插件无关,若开发者同时使用了多个需要配置 entitlements 文件的原生插件,可如上述示例继续添加。

    Certificate renewal

支付流程

参考 Braintree 官方 文档

步骤四、服务器端开发

服务器端开发 Braintree 官网文档

注意:使用本原生插件必须云编译或自定义loader

isSupportPayments

判断手机是否支持 Apple Pay 功能

isSupportPayments(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
{
    status:			//布尔类型;支付环境判断,true|false
}

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.isSupportPayments(function(ret) {
    if (ret) {
        api.alert({msg:JSON.stringify(ret)});
    } 
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

canMakePayments

判断手机是否已加载有可用的支付卡片

包括 Visa 卡、Master 卡、Amex 卡、Discover 卡

canMakePayments(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
{
    status:			//布尔类型;支付环境判断,true|false
}

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.canMakePayments(function(ret) {
    if (ret) {
        api.alert({msg:JSON.stringify(ret)});
    }  
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

addCard

跳转到钱包设置添加银行卡、信用卡

addCard()

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.addCard();

可用性

iOS 系统

可提供的 1.0.0 及更高版本

initWithToken

初始化

initWithToken({params},callback(ret))

params

token:

  • 类型:字符串
  • 描述:从服务器获取的token

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
{
    status:			//布尔类型;是否初始化成功,true|false
}

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.initWithToken({
    token:''
},function(ret) {
    if (ret) {
        api.alert({msg:JSON.stringify(ret)});
    }  
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

paymentRequest

发起支付请求

paymentRequest({params}, callback(ret, err))

params

countryCode:

  • 类型:字符串
  • 描述:The merchant's ISO country code.

currencyCode:

  • 类型:字符串
  • 描述:Currency code for this payment.

merchantIdentifier:

  • 类型:字符串
  • 描述:Identifies the merchant, as previously agreed with Apple. Must match one of the merchant identifiers in the application's entitlement.

items:

  • 类型:数组
  • 描述:商品列表
  • 内部字段:
[{
   name:'',         //字符串类型;商品名字
   price:''         //字符串类型;商品价钱
}]

supportedNetworks:

  • 类型:数组
  • 描述:商户支持的支付网络
  • 取值范围:
  • Amex
  • CartesBancaires
  • ChinaUnionPay
  • Discover
  • Eftpos
  • Electron
  • IDCredit
  • Interac
  • JCB
  • Maestro
  • MasterCard
  • PrivateLabel
  • QuicPay
  • Suica
  • Visa
  • VPay
  • 默认:['Visa','MasterCard','Amex','Discover']

merchantCapabilities:

  • 类型:数组
  • 描述:(可选项)商户的支付处理能力
  • 取值范围:
  • 3DS
  • EMV
  • Credit
  • Debit
  • 默认:['3DS','EMV','Credit','Debit']

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
{
    status:      //布尔类型;是否请求支付成功(不是支付是否成功)
}

err:

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

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.paymentRequest({
    items: [{name:'builder T恤',price:'99.99'}],
    merchantId: 'merchent.com.builder',
    countryCode: '',
    currencyCode:''
}, function(ret, err) {
    if (ret. status) {
        api.alert({msg:JSON.stringify(ret)});
    } else {
        api.alert({msg:JSON.stringify(err)});
    }
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

didAuthorizePaymentListener

获取 nonce 监听,成功获取 nonce 后开始发到服务器端扣款

didAuthorizePaymentListener(callback(ret,err))

callback(ret,err)

ret:

  • 类型:JSON 对象
  • 内部字段:
{
   status:,                       //布尔类型;是否成功返回nonce
    tokenizedApplePayPayment: {    //JSON对象;
       binData: {                  //JSON对象;The BIN data for the card number associated with this nonce
          prepaid:'',              //字符串类型;Whether the card is a prepaid card. Possible values: Yes/No/Unknown
          healthcare:'',           //字符串类型;Whether the card is a healthcare card. Possible values: Yes/No/Unknown
          debit:'',                //字符串类型;Whether the card is a debit card. Possible values: Yes/No/Unknown
          durbinRegulated:'',      //字符串类型;A value indicating whether the issuing bank's card range is regulated by the Durbin Amendment due to the bank's assets. Possible values: Yes/No/Unknown
          commercial:'',           //字符串类型;Whether the card type is a commercial card and is capable of processing Level 2 transactions. Possible values: Yes/No/Unknown
          payroll:'',              //字符串类型;Whether the card is a payroll card. Possible values: Yes/No/Unknown
          issuingBank:'',          //字符串类型;The bank that issued the credit card, if available.
          countryOfIssuance:'',    //字符串类型;The country that issued the credit card, if available.
          productId:''             //字符串类型;The code for the product type of the card (e.g. `D` (Visa Signature Preferred), `G` (Visa Business)), if available.
       },
      nonce:'',                   //字符串类型;The one-time use payment method nonce
      localizedDescription:'',    //字符串类型;A localized description of the payment info
      type:'',                    //字符串类型;The type of the tokenized data, e.g. PayPal, Venmo, MasterCard, Visa, Amex
      isDefault:                  //布尔类型;True if this nonce is the customer's default payment method, otherwise false.
    }
}

err:

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

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus. didAuthorizePaymentListener(function(ret,err) {
    if (ret.status) {
        api.alert({msg:JSON.stringify(ret)});
    } else {
        api.alert({msg:JSON.stringify(err)});
    }
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

didFinishListener

监听完成事件

didFinishListener(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 描述:监听完成事件,只有事件,没有参数

示例代码

var braintreeApplePayPlus = api.require('braintreeApplePayPlus');
braintreeApplePayPlus.didFinishListener(function() {
    alert('支付完成');
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

setApplePayStatus

设置苹果支付状态

setApplePayStatus({params}, callback(ret, err))

params

status:

  • 类型:字符串
  • 描述:支付状态
  • 内部字段:
    • success:成功
    • failure:失败

示例代码

var braintreeeApplePay = api.require('braintreeeApplePay');
braintreeeApplePay.setApplePayStatus({
    status: 'success'
});

可用性

iOS 系统

可提供的 1.0.0 及更高版本

是否仍需要帮助? 请保持联络!
最后更新于 2024/04/24