/** * Builds form given return, success and fail urls * * @return \Symfony\Component\Form\FormView */ public function buildForm() { $orderId = $this->paymentBridge->getOrderId(); $extraData = $this->paymentBridge->getExtraData(); $formBuilder = $this->formFactory->createNamedBuilder(null); if (array_key_exists('transaction_type', $extraData)) { $Ds_Merchant_TransactionType = $extraData['transaction_type']; } else { $Ds_Merchant_TransactionType = '0'; } /* * Creates the return route for Redsys */ $Ds_Merchant_MerchantURL = $this->urlFactory->getReturnRedsysUrl($orderId); /* * Creates the return route, when coming back * from Redsys web checkout and proccess is Ok */ $Ds_Merchant_UrlOK = $this->urlFactory->getReturnUrlOkForOrderId($orderId); /* * Creates the cancel payment route, when coming back * from Redsys web checkout and proccess is error */ $Ds_Merchant_UrlKO = $this->urlFactory->getReturnUrlKoForOrderId($orderId); $Ds_Merchant_Amount = $this->paymentBridge->getAmount(); $Ds_Merchant_Order = $this->formatOrderNumber($this->paymentBridge->getOrderNumber()); $Ds_Merchant_MerchantCode = $this->merchantCode; $Ds_Merchant_Currency = $this->currencyTranslation($this->paymentBridge->getCurrency()); $Ds_Merchant_Terminal = $extraData['terminal']; $merchantParameters = []; $merchantParameters['DS_MERCHANT_AMOUNT'] = $Ds_Merchant_Amount; $merchantParameters['DS_MERCHANT_MERCHANTCODE'] = $Ds_Merchant_MerchantCode; $merchantParameters['DS_MERCHANT_CURRENCY'] = $Ds_Merchant_Currency; $merchantParameters['DS_MERCHANT_TERMINAL'] = $Ds_Merchant_Terminal; $merchantParameters['DS_MERCHANT_ORDER'] = $Ds_Merchant_Order; $merchantParameters['DS_MERCHANT_MERCHANTURL'] = $Ds_Merchant_MerchantURL; $merchantParameters['DS_MERCHANT_URLOK'] = $Ds_Merchant_UrlOK; $merchantParameters['DS_MERCHANT_URLKO'] = $Ds_Merchant_UrlKO; $merchantParameters['DS_MERCHANT_TRANSACTIONTYPE'] = $Ds_Merchant_TransactionType; if (array_key_exists('product_description', $extraData)) { $merchantParameters['DS_MERCHANT_PRODUCTDESCRIPTION'] = $extraData['product_description']; } if (array_key_exists('merchant_titular', $extraData)) { $merchantParameters['DS_MERCHANT_TITULAR'] = $extraData['merchant_titular']; } if (array_key_exists('merchant_name', $extraData)) { $merchantParameters['DS_MERCHANT_MERCHANTNAME'] = $extraData['merchant_name']; } if (array_key_exists('merchant_data', $extraData)) { $merchantParameters['DS_MERCHANT_MERCHANTDATA'] = $extraData['merchant_data']; } $merchantParameters = base64_encode(json_encode($merchantParameters)); $Ds_Merchant_MerchantSignature = $this->redsysSignature->sign($Ds_Merchant_Order, $this->secretKey, $merchantParameters); $formBuilder->setAction($this->url)->setMethod('POST')->add('DS_MERCHANTPARAMETERS', 'hidden', array('data' => $merchantParameters))->add('DS_SIGNATUREVERSION', 'hidden', array('data' => $this->redsysSignature->getSignatureVersion()))->add('DS_SIGNATURE', 'hidden', array('data' => $Ds_Merchant_MerchantSignature)); return $formBuilder->getForm()->createView(); }
/** * Processes the POST request sent by Redsys * * @param array $parameters Array with response parameters * * @return RedsysManager Self object * * @throws InvalidSignatureException * @throws ParameterNotReceivedException * @throws PaymentException */ public function processResult(array $response) { //Check we receive all needed parameters $Ds_Signature = $response['Ds_Signature']; $parameters = (array) json_decode(base64_decode($response['Ds_MerchantParameters'])); $parameters = array_change_key_case($parameters, CASE_UPPER); $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $Ds_Signature; $dsResponse = $parameters['DS_RESPONSE']; $dsAmount = $parameters['DS_AMOUNT']; $dsOrder = $parameters['DS_ORDER']; $dsMerchantCode = $parameters['DS_MERCHANTCODE']; $dsCurrency = $parameters['DS_CURRENCY']; $dsSecret = $this->secretKey; $dsDate = $parameters['DS_DATE']; $dsHour = $parameters['DS_HOUR']; $dsSecurePayment = $parameters['DS_SECUREPAYMENT']; $dsCardCountry = $parameters['DS_CARD_COUNTRY']; $dsAuthorisationCode = $parameters['DS_AUTHORISATIONCODE']; $dsConsumerLanguage = $parameters['DS_CONSUMERLANGUAGE']; $dsCardType = array_key_exists('DS_CARD_TYPE', $parameters) ? $parameters['DS_CARD_TYPE'] : ''; $dsMerchantData = array_key_exists('DS_MERCHANTDATA', $parameters) ? $parameters['DS_MERCHANTDATA'] : ''; $internalSignature = $this->redsysSignature->sign($dsOrder, $dsSecret, $response['Ds_MerchantParameters']); /** * Validate if signature from Redsys and our signature are identical, */ $this->redsysSignature->checkSign($dsSignature, $internalSignature); /** * Adding transaction information to PaymentMethod * * This information is only available in PaymentOrderSuccess event */ $redsysMethod->setDsResponse($dsResponse)->setDsAuthorisationCode($dsAuthorisationCode)->setDsCardCountry($dsCardCountry)->setDsCardType($dsCardType)->setDsConsumerLanguage($dsConsumerLanguage)->setDsDate($dsDate)->setDsHour($dsHour)->setDsSecurePayment($dsSecurePayment)->setDsOrder($dsOrder); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $redsysMethod); /** * when a transaction is successful, $Ds_Response has a value between 0 and 99 */ $this->transactionSuccessful($dsResponse, $redsysMethod); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }