In my iOS app, I'm using the following code to make a connection to a Stripe PHP web page of mine in order to process a customer's transaction:
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];
The code I've used to receive the above response is the following:
<?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);
}
?>
What I can't seem to do is check if the payment went through properly or not. I've currently got the method below and I just want to see if I'm getting ANY response from the server at all. But the NSLog is not printing anything, so I don't think the method is being called. When I check my Stripe Log, it accurately tells me when payments failed/went through (so that part works fine). I simply am not able to get any response back from my PHP page for my iOS app.
-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
NSLog(@"RESPONSE: %@",data);
}
How can I fix that?