PayPal ipnNotificationUrl Turned off and not sending notifications to URL - php

I'm working with paypal adaptive payments API and all things were okay till last month.
The problem is ipnNotificationUrl is not sending any notifications to URL i provided in code.
Here is the code of PayPal adaptive payment,
<?php
class Paypal{
private $api_user;
private $api_pass;
private $api_sig;
private $app_id;
private $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
private $paypalUrl="https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";
private $headers;
public function setDetails($api_u, $api_p, $api_s, $api_id){
$this->api_user = $api_u;
$this->api_pass = $api_p;
$this->api_sig = $api_s;
$this->app_id = $api_id;
$this->headers = array(
"X-PAYPAL-SECURITY-USERID: ".$this->api_user,
"X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
"X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$this->app_id,
);
}
public function getPaymentOptions($paykey){
$pack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey
);
return $this->_paypalSend($pack, "GetPaymentOptions");
}
public function setPaymentOptions(){
}
public function _paypalSend($data,$call){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = json_decode(curl_exec($ch),true);
return $response;
}
public function splitPay($currency, $r1_email, $r2_email, $r1_amount, $r2_amount, $returnUrl, $cancelUrl, $product_name, $indentifier){
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => $currency,
"receiverList" => array("receiver" =>
array(
array(
"amount"=> $r1_amount,
"email"=> $r1_email
),
array(
"amount"=> $r2_amount,
"email"=> $r2_email
)
)
),
"returnUrl" => $returnUrl,
"cancelUrl" => $cancelUrl,
"ipnNotificationUrl" => URL::to('/adaptive_payments'),
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
$response = $this->_paypalSend($createPacket,"Pay");
$paykey = $response['payKey'];
$detailsPack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey,
"receiverOptions" => array(
array(
"receiver" => array("email" => $r1_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => $product_name,
"price" => $r1_amount,
"identifier" => $indentifier
)
)
)
)
),
array(
"receiver" => array("email" => $r2_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => "product 2",
"price" => $r2_amount,
"identifier" => "p2"
)
)
)
)
)
)
);
$response = $this->_paypalSend($detailsPack, "SetPaymentOptions");
$dets = $this->getPaymentOptions($paykey);
return $this->paypalUrl.$paykey;
}
}
And here the response i get,
array(3) { ["responseEnvelope"]=> array(4) { ["timestamp"]=> string(29) "2015-06-04T14:04:07.395-07:00" ["ack"]=> string(7) "Success" ["correlationId"]=> string(13) "6c472863c4053" ["build"]=> string(8) "15743565" } ["payKey"]=> string(20) "AP-5LN44020A0587750B" ["paymentExecStatus"]=> string(7) "CREATED" }
Which is perfectly fine and i can use paykey, but ipnNotificationUrl not working as it should. it doesn't send anything at all at URL.
What t tried to solve the issue,
1) did change URL of ipnNotificationUrl even made hard coded
2) tested with IPN simulator (the listener), worked for test
3) changed return URL and cancel URL to test if others working, also made sure that i'm working with correct file and code
Please HELP!

The code is working fine , it wasn't because paypal had put IPN as queued.
More details here https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNOperations/
Hope this answer will help others.

Related

Telegram Bot Callback-Query not sent

I've created 2 Inline-Button and I want to evaluate the callback_data. But unfortunately, the callback_data is not sent.
<?php
$bot_token = 'There is no Token seen'; // Telegram bot token
$url = "https://api.telegram.org/bot$bot_token/sendMessage";
$content = file_get_contents('php://input');
$update = json_decode($content, TRUE);
$callback_query = $update['callbackQuery'];
$callback_data = $callback_query['data'];
$ser_update = serialize($update);
db_query("INSERT INTO prefix_telegram (text) VALUES ('".$ser_update."')");
if (isset($update['message']['text'])) {
$text = $update['message']['text'];
$chat_id = $update['message']['chat']['id'];
if (strpos($text, 'outi') !== false) {
$reply = utf8_encode("Wähle einen Button!");
$keyboard = array(
"keyboard" => array(
array(
array(
"text" => "Button1",
"callback_data" => "1",
),
array(
"text" => "Button2",
"callback_data" => "2",
),
)
),
"one_time_keyboard" => true,
"resize_keyboard" => true
);
$postfields = array(
'chat_id' => "$chat_id",
'text' => "$reply",
'reply_markup' => json_encode($keyboard)
);
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curld, CURLOPT_URL,$url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close ($curld);
}
}
Result of file_get_contents
Could anyone help me with this problem? I have sent more information than just the text of the clicked button. Thanks!
There is muuuuch to correct.
In line 7, it is $callback_query = $update['callback_query'];
From line 19 to 34:
$keyboard = array(
"inline_keyboard" => array( // inline_keyboard not keyboard
array(
array(
"text" => "Button1",
"callback_data" => "1",
),
array(
"text" => "Button2",
"callback_data" => "2",
),
)
) //Removed onetimekeyboard etc.
);
From 36 to 40:
$postfields = array(
'chat_id' => $chat_id, // you don't have to use quotes when you're using variables or numbers.
'text' => $reply,
'reply_markup' => json_encode($keyboard)
);
The callback_data is not supported for reply_markup.keyboard. It is supported only for reply_markup.inline_keyboard.
You can vote for the issue Add callback_data to KeyboardButton (reply_markup.keyboard).

