gpt4 book ai didi

php - 我正在尝试用 PHP 为服务器/InFrame 支付编写自己的类

转载 作者:搜寻专家 更新时间:2023-10-31 21:31:10 25 4
gpt4 key购买 nike

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

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, "\r\n");
$responseForLog= self::queryStringToArrayRemovingSensitiveData($rawresponse, "\r\n", 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的demo中是在哪里创建的,这个RedirectionURL是怎么生成的?

最佳答案

当您的 notificationURL 收到来自 Sage Pay 的结果发布时,它需要响应,提供 RedirectURL - 当 Sage Pay 无法到达指定的 notificationURL 或没有返回重定向 URL 时,通常会发生此错误。

关于php - 我正在尝试用 PHP 为服务器/InFrame 支付编写自己的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29896545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com