router = $router; $this->transactionManager = $transactionManager; } private function redirectURL(TransactionInterface $transaction): array { return [ 'urlNotification' => $this->router->generate ( 'api_redsys_ipn_paiement', ['publicKey'=>$transaction->getPublicKey()], UrlGeneratorInterface::ABSOLUTE_URL ), 'urlCancel' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnError(), [], UrlGeneratorInterface::ABSOLUTE_URL ), 'urlSuccess' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnSuccess(), [], UrlGeneratorInterface::ABSOLUTE_URL ) ]; } public function init(TransactionInterface $transaction): array { $redSysObject = new RedsysAPI(); $url = $this->redirectURL($transaction); // init object RedSys $redSysObject->setParameter("DS_MERCHANT_AMOUNT", number_format($transaction->getTotal() , 2, '.', '') * 100); $redSysObject->setParameter("DS_MERCHANT_ORDER", sprintf("%08d",$transaction->getId())); $redSysObject->setParameter("DS_MERCHANT_MERCHANTCODE", $transaction->getPaymentMode()->getShopKey()); $redSysObject->setParameter("DS_MERCHANT_CURRENCY", $transaction->getPaymentMode()->getCurrency()); $redSysObject->setParameter("DS_MERCHANT_TRANSACTIONTYPE", '0'); $redSysObject->setParameter("DS_MERCHANT_TERMINAL", $transaction->getPaymentMode()->getTerminal()); $redSysObject->setParameter("DS_MERCHANT_MERCHANTURL", $url['urlNotification']); $redSysObject->setParameter("DS_MERCHANT_URLOK", $url['urlSuccess']); $redSysObject->setParameter("DS_MERCHANT_URLKO", $url['urlCancel']); $redSysParameters = $redSysObject->createMerchantParameters(); $signature = $redSysObject->createMerchantSignature($transaction->getPaymentMode()->getCertificate()); return [ 'url_system_pay' => $transaction->getPaymentMode()->getUrlPayment(), 'HMAC' => 'HMAC_SHA256_V1', 'red_sys_parameters' => $redSysParameters, 'signature' => $signature ]; } public function ipn(TransactionInterface $transaction, string $id_transaction, string $message, float $amount, bool $status) { // Change transaction status on paid if($status){ $transaction->setStatus(TransactionStatusAction::TRANSACTION_PAID); $transaction->setTotalPayer($amount); } else $transaction->setStatus(TransactionStatusAction::TRANSACTION_ERROR); $transaction->setInformation($message); $transaction->setIdTransactionExternal($id_transaction); $this->transactionManager->update($transaction); return true; } }