Fix PHPCS

This commit is contained in:
Laurent Destailleur 2019-05-02 12:28:40 +02:00
parent 0f8c7df6fe
commit ceeb9752ce
6 changed files with 57 additions and 51 deletions

View File

@ -411,4 +411,3 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
return $result; return $result;
} }

View File

@ -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()
]); ]);
} }
/**
* generatePaymentResponse
*
* @param object $intent Intent
* @return void
*/
function generatePaymentResponse($intent) { 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']);
} }