Fix expected format from paymongo subscription endpoints #799

This commit is contained in:
Ramon Gutierrez 2024-08-21 01:16:43 +08:00
parent 919b56688d
commit 0d9da221a7
3 changed files with 17 additions and 12 deletions

View file

@ -326,10 +326,10 @@ apiv2_subscription_plan_details:
controller: App\Controller\CustomerAppAPI\SubscriptionController::getPlanDetails controller: App\Controller\CustomerAppAPI\SubscriptionController::getPlanDetails
methods: [GET] methods: [GET]
apiv2_subscription_paymongo_public_key: #apiv2_subscription_paymongo_public_key:
path: /apiv2/subscription/ppk # path: /apiv2/subscription/ppk
controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymongoPublicKey # controller: App\Controller\CustomerAppAPI\SubscriptionController::getPaymongoPublicKey
methods: [GET] # methods: [GET]
apiv2_subscription_create: apiv2_subscription_create:
path: /apiv2/subscription path: /apiv2/subscription

View file

@ -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) public function getPayMongoPublicKey(Request $req)
{ {
// check requirements // check requirements
@ -54,9 +56,10 @@ class SubscriptionController extends ApiController
// response // response
return new ApiResponse(true, '', [ 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) public function createSubscription(Request $req, PayMongoConnector $pm)
{ {
@ -87,13 +90,14 @@ class SubscriptionController extends ApiController
// create subscription // 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 // 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')); $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.'); return new ApiResponse(false, 'Error creating subscription. Please try again later.');
} }
// response // response
return new ApiResponse(true, '', [ 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'),
]); ]);
} }
} }

View file

@ -126,6 +126,7 @@ class PayMongoConnector
'description' => $plan_data['description'], 'description' => $plan_data['description'],
'interval' => $plan_data['interval'], 'interval' => $plan_data['interval'],
'interval_count' => $plan_data['interval_count'], 'interval_count' => $plan_data['interval_count'],
'cycle_count' => $plan_data['cycle_count'],
'name' => $plan_data['name'], 'name' => $plan_data['name'],
'metadata' => $plan_data['metadata'], 'metadata' => $plan_data['metadata'],
], ],
@ -186,7 +187,7 @@ class PayMongoConnector
'attributes' => [ 'attributes' => [
'first_name' => $cust->getFirstName(), 'first_name' => $cust->getFirstName(),
'last_name' => $cust->getLastName(), 'last_name' => $cust->getLastName(),
'phone' => $cust->getPhoneMobile(), 'phone' => "+63" . $cust->getPhoneMobile(),
'email' => $cust->getEmail(), 'email' => $cust->getEmail(),
'default_device' => 'email', 'default_device' => 'email',
], ],
@ -246,16 +247,16 @@ class PayMongoConnector
$pm_cust = null; $pm_cust = null;
if (isset($found_cust['data']['id'])) { if (isset($found_cust['response']['data'][0]['id'])) {
// we found a customer record // we found a customer record
$pm_cust = $found_cust['data']; $pm_cust = $found_cust['response']['data'][0];
} else { } else {
// we create a new customer record // we create a new customer record
$new_cust = $this->createCustomer($cust); $new_cust = $this->createCustomer($cust);
if (isset($new_cust['data']['id'])) { if (isset($new_cust['response']['data'][0]['id'])) {
// customer record was created successfully // customer record was created successfully
$pm_cust = $new_cust['data']; $pm_cust = $new_cust['response']['data'][0];
} }
} }