diff --git a/config/routes/apiv2.yaml b/config/routes/apiv2.yaml index a7332516..bb534de1 100644 --- a/config/routes/apiv2.yaml +++ b/config/routes/apiv2.yaml @@ -326,10 +326,10 @@ apiv2_subscription_plan_details: controller: App\Controller\CustomerAppAPI\SubscriptionController::getPlanDetails methods: [GET] -apiv2_subscription_paymongo_public_key: - path: /apiv2/subscription/ppk - controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymongoPublicKey - methods: [GET] +#apiv2_subscription_paymongo_public_key: +# path: /apiv2/subscription/ppk +# controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymongoPublicKey +# methods: [GET] apiv2_subscription_create: path: /apiv2/subscription diff --git a/src/Controller/CustomerAppAPI/SubscriptionController.php b/src/Controller/CustomerAppAPI/SubscriptionController.php index 3c3b24d1..33ac8792 100644 --- a/src/Controller/CustomerAppAPI/SubscriptionController.php +++ b/src/Controller/CustomerAppAPI/SubscriptionController.php @@ -43,6 +43,8 @@ class SubscriptionController extends ApiController ]); } + // NOTE: disabling this since we can just include the public key with the subscription creation endpoint + /* public function getPayMongoPublicKey(Request $req) { // check requirements @@ -54,9 +56,10 @@ class SubscriptionController extends ApiController // response return new ApiResponse(true, '', [ - 'content' => $this->getParameter('subscription_paymongo_public_key'), + 'key' => $this->getParameter('subscription_paymongo_public_key'), ]); } + */ public function createSubscription(Request $req, PayMongoConnector $pm) { @@ -87,13 +90,14 @@ class SubscriptionController extends ApiController // create subscription // NOTE: for now we save ourselves the extra API call and assume the plan_id is valid since this won't change often anyway $pm_sub = $pm->createSubscription($pm_cust['id'], $req->request->get('plan_id')); - if (!isset($pm_sub['data']['id'])) { + if (!isset($pm_sub['response']['data']['id'])) { return new ApiResponse(false, 'Error creating subscription. Please try again later.'); } // response return new ApiResponse(true, '', [ - 'subscription_id' => $pm_sub['data']['id'], + 'subscription_id' => $pm_sub['response']['data']['id'], + 'paymongo_public_key' => $this->getParameter('subscription_paymongo_public_key'), ]); } } diff --git a/src/Service/PayMongoConnector.php b/src/Service/PayMongoConnector.php index b39d0fb2..a12c38a0 100644 --- a/src/Service/PayMongoConnector.php +++ b/src/Service/PayMongoConnector.php @@ -126,6 +126,7 @@ class PayMongoConnector 'description' => $plan_data['description'], 'interval' => $plan_data['interval'], 'interval_count' => $plan_data['interval_count'], + 'cycle_count' => $plan_data['cycle_count'], 'name' => $plan_data['name'], 'metadata' => $plan_data['metadata'], ], @@ -186,7 +187,7 @@ class PayMongoConnector 'attributes' => [ 'first_name' => $cust->getFirstName(), 'last_name' => $cust->getLastName(), - 'phone' => $cust->getPhoneMobile(), + 'phone' => "+63" . $cust->getPhoneMobile(), 'email' => $cust->getEmail(), 'default_device' => 'email', ], @@ -246,16 +247,16 @@ class PayMongoConnector $pm_cust = null; - if (isset($found_cust['data']['id'])) { + if (isset($found_cust['response']['data'][0]['id'])) { // we found a customer record - $pm_cust = $found_cust['data']; + $pm_cust = $found_cust['response']['data'][0]; } else { // we create a new customer record $new_cust = $this->createCustomer($cust); - if (isset($new_cust['data']['id'])) { + if (isset($new_cust['response']['data'][0]['id'])) { // customer record was created successfully - $pm_cust = $new_cust['data']; + $pm_cust = $new_cust['response']['data'][0]; } }