for the ipay88 should include a BackendURL need to return with the Response Code as "200" and the Response Data as "RECEIVEOK"/"OK" to acknowledge that the payment status has been received.
The expected result is
but the result i sent is
Here is my code for backendURL
public function backendResponse()
{
$expected_sign = $_POST['Signature'];
$merchantcode = $this->merchantcode;
$merchantkey = $this->merchantkey;
$check_sign = '';
//$ipaySignature = '';
$str = '';
$HashAmount = '';
$orderID = $_POST['RefNo'];
$paymentID = $_POST['PaymentId'];
$paymentStatus = $_POST['Status'];
$amountPaid = $_POST['Amount'];
$transID = $_POST['TransId'];
$remark = $_POST['Remark'];
$errDesc = $_POST['ErrDesc'];
$amount = preg_replace("/[^0-9]/", "", $amountPaid);
$string = $this->iPay88_signature($merchantkey . $merchantcode .
$paymentID . $orderID . $amount . $_POST['Currency'] .
$paymentStatus);
if ($paymentStatus == "1" && $string == $expected_sign) {
echo 'RECEIVEOK';
}
}
Could anyone help? i wanted to send the response data just only RECEIVEOK, without HTML DATA TAG. Thank you so much, really appreciated..
Related
I am developing a WooCommerce payment gateway plugin with WordPress version 5.4.2 and WooCommerce version 3.8.0.
Plugin working fine for few 3-4 trials, but after this I am not able to get redirected to the checkout page. It keeps redirecting to the cart or basket page.
I have also checked the logs, but nothing found there.
I not professional in WordPress.
The plugin has live demo
You can see code below
// Submit payment and handle response
public function process_payment($order_id) {
global $woocommerce;
global $current_user;
//get user details
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
$first_name = $current_user->shipping_first_name;
$last_name = $current_user->shipping_last_name;
$phone_number = $current_user->billing_phone;
$country = $current_user->shipping_country;
$state = $current_user->shipping_state;
$city = $current_user->shipping_city;
$postcode = $current_user->shipping_postcode;
$address_1 = $current_user->shipping_address_1;
$address_2 = $current_user->shipping_address_2;
$udf1 = $first_name." ".$last_name;
$udf2 = $user_email;
$udf3 = $phone_number;
$udf4 = $country." ".$state." ".shipping_city." ".$address_1." ".$address_2." ".$postcode;
$user_email = $_POST['billing_email'];
$first_name = $_POST['billing_first_name'];
$last_name = $_POST['billing_last_name'];
$phone_number = $_POST['billing_phone'];
$country = $_POST['billing_country'];
$state = $_POST['billing_state'];
$city = $_POST['billing_city'];
$postcode = $_POST['billing_postcode'];
$address_1 = $_POST['billing_address_1'];
$address_2 = $_POST['billing_address_2'];
$udf1 = $first_name." ".$last_name;
$udf2 = $user_email;
$udf3 = $phone_number;
$udf4 = $country." ".$state." ".shipping_city." ".$address_1." ".$address_2." ".$postcode;
$order = new WC_Order( $order_id );
$atom_login_id = $this->login_id;
$atom_password = $this->password;
$atom_prod_id = $this->atom_product_id;
$amount = $order->get_total();
$currency = "INR";
$custacc = "1234567890";
$txnid = $order_id;
$clientcode = urlencode(base64_encode(007));
$datenow = date("d/m/Y h:m:s");
$encodedDate = str_replace(" ", "%20", $datenow);
if(!function_exists('wc_get_checkout_url')){
require_once '/includes/wc-core-functions.php';
}
$ru = wc_get_checkout_url();
$data["login"] = $atom_login_id;
$data["pass"] = $atom_password;
$data["prodid"] = $atom_prod_id;
$data['txnid']=$txnid;
$data['amt'] = $amount;
$data['reqHashCode'] = $this->req_hash_code;
$data['requestEncypritonKey'] = $this->req_enc_key;
$data['salt'] = $this->req_salt_key;
$signature = $this->getChecksum($data);
$param = "login=".$atom_login_id."&pass=".$atom_password."&ttype=NBFundTransfer"."&prodid=".$atom_prod_id."&amt=".$amount."&txncurr=".$currency."&txnscamt=0"."&clientcode=".$clientcode."&txnid=".$txnid."&date=".$encodedDate ."&custacc=".$custacc."&udf1=".$udf1."&udf2=".$udf2."&udf3=".$udf3."&udf4=".$udf4."&ru=".$ru;
$param = $param."&signature=".$signature;
$atomenc = new AtomAES();
$encData = $atomenc->encrypt($param, $data['requestEncypritonKey'], $data['salt']);
global $wpdb, $woocommerce;
return array('result' => 'success', 'redirect' => $this->url."?" ."login=".$atom_login_id."&encdata=".strtoupper($encData));
exit;
}
// checking response from payment gateway and show messages on checkout page
function check_atom_response(){
global $woocommerce;
global $wpdb, $woocommerce;
$atomenc = new AtomAES();
$decrypted = $atomenc->decrypt($_POST['encdata'], $this->res_enc_key, $this->res_salt_key);
$array_response = explode('&', $decrypted); //change & to | for production
$equalSplit = array();
foreach ($array_response as $ar) {
$equalSub = explode('=', $ar);
if(!empty($equalSub[1]) && !empty($equalSub[0])){
$temp = array(
$equalSub[0] => $equalSub[1],
);
$equalSplit += $temp;
}
}
if(isset($equalSplit['f_code']) && $this->validateResponse($equalSplit)){
$order = new WC_Order($equalSplit['mer_txn']);
$order_id = $equalSplit['mer_txn'];
$VERIFIED = $equalSplit['f_code'];
if($VERIFIED == 'Ok'){
$VERIFIED = 'complete';
}else{
$VERIFIED = 'pending';
}
$bank_name = $equalSplit['bank_name'];
$bank_txn = $equalSplit['bank_txn'];
$discriminator = $equalSplit['discriminator'];
if($equalSplit['f_code']=='Ok'){
$order->update_status('completed');
$this -> msg['message'] = "Thank you for shopping with us. Your account has been charged <b>Rs".$equalSplit['amt']."</b> for order id <b>".$order_id."</b> and your transaction is successful. Bank Transaction ID is : <b>".$equalSplit['bank_txn']."</b>.";
$this->msg['class'] = 'woocommerce-message';
$this->msg['order'] = $order;
} else if($equalSplit['f_code'] == 'F') {
$return_url = $this->get_return_url($order);
$order->update_status('failed');
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "<b style='color:red;font-size:20px'>The transaction has been failed or declined.</b>";
$this->msg['order'] = $order;
} else {
$order->update_status('cancelled');
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "<b style='color:red;font-size:20px'>The transaction has been cancelled or declined.</b>";
$this->msg['order'] = $order;
}
add_action('the_content', array(&$this, 'showMessage'));
add_filter('cron_schedules', 'new_intervals');
function new_intervals($interval) {
$interval['minutes_30'] = array('interval' => 30*60, 'display' => 'Once 30 minutes');
return $interval;
}
function InitiateMyCron() {
wp_schedule_event(time(), 'minutes_30', 'update_ransaction_status');
}
}
}
Actually the question is how to get an answer from the user at the click of a button?
What should be changed\rewritten in the code?
$access_token = '...';
$api = 'https://api.telegram.org/bot' . $access_token;
$output = json_decode(file_get_contents('php://input'), TRUE);
$message = $output['message']['text'];
$chat_id = $output['message']['chat']['id'];
if ($output['callback_query'] != null){
$data = $output['callback_query']['data'];
$data_id = $output['callback_query']['id'];
$chat = $output['callback_query']['message']['chat']['id'];
switch($data){
case "/123":
answerCallback($data_id, '123');
sendMessage($chat, "123", null);
break;
case "/plz":
answerCallback($data_id, 'plz');
sendMessage($chat, "plz", null);
break;
}
}
elseif ($message != null) {
switch($message) {
case '/test':
$inline_button1 = array("text"=>"123","callback_data"=>"/123");
$inline_button2 = array("text"=>"work plz","callback_data"=>'/plz');
$inline_keyboard = [[$inline_button1,$inline_button2]];
$keyboard=array("inline_keyboard"=>$inline_keyboard);
$replyMarkup = json_encode($keyboard);
sendMessage($chat_id, "ok", $replyMarkup);
break;
}
}
function sendMessage($chat_id, $message, $replyMarkup) {
file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . '&reply_markup=' . $replyMarkup);
}
function answerCallback($id, $text) {
file_get_contents($GLOBALS['api'] . '/answerCallbackQuery?callback_query_id='.$id.'&text='.$text);
}
This code only allows you to get a response from the message /test, and does not respond to button presses.
Uses webhook.
Have a look at your error log. You forgot to provide a value for $replyMarkup.
PHP Warning: Missing argument 3 for sendMessage()
We're currently working with the Twitter API and failed to sucessfully send a tweet to their API. It's always exiting with code 32 in both Java and PHP (made a PHP prototype just for sending the request). I guess I'm missing something about the OAuth1 specification here.
The PHP prototype we're using:
<?PHP
require_once("cURL.php");
$headers = [];
$postParams = [];
$signatureParams = [];
$authString = "";
$URL = "https://api.twitter.com/1.1/statuses/update.json";
$method = "POST";
$token = "someValidToken";
$tokenSecret = "someValidTokenSecret";
$timestamp = time();
$status = "Hi, Twitter!";
$signatureParams['status'] = $status;
$clientID = "someClientID";
$clientSecret = "someClientSecret";
$signatureParams['oauth_consumer_key'] = urlencode($clientID);
$signatureParams['oauth_nonce'] = urlencode(base64_encode($timestamp));
$signatureParams['oauth_signature_method'] = urlencode("HMAC-SHA1");
$signatureParams['oauth_timestamp'] = $timestamp;
$signatureParams['oauth_token'] = urlencode($token);
$signatureParams['oauth_version'] = urlencode("1.0");
$oauthSignature = generateSignature();
$signatureParams["oauth_signature"] = $oauthSignature;
unset($signatureParams['status']);
ksort($signatureParams);
$count = 0;
$authStringLoop = "";
foreach($signatureParams as $key => $signatureParam)
{
if($count++ == 0)
{
$authStringLoop .= "OAuth ";
}
$authStringLoop .= urlencode($key);
$authStringLoop .= "=\"";
$authStringLoop .= urlencode($signatureParam)."\",";
}
$authStringLoop = substr($authStringLoop,0,strlen($authStringLoop)-1);
echo "</br></br>";
echo "AuthString loop: $authStringLoop</br></br>";
$headers = array(
"Authorization: $authStringLoop"
);
var_dump($headers).'</br>';
var_dump(POST($URL,json_encode($status),$headers,0));
function generateSignature()
{
global $clientSecret;
global $signatureParams;
global $URL;
global $method;
global $clientSecret;
global $clientID;
global $tokenSecret;
ksort($signatureParams);
$parameterString = "";
foreach($signatureParams as $key => $signatureParam)
{
$parameterString .= urlencode($key."=".$signatureParam."&");
}
$signingBase = strtoupper($method)."&".urlencode($URL)."&".$parameterString;
$signingKey = urlencode($clientSecret)."&".urlencode($tokenSecret);
var_dump($signingBase);
echo '</br>';
echo "Base64 encoded: ".base64_encode(hash_hmac("SHA1",$signingBase,$signingKey,TRUE));
echo '</br>';
echo "URL encoded: ".urlencode(base64_encode(hash_hmac("SHA1",$signingBase,$signingKey,TRUE)))."</br>";
return base64_encode(hash_hmac("SHA1",$signingBase,$signingKey,TRUE));
}
?>
My guess that there is something wrong with the way the signature is generated. However, all I found was to sort it alphabetically which should be done with the ksort() call. What do we miss here?
I'm trying to make responce to user press inline_button2, after inline_keyboard apper in chat and I click on inline_button2 I suppose object callback_data have data with "callback_data"=>'inline2' but callback_data is null
see screenshot
$access_token = '...';
$api = 'https://api.telegram.org/bot' . $access_token;
$content = file_get_contents("php://input");
$update = json_decode($content, TRUE);
$callback_query = $update['CallbackQuery'];
$callback_data = $callback_query['data'];
$message = $update["message"];
$text = $message["text"];
$chatId = $message["chat"]["id"];
if (!isset($chatId)) {exit;}
switch($callback_data){
case 'inline2':
sendMessage($chatId, "inline2 pressed",null);
break;
default:
sendMessage($chatId, var_export($callback_query,TRUE),null);
break;
}
switch($text) {
case 'inline':
$inline_button1 = array("text"=>"inline1","url"=>"http://google.com", "callback_data"=>'inline1');
$inline_button2 = array("text"=>"inline2","callback_data"=>'inline2');
$inline_keyboard = array(array($inline_button1,$inline_button2));
$keyboard=array("inline_keyboard"=>$inline_keyboard);
sendMessage($chatId, "назад",$keyboard);
break;
}
function sendMessage($chat_id, $message, $replyMarkup) {
$s='';
if (isset($replyMarkup)) {
$s=json_encode($replyMarkup);
}
file_get_contents($GLOBALS['api'] . '/sendMessage?parse_mode=HTML&chat_id=' . $chat_id . '&disable_web_page_preview=true&text=' . urlencode($message) .'&reply_markup='.$s);
}
You are accessing the callback_query wrongly and additionally you need to take the chatId from the callback_query object.
$callback_query = $update['callback_query'];
$callback_data = callback_query["data"];
$chatId = callback_query["message"]["chat"]["id"];
change this $callback_query = $update['CallbackQuery']; to $callback_query = $update['callbackquery'];
you also need to add the following for callbackquery
$message_id = ['callback_query']['message']['message_id']; //callbackquery message id
$chat_id = $callback_query['message']['chat']['id']; // callbackquery chat id
i hope this helps
I am trying to send a curl request to moodle using drupal.But each tiem i run this code i get an error message that function name must be a string.I have tried everything but nothing is working.Can anybody please help me?
function form_fun_cake_submit(&$form, &$form_state) {
$serverUrl=' http://localhost/moodle/my/webservice/rest/server.php?wstoken=d90b5d90db13711d12df525366f15db1';
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'Uk3#0d5w';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = '';
$user1->lang = 'en';
$user1->timezone = 'Australia/Sydney';
$user1->mailformat = 0;
$user1->description = '';
$user1->city = '';
$user1->country = 'AU'; //list of abrevations is in yourmoodle/lang/en/countries
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$rest_format = 'json';
//$server_url = $domain_name . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $function_name;
$server_url = 'localhost/moodle/my' . '/webservice/rest/server.php'. '?wstoken=' . '15bd45a3dab2958b7e8fc237b14f76cd' .'&wsfunction='. $functionName;
dpm($server_url);
require_once('curl.inc');
$curl = new curl;
$rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$resp =$curl($server_url . $rest_format, $params); //This is my line no 78
dpm($rest_format);
$respRc = json_decode($resp, true);
dpm($resp);
echo '</br>************************** Server Response createUser()**************************</br></br>';
echo $server_url . '</br></br>';
var_dump($resp);
}
Line 78 replace $curl(...) with new curl(..), your object instancing is incorrect. What is telling the php log is that you are using a variable as function name aka $curl (nothing to do with $functionName wich might have generated an error later with curl not on compile if it was wrong).
$resp = new curl($server_url . $rest_format, $params);