diff --git a/htdocs/public/stripe/confirm_payment.php b/htdocs/public/stripe/confirm_payment.php index 90f21da6b6b..ea59b13dcb9 100644 --- a/htdocs/public/stripe/confirm_payment.php +++ b/htdocs/public/stripe/confirm_payment.php @@ -97,14 +97,14 @@ dol_syslog("POST=".var_export($_POST, true)); header('Content-Type: application/json'); -# retrieve json from POST body +// retrieve json from POST body $json_str = file_get_contents('php://input'); $json_obj = json_decode($json_str); $intent = null; try { if (isset($json_obj->payment_method_id)) { - # Create the PaymentIntent + // Create the PaymentIntent $intent = \Stripe\PaymentIntent::create([ 'payment_method' => $json_obj->payment_method_id, 'amount' => 1099, @@ -121,32 +121,39 @@ try { } generatePaymentResponse($intent); } catch (\Stripe\Error\Base $e) { - # Display error on client + // Display error on client echo json_encode([ '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' && $intent->next_action->type == 'use_stripe_sdk') { - # Tell the client to handle the action - echo json_encode([ - 'requires_action' => true, - 'payment_intent_client_secret' => $intent->client_secret - ]); - } else if ($intent->status == 'succeeded') { - # The payment didn’t need any additional actions and completed! - # Handle post-payment fulfillment + // Tell the client to handle the action + echo json_encode([ + 'requires_action' => true, + 'payment_intent_client_secret' => $intent->client_secret + ]); + } elseif ($intent->status == 'succeeded') { + // The payment didn’t need any additional actions and completed! + // Handle post-payment fulfillment - // TODO + // TODO - echo json_encode([ - "success" => true - ]); - } else { - # Invalid status - http_response_code(500); - echo json_encode(['error' => 'Invalid PaymentIntent status']); - } + echo json_encode([ + "success" => true + ]); + } else { + // Invalid status + http_response_code(500); + echo json_encode(['error' => 'Invalid PaymentIntent status']); + } }