# iOS App sdk-集成Apple Pay

### 前期准备

* 对接Asiabill客服，获取.csr文件
* 创建Merchant IDs: <https://developer.apple.com/account>
  * developer - Certificates, Identifiers & Profiles - Identifiers
    * 点击Identifiers右边的“+”，新建Merchant IDs
* 创建Apple Pay Payment Processing Certificate，使用上面获取的.csr文件生成
* 创建Apple Pay Merchant Identity Certificate，使用自己的.csr文件生成（注：不需要使用上面粘获取的.csr文件）
* 下载Apple Pay Merchant Identity Certificate，将.cer文件上传给客服，Asiabill将会进行托管。
* Merchant ID，证书都生成好之后，点击ID会展示这样的界面

  <figure><img src="https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FftrNOiJhidL3JLVtMw8S%2F1.png?alt=media&#x26;token=0ac44a49-142d-4876-a373-2729b5147d5a" alt=""><figcaption></figcaption></figure>

### 项目集成

* xCode部分
  * 点击xcode边栏工程 - TARGETS - Capability - 点击“+”，添加ApplePay

    <figure><img src="https://4182117768-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcSYgMg71VCxeEVhWhVFp%2Fuploads%2FuLAwpl9AvQtqZeZob3Wb%2F2.png?alt=media&#x26;token=cf955d66-f595-4c2f-bef8-8abd5cea7994" alt=""><figcaption></figcaption></figure>
  * 如上图勾选准备时创建的Merchant ID，并且更新profile文件
* 代码部分：
  * 在需要调用AsiabillPaySDK的文件中引入头文件

    ```
    #import <PassKit/PassKit.h>
    ```
  * 如果需要支持ApplePay，在创建orderInfo的时候需要加入下面代码：

    * 注：appleMerchantId，必须是在developer后端创建的id

    ```
    // 如果需要使用ApplePay，必须传入appleMerchantId -- 在dev后台生成
    order.appleMerchantId = @"merchant.com.applepay.asiabill";
    // 商品描述
    order.productDes = @"Asiabill";
    ```
  *

### 调试部分

* 需要自己准备测试用的Apple ID，并且改AppleID有绑定卡，能够支持支付
