Send XML data to paylease gateway using php curl - php

I am sending xml data to paylease payment gateway and it shows given below error :
Array
(
[Credentials] => Array
(
[GatewayId] => sssssssssssss
[Username] => ssssssssssssss
)
[Mode] => Array
(
)
[Errors] => Array
(
[Error] => Array
(
[0] => Array
(
[Code] => 146
[Status] => Error
[Message] => GatewayId not found.
)
[1] => Array
(
[Code] => 155
[Status] => Error
[Message] => User failed to be authenticated. GatewayId and username don't match.
)
[2] => Array
(
[Code] => 156
[Status] => Error
[Message] => User failed to be authenticated. Username and password don't match.
)
)
)
)
I am using curl for sending xml request to payment gateway. Please help me out for sending request to payment gateway . I am using given below code :
- $xml = "<?xml version='1.0' encoding='UTF-8'?>
<PayLeaseGatewayRequest>
<Credentials>
<GatewayId>####</GatewayId>
<Username>#####</Username>
<Password>####</Password>
</Credentials>
<Mode>Test</Mode>
<Transactions>
<Transaction>
<TransactionAction>CCPayment</TransactionAction>
<PaymentReferenceId>CC12345</PaymentReferenceId>
<PaymentTraceId>1</PaymentTraceId>
<PayerReferenceId>395</PayerReferenceId>
<PayeeId>129</PayeeId>
<PayerFirstName>John</PayerFirstName>
<PayerLastName>Smith</PayerLastName>
<CreditCardType>Visa</CreditCardType>
<CreditCardNumber>4444444444444448</CreditCardNumber>
<CreditCardExpMonth>05</CreditCardExpMonth>
<CreditCardExpYear>19</CreditCardExpYear>
<CreditCardCvv2>123</CreditCardCvv2>
<BillingFirstName>John</BillingFirstName>
<BillingLastName>Smith</BillingLastName>
<BillingStreetAddress>123 PayLease Street</BillingStreetAddress>
<BillingCity>San Diego</BillingCity>
<BillingState>CA</BillingState>
<BillingCountry>US</BillingCountry>
<BillingZip>92123</BillingZip>
<TotalAmount>1000.00</TotalAmount>
<FeeAmount></FeeAmount>
<Message></Message >
<IncurFee>No</IncurFee>
<SaveAccount>Yes</SaveAccount>
</Transaction>
</Transactions>
</PayLeaseGatewayRequest>";
$url = "https://www.paylease.com/gapi/request.php";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,"xmlRequest=" . $xml );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
$data = curl_exec($ch);
curl_close($ch);
//convert the XML result into array
$array_data = json_decode(json_encode(simplexml_load_string($data)), true);
echo "<pre>";
print_r($array_data);

Related

PHP / FCM : double notification & click not working

I'm using PHP to send browser notifications through cURL (with Firebase) and while notifications are sent to their destination (desktop and mobile browsers), I'm facing two problems:
Each time I send a notification, I get two notifications in the browser. One with the content I have defined (see below) and one empty but considered as a background notification. I think it has something to do with active window but I don't know how to go around this.
When I click on the notification I have received, the link is never working.
I use the following code to send the notification:
$msg = urlencode($message);
$
$data = array(
'title'=>"My title",
'sound' => "default",
'msg'=>"my message",
'data'=>$datapayload,
'body'=>"message",
'color' => "#FF33CC",
'link' => "mylink"
);
if($img)
{
$data["image"] = "xxx";
$data["style"] = "picture";
$data["picture"] = "xxx";
}
$fields = array(
'to'=>$to,
'notification'=>$data,
"priority" => "high",
"link"=>"mylink",
"data"=>$data
);
$headers = array(
'Authorization: key=xxxx',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close( $ch );
When I send notifications with this script, I get the following output from the cURL request:
{"multicast_id":xxx,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"xxx"}]}
And here is an example of the JSON send to FCM:
Array
(
[to] => xxx
[notification] => Array
(
[title] => Notification pour Chrome Samsung
[sound] => default
[msg] => blablabla
[data] => Array
(
[ID] => xxxx
)
[body] => blablabla
[color] => #FF33CC
[link] => https://www.something.com
[image] => https://www.something.com/logo.png
[style] => picture
[picture] => https://www.something.com/logo.png
)
[priority] => high
[link] => https://www.something.com
[data] => Array
(
[title] => blabla
[sound] => default
[msg] => blablabla
[data] => Array
(
[ID] => 653804269445
)
[body] => blablabla
[color] => #FF33CC
[link] => https://www.something.com
[image] => https://www.something.com/logo.png
[style] => picture
[picture] => https://www.something.com/logo.png
)
)
I have tried to use only data or only notification but I still end up with 2 non clickable messages. I saw "click_action" in the documentation but it looks like it was only to be used for Android devices.
Any idea?
Thanks!
Update: the generic messages I get in the notification are obviously coming from the service worker but no matter what I do, updating the service worker doesn't seem to change anything.

Telegram bot get 'chat not found' error when forwards messages in PHP

