I'm stuck on a "simple" stripe integration problem. I have a checkout page where the amount can change on the checkout page, so the paymentIntent needs to change after the amount does. I created a short php app that is IDENTICAL to the one that successfully creates the paymentIntent, but now I'm updating the paymentIntent. I successfully pass in the new cost and the payment intent id to the app. But when I execute the ONE LINE of code to do the update, the fetched php doc throws an error 500. I comment out that ONE LINE and I don't get the error. I tried uploading it to a secure server thinking that was it (but I can run the create.php on my localhost without a problem) that didn't fix it either. I've been working on this for 10 hours and need to get it done tonight. Do you think you could help? here's the code:
\Stripe\Stripe::setApiKey('sk_test_xxx...'); // I have the correct secret key
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
$cost = $json_obj->c;
$paymentId = $json_obj->pi;
\Stripe\PaymentIntent::update(
$paymentId,
['amount' => $cost]
);
$output = [
'amount' => $stripe->amount,
];
echo json_encode($output); // to verify that it changed it
} catch (Error $e) {
http_response_code(500); // even if I comment this line out, i get error 500
echo json_encode(['error' => $e->getMessage()]);
}
::solved:: Ok, my stupid fault. The docs are a little unclear. It has you store the client_secret to actually do the charge later. To update a paymentIntent, you need to pass the paymentIntentId. They start with the same long string of letters and I thought they were the same.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.