Add support for handling multiple paymongo accounts #799
This commit is contained in:
parent
e3649c3d2d
commit
debb399e96
7 changed files with 56 additions and 22 deletions
|
|
@ -17,7 +17,12 @@ parameters:
|
||||||
ios_app_version: "%env(IOS_APP_VERSION)%"
|
ios_app_version: "%env(IOS_APP_VERSION)%"
|
||||||
insurance_premiums_banner_url: "%env(INSURANCE_PREMIUMS_BANNER_URL)%"
|
insurance_premiums_banner_url: "%env(INSURANCE_PREMIUMS_BANNER_URL)%"
|
||||||
enabled_hub_filters: "%env(ENABLED_HUB_FILTERS)%"
|
enabled_hub_filters: "%env(ENABLED_HUB_FILTERS)%"
|
||||||
|
insurance_paymongo_public_key: "%env(INSURANCE_PAYMONGO_PUBLIC_KEY)%"
|
||||||
|
insurance_paymongo_secret_key: "%env(INSURANCE_PAYMONGO_SECRET_KEY)%"
|
||||||
|
insurance_paymongo_webhook_id: "%env(INSURANCE_PAYMONGO_WEBHOOK_ID)%"
|
||||||
subscription_paymongo_public_key: "%env(SUBSCRIPTION_PAYMONGO_PUBLIC_KEY)%"
|
subscription_paymongo_public_key: "%env(SUBSCRIPTION_PAYMONGO_PUBLIC_KEY)%"
|
||||||
|
subscription_paymongo_secret_key: "%env(SUBSCRIPTION_PAYMONGO_SECRET_KEY)%"
|
||||||
|
subscription_paymongo_webhook_id: "%env(SUBSCRIPTION_PAYMONGO_WEBHOOK_ID)%"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
|
|
@ -115,7 +120,6 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
$paymongo: "@App\\Service\\PayMongoConnector"
|
$paymongo: "@App\\Service\\PayMongoConnector"
|
||||||
$webhook_id: "%env(PAYMONGO_WEBHOOK_ID)%"
|
|
||||||
|
|
||||||
# rider tracker service
|
# rider tracker service
|
||||||
App\Service\RiderTracker:
|
App\Service\RiderTracker:
|
||||||
|
|
@ -239,8 +243,6 @@ services:
|
||||||
App\Service\PayMongoConnector:
|
App\Service\PayMongoConnector:
|
||||||
arguments:
|
arguments:
|
||||||
$base_url: "%env(PAYMONGO_BASE_URL)%"
|
$base_url: "%env(PAYMONGO_BASE_URL)%"
|
||||||
$public_key: "%env(PAYMONGO_PUBLIC_KEY)%"
|
|
||||||
$secret_key: "%env(PAYMONGO_SECRET_KEY)%"
|
|
||||||
|
|
||||||
# entity listener for customer vehicle warranty code history
|
# entity listener for customer vehicle warranty code history
|
||||||
App\EntityListener\CustomerVehicleSerialListener:
|
App\EntityListener\CustomerVehicleSerialListener:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
|
@ -19,14 +20,18 @@ class ProcessLatePaymongoTransactionsCommand extends Command
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $paymongo;
|
protected $paymongo;
|
||||||
|
|
||||||
protected $webhook_id;
|
protected $webhook_id;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, PayMongoConnector $paymongo, $webhook_id)
|
public function __construct(EntityManagerInterface $em, PayMongoConnector $paymongo, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->webhook_id = $params->get('insurance_paymongo_webhook_id');
|
||||||
|
|
||||||
$this->paymongo = $paymongo;
|
$this->paymongo = $paymongo;
|
||||||
$this->webhook_id = $webhook_id;
|
$this->paymongo->initialize(
|
||||||
|
$params->get('insurance_paymongo_public_key'),
|
||||||
|
$params->get('insurance_paymongo_secret_key')
|
||||||
|
);
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,7 @@ class CustomerController extends ApiController
|
||||||
public function updateInfo(Request $req)
|
public function updateInfo(Request $req)
|
||||||
{
|
{
|
||||||
// validate params
|
// validate params
|
||||||
$validity = $this->validateRequest($req, [
|
$validity = $this->validateRequest($req);
|
||||||
'first_name',
|
|
||||||
'last_name',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$validity['is_valid']) {
|
if (!$validity['is_valid']) {
|
||||||
return new ApiResponse(false, $validity['error']);
|
return new ApiResponse(false, $validity['error']);
|
||||||
|
|
@ -129,10 +126,21 @@ class CustomerController extends ApiController
|
||||||
$this->session->setCustomer($cust);
|
$this->session->setCustomer($cust);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cust->setFirstName($req->request->get('first_name'))
|
if (!is_null($req->request->get('first_name'))) {
|
||||||
->setLastName($req->request->get('last_name'))
|
$cust->setFirstName($req->request->get('first_name'));
|
||||||
->setEmail($req->request->get('email', ''))
|
}
|
||||||
->setConfirmed($this->session->isConfirmed());
|
|
||||||
|
if (!is_null($req->request->get('last_name'))) {
|
||||||
|
$cust->setLastName($req->request->get('last_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($req->request->get('email'))) {
|
||||||
|
$cust->setEmail($req->request->get('email'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($this->session->isConfirmed())) {
|
||||||
|
$cust->setConfirmed($this->session->isConfirmed());
|
||||||
|
}
|
||||||
|
|
||||||
// if customer user isn't set, set it now
|
// if customer user isn't set, set it now
|
||||||
if ($cust->getCustomerUser() == null) {
|
if ($cust->getCustomerUser() == null) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Controller\CustomerAppAPI;
|
namespace App\Controller\CustomerAppAPI;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||||
|
|
@ -33,7 +34,7 @@ class InsuranceController extends ApiController
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createApplication(Request $req, PayMongoConnector $paymongo, UrlGeneratorInterface $router)
|
public function createApplication(Request $req, PayMongoConnector $paymongo, UrlGeneratorInterface $router, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
// validate params
|
// validate params
|
||||||
$validity = $this->validateRequest($req, [
|
$validity = $this->validateRequest($req, [
|
||||||
|
|
@ -162,6 +163,12 @@ class InsuranceController extends ApiController
|
||||||
$this->em->persist($gt);
|
$this->em->persist($gt);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
|
// initialize paymongo connector
|
||||||
|
$paymongo->initialize(
|
||||||
|
$params->get('insurance_paymongo_public_key'),
|
||||||
|
$params->get('insurance_paymongo_secret_key')
|
||||||
|
);
|
||||||
|
|
||||||
// create paymongo checkout resource
|
// create paymongo checkout resource
|
||||||
$checkout = $paymongo->createCheckout(
|
$checkout = $paymongo->createCheckout(
|
||||||
$cust,
|
$cust,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ class SubscriptionController extends ApiController
|
||||||
$batts = $vehicle->getActiveBatteries();
|
$batts = $vehicle->getActiveBatteries();
|
||||||
|
|
||||||
if (!empty($batts)) {
|
if (!empty($batts)) {
|
||||||
$fee = $batts[0]->getSize()->getSubRecurringFee() ?? 0;
|
$size_fee_raw = $batts[0]->getSize()->getSubRecurringFee();
|
||||||
|
$fee = $size_fee_raw ? bcmul($size_fee_raw, 100) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Controller\CustomerAppAPI;
|
namespace App\Controller\CustomerAppAPI;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
|
|
@ -115,7 +116,7 @@ class VehicleController extends ApiController
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVehicle(Request $req, $id, PayMongoConnector $paymongo)
|
public function getVehicle(Request $req, $id, PayMongoConnector $paymongo, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
// check requirements
|
// check requirements
|
||||||
$validity = $this->validateRequest($req);
|
$validity = $this->validateRequest($req);
|
||||||
|
|
@ -139,7 +140,7 @@ class VehicleController extends ApiController
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return new ApiResponse(true, '', [
|
return new ApiResponse(true, '', [
|
||||||
'vehicle' => $this->generateVehicleInfo($cv, true, true, $paymongo),
|
'vehicle' => $this->generateVehicleInfo($cv, true, true, $paymongo, $params),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +211,7 @@ class VehicleController extends ApiController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listVehicles(Request $req, PayMongoConnector $paymongo)
|
public function listVehicles(Request $req, PayMongoConnector $paymongo, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
// validate params
|
// validate params
|
||||||
$validity = $this->validateRequest($req);
|
$validity = $this->validateRequest($req);
|
||||||
|
|
@ -231,7 +232,7 @@ class VehicleController extends ApiController
|
||||||
// only get the customer's vehicles whose flag_active is true
|
// only get the customer's vehicles whose flag_active is true
|
||||||
$cvs = $this->em->getRepository(CustomerVehicle::class)->findBy(['flag_active' => true, 'customer' => $cust]);
|
$cvs = $this->em->getRepository(CustomerVehicle::class)->findBy(['flag_active' => true, 'customer' => $cust]);
|
||||||
foreach ($cvs as $cv) {
|
foreach ($cvs as $cv) {
|
||||||
$cv_list[] = $this->generateVehicleInfo($cv, true, true, $paymongo);
|
$cv_list[] = $this->generateVehicleInfo($cv, true, true, $paymongo, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
|
|
@ -417,7 +418,7 @@ class VehicleController extends ApiController
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateVehicleInfo(CustomerVehicle $cv, $include_insurance = false, $include_active_sub = false, PayMongoConnector $paymongo)
|
protected function generateVehicleInfo(CustomerVehicle $cv, $include_insurance = false, $include_active_sub = false, PayMongoConnector $paymongo, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
$battery_id = null;
|
$battery_id = null;
|
||||||
if ($cv->getCurrentBattery() != null)
|
if ($cv->getCurrentBattery() != null)
|
||||||
|
|
@ -469,6 +470,12 @@ class VehicleController extends ApiController
|
||||||
// TODO: maybe handle this more elegantly. issue is not sure it is a good idea to update the db for this very transient status as the webhook listener also updates this status right away
|
// TODO: maybe handle this more elegantly. issue is not sure it is a good idea to update the db for this very transient status as the webhook listener also updates this status right away
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case InsuranceApplicationStatus::CREATED:
|
case InsuranceApplicationStatus::CREATED:
|
||||||
|
// initialize paymongo connector
|
||||||
|
$paymongo->initialize(
|
||||||
|
$params->get('insurance_paymongo_public_key'),
|
||||||
|
$params->get('insurance_paymongo_secret_key')
|
||||||
|
);
|
||||||
|
|
||||||
// get latest status on this checkout from paymongo
|
// get latest status on this checkout from paymongo
|
||||||
$checkout = $paymongo->getCheckout($gt->getExtTransactionId());
|
$checkout = $paymongo->getCheckout($gt->getExtTransactionId());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,13 @@ class PayMongoConnector
|
||||||
protected $secret_key;
|
protected $secret_key;
|
||||||
protected $hash;
|
protected $hash;
|
||||||
|
|
||||||
public function __construct($base_url, $public_key, $secret_key)
|
public function __construct($base_url)
|
||||||
{
|
{
|
||||||
$this->base_url = $base_url;
|
$this->base_url = $base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initialize($public_key, $secret_key)
|
||||||
|
{
|
||||||
$this->public_key = $public_key;
|
$this->public_key = $public_key;
|
||||||
$this->secret_key = $secret_key;
|
$this->secret_key = $secret_key;
|
||||||
$this->hash = $this->generateHash();
|
$this->hash = $this->generateHash();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue