Add endpoint for re-checking payment intent status #799
This commit is contained in:
parent
8c61a27376
commit
d7cc0fc3de
2 changed files with 26 additions and 0 deletions
|
|
@ -335,3 +335,8 @@ apiv2_subscription_create:
|
||||||
path: /apiv2/subscription
|
path: /apiv2/subscription
|
||||||
controller: App\Controller\CustomerAppAPI\SubscriptionController::createSubscription
|
controller: App\Controller\CustomerAppAPI\SubscriptionController::createSubscription
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
apiv2_subscription_payment_intent:
|
||||||
|
path: /apiv2/subscription/payment_intent/{pid}
|
||||||
|
controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymentIntent
|
||||||
|
methods: [GET]
|
||||||
|
|
|
||||||
|
|
@ -117,4 +117,25 @@ class SubscriptionController extends ApiController
|
||||||
'paymongo_public_key' => $this->getParameter('subscription_paymongo_public_key'),
|
'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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue