Я создал клиент API супа и настроил все, что было проверено, используя ссылку в браузере и почтальоне. Я хотел интегрировать это после успешной оплаты woocommerce для этой цели. Я добавил фильтр-ловушку, но он, похоже, не работает, и API не вызывается, поскольку я не могу найти его там, где его не хватает.
пользовательский https://example.com/invite.php?agent_id=xyz в этой точке сохраняется переменная сеанса. Затем на сайте WordPress они будут перенаправлены и могут приобрести листинг, например, при успешной оплате API должен быть назван здесь. Это файлы, которые я использую только для начинающих и использую мои базовые знания c, реализующие это.
Функция wordpress:
add_action( 'woocommerce_thankyou', 'processApiFunction');
function processApiFunction( $order_id ){
// Get an instance of the WC_Order object
$order = wc_get_order($order_id);
// Iterating through each WC_Order_Item_Product objects
foreach ($order->get_items() as $item_key => $item ):
## Using WC_Order_Item methods ##
// Item ID is directly accessible from the $item_key in the foreach loop or
$item_id = $item->get_id();
## Using WC_Order_Item_Product methods ##
$product = $item->get_product(); // Get the WC_Product object
$product_id = $item->get_product_id(); // the Product id
$item_type = $item->get_type(); // Type of the order item ("listing or publication")
## Access Order Items data properties (in an array of values) ##
$item_data = $item->get_data();
$product_name = $item_data['name'];
$line_total = $item_data['total'];
endforeach;
//The URL with parameters / query string.
//first check if session variable is stored using a checker php script
$chekerurl = 'https://example.com/api/checkAgentID.php';
$contents1 = file_get_contents($checkerurl);
if($contents1 !== false){
if ($contents1 == 1){
$url = 'https://example.com/api/processApiCall.php?order_id='.$order_id.'&amount='.$line_total.'';
//We use file_get_contents to GET the URL.
$contents2 = file_get_contents($url);
//If $contents is not a boolean FALSE value.
if($contents2 !== false){
//Print out the contents.
echo $contents2;
}
}
}
}
Вот обработчики API, которые я сделал:
processApiCall. php
<?php
require 'icsclient.php';
session_start();
if(isset($_SESSION['agent_id']) && isset($_GET['order_id']) && isset($_GET['amount'])) {
// call the api function
$AgentID = $_SESSION['agent_id'];
$SlotOrdersID = $_GET['order_id'];
$OrderTotal = $_GET['amount'];
ProcessAgentPayment($AgentID, $SlotOrdersID, $OrderTotal);
}
else {
header("Location: https://example.com/");
}
function ProcessAgentPayment($AgentID, $SlotOrdersID, $OrderTotal) // Process agent payment
{
$LoginDetails = array('email' => $myAdminEmail, 'passwd' => $myAdminPassword, 'devid' => $devid);
// Start of client details
$ClientPath = "https://www.example.com/icswebserv/icsserver.php"; // Path to Server
$_SESSION['CurrentAdminID'] = 0; // The APIs use this session to store your internal Admin ID
$icsResult = icsconnect($LoginDetails, $ClientPath); // Create connection to server
if ($icsResult == "Connected")
{
$transdate = date("Y-m-d");
$agentid = $AgentID;
$salesamount = $OrderTotal;
$campaignid = 13;
$icsResult = icsupdate_trans($transdate, $agentid, $salesamount, $campaignid);
$msg = "Doen";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
mail("saifaliunity@gmail.com","Success",$msg);
return (console_log($icsResult, $with_script_tags = false));
}
}
// }
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
?>
getSessionData. php
<?php
session_start();
checkAgentID();
function checkAgentID(){
if(isset($_SESSION['agent_id']))
echo $_SESSION['agent_id'];
else echo null;
}
?>
setSessiondata. php
<?php
session_start();
checkAgentID();
function checkAgentID(){
if(!isset($_SESSION['agent_id']) && isset($_GET['agent_id']))
$_SESSION['agent_id'] = $_GET['agent_id'];
}
?>
checkAgentID. php
<?php
session_start();
checkAgentID();
function checkAgentID(){
if(isset($_SESSION['agent_id']))
echo 1;
else echo 0;
}
?>
Используя эту ссылку https://example.com/api/processApiCall.php?order_id=12344&amount=1 Я вижу, что API работает правильно, но как-то внутри WordPress, он не работает, он не вызывает API.
Пожалуйста, помогите мне, потому что какой-то код может не иметь смысла для вас, я просто хотел сделать его настолько простым, насколько смогу.
Спасибо