gpt4 book ai didi

ios - apple pay 在真机上不可用

转载 作者:行者123 更新时间:2023-11-29 11:35:48 38 4
gpt4 key购买 nike

我使用 swift 在 ios 中实现了 apple pay with stripe。因此,当测试程序时,它可以在模拟器上运行良好,但在真实设备上运行不佳。要使用真实设备测试 Apple Pay,它不会显示处理交易的付款表。我的疑问是在真实设备上使用 apple pay 进行测试,我们可以将测试卡添加到钱包或拥有沙盒帐户吗?使用stripe gate方式需要在钱包中添加测试卡吗?你能给我说清楚吗?

这是我的代码:

import UIKit
import PassKit
import Stripe

class ViewController: UIViewController {

let request = PKPaymentRequest()
var paymentStatus = PKPaymentAuthorizationStatus.failure
var paymentController: PKPaymentAuthorizationController?

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@IBAction func applepay(_ sender: Any) {
let merchantIdentifier = "merchant.Appplepay"
let paymentNetworks = [PKPaymentNetwork.masterCard, PKPaymentNetwork.visa,PKPaymentNetwork.amex,PKPaymentNetwork.discover,PKPaymentNetwork.interac]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks)
{

request.merchantIdentifier = "merchant.Appplepay"
request.countryCode = "US"
request.currencyCode = "USD"
request.supportedNetworks = paymentNetworks
request.merchantCapabilities = .capability3DS
request.requiredShippingAddressFields = [.phone, .email,.postalAddress,.all]
request.paymentSummaryItems = [PKPaymentSummaryItem(label: "Fancy Hat", amount: 50.00),
// The final line should represent your company;
// it'll be prepended with the word "Pay" (i.e. "Pay iHats, Inc $50")
PKPaymentSummaryItem(label: "iHats, Inc", amount: 50.00),]
} else {
// Traditional checkout flow
}
func applePaySupported() -> Bool {
return PKPaymentAuthorizationViewController.canMakePayments() && PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.amex, .visa, .masterCard])
}
// Setup payment authorization view controller
if Stripe.canSubmitPaymentRequest(request) {
// Setup payment authorization view controller
let paymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)
paymentAuthorizationViewController?.delegate = self

// Present payment authorization view controller
self.present((paymentAuthorizationViewController)!, animated: true,completion: nil)
}
else {
// There is a problem with your Apple Pay configuration
print("Failed to present PaymentSheet");
}

}

}
extension ViewController : PKPaymentAuthorizationViewControllerDelegate {

func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
if payment.shippingContact?.emailAddress == nil || payment.shippingContact?.phoneNumber == nil {
paymentStatus = .invalidShippingContact
} else {
STPAPIClient.shared().createToken(with: payment) { (token: STPToken?, error)-> Void in
print("Stripe token is \(String(describing: token!))")
//self.paymentStatus = .success
completion(.success)

}
}

}

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


}

最佳答案

回答有关在真实设备上进行测试的问题:您只能将真实卡添加到钱包以用于 Apple Pay,但是如果您使用测试条 api key ,that is detected by stripe and your real card will not be charged

不知道为什么没有看到一些代码就没有在真实设备上显示付款表,但你会想确保设备设置为 apple pay,主要是它有卡添加到钱包(你支持的)

并非所有国家/地区 support Apple Pay因此并不总是有向钱包添加卡的选项,这意味着 Apple Pay 表不会显示,因为 if Stripe.canSubmitPaymentRequest(request) 返回 false。

关于ios - apple pay 在真机上不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49445470/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com