Add Stripe payment intent simulation endpoint for testing
This new endpoint allows simulating Stripe payment intents for debugging purposes. It includes validation checks for session, order existence, and payment intent status, ensuring controlled execution. This functionality is intended strictly for testing and should not be used in production environments.
This commit is contained in:
@@ -127,6 +127,4 @@ class stripe_endpoint_payment_intents
|
||||
{
|
||||
return self::getClient()->paymentIntents->capture($id, $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -464,6 +464,50 @@ class ordersRoute
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
$this->post('/orders/module/stripe/debug/simulate_payment', function () {
|
||||
// Require the user to be logged in
|
||||
global $response;
|
||||
$this->requirePermission('debug_simulate_payment_intent');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Get the post data
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
// Check if the required fields are set
|
||||
if (!isset($data['id'])) {
|
||||
$response->error('ID is required', 400);
|
||||
}
|
||||
// Get the current order
|
||||
$order = (new orders_o())->getOrderById((int)$data['id']);
|
||||
// Check if the order exists
|
||||
if (!$order->exists()) {
|
||||
$response->error('Order not found', 400);
|
||||
}
|
||||
// Check if the order has a payment intent
|
||||
$stripe_payment_intents = new stripe_payment_intents_o();
|
||||
if (!$stripe_payment_intents->doesOrderHavePaymentIntent((int)$order->id)) {
|
||||
$response->error('Order does not have a payment intent', 400);
|
||||
}
|
||||
$stripe_payment_intents->selectOrderPaymentIntent((int)$order->id);
|
||||
// Simulate the payment
|
||||
$stripe = new stripe();
|
||||
//$paymentIntent = $stripe->readers->simulatePayment(
|
||||
// $stripe_payment_intents->payment_intent_id->value(),
|
||||
//);
|
||||
$response->success('TEST_SUCCESS', 200);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('orders', 'global', 1, 0, 'SIMULATE_PAYMENT_INTENT', 'No user found, or invalid session');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
},
|
||||
[
|
||||
'simulate_payment_intent' => 'Simulate a payment intent, this is only for testing purposes and should under no circumstances be used in production'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user