StripeでApple payを使うためには、Stripe側でCert Signing Requestを作成し、Apple Developer Centerで発行した証明書をStripeに登録する必要があるのでその備忘録。
Stripeにアプリケーションを追加
まずはStripeにアクセスして 新規アプリケーションを登録
を押します。
https://dashboard.stripe.com/settings/payments/apple_pay
![stripe apple pay](/blog/2023/11/stripe_apple_pay.webp)
ボタンを押すとApple Developer Centerに登録するための Stripe.certSignningRequest
をダウンロードできます。
Apple Developer Centerへの登録
https://developer.apple.com/account/resources/identifiers/list/merchant
Certificates, Identifiers & ProfilesのIdentifiersにMerchant IDを登録します。
左上のプラスボタンから登録を進めます。
![apple identifiers](/blog/2023/11/apple_identifiers.webp)
登録はMerrchant IDsを選択
![apple merchant ids](/blog/2023/11/apple_merchant_ids.webp)
merchantのprefixは自動で付くようになっているので、merchant.[app domain]
で登録します。
![apple register merchant id](/blog/2023/11/apple_register_merchant_id.webp)
作成したら一覧に戻って、作ったIdentifiersを選択します。
Apple Pay Payment Processing Certificate
の Create Certificate
を選択
![apple edit merchant id](/blog/2023/11/apple_edit_merchant_id.webp)
Stripeからダウンロードした certSigningRequest
ファイルをアップロードします。
![apple upload cert](/blog/2023/11/apple_upload_cert.webp)
そうすると apple_pay.cer
という証明書がダウンロードできます。
Stripeに証明書の登録
証明書をダウンロードしたらStripeで apple_pay.cer
を登録します。
![stripe upload cert](/blog/2023/11/stripe_upload_cert.webp)
こうなっていれば完了です。
![stripe ios certs](/blog/2023/11/stripe_ios_certs.webp)
Xcodeでの登録
証明書の登録ができたら、最後にXcodeのCapabilitiesからApple Payに登録したmerchant idを追加すれば設定は完了です。
![xcode apple pay](/blog/2023/11/xcode_apple_pay.webp)
アプリ側での確認方法
アプリからはAPI経由でbooleanが返ってくるので、Apple Payをサポートしていたらボタンを表示などができます。
試している感じだとアカウントにApple Payのカードが登録されていたらtrueが返ってきました。
StripeAPI.deviceSupportsApplePay()
私はFlutter Stripe というライブラリ経由で使っているので、Dartではこうなります。
Stripe.instance.isPlatformPaySupported();