Requesting Api Call using cURL

Someone could help me ? I'm trying to do a request by the code bellow, but anything happen, any message appears. I believe my code it's right:
public function subscribe(){
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';
$json_string = json_encode(array(
"MerchantOrderId"=>"2014113245231706",
"Customer" => array(
"Name" => "Comprador rec programada"
),
"Payment" => array(
"Type" => "CreditCard",
"Amount" => 1500,
"Installments" => 1,
"SoftDescriptor" => "Assinatura Fraldas"
)
));
$ch = curl_init($json_url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $json_string
);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch); // Getting jSON result string
print_r($result);
}
Find link with instructions of the site:
you will reiceive this:
[
{
"Code": 114,
"Message": "The provided MerchantId is not in correct format"
}
]
with this code:
function subscribe(){
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';
$json_string = json_encode(
array(
"MerchantOrderId"=>"2014113245231706",
"Customer" => array(
"Name" => "Comprador rec programada"
),
"Payment" => array(
"Type" => "CreditCard",
"Amount" => 1500,
"Installments" => 1,
"SoftDescriptor" => "Assinatura Fraldas"
)
)
);
$headers = array(
'Content-Type: application/json',
'MerchantId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
'MerchantKey: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
'RequestId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx'
);
$ch = curl_init($json_url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $json_string
);
curl_setopt_array( $ch, $options ); $result = curl_exec($ch);
print_r($result);
}
subscribe()
It would be interesting what HTTP status code you get:
print_r(curl_getinfo($ch, CURLINFO_HTTP_CODE));

Confused on a SecureNet response code using cURL

