/**
  * @param $url
  * @param $data
  * @param int $ttl
  * @param string $caCertPath
  * @return array
  */
 public static function requestPost($url, $data, $ttl = 30, $caCertPath = '')
 {
     set_time_limit(60);
     $output = array();
     $curlSession = curl_init();
     curl_setopt($curlSession, CURLOPT_URL, $url);
     curl_setopt($curlSession, CURLOPT_HEADER, 0);
     curl_setopt($curlSession, CURLOPT_POST, 1);
     curl_setopt($curlSession, CURLOPT_POSTFIELDS, SagepayUtil::arrayToQueryString($data, '&', true));
     curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlSession, CURLOPT_TIMEOUT, $ttl);
     curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
     if (!empty($caCertPath)) {
         curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 1);
         curl_setopt($curlSession, CURLOPT_CAINFO, $caCertPath);
     } else {
         curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 0);
     }
     $rawresponse = curl_exec($curlSession);
     if (curl_getinfo($curlSession, CURLINFO_HTTP_CODE) !== 200) {
         $output['Status'] = "FAIL";
         $output['StatusDetails'] = "Server Response: " . curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
         $output['Response'] = $rawresponse;
         return $output;
     }
     if (curl_error($curlSession)) {
         $output['Status'] = "FAIL";
         $output['StatusDetail'] = curl_error($curlSession);
         $output['Response'] = $rawresponse;
         return $output;
     }
     curl_close($curlSession);
     $response = SagepayUtil::queryStringToArray($rawresponse, "\r\n");
     return array_merge($output, $response);
 }
Exemple #2
0
 /**
  * Return data for result query
  *
  * @param boolean $isSuccess
  * @return array
  * @throws SagepayApiException
  */
 private function _resultData($isSuccess = false)
 {
     $formPassword = $this->sagepayConfig->getFormPassword();
     $env = $this->sagepayConfig->getEnv();
     $crypt = filter_input(INPUT_GET, 'crypt');
     $decrypt = SagepayUtil::decryptAes($crypt, $formPassword[$env]);
     $decryptArr = SagepayUtil::queryStringToArray($decrypt);
     if (!$decrypt || empty($decryptArr)) {
         throw new SagepayApiException('Invalid crypt input');
     }
     $helperMessage = new HelperMessage();
     $basket = $this->getBasketFromProducts();
     $items = array();
     // Get products from basket
     if ($basket) {
         foreach ($basket->getItems() as $item) {
             $items[] = array('productUrlImage' => $this->getProductUrlImage($item->getDescription()), 'description' => $item->getDescription(), 'quantity' => $item->getQuantity());
         }
     }
     return array('env' => $env, 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => $this->integrationType, 'basket' => array('items' => $items), 'decrypt' => $decryptArr, 'currency' => $this->sagepayConfig->getCurrency(), 'isSuccess' => $isSuccess, 'message' => $helperMessage->getMessage($decryptArr['Status']), 'res' => array('vpsTxId' => $decryptArr['VPSTxId'], 'txAuthNo' => isset($decryptArr['TxAuthNo']) ? $decryptArr['TxAuthNo'] : '', 'Surcharge' => isset($decryptArr['Surcharge']) ? $decryptArr['Surcharge'] : '', 'BankAuthCode' => isset($decryptArr['BankAuthCode']) ? $decryptArr['BankAuthCode'] : '', 'DeclineCode' => isset($decryptArr['DeclineCode']) ? $decryptArr['DeclineCode'] : '', 'GiftAid' => isset($decryptArr['GiftAid']) && $decryptArr['GiftAid'] == 1, 'avsCv2' => isset($decryptArr['AVSCV2']) ? $decryptArr['AVSCV2'] : '', 'addressResult' => isset($decryptArr['AddressResult']) ? $decryptArr['AddressResult'] : '', 'postCodeResult' => isset($decryptArr['PostCodeResult']) ? $decryptArr['PostCodeResult'] : '', 'cv2Result' => isset($decryptArr['CV2Result']) ? $decryptArr['CV2Result'] : '', '3DSecureStatus' => isset($decryptArr['3DSecureStatus']) ? $decryptArr['3DSecureStatus'] : '', 'CAVV' => isset($decryptArr['CAVV']) ? $decryptArr['CAVV'] : '', 'cardType' => isset($decryptArr['CardType']) ? $decryptArr['CardType'] : '', 'last4Digits' => isset($decryptArr['Last4Digits']) ? $decryptArr['Last4Digits'] : '', 'expiryDate' => isset($decryptArr['ExpiryDate']) ? $decryptArr['ExpiryDate'] : '', 'addressStatus' => isset($decryptArr['AddressStatus']) ? $decryptArr['AddressStatus'] : '', 'payerStatus' => isset($decryptArr['PayerStatus']) ? $decryptArr['PayerStatus'] : ''));
 }
function eme_sagepay_notification()
{
    $sagepay_demo = get_option('eme_sagepay_demo');
    if ($sagepay_demo == 1) {
        $sagepay_pwd = get_option('eme_sagepay_test_pwd');
    } else {
        $sagepay_pwd = get_option('eme_sagepay_live_pwd');
    }
    require_once 'payment_gateways/sagepay/eme-sagepay-util.php';
    $decrypt = SagepayUtil::decryptAes($crypt, $sagepay_pwd);
    $decryptArr = SagepayUtil::queryStringToArray($decrypt);
    if ($decrypt && !empty($decryptArr)) {
        if ($decryptArr['Status'] == 'OK') {
            $payment_id = $decryptArr['VendorTxCode'];
            eme_update_payment_payed($payment_id);
        }
    }
}