I am getting errors like: Bad Request: chat not found when I want to forward a message from a group where the bot is an administrator.
Scenario:
A public group called #PucciPruebas where the bot (#Comitentesbot) is an admin along with me (#fpucci).
A test user (#fernandoPucci)
I (#fpucci) and the test user (#fernandopucci) have previously written to the bot privately.
The idea is that when a member writes in the group, the bot forwards the message to me privately.
When I write in the group for example This is a test message, the bot receives this data:
Array (
[update_id] => 768460433
[message] => Array (
[message_id] => 8
[from] => Array (
[id] => 1026410801
[is_bot] =>
[first_name] => ??????????????????????¸ ???
[last_name] => ???????????????
[username] => FPucci
[language_code] => es
)
[chat] => Array (
[id] => -1001511892400
[title] => PucciPruebas
[username] => PucciPublico
[type] => supergroup
)
[date] => 1653597954
[text] => This is a test message
)
)
The code in PHP is:
$tipo = $datain["message"]["chat"]["type"];
$chatid = $datain["message"]["chat"]["id"];
$msgid = $datain["message"]["message_id"];
$title = $datain["message"]["chat"]["title"];
if ("private"==$tipo || "PucciPruebas"==$title)
Reenviar("#fpucci", $chatid, $msgid);
function Reenviar ($a_chat, $from_chat, $message){
global $chatId, $comitentesapi;
$params=[
'chat_id' => "$a_chat",
'from_chat_id' => "$from_chat",
'message_id' => "$message",
];
$ch = curl_init("$comitentesapi/forwardMessage");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
}
So, what am I missing, forgetting, or doing wrong?
---------edit--------
I append after the curl_close($ch), the following line as other way to send the message, and get the same result:
file_get_contents("$comitentesapi/forwardMessage?disable_notification=true&chat_id=$a_chat&from_chat_id=$from_chat&message_id=$message&parse_mode=HTML");

Getting an XML file in a .asp URL

I need to grab XML data from an .asp URL and cannot figure out where it goes wrong. Tried:
<?php
$url = "http://bookings.emperordivers.com/webScheduleSpecificXML_all.asp";
$feed = file_get_contents($url);
$xml = simplexml_load_string($feed);
// Display the first post title
echo $xml->Schedules->Schedule[0]->Boat;
I hoped this would work, but suspected that the .asp URL is blocking somehow so alternatively tried:
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data('http://bookings.emperordivers.com/webScheduleSpecificXML_all.asp');
$xml = simplexml_load_string($returned_content);
// Display the first post title
echo $xml->Schedules->Schedule[0]->Boat;
In both case a beautiful white screen. Is there a simple trick to get this working?
Your not accessing it correctly:
echo $xml->Schedule[0]->Boat;
The format is:
SimpleXMLElement Object
(
[Schedule] => Array
(
[0] => SimpleXMLElement Object
(
[Start] => 2017-09-24
[Duration] => 7
[Boat] => MV Emperor Orion
[Itinerary] => Best of Maldives
[Dep-Arr] => Male
[Spaces] => 4
[Rates] => SimpleXMLElement Object
(
[Rate] => Array
(
[0] => 1149
[1] => 1,057.08
[2] => 1,367.31
)
)
)
...

How to get data from an array inside json data php

I have the following array of json data. When I try to loop using a for each, php gives me the error "Object of class stdClass could not be converted to string". I want to access the nameserver in the authns array, and the soa array. How do I go about doing that?
stdClass Object (
[error] =>
[domain] => whoisdoma.net
[ip_address] => 108.162.199.120
[authns] => stdClass Object (
[nameserver] => uma.ns.cloudflare.com
[ip] => 173.245.58.146
[location] => San Francisco
)
[soa] => stdClass Object (
[nameserver] => tom.ns.cloudflare.com
[email] => dns.cloudflare.com
[serial] => 2015505396
[refresh] => 10000
[retry] => 2400
[expiry] => 604800
[minimum] => 3600
)
)
This is the code I'm using to get the data:
<?php
$domain = $_GET['domain'];
//set the url
$url = "http://api.site.ga/v1/dns/lookup?domain=".$domain;
//start a curl session
$ch = curl_init();
$timeout = 5;
//set curl options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//get the data
$data = curl_exec($ch);
//decode the data
$jsonData = json_decode($data);
//close the curl session
curl_close($ch);
?>
This is the for each loop I'm using
<?php
foreach($jsonData->authns as $authns)
{
echo $authns->nameserver;
}
?>
You need to decode the json object using an associative array.
Here is an exmaple:
$data = json_decode(file_get_contents('http://api.domain.com/call'), true);
$data is now an associative array.
You are looping through authns while it is an object by itself. So your nameserver which you want is actually $authns in its first iteration.
Just access it like $jsonData->authns->nameserver
try this for yourself
foreach($jsonData->authns as $authns)
{
echo $authns;
}

Post multidimensional array using CURL and get the result on server

I am sending data from my local machine to server using CURL. And the data is multidimensional array.
Array
(
[0] => stdClass Object
(
[id] => 1
)
[1] => stdClass Object
(
[id] => 0
)
[2] => stdClass Object
(
[id] => 11
)
)
I am using this below code for sending the data.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "my_url");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array); // $array is my above data
But at server when I try to put this incoming data to file or just print_r it gives me this below output
Array
(
[0] => Array
[1] => Array
[2] => Array
)
But I want the output in multidimensional.
I tried with print_r($_POST[0]) but it gives only Array text.
cURL can only accept a simple key-value paired array where the values are strings, it can't take an array like yours which is an array of objects. However it does accept a ready made string of POST data, so you can build the string yourself and pass that instead:
$str = http_build_query($array);
...
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
A print_r($_POST) on the receiving end will show:
Array
(
[0] => Array
(
[id] => 1
)
[1] => Array
(
[id] => 0
)
[2] => Array
(
[id] => 11
)
)
I would give a go to serialize and unserialize:
1) Before sending your array, serialize it (and set your transfer mode to binary):
(...)
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // need this to post serialized data
curl_setopt($ch, CURLOPT_POSTFIELDS, serialize($array)); // $array is my above data
2) When you receive the data, unserialize it:
$array = unserialize($_POST);
More details here and here
$param['sub_array'] = json_encode($sub_array);
and on the other side
$sub_array= json_decode($_POST['sub_array']);

Categories