ios Apple Pay集成- Swift

gdrx4gfi  于 2023-02-10  发布在  iOS
关注(0)|答案(1)|浏览(220)

我正在整合apple pay。我正在遵循apple pay文档。这是我的代码。

import UIKit
import PassKit

class ApplePayViewController: UIViewController {

@IBOutlet var lblLoading : UILabel!
@IBOutlet var loader : UIActivityIndicatorView!

var totalAmount = "100.0"
let paymentRequest = PKPaymentRequest()
override func viewDidLoad() {
    super.viewDidLoad()
    // Set up the payment request
    paymentRequest.merchantIdentifier = "merchant.com.apple.example"
    paymentRequest.supportedNetworks = [.visa, .masterCard, .amex, .discover]
    paymentRequest.merchantCapabilities = .capability3DS
    paymentRequest.countryCode = "US"
    paymentRequest.currencyCode = "USD"
    
    // Add a payment item
    let item = PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(string: totalAmount))
    paymentRequest.paymentSummaryItems = [item]
    
    // Check if the device is capable of making payments
    if PKPaymentAuthorizationViewController.canMakePayments() {
        let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
        authorizationViewController?.delegate = self
        present(authorizationViewController!, animated: true, completion: nil)
    } else {
        SharedManager.showAlertWithMessage(title: NSLocalizedString("Sorry", comment: ""), alertMessage: "This device is not capable of making payments.", viewController: self)
    }
}}

扩展苹果支付视图控制器:PK支付授权视图控制器委托{

func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
    controller.dismiss(animated: true, completion: nil)
}

func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
    // Verify the payment with your server
    // ...
    
    completion(PKPaymentAuthorizationResult(status: .success, errors: nil))
}}

在didAuthorizePayment委托中,我不知道如何与服务器验证付款。我在文档中找不到任何与此相关的函数或后数据。您能帮助我吗?
谢谢

k4emjkb1

k4emjkb11#

你需要有一个支付处理器(如条纹),实际上做交易。
请参阅本教程:https://www.kodeco.com/2113-apple-pay-tutorial-getting-started
它解释了如何使用Stripe执行此操作。
在这个函数中,如果Stripe成功,您还必须告诉您自己的后端发送产品或用户订购的任何东西所需的所有信息。

相关问题