Add endpoint for subscription paymongo public key #799
This commit is contained in:
parent
96a7cc929e
commit
219d5c09d3
3 changed files with 38 additions and 2 deletions
|
|
@ -324,4 +324,9 @@ apiv2_static_content:
|
|||
apiv2_subscription_fee:
|
||||
path: /apiv2/subscription/fee
|
||||
controller: App\Controller\CustomerAppAPI\SubscriptionController::getRecurringFee
|
||||
methods: [GET]
|
||||
|
||||
apiv2_subscription_paymongo_public_key:
|
||||
path: /apiv2/subscription/ppk
|
||||
controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymongoPublicKey
|
||||
methods: [GET]
|
||||
|
|
@ -18,6 +18,7 @@ parameters:
|
|||
insurance_premiums_banner_url: "%env(INSURANCE_PREMIUMS_BANNER_URL)%"
|
||||
enabled_hub_filters: "%env(ENABLED_HUB_FILTERS)%"
|
||||
subscription_recurring_fee: "%env(SUBSCRIPTION_RECURRING_FEE)%"
|
||||
subscription_paymongo_public_key: "%env(SUBSCRIPTION_PAYMONGO_PUBLIC_KEY)%"
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
|
|
|
|||
|
|
@ -5,9 +5,39 @@ namespace App\Controller\CustomerAppAPI;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||
|
||||
use App\Entity\CustomerVehicle;
|
||||
|
||||
class SubscriptionController extends ApiController
|
||||
{
|
||||
public function getRecurringFee(Request $req)
|
||||
public function getRecurringFee(Request $req, $cv_id)
|
||||
{
|
||||
// check requirements
|
||||
$validity = $this->validateRequest($req);
|
||||
|
||||
if (!$validity['is_valid']) {
|
||||
return new ApiResponse(false, $validity['error']);
|
||||
}
|
||||
|
||||
// get customer vehicle
|
||||
$cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id);
|
||||
|
||||
// check if it exists
|
||||
if ($cv == null) {
|
||||
return new ApiResponse(false, 'Vehicle does not exist.');
|
||||
}
|
||||
|
||||
// check if it's owned by customer
|
||||
if ($cv->getCustomer()->getID() != $this->session->getCustomer()->getID()) {
|
||||
return new ApiResponse(false, 'Invalid vehicle.');
|
||||
}
|
||||
|
||||
// response
|
||||
return new ApiResponse(true, '', [
|
||||
'amount' => $this->getParameter('subscription_recurring_fee'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPayMongoPublicKey(Request $req)
|
||||
{
|
||||
// check requirements
|
||||
$validity = $this->validateRequest($req);
|
||||
|
|
@ -18,7 +48,7 @@ class SubscriptionController extends ApiController
|
|||
|
||||
// response
|
||||
return new ApiResponse(true, '', [
|
||||
'amount' => $this->getParameter('subscription_recurring_fee'),
|
||||
'content' => $this->getParameter('subscription_paymongo_public_key'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue