/** * 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; }
/** * Processes the POST request sent by Redsys. * * @param array $parameters Array with response parameters * * @return RedsysManager Self object * * @throws InvalidSignatureException Invalid signature * @throws ParameterNotReceivedException Invalid parameters * @throws PaymentException Payment exception */ public function processResult(array $parameters) { $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $parameters['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'] : ''; if ($dsSignature != $this->expectedSignature($dsAmount, $dsOrder, $dsMerchantCode, $dsCurrency, $dsResponse, $dsSecret)) { throw new InvalidSignatureException(); } /** * 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. */ if (!$this->transactionSuccessful($dsResponse)) { /** * Payment paid failed. * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $redsysMethod); throw new PaymentException(); } /** * Payment paid successfully. * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }
/** * 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 $parameters) { //Check we receive all needed parameters $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $parameters['Ds_Signature']; $dsParams = $parameters['Ds_MerchantParameters']; $dsVersion = $parameters['Ds_SignatureVersion']; $paramsDecoded = base64_decode(strtr($dsParams, '-_', '+/')); $this->varsPay = json_decode($paramsDecoded, true); $dsResponse = $this->varsPay['Ds_Response']; $dsAmount = $this->varsPay['Ds_Amount']; $dsOrder = $this->varsPay['Ds_Order']; $dsMerchantCode = $this->varsPay['Ds_MerchantCode']; $dsCurrency = $this->varsPay['Ds_Currency']; $dsDate = $this->varsPay['Ds_Date']; $dsHour = $this->varsPay['Ds_Hour']; $dsSecurePayment = $this->varsPay['Ds_SecurePayment']; $dsCardCountry = $this->varsPay['Ds_Card_Country']; $dsAuthorisationCode = $this->varsPay['Ds_AuthorisationCode']; $dsConsumerLanguage = $this->varsPay['Ds_ConsumerLanguage']; $dsCardType = array_key_exists('Ds_Card_Type', $this->varsPay) ? $this->varsPay['Ds_Card_Type'] : ''; $dsMerchantData = array_key_exists('Ds_MerchantData', $this->varsPay) ? $this->varsPay['Ds_MerchantData'] : ''; if ($dsSignature != $this->expectedSignature($dsParams)) { throw new InvalidSignatureException(); } /** * 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 */ if (!$this->transactionSuccessful($dsResponse)) { /** * Payment paid failed * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $redsysMethod); throw new PaymentException(); } /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }