我正在尝试用PHP编写自己的类以进行服务器/帧内付款



我需要一些帮助我正在尝试用PHP编写自己的类用于服务器/帧内付款。这是类:

class SagePay {
    public $VPSProtocol = 3.00;
    public $TxType = "PAYMENT";
    public $Vendor = "************";
    public $VendorTxCode ;
    public $Amount = 11.75;
    public $Currency = "GBP";
    public $Description = "By Def";
    public $NotificationURL = NOTIFICATIONURL ;
    public $BillingSurname ;
    public $BillingFirstnames ;
    public $BillingAddress1 ;
    public $BillingCity ;
    public $BillingPostCode ;
    public $BillingCountry = "GB";
    public $DeliverySurname ;
    public $DeliveryFirstnames ;//= Fname Mname
    public $DeliveryAddress1 ;//= BillAddress Line 1
    public $DeliveryCity ;//= BillCity
    public $DeliveryPostCode ;//= W1A 1BL
    public $DeliveryCountry = "GB";
    public $StoreToken = 1;
    public $CustomerName ;//= Fname Mname Surname
    public $CustomerEMail ;//= customer@example.com
    public $VendorEMail ;//= 
    public $SendEMail =1;//= 0 1 е да прати и на двамата емайли
    public $eMailMessage ;//=  нещо се пише тука
    public $BillingAddress2 ;//= BillAddress Line 2
    public $BillingPhone ;//= 44 (0)7933 000 000
    public $ApplyAVSCV2 = 0;
    public $Apply3DSecure = 0;
    public $AllowGiftAid = 0;
    public $BillingAgreement = 1;
    public $DeliveryAddress2 ;//= BillAddress Line 2
    public $DeliveryPhone ;//= 44 (0)7933 000 000
    public $Profile = "LOW";
    public $AccountType = "E";
    protected $url = "https://test.sagepay.com/gateway/service/vspserver-register.vsp";// must be changet from test to live
    static protected $nonSensitiveRequestDataArray = array("VPSProtocol", "TxType", "Vendor", "VendorTxCode", "Amount","Currency", "Description");
    static protected $nonSensitiveResponseDataArray = array("VPSProtocol", "Status", "StatusDetail", "VPSTxId");
    function __construct() {
      define('SAGEPAY_SDK_PATH', dirname(__FILE__));
      $data = get_object_vars($this);
    }

    static public 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, self::arrayToQueryString($data));
        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);
        $requestForLog= self::arrayToQueryStringRemovingSensitiveData($data,self::$nonSensitiveRequestDataArray ) ; 
        $response = self::queryStringToArray($rawresponse, "rn");
        $responseForLog= self::queryStringToArrayRemovingSensitiveData($rawresponse, "rn", self::$nonSensitiveResponseDataArray );         
        self::log("Request:" . PHP_EOL . $requestForLog);
        $res = array_merge($output, $response);
        return $res;
    }
    protected static function arrayToQueryString(array $data, $delimiter = '&', $urlencoded = false){
        $queryString = '';
        $delimiterLength = strlen($delimiter);
        // Parse each value pairs and concate to query string
        foreach ($data as $name => $value)
        {   
            // Apply urlencode if it is required
            if ($urlencoded)
            {
                $value = urlencode($value);
            }
            $queryString .= $name . '=' . $value . $delimiter;
        }
        // remove the last delimiter
        return substr($queryString, 0, -1 * $delimiterLength);
    }
    protected static function arrayToQueryStringRemovingSensitiveData(array $data,array $nonSensitiveDataKey, $delimiter = '&', $urlencoded = false){
        $queryString = '';
        $delimiterLength = strlen($delimiter);
        // Parse each value pairs and concate to query string
        foreach ($data as $name => $value)
        {
           if (!in_array($name, $nonSensitiveDataKey)){
                $value=MASK_FOR_HIDDEN_FIELDS;
           }
           else if ($urlencoded){
                $value = urlencode($value);
           }
            // Apply urlencode if it is required
           $queryString .= $name . '=' . $value . $delimiter;
        }
        // remove the last delimiter
        return substr($queryString, 0, -1 * $delimiterLength);
    }
    protected static function queryStringToArray($data, $delimeter = "&"){
        // Explode query by delimiter
        $pairs = explode($delimeter, $data);
        $queryArray = array();
        // Explode pairs by "="
        foreach ($pairs as $pair)
        {
            $keyValue = explode('=', $pair);
            // Use first value as key
            $key = array_shift($keyValue);
            // Implode others as value for $key
            $queryArray[$key] = implode('=', $keyValue);
        }
        return $queryArray;
    }
    protected static function queryStringToArrayRemovingSensitiveData($data, $delimeter = "&", $nonSensitiveDataKey){  
        // Explode query by delimiter
        $pairs = explode($delimeter, $data);
        $queryArray = array();
        // Explode pairs by "="
        foreach ($pairs as $pair)
        {
            $keyValue = explode('=', $pair);
            // Use first value as key
            $key = array_shift($keyValue);
            if (in_array($key, $nonSensitiveDataKey)){
              $keyValue = explode('=', $pair);
            }
            else{
              $keyValue = array(MASK_FOR_HIDDEN_FIELDS);
            }
            // Implode others as value for $key
            $queryArray[$key] = implode('=', $keyValue);
        }
        return $queryArray;
    }
    protected static function log($message){
        return true;
    }
    public function createVendorTxCode(){
      $timestamp = time();
      $random_number = rand(0,32000)*rand(0,32000);
      return "{$timestamp}-{$random_number}";
    }
}

IFrame 已正确创建。我在 IFrame 中正确填写了所有内容,结果是:

HTTP Status Code:   500
HTTP Status Message:    The request was unsuccessful due to an unexpected condition encountered by the server.
Error Code :    5006
Error Description : Unable to redirect to Vendor's web site. The Vendor failed to provide a RedirectionURL.

在PHP的演示中在哪里创建以及如何生成此重定向URL?

当您的通知URL收到来自Sage Pay的结果帖子时,它需要响应,提供重定向URL - 此错误通常发生在Sage Pay无法访问指定的通知URL或没有返回重定向URL时。

我停止了GZIP压缩,一切都很好。SagePay对INPUT_POST的回应

最新更新