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; }