Fix expected format from paymongo subscription endpoints #799
This commit is contained in:
parent
919b56688d
commit
0d9da221a7
3 changed files with 17 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue