检查Stripe Payment是否失败或成功

时间:2015-06-10 03:15:00

标签: php ios objective-c stripe-payments

在我的iOS应用中,我使用以下代码连接到我的Stripe PHP网页以处理客户的交易:

   NSString *dataUrl = [NSString stringWithFormat:@"http://www.somesite?stripeToken=%@",token.tokenId];
    NSURL *url = [NSURL URLWithString:dataUrl];

    // 2
    NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession]
                                          dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}];

    // 3
    [downloadTask resume];

我用来接收上述回复的代码如下:

<?php

require_once('vendor/autoload.php');


// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("private");

// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];

// Create the charge on Stripe's servers - this will charge the user's card
try {

    $charge = \Stripe\Charge::create(array(
  "amount" => 1000, // amount in cents, again
  "currency" => "cad",
  "source" => $token,
  "description" => "Example charge")
);
    $string = "success";
    echo json_encode($string); 

} catch(\Stripe\Error\Card $e) {
    $string = "The card has been declined.";
    echo json_encode($string); 
}

?>

我无法做的就是检查付款是否正常。我现在有了下面的方法,我只是想知道我是否从服务器得到任何响应。但是NSLog没有打印任何东西,所以我不认为这个方法被调用了。当我检查我的Stripe Log时,它会准确地告诉我付款失败/通过的时间(这样部分工作正常)。我只是无法从我的iOS应用程序的PHP页面获得任何回复。

-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
    NSLog(@"RESPONSE: %@",data);
}

我该如何解决?

0 个答案:

没有答案