/**
  * Process the IRN data
  *
  */
 public function processRequest()
 {
     $return_array = array();
     $this->validate();
     $this->mergeErrorLogs($this->error_log);
     if (!$this->error_log[self::DEBUG_FATAL]) {
         $process_string = Tools::strlen($this->_merchant_id) . $this->_merchant_id;
         $process_string .= Tools::strlen($this->payu_ref_no) . $this->payu_ref_no;
         $process_string .= Tools::strlen($this->order_amount) . $this->order_amount;
         $process_string .= Tools::strlen($this->order_currency) . $this->order_currency;
         $irn_date = date('Y-m-d H:i:s', time());
         $process_string .= Tools::strlen($irn_date) . $irn_date;
         $process_string .= $this->hash_product_ids;
         $process_string .= $this->hash_product_qtys;
         $process_string .= '00';
         $process_string .= Tools::strlen($this->refund_amount) . $this->refund_amount;
         $hash = PayuSignature::generateHmac($this->_secret_key, $process_string);
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_URL, $this->irn_query_url);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
         $value = 'MERCHANT=' . $this->_merchant_id . '&ORDER_REF=' . $this->payu_ref_no . '&ORDER_AMOUNT=' . $this->order_amount . '&ORDER_CURRENCY=' . $this->order_currency . '&IRN_DATE=' . $irn_date . '&ORDER_HASH=' . $hash . '&REGENERATE_CODES=&LICENSE_HANDLING=&AMOUNT=' . $this->refund_amount . '&' . $this->product_string;
         curl_setopt($curl, CURLOPT_POSTFIELDS, $value);
         curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
         $contents = curl_exec($curl);
         curl_close($curl);
         if (strpos($contents, '|') !== false) {
             $contents = explode('|', $contents);
             $return_array['RESPONSE_CODE'] = $contents[1];
             $return_array['RESPONSE_MSG'] = $contents[2];
         } else {
             $return_array['RESPONSE'] = $contents;
         }
         $return_array['ERRORS'] = $this->all_errors[self::DEBUG_ALL];
         return $return_array;
     } else {
         return $this->all_errors[self::DEBUG_ALL];
     }
 }
示例#2
0
 /**
  * Interpret instant payment notification
  *
  * @param array $params
  * @return array|bool
  */
 public function interpretIPN(array $params)
 {
     if (!isset($params['REFNOEXT'], $params['HASH'], $params['ORDERSTATUS'], $params['REFNO'], $params['IPN_TOTALGENERAL'], $params['CURRENCY'], $params['HASH'], $params['IPN_PID'], $params['IPN_PNAME'], $params['IPN_DATE'])) {
         return array('error' => 'One or more parameters are missing');
     }
     $order_id = (int) $params['REFNOEXT'];
     if (empty($order_id)) {
         return array('error' => 'Missing REFNOEXT');
     }
     if ($this->getBusinessPartnerSetting('type') !== self::BUSINESS_PARTNER_TYPE_EPAYMENT) {
         return array('error' => 'Incorrect business partner');
     }
     if (!Configuration::get('PAYU_EPAYMENT_IPN')) {
         return array('error' => 'IPN disabled');
     }
     if ($params['HASH'] != PayuSignature::generateHmac(Configuration::get('PAYU_EPAYMENT_SECRET_KEY'), PayuSignature::signatureString($params, array('HASH')))) {
         return array('error' => 'Invalid signature');
     }
     try {
         $history = new OrderHistory();
         $history->id_order = $order_id;
         switch ($params['ORDERSTATUS']) {
             case 'PAYMENT_AUTHORIZED':
             case 'PAYMENT_RECEIVED':
                 $new_status = (int) Configuration::get('PAYU_PAYMENT_STATUS_COMPLETED');
                 $history->changeIdOrderState($new_status, $order_id);
                 $history->addWithemail(true);
                 $order = new Order($order_id);
                 if (version_compare(_PS_VERSION_, '1.5', 'ge')) {
                     $payment = $order->getOrderPaymentCollection();
                     $payments = $payment->getAll();
                     $payments[$payment->count() - 1]->transaction_id = $params['REFNO'];
                     $payments[$payment->count() - 1]->update();
                 }
                 $this->updatePayuTransaction($order_id, (int) $params['REFNO'], $params['IPN_TOTALGENERAL'], $params['CURRENCY']);
                 break;
         }
         $date = date('YmdGis');
         $response_params = array($params['IPN_PID'][0], $params['IPN_PNAME'][0], $params['IPN_DATE'], $date);
         $hash = PayuSignature::generateHmac(Configuration::get('PAYU_EPAYMENT_SECRET_KEY'), PayuSignature::signatureString($response_params, array('HASH')));
         return array('date' => $date, 'hash' => $hash);
     } catch (Exception $e) {
         Logger::addLog($this->displayName . ' ' . trim($e->getCode() . ' ' . $e->getMessage() . ' id_order: ' . $order_id), 1);
         return false;
     }
 }
 /**
  * Process the IDN data
  *
  * @return TRUE on success
  */
 public function processRequest()
 {
     $this->validate();
     if (!isset($this->all_errors[self::DEBUG_FATAL]) || !$this->all_errors[self::DEBUG_FATAL]) {
         $process_string = Tools::strlen($this->merchant_id) . $this->merchant_id;
         $process_string .= Tools::strlen($this->payu_ref_no) . $this->payu_ref_no;
         $process_string .= Tools::strlen($this->order_amount) . $this->order_amount;
         $process_string .= Tools::strlen($this->order_currency) . $this->order_currency;
         $idn_date = date('Y-m-d H:i:s', time());
         $process_string .= Tools::strlen($idn_date) . $idn_date;
         if (!empty($this->order_charge_amount)) {
             $process_string .= Tools::strlen($this->order_charge_amount) . $this->order_charge_amount;
         }
         if (!empty($this->order_idn_prn)) {
             $process_string .= Tools::strlen($this->order_idn_prn) . $this->order_idn_prn;
         }
         $hash = PayuSignature::generateHmac($this->secret_key, $process_string);
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_URL, $this->idn_query_url);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($curl, CURLOPT_POSTFIELDS, 'MERCHANT=' . $this->merchant_id . '&ORDER_REF=' . $this->payu_ref_no . '&ORDER_AMOUNT=' . $this->order_amount . '&ORDER_CURRENCY=' . $this->order_currency . '&IDN_DATE=' . $idn_date . '&' . (!empty($this->order_charge_amount) ? 'CHARGE_AMOUNT=' . $this->order_charge_amount . '&' : '') . (!empty($this->order_idn_prn) ? 'IDN_PRN=' . $this->order_idn_prn . '&' : '') . 'ORDER_HASH=' . $hash);
         curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
         $contents = curl_exec($curl);
         curl_close($curl);
         if (preg_match('#<EPAYMENT>(.+)\\|(.+)\\|(.+)\\|(.+)\\|(.+)</EPAYMENT>#i', $contents, $matches)) {
             $retval = array('RESPONSE_CODE' => $matches[2], 'RESPONSE_MSG' => $matches[3]);
             return $retval;
         }
         return array('RESPONSE_CODE' => '-1', 'RESPONSE_MSG' => 'Invalid response to IDN request: "' . Tools::substr($contents, 0, 20) . '"');
     } else {
         return $this->all_errors[self::DEBUG_ALL];
     }
 }
 /**
  * Method will calculate the hash string
  *
  * @return int 1 on success
  */
 private function makeHash()
 {
     $this->hash = PayuSignature::generateHmac($this->secret_key, $this->hash_string);
     return 1;
 }