使用 swift 和 flutter 集成 Stripe SDK

Stripe SDK integration using swift and flutter

我正在尝试使用 flutter 将 Apple Pay 集成到 iOS 中。我正在使用方法通道与 swift 通信并完成付款流程。我已经按照 link

中的文档进行操作

但是,我相信我卡在了最后的部分,我不明白如何继续流程。由于我使用的是 flutter UIs,因此我不需要 iOS ViewControllers。

这是我目前在 AppDelegate.swift:

中尝试过的代码
func handleApplePayButtonTapped(result: FlutterResult){
    let merchantIdentifier = "my.apple.merchant.id"
    let paymentRequest = Stripe.paymentRequest(withMerchantIdentifier:merchantIdentifier, country:"US", currency:"USD")
    paymentRequest.paymentSummaryItems = [
    PKPaymentSummaryItem(label:"Fancy Hat", amount:50.00),
    PKPaymentSummaryItem(label:"iHats, Inc", amount:50.00),
    ]

    if Stripe.canSubmitPaymentRequest(paymentRequest){
        //next steps ???
        result(String("Can submit payment request"))
    }else{
        result(String("Can't submit payment request"))
    }
}

我在 flutter 中调用此代码 UI 使用此代码:

Future<void> _doPayment() async {
String returnMsg;
try {
  final bool result = await platform.invokeMethod('checkIfDeviceSupportsApplePay');
  if(result){
    final String status = await platform.invokeMethod('handleApplePayButtonTapped');
    print(status);
  }
  returnMsg = '$result';
} on PlatformException catch (e) {
  returnMsg = "Failed: '${e.message}'.";
}
print(returnMsg);}

我已经有一个 Stripe 可发布密钥以及一个 Heroku 部署的后端。如果你检查了我的 swift 代码,你会看到我现在卡在哪里。

我已经理解了流程,剩下要做的是

我对 swift 语言很陌生,代码示例对我继续学习很有帮助。

谢谢。

您似乎在关注 Stripe Custom iOS 集成,使用本机 PKPaymentAuthorizationViewController。

您应该在此处通读集成步骤:https://stripe.com/docs/mobile/ios/custom#apple-pay

基本上,您接下来的步骤是

  • 使用 paymentRequest 实例化 PKPaymentAuthorizationViewController
  • 将自己设为它的代表
  • 呈现 PKPaymentAuthorizationViewController
  • 实施相关委托方法以取回 Apple Pay 令牌 (PKToken)
  • 将 PKToken 转换为 STPToken(一种 Stripe 令牌)

以上 link 中详细介绍了所有这些步骤和更多步骤。