【问题标题】:Stripe API (PHP) & Parse条纹 API (PHP) 和解析
【发布时间】: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


【解决方案1】:

好的,我想通了。我不得不玩了一下,但是,我认为其他人会发现这很有用。

在我的 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);

   ?>

【讨论】:

    猜你喜欢
    • 2015-12-09
    • 2016-07-26
    • 2017-03-14
    • 1970-01-01
    • 2020-05-10
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多