Ejemplo n.º 1
0
 public function testPaymentSuccess()
 {
     $dsResponse = 0;
     $dsAuthorisationCode = '222FFF';
     $dsCardCountry = 'ESP';
     $dsCardType = 'y';
     $dsConsumerLanguage = 'y';
     $dsDate = 'X';
     $dsHour = 'X';
     $dsSecurePayment = '1';
     $parameters = array('Ds_Date' => $dsDate, 'Ds_Hour' => $dsHour, 'Ds_Terminal' => '1', 'Ds_SecurePayment' => $dsSecurePayment, 'Ds_Signature' => '9A163AA5034368367665866E62D603A5A92C5D35', 'Ds_Response' => $dsResponse, 'Ds_Amount' => '99', 'Ds_Order' => '0001', 'Ds_MerchantCode' => '999008881', 'Ds_Currency' => '978', 'Ds_TransactionType' => '2', 'Ds_MerchantData' => 'Mis datos', 'Ds_Card_Country' => $dsCardCountry, 'Ds_AuthorisationCode' => $dsAuthorisationCode, 'Ds_ConsumerLanguage' => $dsConsumerLanguage, 'Ds_Card_Type' => $dsCardType);
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge));
     $this->redsysMethod->expects($this->any())->method('setDsResponse')->with($this->equalTo($dsResponse))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsAuthorisationCode')->with($this->equalTo($dsAuthorisationCode))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsCardCountry')->with($this->equalTo($dsCardCountry))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsCardType')->with($this->equalTo($dsCardType))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsConsumerLanguage')->with($this->equalTo($dsConsumerLanguage))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsDate')->with($this->equalTo($dsDate))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsHour')->with($this->equalTo($dsHour))->will($this->returnValue($this->redsysMethod));
     $this->redsysMethod->expects($this->any())->method('setDsSecurePayment')->with($this->equalTo($dsSecurePayment))->will($this->returnValue($this->redsysMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge));
     $this->redsysManager->processResult($parameters);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }