gpt4 book ai didi

php - Stripe API (PHP) 和解析

转载 作者:行者123 更新时间:2023-11-30 13:44:29 24 4
gpt4 key购买 nike

我正在 iOS 上使用 swift 构建一个应用程序,并使用 stripe 接受付款。我创建了一个用于创建客户的表单,成功保存后,我回调 customerID 并将其保存到我的 Parse 数据库中。

下面是上述代码:

X 代码:

    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 检索客户

最佳答案

好吧,我明白了。我不得不尝试一下,但是,我认为其他人会发现这很有用。

在我的 xcode 文件中我更改了

    let myCustomerID = user!.valueForKey("secretID") as! String 

    let myCustomerID = user?["secretID"] as? String

在我的 PHP 文件中,我将代码更改为以下内容:

    // Get the credit card details submitted by the form
$amount = $_POST['amount'];
$customerId = $_POST['cus'];
$cu = \Stripe\Customer::retrieve($customerId);

// 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 - Stripe API (PHP) 和解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35141613/

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