Apple Pay 申請流程手把手教學

Michael Revlis
10 min readMar 31, 2022

Apple Pay 的一些相關知識可以先參考 一次看懂 Apple Pay 惱人的啟用設定和專有名詞

本篇只講流程操作:
Step 1: 註冊 merchant ID
Step 2: 產出 CSR(手動 or openssl)
Step 3: 用 CSR 向 Apple 申請 Apple Pay payment certificate
Step 4: 在欲使用 Apple Pay 的 app ID 上綁定 merchant ID
Step 5: 更新 Xcode 專案(optional)

Step 1: 註冊 merchant ID

向 Apple 申請一組用來代表商家可接受付款的 ID。先登入 Apple Developer Account,找到 Certificates, Identifiers & Profiles,再選擇 identifiers,此時右上角選 Merchant IDs 會看到以下的畫面,點選 Register a Merchant ID 就可以註冊 merchant ID 了。

path: Apple Developer Account > Certificates, Identifiers & Profiles > identifiers > Merchant IDs > Register a Merchant ID

merchant ID 的命名上是有規範的,必須要以 merchant. 開頭,例如:merchant.demoapp.mycompany.com。順帶一提, description 是不能有特殊符號,底線 _也不行。

另外說明一下,每個 Apple 帳號是可以申請多組 merchant ID 的,其實務上的應用可能如下:

每個 app 可以綁定多組 merchant ID:例如你的 app 是一個商城,上面有 A, B, C 三個賣家,因各自的收款對象、可接受的國際信用卡組織不同等商業面需要,故有必要分開來設定。則可以申請三個不同的 merchant IDs,並在專案的程式碼中針對不同的 merchant ID 指定不同的國際信用卡組織 supportedNetworks(ex. .visa, .masterCard),或是可接收的收單類型merchantCapabilities(ex. .capability3DS, .capabilityDebit

每個 merchant ID 可以綁定在多個 app 上:例如你的公司針對不同客群的使用習慣,共出了兩個 app,此時就可以只申請一組 merchant ID,並讓這兩個 app 都綁定同一組 merchant ID。又或者你也在網頁上實作了 Apple Pay,則網頁跟 app 的 merchant ID 也可以使用同一個。

Step 2: 產出 CSR (certificate signing request)

option 1: 手動操作

打開 Keychain > 左上角鑰匙圈存取 > 憑證輔助程式 > 從憑證授權要求憑證

輸入電子郵件一般名稱,選擇 儲存到磁碟指定密鑰配對資訊

指定儲存的檔名、位置

選擇密鑰配對資訊,再按下「繼續」後就完成了
* 密鑰大小:256 bit
* 演算法:ECC

option 2: command line 操作 (openssl)

下述指令會產出一個使用 ECC 演算法(prime256v1)的 private key(產出的檔名叫 private.key

openssl ecparam -out private.key -name prime256v1 -genkey

使用剛剛得到的 private.key 去產出一個大小為 256 bit 的 CSR(產出的檔名叫 request.csr)

openssl req -new -sha256 -key private.key -nodes -out request.csr

Step 3: 用 CSR 向 Apple 申請 Apple Pay payment certificate

再次來到 Apple Developer Account > Certificates, Identifiers & Profiles > identifiers > Merchant IDs 點選剛剛在 Step 1 註冊的 merchant ID,會看到如下畫面,選擇 Create Certificate

如果是第一次幫這個 merchant ID 做設定的話,會跳出Will payment associated with ... be processed exclusively in China?,這指的是當前的 merchant ID 相關的付款只在 China 使用,根據你自己的需求,如果是在 China 以外的地區皆要選擇 NO

上傳剛剛 Step 2 產出的 CSR。

接著順著流程走 Continue > Download > Done,就可以下載到 Apple Pay payment certificate,檔名應為預設的 apple_pay.cer。同時我們也可以在 Apple Developer Account > Certificates, Identifiers & Profiles > Certificates 可看到多一張 Name 為 Step 1 產的 Merchant ID 的 certificate,且它的 Type 是 Apple Pay Payment Processing。

Step 4: 在欲使用 Apple Pay 的 app ID 上綁定 merchant ID

在 Apple Developer Account > Certificates, Identifiers & Profiles > Identifiers > App ID 找到欲使用 Apple Pay 的 app,點進去後在 Capabilities 這邊我們要把 Apple Pay Payment Processing 給 enabled。

打勾後右邊的 Configure 會變成 Edit,注意這邊的 Enabled Merchant IDs 旁邊括號的數字是 0,意味著這個 app 雖然有啟用 Apple Pay,但卻沒有綁定任何的 merchant ID。

點擊 Edit 後就可以選擇此 app 想要綁定的 merchant ID(複選)。這邊也是 Step 1 中所說的,如果一個 app 想要有多組 merchant IDs,就是在這裡設定。

按下 Continue 後會出現以下這個警告,別緊張。由於 app ID 的 capability 變了,所以連帶也要更新 provisioning profile,並用新的 provisioning profile 打包新的 app 並送審,如此以來新版的 app 使用者才可以使用者個功能。所以這邊我們就放心地按下 Confirm 就好。

至於關於 signing, CSR, certificate, provisioning profile 之間的關係,這邊有詳盡的說明。或參考我另一篇輕鬆一點的介紹文章:

順帶一提,沒有指定 merchant 就代表這個 Apple Pay 沒有處理收款的對象,就像是你買了汽車(app ID),申請了營業用車牌(merchant ID),但卻沒有向主管機關(Apple)登記這個車牌是要給這部汽車用的,所以是無法上路載客。故如果沒有綁定 merchant ID,或是 merchant ID 中沒有有效的 payment certificate 的話,你的 app 雖然還是可以叫出 Apple Pay payment sheet,但在使用者同意付款授權後會看到以下的錯誤訊息(還是可以硬開車上路,但遇到臨檢就會被攔下來):

Step 5: 更新 Xcode 專案(optional)

這個步驟其實是非必要的,因為一般情況下不論是使用 Xcode 的 automatically manage signing 或是使用其它 signing 自動化工具(如 fastlane),只要確保 archive 時會使用新的 provisioning profile 即可。至於 Xcode 專案的 capabilities 有沒有更新則沒有關係。但如果你想要在 Xcode 上先試跑 Apple Pay 看看的話,就還是得設定。

打開 Xcode 並找到要使用 Apple Pay 的 target,選擇 Signing & Capabilities,由於 capabilities 預設是沒有 Apple Pay 的所以我們要新增它,並且輸入 Step 1 產的 merchant ID。

另外剛剛 Step 4 最後面有提示我們 provisioning profile 會被更新,所以我們也要去 Apple Developer Account > Certificates, Identifiers & Profiles > Profiles 中找到我們的 provisioning profile,下載下來並 import 到 Xcode 專案中。

以上就是如何產生、設定 Apple Pay 的 merchant ID, payment certificate , capabilities 和 provisioning profile。

至於想看官方的流程說明可以參考:

https://developer.apple.com/library/archive/ApplePay_Guide/Configuration.html#//apple_ref/doc/uid/TP40014764-CH2-SW1

https://help.apple.com/developer-account/#/devb2e62b839?sub=dev103e030bb

--

--