Update confirm_payment.php
This commit is contained in:
parent
3e99a40b9e
commit
31022e6753
@ -97,14 +97,14 @@ dol_syslog("POST=".var_export($_POST, true));
|
|||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
# retrieve json from POST body
|
// retrieve json from POST body
|
||||||
$json_str = file_get_contents('php://input');
|
$json_str = file_get_contents('php://input');
|
||||||
$json_obj = json_decode($json_str);
|
$json_obj = json_decode($json_str);
|
||||||
|
|
||||||
$intent = null;
|
$intent = null;
|
||||||
try {
|
try {
|
||||||
if (isset($json_obj->payment_method_id)) {
|
if (isset($json_obj->payment_method_id)) {
|
||||||
# Create the PaymentIntent
|
// Create the PaymentIntent
|
||||||
$intent = \Stripe\PaymentIntent::create([
|
$intent = \Stripe\PaymentIntent::create([
|
||||||
'payment_method' => $json_obj->payment_method_id,
|
'payment_method' => $json_obj->payment_method_id,
|
||||||
'amount' => 1099,
|
'amount' => 1099,
|
||||||
@ -121,23 +121,30 @@ try {
|
|||||||
}
|
}
|
||||||
generatePaymentResponse($intent);
|
generatePaymentResponse($intent);
|
||||||
} catch (\Stripe\Error\Base $e) {
|
} catch (\Stripe\Error\Base $e) {
|
||||||
# Display error on client
|
// Display error on client
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'error' => $e->getMessage()
|
'error' => $e->getMessage()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePaymentResponse($intent) {
|
/*
|
||||||
|
* generate payment response
|
||||||
|
*
|
||||||
|
* @param \Stripe\PaymentIntent $intent PaymentIntent
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function generatePaymentResponse($intent)
|
||||||
|
{
|
||||||
if ($intent->status == 'requires_source_action' &&
|
if ($intent->status == 'requires_source_action' &&
|
||||||
$intent->next_action->type == 'use_stripe_sdk') {
|
$intent->next_action->type == 'use_stripe_sdk') {
|
||||||
# Tell the client to handle the action
|
// Tell the client to handle the action
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'requires_action' => true,
|
'requires_action' => true,
|
||||||
'payment_intent_client_secret' => $intent->client_secret
|
'payment_intent_client_secret' => $intent->client_secret
|
||||||
]);
|
]);
|
||||||
} elseif ($intent->status == 'succeeded') {
|
} elseif ($intent->status == 'succeeded') {
|
||||||
# The payment didn’t need any additional actions and completed!
|
// The payment didn’t need any additional actions and completed!
|
||||||
# Handle post-payment fulfillment
|
// Handle post-payment fulfillment
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
@ -145,7 +152,7 @@ function generatePaymentResponse($intent) {
|
|||||||
"success" => true
|
"success" => true
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
# Invalid status
|
// Invalid status
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
echo json_encode(['error' => 'Invalid PaymentIntent status']);
|
echo json_encode(['error' => 'Invalid PaymentIntent status']);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user