【发布时间】:2016-05-10 13:23:54
【问题描述】:
我正在 iOS 上快速构建一个应用程序,并且我正在使用条带接受付款。我创建了一个创建客户的表单,并在成功保存后回调 customerID 并将其保存到我的 Parse 数据库中。
下面是上面的代码:
XCODE:
let myCustomerID = user!.valueForKey("secretID") as! String
self.sendTokenToServer(myCustomerID, myAmount: cost)
func sendTokenToServer(aCustomer: String, myAmount: String) {
var theamount = myAmount
// SEND REQUEST TO PHP FILE IN WEBSERVER
let url = NSURL(string: ".../cutomeragain.php")
var request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
let body = "custID=\(aCustomer)&amount=\(theamount)"
request.HTTPBody = body.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
// SEND ASYNCHORNOUS REQUEST
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
(response, data, error) -> Void in
if error == nil {
}
}
当我去通过ID向客户收费时,它不接受收费。下面是PHP代码:
<?php
require_once('stripe-php/init.php');
\Stripe\Stripe::setApiKey('xxx');
// Get the credit card details submitted by the form
$amount = $_POST['amount'];
$customerId = $_POST['custID'];
$cutomer = \Stripe\Customer::retrieve('custID');
// Charge the Customer instead of the card
$charge = \Stripe\Charge::create(array(
"amount" => $amount,
"currency" => "usd",
"customer" => $customerId)
);
// create a json output with completion variable, (this will be read from the ios app as response)
$json = array(
'completion' => 'done',
'completion1' => $cutomerId,
'ok' => $cutomer-id
);
echo json_encode($json);
?>
我的 PHP 文件中是否缺少某些内容?我尝试了许多不同的方法。 IE。使用
从 Stripe 检索客户【问题讨论】:
-
不接受收费是什么意思,会出现什么错误?
-
它没有返回错误。对 Web 服务的调用会成功,但是费用不会发布到 Stripe。
标签: php ios swift parse-platform stripe-payments