Securepay is not working - php

I have implemented Secure pay payment gateway in my website. It was working fine but from yesterday it is not working. I did not get any response from secure server. Also I am getting an error.
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/securepay.php
Line Number: 479
In securepay.php 479 number line is
($this->_TranslateServerCode($this->ResponseTree->Status->statusCode) == SECUREPAY_STATUS_OK);
and full function is below
function TestConnection() {
$this->RequestXml = $this->_ComposeEcho();
$this->ResponseXml = $this->_Dispatch($this->RequestXml);
$this->ResponseTree = simplexml_load_string($this->ResponseXml);
return ($this->_TranslateServerCode($this->ResponseTree->Status->statusCode) == SECUREPAY_STATUS_OK);
}
Below is my sample code:
include('securepay.php');
$sp = new SecurePay('ABC0001','abc123', TRUE);
$sp->TestMode();
$sp->TestConnection();
$sp->Cc = 4111111111111111;
$sp->ExpiryDate = '07/20';
$sp->ChargeAmount = 1500;
$sp->ChargeCurrency = 'AUD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
if ($sp->Valid()) {
$response = $sp->Process();
if ($response == SECUREPAY_STATUS_APPROVED) {
echo "Transaction was a success\n";
} else {
echo "Transaction failed with the error code: $response\n";
echo "XML Dump: " . print_r($sp->ResponseXml,1) . "\n";
}
} else {
die("Your data is invalid\n");
}
Please help me how to solve it.

You can use the following curl REST API code:
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, 'https://test.api.securepay.com.au/xmlapi/payment' );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, false );
curl_setopt ( $ch, CURLOPT_MAXREDIRS, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
'Content-Type: application/json'
) );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $jsonRequest );
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 );
$result = curl_exec ( $ch );
Here $jsonRequest will consist of request data like "credit card payment". You can use the following link to find the JSON request data and test it.
SecurePay Sandbox Testing Environment

Related

How can I send order Id in the url and get response?

Here is my code And After execute this code i got this error "Response : {"Message":"No HTTP resource was found that matches the request URI 'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'.","MessageDetail":"No action was found on the controller 'WooCommerceApi' that matches the request."}"
function my_api_call( $order_id ){
// Order Setup Via WooCommerce
$order = new WC_Order( $order_id );
// Iterate Through Items
$items = $order->get_items();
$url = "http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData";
$orderid = "OrderId=".$order_id;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $orderid);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
write_log ("Order Id for new user: " .$orderid ." and Response is : ".$response);
}
add_action( 'woocommerce_payment_complete', 'my_api_call');
I hope You will understad may question. And I want to print Json
response also in the file

PHP cURL and Simple HTML Dom

I'm sorry, but I speak a little English only.
I use this:
<?php
function file_get_contents_curl ( $url ) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); //
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); //
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; rv:71.0) Gecko/20100101 Firefox/71.0' ); // spoof
$data = curl_exec ( $ch );
curl_close ( $ch );
return $data;
}
include ( __DIR__ . '/simplehtmldom_1_9_1/simple_html_dom.php' );
// 1. OK: $url = 'https://www.p***hub.com/model/ashley-porner';
// 2. OK: $url = 'https://www.p***hub.com/model/ashley-diamond-and-diamond-king';
// 3. NOT OK: $url = 'https://www.p***hub.com/model/ambercashh';
// 4. NOT OK: $url = 'https://www.p***hub.com/model/autumn-raine';
$html = file_get_contents_curl ( $url );
$html = str_get_html ( $html );
var_dump ( $html ); // boolean(false) if NOT OK
?>
The 1-2. URL is ok, but the 3-4. URL is not ok. Not show, no view. The return is false.
I try change from 600000 to 6000000 (~/simplehtmldom_1_9_1/simple_html_dom.php), but the new value is more loading time and than crashed my website:
// OLD: defined('MAX_FILE_SIZE') || define('MAX_FILE_SIZE', 600000);
defined('MAX_FILE_SIZE') || define('MAX_FILE_SIZE', 6000000); // NEW
What is the problem?
Thanks.
As test you can run the following - obviously the urls will need editing but it shows reasonable performance - why you were running out of memory must therefore lie in code not included
<?php
function file_get_contents_curl ( $url ) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; rv:71.0) Gecko/20100101 Firefox/71.0' ); // spoof
$data = curl_exec ( $ch );
curl_close ( $ch );
return $data;
}
$start=time();
$memstart=memory_get_usage();
$baseurl='https://www.*******.com/model/';
$models=['ashley-porner','ashley-diamond-and-diamond-king','ambercashh','autumn-raine'];
libxml_use_internal_errors( true );
$dom=new DOMDocument;
$dom->validateOnParse=false;
$dom->recover=true;
$dom->strictErrorChecking=false;
/* do some expensive DOM operations to test performance */
$query='//section[ #class="topProfileHeader" ]/div/div/div[ #class="content-columns" ]/div[ #class="infoPiece" ]';
foreach( $models as $model ){
$url = $baseurl . $model;
$res = file_get_contents_curl( $url );
$dom->loadHTML( $res );
$xp=new DOMXPath( $dom );
libxml_clear_errors();
$col=$xp->query( $query );
if( $col->length > 0 ){
foreach( $col as $node ) {
echo str_repeat( '.', strlen( $node->nodeValue ) ) . '<br />';
}
}
}
$memory=memory_get_usage() - $memstart;
printf(
'<div style="padding:1rem; border:1px solid red;">Script took approx: %ss - consumed: %sMb, Peak memory consumption: %sMb</div>',
( time() - $start ),
round( $memory / pow(1024,2), 2 ),
round( memory_get_peak_usage() / pow(1024,2), 2 )
);
?>

