我正在尝试使用以下代码将交易数据从我的iOS应用程序发布到我的php后端(我发布条带令牌) . 但是,当我这样做时,服务器返回状态代码500错误 . 知道为什么这是/我在下面做错了什么?
payment.php (backend)
<?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("secretkeyhere");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'cad',
'description' => 'Example charge',
'source' => $token,
]);
?>
ViewController.m
NSString *curr = @"CAD";
NSURL *url = [NSURL URLWithString:@"http://url.com/payment.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
NSString *body = [NSString stringWithFormat:@"stripeToken=%@", token.tokenId];
request.HTTPBody = [body dataUsingEncoding:NSUTF8StringEncoding];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDataTask *task =
[session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (error)
{
completion(PKPaymentAuthorizationStatusFailure);
;
}
else
{
NSLog(@"THE RESPONSE IS %@", response);
completion(PKPaymentAuthorizationStatusSuccess);
NSLog(@"Server success!");
NSLog(@"Stripe success!");
}
}];
[task resume];