router = $router; $this->transactionManager = $transactionManager; } /** * @param TransactionInterface $transaction * @return array */ public function init(TransactionInterface $transaction): array { // Recuperate certificate for payment mode $certificat = $transaction->getPaymentMode()->getCertificate(); // Create Array parameters $parameters['params']=[ 'vads_action_mode' => utf8_encode('INTERACTIVE'), 'vads_amount' => number_format($transaction->getTotal() , 2, '.', '') * 100, // montant en centimes 'vads_ctx_mode' => utf8_encode($transaction->getPaymentMode()->getContext()), 'vads_currency' => $transaction->getPaymentMode()->getCurrency(), 'vads_page_action' => utf8_encode('PAYMENT'), 'vads_payment_config' => utf8_encode('SINGLE'), 'vads_site_id' => $transaction->getPaymentMode()->getShopKey(), 'vads_trans_date' => gmdate('YmdHis'), // Date Format UTC 'vads_trans_id' => sprintf("%06d",$transaction->getId()), 'vads_version' => utf8_encode('V2'), 'vads_cust_email' => utf8_encode($transaction->getUser()->getEmail()), 'vads_cust_first_name' => utf8_encode($transaction->getUser()->getFirstName()), 'vads_cust_last_name' => utf8_encode($transaction->getUser()->getLastName()), 'vads_redirect_success_timeout' => 3, 'vads_redirect_success_message' => utf8_encode("Redirection vers la boutique dans 5 sec"), 'vads_redirect_error_timeout' => 3, 'vads_redirect_error_message' => utf8_encode("Redirection vers la boutique dans 5 sec"), 'vads_return_mode' => "POST", 'vads_url_success' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnSuccess(), [], UrlGeneratorInterface::ABSOLUTE_URL ), 'vads_url_cancel' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnError(), [], UrlGeneratorInterface::ABSOLUTE_URL ), 'vads_url_error' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnError(), [], UrlGeneratorInterface::ABSOLUTE_URL ), 'vads_url_refused' => $this->router->generate ( $transaction->getPaymentMode()->getUrlReturnError(), [], UrlGeneratorInterface::ABSOLUTE_URL ), 'vads_url_check' => $this->router->generate ( 'api_systempay_ipn_paiement', array ('publicKey' => $transaction->getPublicKey()), UrlGeneratorInterface::ABSOLUTE_URL ) ]; $signature_content = ''; // Sort fields alphabetically ksort($parameters['params']); // Recover 'vads_' index, and concatenate them with the separator "+" foreach ($parameters['params'] as $key => $value){ if (substr($key,0,5) == 'vads_'){ $signature_content .= $value."+"; } } // Add certificate to the of string signature $signature_content .= $certificat; // Encoding the base64 encoded string with the HMAC-SHA-256 algorithm $parameters['params']['signature'] = base64_encode(hash_hmac('sha256', $signature_content,$certificat,true)); $parameters['url_system_pay'] = $transaction->getPaymentMode()->getUrlPayment(); return $parameters; } /** * @param TransactionInterface $transaction * @param string $id_transaction * @param string $message * @param float $amount * @param bool $status * @return bool */ 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; } }