Inline keyboard Telegram bot [PHP]

I want that my bot when I write /orario he answer me with a inline keyboard.
So.. I created an array for my keyboard in this way:
$tastierino_giorno = '[{"text":"Testo","callback_data":"StampaMessaggio"}]';
and in another function I write this:
function tastieraInline($chatid, $tastierino)
{
global $token;
$messaggio = "Scegli per che giorno inviare il messaggio:";
$tastiera = '&reply_markup={"inline_keyboard":
['.urlencode($tastierino).'],"resize_keyboard":true}';
$url = "https://api.telegram.org/$token/sendMessage?chat_id=$chatId&parse_mode=HTML&text=".urlencode($messaggio).$tastiera;
file_get_contents($url);
}
After this, with an if, I check if the users has write "/orario".
} elseif($message == "/orario"){
tastieraInline($chatid, $tastierino_giorno);
}
Now the problem is that it doesn't works... what's the problem?
Change
$tastiera = '&reply_markup={"inline_keyboard":
['.urlencode($tastierino).'],"resize_keyboard":true}';
to
$tastiera = '&reply_markup='.urlencode('{"inline_keyboard":
['.$tastierino.'],"resize_keyboard":true}');
you should URL encode the whole JSON data
You should pay attention to the result returned from your telegram calls. file_get_contents is great for getting something working quickly but doesn't return any error information.
You should use curl or a library like guzzle. An example for curl:
$ch = curl_init( $url );
if ( $ch == FALSE )
{
error_log( "Error initialising curl" );
return FALSE;
}
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_POST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 1 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_FORBID_REUSE, 1 );
// Set TCP timeout to 30 seconds
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Connection: Close' ) );
$result = curl_exec( $ch );
$error = curl_errno( $ch );
$errorStr = curl_error( $ch );
curl_close( $ch );
if ( $error != 0 )
{
return array( $errorStr, $result );
}
return $result;
Guzzle is a lot simpler if you don't mind installing an additional library.
Hopefully this will get you the error string from your failed telegram calls.
Onto your actual issue. You should create json for the keyboard markup using json_encode rather than appending strings. http_build_query makes building URLs much easier.

FCM sending notification through fcm console to my ios device but from php service it is not sending the notification

