Example #1
0
 /**
  * @param UserInterface $user
  * @param string $description
  * @return Wallet
  */
 public function findOrCreateWallet(UserInterface $user, $description = 'current wallet')
 {
     if ($user->getMangoWalletId()) {
         $wallet = $this->mangopayHelper->Wallets->get($user->getMangoWalletId());
         // else, create a new mango user
     } else {
         $wallet = $this->createWalletForUser($user, $description);
     }
     return $wallet;
 }
Example #2
0
 public function createMangoUser(UserInterface $user)
 {
     $mangoUser = new UserNatural();
     $mangoUser->Email = $user->getEmail();
     $mangoUser->FirstName = $user->getFirstname();
     $mangoUser->LastName = $user->getLastname();
     $mangoUser->Birthday = $user->getBirthDate();
     $mangoUser->Nationality = $user->getNationality();
     $mangoUser->CountryOfResidence = $user->getCountry();
     $mangoUser->Tag = $user->getId();
     $mangoUser = $this->mangopayHelper->Users->Create($mangoUser);
     $event = new UserEvent($user, $mangoUser);
     $this->dispatcher->dispatch(AppVentusMangopayEvents::NEW_USER, $event);
     $user->setMangoUserId($mangoUser->Id);
     $this->entityManager->persist($user);
     $this->entityManager->flush();
     return $mangoUser;
 }
 /**
  * execute a pre authorisation
  * @param CardPreAuthorisation $preAuthorisation
  * @param UserInterface        $buyer
  * @param Wallet               $wallet
  * @param integer              $feesAmount
  * @param integer              $amount           0 to 100
  *
  * @return PayIn
  */
 public function executePreAuthorisation(CardPreAuthorisation $preAuthorisation, UserInterface $buyer, Wallet $wallet, $feesAmount, $amount = null)
 {
     if (!$amount) {
         $amount = $preAuthorisation->getDebitedFunds();
     }
     $payIn = new PayIn();
     $payIn->AuthorId = $buyer->getMangoUserId();
     $payIn->CreditedWalletId = $wallet->Id;
     $payIn->PreauthorizationId = $preAuthorisation->getMangoId();
     $payIn->PaymentDetails = new PayInPaymentDetailsPreAuthorized();
     $payIn->ExecutionDetails = new PayInExecutionDetailsDirect();
     $fees = new Money();
     $fees->Currency = 'EUR';
     $fees->Amount = $feesAmount;
     $payIn->Fees = $fees;
     $debitedFunds = new Money();
     $debitedFunds->Currency = 'EUR';
     $debitedFunds->Amount = $amount;
     $payIn->DebitedFunds = $debitedFunds;
     $payIn = $this->mangopayHelper->PayIns->Create($payIn);
     if (property_exists($payIn, 'Status') && $payIn->Status != "FAILED") {
         $event = new PayInEvent($payIn);
         $this->dispatcher->dispatch(AppVentusMangopayEvents::NEW_PAY_IN, $event);
         return $payIn;
     }
     $event = new PayInEvent($payIn);
     $this->dispatcher->dispatch(AppVentusMangopayEvents::ERROR_PAY_IN, $event);
     throw new \Exception('PayIn creation failed');
 }