【发布时间】:2016-12-17 10:08:24
【问题描述】:
iOS 应用上的 Stripe 集成存在问题。
根据 Stripe 文档,
1) iOS 应用需要先生成令牌,然后将该令牌传递给自己服务器上的 php lib
导入 UIKit 导入条纹 类视图控制器:UIViewController,STPPaymentCardTextFieldDelegate { 让 paymentTextField = STPPaymentCardTextField() 覆盖 func viewDidLoad() { super.viewDidLoad() Stripe.setDefaultPublishableKey("pk_test_xxxxxxxxxxxxxxxxxxxxx") // 在加载视图后做任何额外的设置,通常是从一个 nib。 paymentTextField.frame = CGRectMake(15, 15, CGRectGetWidth(self.view.frame) - 30, 44) paymentTextField.delegate = self view.addSubview(paymentTextField) } 覆盖 func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // 处理所有可以重新创建的资源。 } @IBAction 函数保存(发件人:AnyObject){ 如果让卡:STPCardParams = paymentTextField.cardParams { STPAPIClient.sharedClient().createTokenWithCard(card) { (token, error) -> Void in 如果让错误=错误{ 打印(错误) } else if let token = token { self.createBackendChargeWithToken(token) { 状态 } } } } } func createBackendChargeWithToken(token: STPToken, 完成: PKPaymentAuthorizationStatus -> ()) { 让 url = NSURL(string: "http://localhost:7777/myproject/index.php/rest/stripe/submit")! 让请求 = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" 让 body = "stripeToken=\(token.tokenId)" 打印(正文) request.HTTPBody = body.dataUsingEncoding(NSUTF8StringEncoding) 让配置 = NSURLSessionConfiguration.ephemeralSessionConfiguration() 让会话 = NSURLSession(配置:配置) 打印(请求) let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in 如果错误!= nil { 完成(PKPaymentAuthorizationStatus.Failure) print("充电失败") } 别的 { 完成(PKPaymentAuthorizationStatus.Success) print("成功转帐") 打印(PKPaymentAuthorizationStatus.Success) } } 任务.resume() } }2) php lib 像这样执行到 Stripe API
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxx"); if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $token = $_POST['stripeToken']; $charge = \Stripe\Charge::create(array( "amount" => 5000, // 以美分为单位的金额,所以需要乘以 100 .. $amount * 100 "货币" => "美元", “来源” => $token, “描述” => “来自 iOS 的测试订单” )); }3) 它工作正常,我可以在 Stripe Dashboard 收到付款交易。
4) 但是当我切换到另一个条带帐户(如客户帐户)时,我需要更改 Publishable Key(From Mobile App) 和 Secret Key(From Server Side) 对吗?
5) 更改新密钥后,Stripe Dashboard 无法再收到付款。这是来自 Stripe 的日志消息。
{错误: { 类型:“invalid_request_error” 消息:“Stripe 不再支持使用 TLS 1.0 发出的 API 请求。请使用 TLS 1.2 或更高版本发起 HTTPS 连接。您可以在 https://stripe.com/blog/upgrading-tls 了解更多信息。”} }错误状态为 401
我的问题是为什么从另一个 Stripe 帐户切换 API(可发布和秘密)密钥时应用程序无法运行?
【问题讨论】:
标签: stripe-payments