FCM sending notification through fcm console to my ios device but from php service it is not sending the notification . I want to send notification to my app using FCM . I have implemented web services in php to send message to app on my app server. I created 4 services for this purpose.
group_create.php
device_add.php
device_remove.php
send_comments.php
after creating group i got a notification key successfully and register a registraion id with fcm . when i call send_comments.php with notification key , it returns json data with {"success":1,"failure":0} . But i didn't get any notification on my ios. I have implemented all methods properly. It working well with fcm console but not with php service. Can anyon eknow about this. I am attaching all 4 php files with it. Please help me.
group_create.php
<?php
$url = 'https://android.googleapis.com/gcm/notification';
$notification_key_name = $_REQUEST['notification_key_name'];
$regid = $_REQUEST['regid'];
$fields = array(
"operation"=>"create",
"notification_key_name"=>$notification_key_name,
"registration_ids"=> array($regid)
);
$fields = json_encode( $fields );
$headers = array (
"Authorization:key=A************************",
"Content-Type:application/json",
"project_id:78508******"
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
//echo $result;
$res_notification_key = json_decode($result,true);
if(array_key_exists('notification_key', $res_notification_key)){
$notification_key = $res_notification_key['notification_key'];
echo $notification_key;
}
else{
echo $result;
}
curl_close ( $ch );
?>
device_add.php
<?php
$senderId = "785********";
$notification_key_name= $_REQUEST['notification_key_name'];
$reg_id = $_REQUEST['regid'];
$notification_key = $_REQUEST['not_key'];
$apiKey =
$url = 'https://android.googleapis.com/gcm/notification';
$headers = array (
"Accept:application/json",
"Authorization:key=A******************",
"Content-Type:application/json",
"project_id:78508*****"
);
$fields = array(
"operation"=>"add",
"notification_key_name"=> $notification_key_name,
"registration_ids"=> array($reg_id),
"notification_key"=>$notification_key
);
$fields = json_encode( $fields );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
echo $result;
$res_notification_key = json_decode($result,true);
if(array_key_exists('notification_key', $res_notification_key)){
$notification_key = $res_notification_key['notification_key'];
echo $notification_key;
}
else{
echo $result;
}
curl_close ( $ch );
?>
device_remove.php
<?php
$senderId = "78508*****";
$notification_key_name= $_REQUEST['notification_key_name'];
$reg_id = $_REQUEST['regid'];
$notification_key = $_REQUEST['not_key'];
$apiKey =
$url = 'https://android.googleapis.com/gcm/notification';
$headers = array (
"Accept:application/json",
"Authorization:key=A***********",
"Content-Type:application/json",
"project_id:78508*****"
);
$fields = array(
"operation"=>"remove",
"notification_key_name"=> $notification_key_name,
"registration_ids"=> array($reg_id),
"notification_key"=>$notification_key
);
$fields = json_encode( $fields );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
echo $result;
$res_notification_key = json_decode($result,true);
if(array_key_exists('notification_key', $res_notification_key)){
$notification_key = $res_notification_key['notification_key'];
echo $notification_key;
}
else{
echo $result;
}
curl_close ( $ch );
?>
send_comments.php
<?php
$senderId = "78508*****";
$notification_key = $_REQUEST['not_key'];
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array (
"Authorization:key=A*****************",
"Content-Type:application/json",
);
$msg = array("hello"=>"This is a Firebase Cloud Messaging Device Group Message!");
$msg_dict = json_encode($msg);
//echo $msg_dict;
$fields = array(
"to"=>$notification_key,
"data"=>array(
"message" => "hell",
),
);
$fields = json_encode( $fields );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
echo $result;
$res_notification_key = json_decode($result,true);
curl_close ( $ch );
?>
APNs follows a format
{"aps":{"alert":"Testing.. (0)","badge":1,"sound":"default"}}
i.e.,
{
"aps":{
"alert":"message here"
}
}
if the format sending from server side is this,then only iPhone will display notifications,other wise notification data will only print in console through
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
// Print full message
NSLog(#"Notification :%#", remoteMessage.appData);
}
but not display in notifications list.

Transfer array from one page to another using CURL

Im trying to transfer an array of data between two files.
The sender.php code (the file sending the array using POST method)
$url = 'http://localhost/receiver.php';
$myvars = array("one","two","three")
$post_elements = array('myvars'=>$myvars);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_elements);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
echo "$response";
The receiver.php code (The file receiving the array from sender.php file and then take each element of the array and echo it and also put it in a document saved.txt.
echo $_POST($myvars); // To test the output of the received data.
foreach($myvars as $item) {
if (!empty($item)) {
echo $item."<br>";
$myfile = file_put_contents('Saved.txt', (" Name: ". ($_POST["$item"])) . PHP_EOL , FILE_APPEND);
}
}
The array isn't being transferred to the receiver.php or I am not catching it. In the document output I have only in the place of the variable $item instead of each element of the array.
Edit:
Added the following code in the receiving file in order to get the array elements from inside but all I get is array printed out:
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
echo $thing;
}
} else {
echo $stuff;
}
}
By adding on the receiving file the following:
echo "<pre>";
print_r($_POST);
echo "</pre>";
I get the following:
Array
(
[myvars] => Array
)
OK, the bottom line of the discussion in the comments above leads to this result:
The sending part:
<?php
$url = 'http://localhost/out.php';
$myvars = array("one","two","three");
$post_elements = array('myvars'=>$myvars);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($post_elements));
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
print_r($response);
The receiving part:
<?php
print_r($_POST);
The output on the sending side is:
Array ( [myvars] => Array ( [0] => one [1] => two [2] => three ) )
which basically says that you can simply use $_POST['myvars'] on the receiving side which will exactly hold the scalar array you want to transfer.
try to serialize the array because it always helps me :
$url = 'http://localhost/receiver.php';
$myvars = array("one","two","three");
$myvars_post=join(" ",$myvars);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, "array=".urldecode($myvars_post));
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
echo "$response";
and in the receiver.php use :
print_r($_POST);

Categories