I have searched Google and StackOverflow about this error, and I am having trouble finding results. Perhaps there is someone out there that can point me in the right direction, as I have never worked with the SecureNet API before.
I have a working form in PHP, however when submitting it to SecureNet, I get this as a response:
{"success":false,"result":"AUTHENTICATION_ERROR","responseCode":3,"message":"SecureNetId and SecureNetKey should be passed as Basic authentication tokens or in request object.","responseDateTime":"2015-08-27T02:58:12.54Z","rawRequest":null,"rawResponse":null,"jsonRequest":null}bool(true)
Here is my code:
$url = 'https://gwapi.demo.securenet.com/api/Payments/Charge';
$data = array(
"publickey" => $apiPkey,
"amount" => $donationAmount,
"card" => array(
"number" => $cardNumber,
"cvv" => $cvv,
"expirationDate" => $expiryMonth . '/' . $expiryYear,
"address" => array(
"line1" => $address,
"city" => $city,
"state" => $state,
"zip" => $zip
),
"firstName" => "Jack",
"lastName" => "Test"
),
"extendedInformation" => array(
"typeOfGoods" => "DIGITAL"
),
"developerApplication" => array(
"developerId" => $apiID,
"version" => $apiVersion
)
);
$secureNet = http_build_query($data);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $secureNet);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
var_dump($result);
curl_close($ch);
I figured it out, I wasn't sending the headers.
$headers = array(
"Authorization: Basic " . base64_encode($apidID . ':' . $apiSkey)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

Sending Push notification through pushwoosh from php

I am trying to send push notification through push woosh such like this :
is anybody help me how to send push notification on device from this code
function pwCall(
'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
"devices" => PW_DEVICETOKEN,
'notifications' => array(
'send_date' =>'now', //gmdate('d-m-Y H:i', strtotime('2014-04-07 20:35')),
'content' => 'my custom notification testing ',
'link' => 'http://pushwoosh.com/',
'content' => array("en" => "English","ru" =>"Русский","de"=>"Deutsch")
),
'page_id' => 16863,
'link' => 'http://google.com',
'data' => array( 'custom' => 'json data' ),
)
);
I am getting error such as
Array ( [status_code] => 210 [status_message] => Cannot parse date [response] => )
notifications should be array of objects in JSON notation. In PHP it will be array of arrays. This is because you can create multiple notifications in one request.
final JSON for notifications field:
"notifications":[{ ... notification properties... }, { ... second notification properties ... }, ...]
There are only 3 root parameters in request: application(OR applications_group), auth, and notifications. Other parameters are parameters of notification, not request.
Finally your PHP call should be like following:
pwCall("createMessage", array(
"auth" => PW_AUTH,
"application" => PW_APPLICATION,
"notifications" => array(
array(
"send_date" => "now",
"content" => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch"),
"link" => "http://pushwoosh.com/",
"page_id" => 16863,
"devices" => array( PW_DEVICETOKEN ),
"data" => array( "custom" => "json data" )
)
)
));
All notification's fields except of send_date and content are optional and can be omited
By the looks of it, your date is not formatted correctly. You're passing an ordinary string consisting of the word "now". What you'll want to do is something along the lines of the following:
function pwCall("createMessage", array(
"application" => PW_APPLICATION,
"auth" => PW_AUTH,
"devices" => PW_DEVICETOKEN,
"notifications" => array(
"send_date" => gmdate("Y-m-d H:i"),
"content" => "My custom notification",
"link" => "http://pushwoosh.com/",
"content" => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch")
),
"page_i" => 16863,
"link" => "http://google.com",
"data" => array("custom" => "json data"),
)
);
we've developped an API to easily call the Pushwoosh Web Services.
This API should be a good quality one and is fully tested (very high code coverage).
https://github.com/gomoob/php-pushwoosh
$push_auth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$push_app_id = 'XXXXX-XXXXX';
$push_debug = false;
$title = ''; // pushwoosh title
$banner = ''; // pushwoosh banner
$send_date = 'now'; // pushwoosh date
$android_header = ''; // pushwoosh android header
$android_custom_icon = '' pushwoosh notification icon;
sendpush('createMessage', array(
'application' => $push_app_id,
'auth' => $push_auth,
'notifications' => array(
array(
'send_date' => $send_date,
'content' => $title,
'android_header'=>$android_header,
'android_custom_icon' =>$android_custom_icon,
'android_badges' => 2,
'android_vibration' => 1,
'android_priority' => 1,
'data' => array('custom' => 'json data'),
),
)
));
function sendpush($method, $data) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && self::$push_de) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
return $info;
}
}

PayPal Adaptive Payments Certificate Error

I am trying to implement PayPal Adaptive Payments, but as soon as I try to post with cURL, I get a NULL response and curl_error() gives the following error:
0NSS: client certificate not found (nickname not specified)
Here is the full PHP code, I am using sandbox. Some sensitive info is starred (*).
<?php
class PayPal {
public $API_USER = "*********.gmail.com";
public $API_PASSWORD = "********************";
public $API_SIGNATURE = "******************************";
public $API_APP_ID = "APP-80W284485P519543T";
public $apiUrl = "https://svcs.sandbox.paypal.com/AdaptivePayments/";
public $paypalUrl = "https://sandbox.paypal.com/webscr?cmd=ap-payment&paykey=";
public $headers = array();
function __construct() {
$this->headers = array(
"X-PAYPAL-SECURITY-USERID : " . $this->API_USER,
"X-PAYPAL-SECURITY-PASSWORD : " . $this->API_PASSWORD,
"X-PAYPAL-SECURITY-SIGNATURE : " . $this->API_SIGNATURE,
"X-PAYPAL-REQUEST-DATA-FORMAT : JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT : JSON",
"X-PAYPAL-APPLICATION-ID : " . $this->API_APP_ID
);
}
function paypalSend($data, $call) {
$ch = curl_init();
$curl_params = array(
CURLOPT_URL => $this->apiUrl . $call,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_HTTPHEADER => $this->headers,
CURLOPT_POSTFIELDS => json_encode($data)
);
curl_setopt_array($ch, $curl_params);
$result = curl_exec($ch);
echo(curl_errno($ch));
echo(curl_error($ch));
curl_close($ch);
return json_decode($result, TRUE);
}
function getPayKey() {
$createPacket = array(
"actionType" => "PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "5.00",
"email" => "*********#gmail.com"
)
)
),
"returnUrl" => "http://example.com/success",
"cancelUrl" => "http://example.com/failure",
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll"
)
);
// paypal Send
$response = $this->paypalSend($createPacket, "Pay");
var_dump($response);
}
}
$pp = new Paypal();
$pp->getPayKey();
?>

Categories