diff --git a/services/nginx/app/modules/stripe/endpoints/stripe_endpoint_payment_intents.php b/services/nginx/app/modules/stripe/endpoints/stripe_endpoint_payment_intents.php index e56655a4..a2dcd2d4 100644 --- a/services/nginx/app/modules/stripe/endpoints/stripe_endpoint_payment_intents.php +++ b/services/nginx/app/modules/stripe/endpoints/stripe_endpoint_payment_intents.php @@ -127,6 +127,4 @@ class stripe_endpoint_payment_intents { return self::getClient()->paymentIntents->capture($id, $data); } - - } \ No newline at end of file diff --git a/services/nginx/app/routes/ordersRoute.php b/services/nginx/app/routes/ordersRoute.php index 86f9388b..fbbdeb9a 100644 --- a/services/nginx/app/routes/ordersRoute.php +++ b/services/nginx/app/routes/ordersRoute.php @@ -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' + ] + ); } /**