Add endpoint for re-checking payment intent status #799

This commit is contained in:
Ramon Gutierrez 2024-08-22 06:19:42 +08:00
parent 8c61a27376
commit d7cc0fc3de
2 changed files with 26 additions and 0 deletions

View file

@ -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]

View file

@ -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,
]);
}
}