From 7731f1d0a4f3572b301348180300ea5dcbb87ada Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Wed, 24 Oct 2018 11:52:06 +0200 Subject: [PATCH 01/14] update bank informations --- Entity/BankInformationInterface.php | 16 ++++++------ Helper/BankInformationHelper.php | 38 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Entity/BankInformationInterface.php b/Entity/BankInformationInterface.php index 1dac2e0..6d31441 100644 --- a/Entity/BankInformationInterface.php +++ b/Entity/BankInformationInterface.php @@ -11,42 +11,42 @@ interface BankInformationInterface /** * BankInformation address. * - * @var string + * @return string */ public function getBankInformationStreetAddress(); /** * BankInformation address. * - * @var string + * @return string */ public function getBankInformationAdditionalStreetAddress(); /** * BankInformation address. * - * @var string + * @return string */ public function getBankInformationCity(); /** * BankInformation address. * - * @var string + * @return string */ public function getBankInformationPostalCode(); /** * BankInformation address. * - * @var string + * @return string */ public function getBankInformationCountry(); /** * BankInformation name. * - * @var string + * @return string */ public function getBankInformationFullName(); @@ -54,14 +54,14 @@ public function getBankInformationFullName(); * It represents the amount debited on the bank account of the Author.In cents so 100€ will be written like « Amount » : 10000 * DebitedFunds – Fees = CreditedFunds (amount received on wallet). * - * @var string + * @return string */ public function getIban(); /** * The user bank informations belongs to * - * @var UserInterface + * @return UserInterface */ public function getUser(); diff --git a/Helper/BankInformationHelper.php b/Helper/BankInformationHelper.php index 30caa29..a11938f 100644 --- a/Helper/BankInformationHelper.php +++ b/Helper/BankInformationHelper.php @@ -77,4 +77,42 @@ public function createBankAccount(BankInformationInterface $bankInformation) return $bankAccount; } + + /** + * @param BankInformationInterface $bankInformation + * @return BankAccount + * @throws \Exception + */ + public function udpateBankAccount(BankInformationInterface $bankInformation) + { + /** @var UserInterface $user */ + $user = $bankInformation->getUser(); + $bankAccount = $this->mangopayHelper->Users->GetBankAccount($user->getMangoUserId(), $bankInformation->getMangoBankAccountId()); + + $bankAccount->OwnerName = $bankInformation->getBankInformationFullName(); + $bankAccount->UserId = $mangoUser->Id; + $bankAccount->Type = 'IBAN'; + + $address = new \MangoPay\Address(); + $userAddress = $bankInformation->getBankInformationStreetAddress(); + $city = $bankInformation->getBankInformationCity(); + $postalCode = $bankInformation->getBankInformationPostalCode(); + if (null == $userAddress || null == $city || null == $postalCode) { + throw new NotFoundHttpException(sprintf('address, city or postalCode missing for BankInformation of User id : %s', $user->getId())); + } + $address->AddressLine1 = $userAddress; + $address->AddressLine2 = $bankInformation->getBankInformationAdditionalStreetAddress(); + $address->City = $city; + $address->Country = $bankInformation->getBankInformationCountry(); + $address->PostalCode = $postalCode; + $bankAccount->OwnerAddress = $address; + + if ($bankInformation->getIban() !== $bankAccount->Details->IBAN) { + $bankAccount->Details->IBAN = $bankInformation->getIban(); + } + + $bankAccount = $this->mangopayHelper->Us$bankInformation->getIban()ers->UpdateBankAccount($mangoUser->Id, $bankAccount); + + return $bankAccount; + } } From f6962b516cedbe9ccd76a0b5eee9a37aae7e165d Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Wed, 24 Oct 2018 11:53:00 +0200 Subject: [PATCH 02/14] add mandate management --- Helper/MandateHelper.php | 74 +++++++++++++++++++++++++++++ Helper/PaymentDirectDebitHelper.php | 58 ++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 Helper/MandateHelper.php create mode 100644 Helper/PaymentDirectDebitHelper.php diff --git a/Helper/MandateHelper.php b/Helper/MandateHelper.php new file mode 100644 index 0000000..3b411d1 --- /dev/null +++ b/Helper/MandateHelper.php @@ -0,0 +1,74 @@ +mangopayHelper = $mangopayHelper; + $this->userHelper = $userHelper; + $this->dispatcher = $dispatcher; + } + + /** + * @param BankInformationInterface $user + * + * @return Mandate + */ + public function findOrCreateMandate(BankInformationInterface $bankInformation) + { + $bankInformationId = $bankInformation->getMangoBankAccountId(); + $userId = $bankInformation->getUser()->getMangoUserId(); + $mandates = $this->mangopayHelper->Users->GetMandatesForBankAccount($userId, $bankInformationId, null, (new Sorting())->AddField('CreationDate', 'DESC')); + $mandate = $mandates->first(); + + if (empty($mandates)) { + $mandate = $this->createMandateForBankInformation($bankInformation); + // else, create a new mango user + } else { + $mandate = $mandates->first(); + } + + return $wallet; + } + + public function createMandateForBankInformation(BankInformationInterface $bankInformation, $returnUrl = 'http://example.com/') + { + $bankInformationId = $bankInformation->getMangoBankAccountId(); + $userId = $bankInformation->getUser()->getMangoUserId(); + + $mandate = new Mandate(); + $mandate->BankAccountId = $bankInformationId; + $user = $bankInformation->getUser(); + if ($user instanceof LegalUserInterface) { + $culture = $user->getLegalRepresentativeNationality(); + } else { + $culture = $user->getNationality(); + } + $mandate->Culture = $culture; + $mandate->ReturnURL = $returnUrl; + $mangoMandate = $this->mangopayHelper->Mandates->Create($mandate, json_encode([ + 'bankInformation' => $bankInformationId, + 'user' => $userId, + ])); + + return $mangoMandate; + } +} diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php new file mode 100644 index 0000000..fc1b75c --- /dev/null +++ b/Helper/PaymentDirectDebitHelper.php @@ -0,0 +1,58 @@ +mangopayHelper = $mangopayHelper; + $this->mandateHelper = $mandateHelper; + } + + public function createDirectDebitPayin(UserInterface $userDebited, UserInterface $userCredited, $amount, $fees, $statementDescriptor = null) + { + $mandate = $this->mandateHelper->findOrCreateMandate($delivery->getFreightForwarder()->getManagedCompany()); + + $payin = new PayIn(); + $payin->AuthorId = $userDebited->getMangoUserId(); + $payin->CreditedUserId = $userCredited->getMangoUserId(); + $payin->CreditedWalletId = $userCredited->getMangoWalletId(); + + $debitedFunds = new Money(); + $debitedFunds->Currency = 'EUR'; + $debitedFunds->Amount = $amount; + + $fees = new Money(); + $fees->Currency = 'EUR'; + $fees->Amount = $fees; + + $payin->DebitedFunds = $debitedFunds; + $payin->Fees = $fees; + $payin->MandateId = $mandate->Id; + + $payin->PaymentDetails = new PayInPaymentDetailsDirectDebitDirect(); + $payin->PaymentDetails->MandateId = $mandate->Id; + $payin->PaymentDetails->StatementDescriptor = $statementDescriptor; + + return $this->mangopayHelper->PayIns->Create($payin); + } +} From 1057889ba7d9856e3078013b67d767e62b334499 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Wed, 24 Oct 2018 12:02:54 +0200 Subject: [PATCH 03/14] fix typo --- Helper/BankInformationHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/BankInformationHelper.php b/Helper/BankInformationHelper.php index a11938f..86c1787 100644 --- a/Helper/BankInformationHelper.php +++ b/Helper/BankInformationHelper.php @@ -83,7 +83,7 @@ public function createBankAccount(BankInformationInterface $bankInformation) * @return BankAccount * @throws \Exception */ - public function udpateBankAccount(BankInformationInterface $bankInformation) + public function updateBankAccount(BankInformationInterface $bankInformation) { /** @var UserInterface $user */ $user = $bankInformation->getUser(); @@ -111,7 +111,7 @@ public function udpateBankAccount(BankInformationInterface $bankInformation) $bankAccount->Details->IBAN = $bankInformation->getIban(); } - $bankAccount = $this->mangopayHelper->Us$bankInformation->getIban()ers->UpdateBankAccount($mangoUser->Id, $bankAccount); + $bankAccount = $this->mangopayHelper->Users->UpdateBankAccount($mangoUser->Id, $bankAccount); return $bankAccount; } From d2d287186983b8006ab973511e47f4d5d8af7326 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Thu, 25 Oct 2018 12:22:53 +0200 Subject: [PATCH 04/14] get a payin --- Helper/PaymentDirectDebitHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php index fc1b75c..d1cffac 100644 --- a/Helper/PaymentDirectDebitHelper.php +++ b/Helper/PaymentDirectDebitHelper.php @@ -55,4 +55,9 @@ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface return $this->mangopayHelper->PayIns->Create($payin); } + + public function getPayin($payinId) + { + return $this->mangopayHelper->PayIns->Get($payinId); + } } From a21de11f6d80fce435c774e984bccfcda84dedd8 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Fri, 26 Oct 2018 19:36:18 +0200 Subject: [PATCH 05/14] inject logger --- Helper/MandateHelper.php | 10 ++++------ Resources/config/services.yml | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Helper/MandateHelper.php b/Helper/MandateHelper.php index 3b411d1..f856883 100644 --- a/Helper/MandateHelper.php +++ b/Helper/MandateHelper.php @@ -23,8 +23,6 @@ class MandateHelper public function __construct(MangopayHelper $mangopayHelper) { $this->mangopayHelper = $mangopayHelper; - $this->userHelper = $userHelper; - $this->dispatcher = $dispatcher; } /** @@ -36,17 +34,17 @@ public function findOrCreateMandate(BankInformationInterface $bankInformation) { $bankInformationId = $bankInformation->getMangoBankAccountId(); $userId = $bankInformation->getUser()->getMangoUserId(); - $mandates = $this->mangopayHelper->Users->GetMandatesForBankAccount($userId, $bankInformationId, null, (new Sorting())->AddField('CreationDate', 'DESC')); - $mandate = $mandates->first(); + $pagination = null; + $mandates = $this->mangopayHelper->Users->GetMandatesForBankAccount($userId, $bankInformationId, $pagination, (new Sorting())->AddField('CreationDate', 'DESC')); if (empty($mandates)) { $mandate = $this->createMandateForBankInformation($bankInformation); // else, create a new mango user } else { - $mandate = $mandates->first(); + $mandate = array_shift($mandates); } - return $wallet; + return $mandate; } public function createMandateForBankInformation(BankInformationInterface $bankInformation, $returnUrl = 'http://example.com/') diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1dc5ed9..48baba0 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -13,6 +13,10 @@ services: - "%troopers_mangopay.base_url%" - "%troopers_mangopay.debug_mode%" - "@event_dispatcher" + calls: + - method: setLogger + arguments: + - '@logger' troopers_mangopay.mango_api: alias: Troopers\MangopayBundle\Helper\MangopayHelper \ No newline at end of file From 2c591176b5233c98b419833169154dfe5e6df40c Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Fri, 26 Oct 2018 19:48:44 +0200 Subject: [PATCH 06/14] add getPayin method --- Helper/PaymentDirectDebitHelper.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php index fc1b75c..6a14f00 100644 --- a/Helper/PaymentDirectDebitHelper.php +++ b/Helper/PaymentDirectDebitHelper.php @@ -5,22 +5,16 @@ use MangoPay\Money; use MangoPay\PayIn; use MangoPay\PayInPaymentDetailsDirectDebitDirect; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\Routing\Matcher\UrlMatcherInterface; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Troopers\MangopayBundle\Entity\Transaction; -use Troopers\MangopayBundle\Entity\TransactionInterface; use Troopers\MangopayBundle\Entity\UserInterface; +use Troopers\MangopayBundle\Helper\MangopayHelper; class PaymentDirectDebitHelper { - private $mangopayHelper; - private $router; - private $dispatcher; + protected $mangopayHelper; /** * @var MandateHelper */ - private $mandateHelper; + protected $mandateHelper; public function __construct(MangopayHelper $mangopayHelper, MandateHelper $mandateHelper) { @@ -28,9 +22,17 @@ public function __construct(MangopayHelper $mangopayHelper, MandateHelper $manda $this->mandateHelper = $mandateHelper; } + /** + * @param UserInterface $userDebited + * @param UserInterface $userCredited + * @param int $amount + * @param int $fees + * @param string|null $statementDescriptor + * @return PayIn + */ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface $userCredited, $amount, $fees, $statementDescriptor = null) { - $mandate = $this->mandateHelper->findOrCreateMandate($delivery->getFreightForwarder()->getManagedCompany()); + $mandate = $this->mandateHelper->findOrCreateMandate($userDebited); $payin = new PayIn(); $payin->AuthorId = $userDebited->getMangoUserId(); @@ -47,7 +49,6 @@ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface $payin->DebitedFunds = $debitedFunds; $payin->Fees = $fees; - $payin->MandateId = $mandate->Id; $payin->PaymentDetails = new PayInPaymentDetailsDirectDebitDirect(); $payin->PaymentDetails->MandateId = $mandate->Id; @@ -55,4 +56,9 @@ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface return $this->mangopayHelper->PayIns->Create($payin); } + + public function getPayin() + { + return $this->mangopayHelper->PayIns->Get($payin); + } } From 2548004a7d34e8d5986461f5e7edbeafe082e03f Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Fri, 26 Oct 2018 19:49:17 +0200 Subject: [PATCH 07/14] rename getBankAccountId --- Helper/PaymentOutHelper.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Helper/PaymentOutHelper.php b/Helper/PaymentOutHelper.php index 3ecbbb2..e7a945f 100644 --- a/Helper/PaymentOutHelper.php +++ b/Helper/PaymentOutHelper.php @@ -23,7 +23,7 @@ public function __construct(MangopayHelper $mangopayHelper) public function buildPayOutPaymentDetailsBankWire(UserInterface $user) { $meanOfPaymentDetails = new PayOutPaymentDetailsBankWire(); - if (null == $bankAccountId = $user->getBankAccountId()) { + if (null == $bankAccountId = $user->getMangoBankAccountId()) { throw new NotFoundHttpException(sprintf('bankAccount not found for id : %s', $user->getId())); } $meanOfPaymentDetails->BankAccountId = $bankAccountId; @@ -42,17 +42,15 @@ public function buildMoney($amount = '0', $currency = 'EUR') public function createPayOutForUser(UserInterface $user, $debitedFunds, $fees = '0') { - $debitedFunds = $this->buildMoney($debitedFunds); - $fees = $this->buildMoney($fees); $meanOfPaymentDetails = $this->buildPayOutPaymentDetailsBankWire($user); $payOut = new PayOut(); $payOut->AuthorId = $user->getMangoUserId(); $payOut->DebitedWalletId = $user->getMangoWalletId(); $payOut->PaymentType = 'BANK_WIRE'; - $payOut->DebitedFunds = $debitedFunds; + $payOut->DebitedFunds = $this->buildMoney($debitedFunds); $payOut->MeanOfPaymentDetails = $meanOfPaymentDetails; - $payOut->fees = $fees; + $payOut->fees = $this->buildMoney($fees); return $this->mangopayHelper->PayOuts->Create($payOut); } From 2a317dfe07137f644645282365c842a63eca56af Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Sun, 28 Oct 2018 11:50:42 +0100 Subject: [PATCH 08/14] get bank information from user --- Entity/UserInterface.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Entity/UserInterface.php b/Entity/UserInterface.php index 1e828eb..6c4f76a 100644 --- a/Entity/UserInterface.php +++ b/Entity/UserInterface.php @@ -38,4 +38,9 @@ public function getMangoCardId(); * @var int */ public function getMangoBankAccountId(); + + /** + * @var int + */ + public function getBankInformation(); } From 56ba3ec866a602d1eaf0ebf8bb1341dd7ab93b99 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Tue, 20 Nov 2018 18:38:44 +0100 Subject: [PATCH 09/14] use PayInPaymentDetailsDirectDebit with ExecutionDetails --- Helper/PaymentDirectDebitHelper.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php index f9c329c..f9fc530 100644 --- a/Helper/PaymentDirectDebitHelper.php +++ b/Helper/PaymentDirectDebitHelper.php @@ -4,9 +4,11 @@ use MangoPay\Money; use MangoPay\PayIn; +use MangoPay\PayInExecutionDetailsDirect; +use MangoPay\PayInPaymentDetailsDirectDebit; use MangoPay\PayInPaymentDetailsDirectDebitDirect; +use MangoPay\PayInPaymentType; use Troopers\MangopayBundle\Entity\UserInterface; -use Troopers\MangopayBundle\Helper\MangopayHelper; class PaymentDirectDebitHelper { @@ -43,17 +45,19 @@ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface $debitedFunds->Currency = 'EUR'; $debitedFunds->Amount = $amount; - $fees = new Money(); - $fees->Currency = 'EUR'; - $fees->Amount = $fees; + $mangoFees = new Money(); + $mangoFees->Currency = 'EUR'; + $mangoFees->Amount = $fees; $payin->DebitedFunds = $debitedFunds; - $payin->Fees = $fees; + $payin->Fees = $mangoFees; - $payin->PaymentDetails = new PayInPaymentDetailsDirectDebitDirect(); + $payin->PaymentDetails = new PayInPaymentDetailsDirectDebit(); $payin->PaymentDetails->MandateId = $mandate->Id; $payin->PaymentDetails->StatementDescriptor = $statementDescriptor; + $payin->ExecutionDetails = new PayInExecutionDetailsDirect(); + return $this->mangopayHelper->PayIns->Create($payin); } From 41b9a6bbe0e3365fb232f5e1d55811a412166d62 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Tue, 20 Nov 2018 18:39:43 +0100 Subject: [PATCH 10/14] inject returnUrl for mandates --- Helper/MandateHelper.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Helper/MandateHelper.php b/Helper/MandateHelper.php index f856883..7e95338 100644 --- a/Helper/MandateHelper.php +++ b/Helper/MandateHelper.php @@ -30,7 +30,7 @@ public function __construct(MangopayHelper $mangopayHelper) * * @return Mandate */ - public function findOrCreateMandate(BankInformationInterface $bankInformation) + public function findOrCreateMandate(BankInformationInterface $bankInformation, $returnUrl = 'http://example.com/') { $bankInformationId = $bankInformation->getMangoBankAccountId(); $userId = $bankInformation->getUser()->getMangoUserId(); @@ -38,7 +38,7 @@ public function findOrCreateMandate(BankInformationInterface $bankInformation) $mandates = $this->mangopayHelper->Users->GetMandatesForBankAccount($userId, $bankInformationId, $pagination, (new Sorting())->AddField('CreationDate', 'DESC')); if (empty($mandates)) { - $mandate = $this->createMandateForBankInformation($bankInformation); + $mandate = $this->createMandateForBankInformation($bankInformation, $returnUrl); // else, create a new mango user } else { $mandate = array_shift($mandates); @@ -62,10 +62,13 @@ public function createMandateForBankInformation(BankInformationInterface $bankIn } $mandate->Culture = $culture; $mandate->ReturnURL = $returnUrl; - $mangoMandate = $this->mangopayHelper->Mandates->Create($mandate, json_encode([ + $mangoMandate = $this->mangopayHelper->Mandates->Create($mandate, md5(json_encode([ 'bankInformation' => $bankInformationId, 'user' => $userId, - ])); + ]))); + + $bankInformation->setMangoMandateId($mandate->Id); + $bankInformation->setMangoMandateUrl($mandate->RedirectURL); return $mangoMandate; } From 55e25ae958e34ca403b4a260529aa549eb3f1b0c Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Tue, 20 Nov 2018 19:55:51 +0100 Subject: [PATCH 11/14] create a sandbox mode to inject testing values --- DependencyInjection/Configuration.php | 1 + .../TroopersMangopayExtension.php | 3 ++- Entity/BankInformationInterface.php | 2 ++ Helper/BankInformationHelper.php | 17 ++++++++++++++--- Helper/User/LegalUserHelper.php | 10 ++++++++-- Helper/User/NaturalUserHelper.php | 17 ++++++++++++++--- Resources/config/services.yml | 5 ++++- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 72f6064..1958b9d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ public function getConfigTreeBuilder() $rootNode ->children() + ->booleanNode('sandbox_mode')->defaultValue(false)->end() ->booleanNode('debug_mode')->defaultValue(false)->end() ->scalarNode('client_id')->isRequired()->end() ->scalarNode('client_password')->isRequired()->end() diff --git a/DependencyInjection/TroopersMangopayExtension.php b/DependencyInjection/TroopersMangopayExtension.php index 72f8511..d045c35 100644 --- a/DependencyInjection/TroopersMangopayExtension.php +++ b/DependencyInjection/TroopersMangopayExtension.php @@ -25,7 +25,8 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); - $container->setParameter('troopers_mangopay.debug_mode', $config['debug_mode'] === true); + $container->setParameter('troopers_mangopay.sandbox_mode', $config['sandbox_mode']); + $container->setParameter('troopers_mangopay.debug_mode', $config['debug_mode']); $container->setParameter('troopers_mangopay.client_id', $config['client_id']); $container->setParameter('troopers_mangopay.client_password', $config['client_password']); $container->setParameter('troopers_mangopay.base_url', $config['base_url']); diff --git a/Entity/BankInformationInterface.php b/Entity/BankInformationInterface.php index 6d31441..8c6987c 100644 --- a/Entity/BankInformationInterface.php +++ b/Entity/BankInformationInterface.php @@ -68,4 +68,6 @@ public function getUser(); public function getMangoBankAccountId(); public function setMangoBankAccountId($mangoBankAccountId); + public function setMangoMandateId($mangoMandateId); + public function setMangoMandateUrl($mangoMandateUrl); } diff --git a/Helper/BankInformationHelper.php b/Helper/BankInformationHelper.php index 86c1787..24d7acd 100644 --- a/Helper/BankInformationHelper.php +++ b/Helper/BankInformationHelper.php @@ -13,11 +13,13 @@ class BankInformationHelper { private $mangopayHelper; private $userHelper; + private $mangopaySandbox; - public function __construct(MangopayHelper $mangopayHelper, UserHelper $userHelper) + public function __construct(MangopayHelper $mangopayHelper, UserHelper $userHelper, $mangopaySandbox) { $this->mangopayHelper = $mangopayHelper; $this->userHelper = $userHelper; + $this->mangopaySandbox = $mangopaySandbox; } /** @@ -67,7 +69,12 @@ public function createBankAccount(BankInformationInterface $bankInformation) $bankAccount->OwnerAddress = $address; $bankAccountDetailsIban = new BankAccountDetailsIBAN(); - $bankAccountDetailsIban->IBAN = $bankInformation->getIban(); + + $iban = $bankInformation->getIban(); + if ($this->mangopaySandbox) { + $iban = "FR7611808009101234567890147"; + } + $bankAccountDetailsIban->IBAN = $iban; $bankAccount->Details = $bankAccountDetailsIban; @@ -108,7 +115,11 @@ public function updateBankAccount(BankInformationInterface $bankInformation) $bankAccount->OwnerAddress = $address; if ($bankInformation->getIban() !== $bankAccount->Details->IBAN) { - $bankAccount->Details->IBAN = $bankInformation->getIban(); + $iban = $bankInformation->getIban(); + if ($this->mangopaySandbox) { + $iban = "FR7611808009101234567890147"; + } + $bankAccount->Details->IBAN = $iban; } $bankAccount = $this->mangopayHelper->Users->UpdateBankAccount($mangoUser->Id, $bankAccount); diff --git a/Helper/User/LegalUserHelper.php b/Helper/User/LegalUserHelper.php index b056bcb..dade6a3 100644 --- a/Helper/User/LegalUserHelper.php +++ b/Helper/User/LegalUserHelper.php @@ -24,12 +24,14 @@ class LegalUserHelper private $mangopayHelper; private $dispatcher; private $KYCHelper; + private $mangopaySandbox; - public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInterface $dispatcher, KYCHelper $KYCHelper) + public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInterface $dispatcher, KYCHelper $KYCHelper, $mangopaySandbox) { $this->mangopayHelper = $mangopayHelper; $this->dispatcher = $dispatcher; $this->KYCHelper = $KYCHelper; + $this->mangopaySandbox = $mangopaySandbox; } public function createMangoUser(LegalUserInterface $user) @@ -44,7 +46,11 @@ public function createMangoUser(LegalUserInterface $user) $mangoUser->LegalPersonType = $user->getLegalPersonType(); $mangoUser->Name = $user->getName(); $mangoUser->Email = $user->getEmail(); - $mangoUser->LegalRepresentativeFirstName = $user->getLegalRepresentativeFirstName(); + $legalRepresentativeFirstName = $user->getLegalRepresentativeFirstName(); + if ($this->mangopaySandbox) { + $legalRepresentativeFirstName = "Successful"; + } + $mangoUser->LegalRepresentativeFirstName = $legalRepresentativeFirstName; $mangoUser->LegalRepresentativeLastName = $user->getLegalRepresentativeLastName(); $mangoUser->LegalRepresentativeBirthday = $birthday ? $birthday->getTimestamp() : null; $mangoUser->LegalRepresentativeNationality = $user->getLegalRepresentativeNationality(); diff --git a/Helper/User/NaturalUserHelper.php b/Helper/User/NaturalUserHelper.php index 5e56392..6eb5d81 100644 --- a/Helper/User/NaturalUserHelper.php +++ b/Helper/User/NaturalUserHelper.php @@ -18,11 +18,13 @@ class NaturalUserHelper { private $mangopayHelper; private $dispatcher; + private $mangopaySandbox; - public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInterface $dispatcher) + public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInterface $dispatcher, $mangopaySandbox) { $this->mangopayHelper = $mangopayHelper; $this->dispatcher = $dispatcher; + $this->mangopaySandbox = $mangopaySandbox; } public function createMangoUser(NaturalUserInterface $user) @@ -35,7 +37,11 @@ public function createMangoUser(NaturalUserInterface $user) } $mangoUser = new UserNatural(); $mangoUser->Email = $user->getEmail(); - $mangoUser->FirstName = $user->getFirstName(); + $firstname = $user->getFirstName(); + if ($this->mangopaySandbox) { + $firstname = "Successful"; + } + $mangoUser->FirstName = $firstname; $mangoUser->LastName = $user->getLastName(); $mangoUser->Birthday = $birthday ? $birthday->getTimestamp() : null; $mangoUser->Nationality = $user->getNationality(); @@ -60,7 +66,12 @@ public function updateMangoUser(NaturalUserInterface $user) $mangoUser = $this->mangopayHelper->Users->get($mangoUserId); $mangoUser->Email = $user->getEmail(); - $mangoUser->FirstName = $user->getFirstname(); + + $firstname = $user->getFirstName(); + if ($this->mangopaySandbox) { + $firstname = "Successful"; + } + $mangoUser->FirstName = $firstname; $mangoUser->LastName = $user->getLastname(); $mangoUser->Birthday = $birthdate; $mangoUser->Nationality = $user->getNationality(); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 48baba0..512c413 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,4 +1,7 @@ services: + _defaults: + bind: + $mangopaySandbox: '%troopers_mangopay.sandbox_mode%' Troopers\MangopayBundle\: autowire: true @@ -19,4 +22,4 @@ services: - '@logger' troopers_mangopay.mango_api: - alias: Troopers\MangopayBundle\Helper\MangopayHelper \ No newline at end of file + alias: Troopers\MangopayBundle\Helper\MangopayHelper From 5d32ebde9e424cb0c6727f9800ba8ff177b14a13 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Wed, 21 Nov 2018 11:23:39 +0100 Subject: [PATCH 12/14] php md fixes --- Entity/LegalUserInterface.php | 4 ++++ Entity/NaturalUserInterface.php | 2 +- Entity/UserInterface.php | 4 ++++ Helper/BankInformationHelper.php | 2 +- Helper/KYCHelper.php | 2 +- Helper/PaymentDirectDebitHelper.php | 2 +- Helper/User/LegalUserHelper.php | 11 ++++++----- Helper/User/NaturalUserHelper.php | 7 ++++--- composer.json | 2 +- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Entity/LegalUserInterface.php b/Entity/LegalUserInterface.php index 0aa39f9..7339ce5 100644 --- a/Entity/LegalUserInterface.php +++ b/Entity/LegalUserInterface.php @@ -140,6 +140,7 @@ public function getCompanyNumber(); * behalf of the legal entity */ public function getLegalRepresentativeProofOfIdentityId(); + public function setLegalRepresentativeProofOfIdentityId($id); /** * @var string @@ -147,6 +148,7 @@ public function getLegalRepresentativeProofOfIdentityId(); * the following information is mentioned: business name, activity, registered address, shareholding… */ public function getStatuteId(); + public function setStatuteId($id); /** * @var string @@ -155,12 +157,14 @@ public function getStatuteId(); * authority */ public function getProofOfRegistrationId(); + public function setProofOfRegistrationId($id); /** * @var string * Shareholder declaration (as https://www.mangopay.com/terms/shareholder-declaration/Shareholder_Declaration-EN.pdf) */ public function getShareholderDeclarationId(); + public function setShareholderDeclarationId($id); /** * @var File diff --git a/Entity/NaturalUserInterface.php b/Entity/NaturalUserInterface.php index 478b99f..a6a76f4 100644 --- a/Entity/NaturalUserInterface.php +++ b/Entity/NaturalUserInterface.php @@ -60,7 +60,7 @@ public function getPostalCode(); * @var \DateTime * User’s birthdate. */ - public function getBirthday() :?\DateTime; + public function getBirthday(); /** * @var string diff --git a/Entity/UserInterface.php b/Entity/UserInterface.php index 6c4f76a..ade8d5b 100644 --- a/Entity/UserInterface.php +++ b/Entity/UserInterface.php @@ -23,21 +23,25 @@ public function getEmail(); * @var int */ public function getMangoUserId(); + public function setMangoUserId($id); /** * @var int */ public function getMangoWalletId(); + public function setMangoWalletId($id); /** * @var int */ public function getMangoCardId(); + public function setMangoCardId($id); /** * @var int */ public function getMangoBankAccountId(); + public function setMangoBankAccountId($id); /** * @var int diff --git a/Helper/BankInformationHelper.php b/Helper/BankInformationHelper.php index 24d7acd..bfa22f5 100644 --- a/Helper/BankInformationHelper.php +++ b/Helper/BankInformationHelper.php @@ -97,7 +97,7 @@ public function updateBankAccount(BankInformationInterface $bankInformation) $bankAccount = $this->mangopayHelper->Users->GetBankAccount($user->getMangoUserId(), $bankInformation->getMangoBankAccountId()); $bankAccount->OwnerName = $bankInformation->getBankInformationFullName(); - $bankAccount->UserId = $mangoUser->Id; + $bankAccount->UserId = $user->getMangoUserId(); $bankAccount->Type = 'IBAN'; $address = new \MangoPay\Address(); diff --git a/Helper/KYCHelper.php b/Helper/KYCHelper.php index 5fefcb3..8b3bef6 100644 --- a/Helper/KYCHelper.php +++ b/Helper/KYCHelper.php @@ -39,7 +39,7 @@ public function createDocument(File $file) { $page = new KycPage(); - if (false === $file = @file_get_contents($value->getPathname(), FILE_BINARY)) { + if (false === $file = @file_get_contents($file->getPathname(), FILE_BINARY)) { throw new TransformationFailedException(sprintf('Unable to read the "%s" file', $value->getPathname())); } diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php index f9fc530..087e57b 100644 --- a/Helper/PaymentDirectDebitHelper.php +++ b/Helper/PaymentDirectDebitHelper.php @@ -34,7 +34,7 @@ public function __construct(MangopayHelper $mangopayHelper, MandateHelper $manda */ public function createDirectDebitPayin(UserInterface $userDebited, UserInterface $userCredited, $amount, $fees, $statementDescriptor = null) { - $mandate = $this->mandateHelper->findOrCreateMandate($userDebited); + $mandate = $this->mandateHelper->findOrCreateMandate($userDebited->getBankInformation()); $payin = new PayIn(); $payin->AuthorId = $userDebited->getMangoUserId(); diff --git a/Helper/User/LegalUserHelper.php b/Helper/User/LegalUserHelper.php index dade6a3..abd7d10 100644 --- a/Helper/User/LegalUserHelper.php +++ b/Helper/User/LegalUserHelper.php @@ -34,7 +34,7 @@ public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInter $this->mangopaySandbox = $mangopaySandbox; } - public function createMangoUser(LegalUserInterface $user) + public function createMangoUser(UserInterface $user) { $birthday = null; if ($user->getLegalRepresentativeBirthday() instanceof \Datetime) { @@ -80,19 +80,19 @@ public function createMangoUser(LegalUserInterface $user) if (null !== $document = $user->getProofOfRegistration()) { $mangoDocument = $this->createDocument($document, $user); $mangoUser->ProofOfRegistration = $mangoDocument->Id; - $user->getProofOfRegistrationId($mangoDocument->Id); + $user->setProofOfRegistrationId($mangoDocument->Id); } if (null !== $document = $user->getLegalRepresentativeProofOfIdentity()) { $mangoDocument = $this->createDocument($document, $user); $mangoUser->LegalRepresentativeProofOfIdentity = $mangoDocument->Id; - $user->getLegalRepresentativeProofOfIdentityId($mangoDocument->Id); + $user->setLegalRepresentativeProofOfIdentityId($mangoDocument->Id); } if (null !== $document = $user->getStatute()) { $mangoDocument = $this->createDocument($document, $user); $mangoUser->Statute = $mangoDocument->Id; - $user->getStatuteId($mangoDocument->Id); + $user->setStatuteId($mangoDocument->Id); } $event = new UserEvent($user, $mangoUser); @@ -101,8 +101,9 @@ public function createMangoUser(LegalUserInterface $user) return $mangoUser; } - public function updateMangoUser(LegalUserInterface $user) + public function updateMangoUser(UserInterface $user) { + $birthday = null; if ($user->getLegalRepresentativeBirthday() instanceof \Datetime) { $birthday = $user->getLegalRepresentativeBirthday()->getTimestamp(); } diff --git a/Helper/User/NaturalUserHelper.php b/Helper/User/NaturalUserHelper.php index 6eb5d81..9d85d32 100644 --- a/Helper/User/NaturalUserHelper.php +++ b/Helper/User/NaturalUserHelper.php @@ -27,7 +27,7 @@ public function __construct(MangopayHelper $mangopayHelper, EventDispatcherInter $this->mangopaySandbox = $mangopaySandbox; } - public function createMangoUser(NaturalUserInterface $user) + public function createMangoUser(UserInterface $user) { $birthday = null; if ($user->getBirthday() instanceof \Datetime) { @@ -59,8 +59,9 @@ public function createMangoUser(NaturalUserInterface $user) public function updateMangoUser(NaturalUserInterface $user) { + $birthday = null; if ($user->getBirthday() instanceof \Datetime) { - $birthdate = $user->getBirthday()->getTimestamp(); + $birthday = $user->getBirthday()->getTimestamp(); } $mangoUserId = $user->getMangoUserId(); $mangoUser = $this->mangopayHelper->Users->get($mangoUserId); @@ -73,7 +74,7 @@ public function updateMangoUser(NaturalUserInterface $user) } $mangoUser->FirstName = $firstname; $mangoUser->LastName = $user->getLastname(); - $mangoUser->Birthday = $birthdate; + $mangoUser->Birthday = $birthday; $mangoUser->Nationality = $user->getNationality(); $mangoUser->CountryOfResidence = $user->getCountry(); $mangoUser->Tag = $user->getId(); diff --git a/composer.json b/composer.json index 2bd7083..05c71e7 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": "~5.3|~7", + "php": "~5.5|~7", "symfony/framework-bundle": "~3.4|~4", "mangopay/php-sdk-v2": ">=2.0", "stof/doctrine-extensions-bundle": "~1.2", From df4794fc78ccd6647119e3c9ac1a4f57eef81ec6 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Thu, 22 Nov 2018 18:12:18 +0100 Subject: [PATCH 13/14] define getPayout shortcut --- Helper/PaymentDirectDebitHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Helper/PaymentDirectDebitHelper.php b/Helper/PaymentDirectDebitHelper.php index 087e57b..57ca25c 100644 --- a/Helper/PaymentDirectDebitHelper.php +++ b/Helper/PaymentDirectDebitHelper.php @@ -65,4 +65,9 @@ public function getPayin($payinId) { return $this->mangopayHelper->PayIns->Get($payinId); } + + public function getPayout($payoutId) + { + return $this->mangopayHelper->PayOuts->Get($payoutId); + } } From 2a92d5b34fa2a33a6da6d1a76289fbdadaa77724 Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Sun, 25 Nov 2018 18:35:57 +0100 Subject: [PATCH 14/14] create kyc documents --- Helper/User/LegalUserHelper.php | 40 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Helper/User/LegalUserHelper.php b/Helper/User/LegalUserHelper.php index abd7d10..7022784 100644 --- a/Helper/User/LegalUserHelper.php +++ b/Helper/User/LegalUserHelper.php @@ -3,7 +3,10 @@ namespace Troopers\MangopayBundle\Helper\User; use Doctrine\ORM\EntityManager; +use MangoPay\KycDocument; +use MangoPay\KycDocumentStatus; use MangoPay\KycLevel; +use MangoPay\KycPage; use MangoPay\User; use MangoPay\UserLegal; use MangoPay\UserNatural; @@ -18,6 +21,7 @@ use Troopers\MangopayBundle\Helper\MangopayHelper; use MangoPay\BankAccount; use MangoPay\BankAccountDetailsIBAN; +use MangoPay\KycDocumentType; class LegalUserHelper { @@ -78,23 +82,29 @@ public function createMangoUser(UserInterface $user) $user->setMangoUserId($mangoUser->Id); if (null !== $document = $user->getProofOfRegistration()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::RegistrationProof); $mangoUser->ProofOfRegistration = $mangoDocument->Id; $user->setProofOfRegistrationId($mangoDocument->Id); } if (null !== $document = $user->getLegalRepresentativeProofOfIdentity()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::IdentityProof); $mangoUser->LegalRepresentativeProofOfIdentity = $mangoDocument->Id; $user->setLegalRepresentativeProofOfIdentityId($mangoDocument->Id); } if (null !== $document = $user->getStatute()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::ArticlesOfAssociation); $mangoUser->Statute = $mangoDocument->Id; $user->setStatuteId($mangoDocument->Id); } + if (null !== $document = $user->getShareholderDeclaration()) { + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::ShareholderDeclaration); + $mangoUser->ShareholderDeclaration = $mangoDocument->Id; + $user->setShareholderDeclarationId($mangoDocument->Id); + } + $event = new UserEvent($user, $mangoUser); $this->dispatcher->dispatch(TroopersMangopayEvents::NEW_USER, $event); @@ -129,25 +139,25 @@ public function updateMangoUser(UserInterface $user) if (null !== $document = $user->getProofOfRegistration()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::RegistrationProof); $mangoUser->ProofOfRegistration = $mangoDocument->Id; $user->setProofOfRegistrationId($mangoDocument->Id); } if (null !== $document = $user->getLegalRepresentativeProofOfIdentity()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::IdentityProof); $mangoUser->LegalRepresentativeProofOfIdentity = $mangoDocument->Id; $user->setLegalRepresentativeProofOfIdentityId($mangoDocument->Id); } if (null !== $document = $user->getStatute()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::ArticlesOfAssociation); $mangoUser->Statute = $mangoDocument->Id; $user->setStatuteId($mangoDocument->Id); } if (null !== $document = $user->getShareholderDeclaration()) { - $mangoDocument = $this->createDocument($document, $user); + $mangoDocument = $this->createDocument($document, $user, KycDocumentType::ShareholderDeclaration); $mangoUser->ShareholderDeclaration = $mangoDocument->Id; $user->setShareholderDeclarationId($mangoDocument->Id); } @@ -157,10 +167,20 @@ public function updateMangoUser(UserInterface $user) return $mangoUser; } - protected function createDocument(File $file, UserInterface $user) + protected function createDocument($fileContent, UserInterface $user, $type) { - $document = $this->KYCHelper->createDocument($file); - $document = $this->mangopayHelper->Users->CreateKycDocument($user->getMangoUserId(), $document); + $kycDocument = new KycDocument(); + $kycDocument->UserId = $user->getMangoUserId(); + $kycDocument->Type = $type; + $kycDocument->Status = KycDocumentStatus::ValidationAsked; + + $document = $this->mangopayHelper->Users->CreateKycDocument($user->getMangoUserId(), $kycDocument); + + $page = new KycPage(); + $page->File = $fileContent; + + $this->mangopayHelper->Users->CreateKycPage($user->getMangoUserId(), $document->Id, $page); + return $document; }