From d7cc0fc3de6f9b469c3bc835a8e322db78a50dad Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Thu, 22 Aug 2024 06:19:42 +0800 Subject: [PATCH] Add endpoint for re-checking payment intent status #799 --- config/routes/apiv2.yaml | 5 +++++ .../CustomerAppAPI/SubscriptionController.php | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/config/routes/apiv2.yaml b/config/routes/apiv2.yaml index bb534de1..5faa26dc 100644 --- a/config/routes/apiv2.yaml +++ b/config/routes/apiv2.yaml @@ -335,3 +335,8 @@ apiv2_subscription_create: path: /apiv2/subscription controller: App\Controller\CustomerAppAPI\SubscriptionController::createSubscription methods: [POST] + +apiv2_subscription_payment_intent: + path: /apiv2/subscription/payment_intent/{pid} + controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymentIntent + methods: [GET] diff --git a/src/Controller/CustomerAppAPI/SubscriptionController.php b/src/Controller/CustomerAppAPI/SubscriptionController.php index 60d3cda4..870c1cb2 100644 --- a/src/Controller/CustomerAppAPI/SubscriptionController.php +++ b/src/Controller/CustomerAppAPI/SubscriptionController.php @@ -117,4 +117,25 @@ class SubscriptionController extends ApiController 'paymongo_public_key' => $this->getParameter('subscription_paymongo_public_key'), ]); } + + public function getPaymentIntent(Request $req, $pid, PayMongoConnector $pm) + { + // check requirements + $validity = $this->validateRequest($req); + + if (!$validity['is_valid']) { + return new ApiResponse(false, $validity['error']); + } + + // get payment intent + $pi = $pm->getPaymentIntent($pid); + if (empty($pi['response']['data']['id'])) { + return new ApiResponse(false, 'Error retrieving payment intent. Please try again later.'); + } + + // response + return new ApiResponse(true, '', [ + 'payment_intent' => $pi, + ]); + } }