public function findOrCreateMangoUser(UserInterface $user) { if ($mangoUserId = $user->getMangoUserId()) { $mangoUser = $this->mangopayHelper->Users->get($mangoUserId); } else { $mangoUser = $this->createMangoUser($user); } 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'); }