我实现了带条纹的Apple Pay。我将数据条用作付款处理器。我将Stripe组件集成到我的应用程序中,并使用Apple Pay接受付款。我在iPhone 6和iPhone 6 plus上对其进行了测试,并且设备具有有效的卡。但是,如果我尝试创建付款请求,StripeClient.CanSubmitPaymentRequest始终在真实设备中返回false。在模拟器中工作正常。我将所有必需的证书添加到我的应用程序中。但这在实际设备中不起作用。如何解决那个问题。这是我的代码:
@IBAction func applepay(_ sender: Any) {
let merchantIdentifier = "merchant.deyaPayApplepay"
let paymentRequest = Stripe.paymentRequest(withMerchantIdentifier: merchantIdentifier, country: "US", currency: "usd")
// Configure the line items on the payment request
paymentRequest.paymentSummaryItems = [
//PKPaymentSummaryItem(label: "Fancy Hat", amount:NSDecimalNumber(value :amount)),
// The final line should represent your company;
// it'll be prepended with the word "Pay" (i.e. "Pay iHats, Inc $50")
PKPaymentSummaryItem(label: "amount to be added", amount:NSDecimalNumber(value :amount)),
]
if Stripe.canSubmitPaymentRequest(paymentRequest) {
// Setup payment authorization view controller
let paymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
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("apple pay is not configred properly");
}
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
STPAPIClient.shared().createToken(with: payment) { (token: STPToken?, error)-> Void in
print("Stripe token is \(String(describing: token!))")
completion(.success)
let b = String(describing: token!)
let parameters: Parameters = [
"Token":b,
"Amount":self.amount,
"AuthID":self.authid!
]
Alamofire.request("https://us-central1-deyapay-192704.cloudfunctions.net/Add/post", method: .post, parameters: parameters, encoding: JSONEncoding.default)
.responseJSON{ response in switch response.result{
case .success(let JSON):
let response = JSON as! NSDictionary
let TransId = response.object(forKey: "Token")! as! String
print(TransId)
let vc1 = self.storyboard?.instantiateViewController(withIdentifier: "TransactionSucess")as! TransactionSucess
vc1.transaction = TransId
vc1.amt = self.amount
self.present(vc1, animated: true,completion: nil)
//self.present(vc, animated: true,completion: nil)
case .failure(let error):
print("Request Failed with error:\(error)")
_ = self.storyboard?.instantiateViewController(withIdentifier: "Payments")as! Payments
// paymentpass.amount = (self?.amounttopay)!
//self?.navigationController?.pushViewController(paymentpass, animated: true)
self.navigationController?.popViewController(animated: true)
}
}
}
}
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
//Dismiss payment authorization view controller
dismiss(animated: true, completion: {
if (true) {
// print("Payment Success")
// Show a receipt page...
}
})
}
如何在真实设备中显示Apple Pay?