我正试图在woocommerce中集成支付网关,并确认交易是否批准,我必须向支付网关端点发送API请求,但问题是我的URL变量($this->sessionURL)不工作。
我正在公共函数setSessionURL()中设置$this->sessionURL。
class Windcave_Sessions{
public function __construct()
{
$this->sessionID = '';
$this->sessionURL= '';
add_action('woocommerce_before_checkout_billing_form', array( $this, 'test_container' ));
add_action("rest_api_init", array($this, "windcave_query_session"));
}
public function test_container(){
$this->sessionURL = $this->setSessionURL($this->sessionID);
if(empty($this->sessionURL)){
return;
}
else{
$urlVal = 'https://uat.windcave.com/api/v1/sessions/00001200057642070c56cd51cccd7b03';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->sessionURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic afa*************='
),
));
$response = curl_exec($curl);
curl_close($curl);
$sessionObj = json_decode($response);
foreach ($sessionObj->transactions as $obj) {
// check authorization
if($obj->authorised){
$GLOBALS['authorisedPayment'] = "true";
}
else {
$GLOBALS['authorisedPayment'] = "false";
}
$GLOBALS ['responseText'] = $obj->responseText;
}
$returnValue = array(
"authorize"=> $GLOBALS['authorisedPayment'],
"responseText"=> $GLOBALS['responseText']
);
if($GLOBALS['authorisedPayment'] === "true"){
return true;
}
else if($GLOBALS['authorisedPayment'] === "false") {
return $returnValue['responseText'];
}
}
}
public function setSessionURL($sessionID){
return "https://uat.windcave.com/api/v1/sessions/".$sessionID;
}
public function windcave_query_session(){
echo $this->sessionID;
//update board
register_rest_route("inspiry/v1/", "query-session", array(
"methods" => "POST",
"callback" => array($this, 'test_container')
));
}
}
$windcaveSession = new Windcave_Sessions();
// add iframe container
?>```
您必须为您的类定义$sessionURL以便在其中存储信息。这是整堂课还是剪接课?
如果它是一个完整的类,你必须这样定义变量:
class foo{
var $sessionURL = "";
}
之后,您可以使用它与$this->sessionURL