paypal single payout blank response - php

I want to integrate paypal's single payout method in my system, as I want to send money to my sellers, when they request for withdrawal. I have generated an "Access token key" for this and making a curl call from PHP script. But the response is a blank string. I have tried curl_error($curl); but this also doesn`t do anything. Below is my code
// data to be sent
$data = [
'sender_batch_header' => [
'email_subject' => "You have a payment",
'sender_batch_id' => "125458268"
],
'items' => [
[
'recipient_type' => "EMAIL",
'amount' => [
'value' => "12.00",
'currency' => "USD"
],
'receiver' => 'myselle#gmail.com',
'note' => 'A trial for single payout',
'sender_item_id' => "2014031400456"
],
],
];
//curl link for single payout with sync off
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true");
$header = array(
"Content-Type: application/json",
"Authorization: Bearer ".$access_token ,
);
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
But here my $rep is a blank string, tried getting single payout details as well, but this also returns blank string...please help..thanx in advance.

After 2 days of search I found an answer, which was very easy. I didn't use paypal's single payout, instead of that I used it's Implicit Payments operation of PAY API. Below is the code for it..
$receiver[] = array(
'amount' => '125.00',//amount to be transferred
'email' => 'seller#gmail.com',// paypal email id to which you want to send money
);
$result = $paypal->call(
array(
'actionType' => 'PAY',
'currencyCode' => 'USD',
'feesPayer' => 'EACHRECEIVER',
'memo' => 'Withdrawal request no. 356',
'cancelUrl' => '/cancel.php',
'returnUrl' => '/success.php',
'senderEmail' => 'admin.business#gmail.com', // email id of admin's business account, from which amount will be transferred.
'receiverList' => array(
'receiver'=>$receiver
)
), 'Pay'
);
function call($values,$type)
{
$header = array(
"X-PAYPAL-SECURITY-USERID: ".$config['userid'],
"X-PAYPAL-SECURITY-PASSWORD: ".$config['password'],
"X-PAYPAL-SECURITY-SIGNATURE: ".$config['signature'],
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$config['appid'];
);
$curl = curl_init("https://svcs.sandbox.paypal.com/AdaptivePayments/");
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
return $response;
}
If you are the API caller and you specify your email address in the senderEmail field, PayPal sets the payment to be implicitly approved, without redirection to PayPal. (Alternatively, you can use sender.accountId.)

Related

Podbean API Publish New Episode invalid type

I'm trying to publish new podcasts via the api, I've successfully upload the mp3 and jpg, which gives 600 seconds to then publish. The podcast 'type' is required and one of the acceptable values is 'public. Here the response:
{"error":"input_params_invalid","error_description":"Episode type is invalid."}
I'm doing this in PHP. I've been successfully connecting to the API, it is not a token issue.
$params = [
'access_token'=> $token,
'type' => 'public',
'apple_episode_typeoptional' => 'full',
'status' => 'publish',
'media_key' => $files['audio'],
'logo_key' => $files['image'],
'title' => 'Good day',
'content' => 'Time you <b>enjoy</b> wasting, was not wasted.'
];
$params = http_build_query($params);
// . '?' . $params,
// CURLOPT_POSTFIELDS => $params
$options = [
CURLOPT_URL => $url . '?' . $params,
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE
];
$response = $this->getPodbean($options);
UPDATE:
This is what is holding me up. I don't think I have converted curl -v -H "Content-Type: image/jpeg" -T /your/path/file.ext "{presigned_url}" correctly. I added CURLOPT_USERPWD because without it I was getting a 403, now I get 400. I added token for good measure but it doesn't seem to affect anything one way or the other.
$imageMime = mime_content_type($image_path);
$filename = basename($image_path);
$cfile = curl_file_create($image_path, $imageMime, $filename);
//Open the file using fopen.
$fileHandle = fopen($image_path, 'r');
$options = [
CURLOPT_URL => $presigned_url,
CURLOPT_USERPWD => "$this->client_id:$this->client_secret",
CURLOPT_POSTFIELDS => http_build_query(['image_upload' => $cfile, 'access_token'=> $token]),
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => http_build_query(['Content-Type' => $imageMime]),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE
];
$this->getPodbean($options);

sms api integration with php - smsedge.com telnyx.com

Did anyone used https://smsedge.com/ or https://telnyx.com
I am trying to use the PHP api, but no luck with smsedge .
Telnyx works like a charm but I could not find a way to send like a bulk sms.
Tryed the help section, they just posted me a link, but it doesnt work :(
<?php
require_once __DIR__.'/vendor/autoload.php';
\Telnyx\Telnyx::setApiKey('myapikey');
\Telnyx\Message::Create([
"from" => "TShop",
"to" => "+4473836955xx",
"text" => "Hello, World! visit www.google.com",
"messaging_profile_id" => "40017370-b28d-425f-8785-92a64f52ea60"
]);
Is there any way to send to multiple number all at once ?
Also : I am new to php and still reading trying to figure it out .
Thanks in advance .
I struggled many hours to find a service and found one service that does bulk sms :
https://www.infobip.com/
Here is an example(just replace the <api_key> with your key)
$curl = curl_init();
$fields = [
'messages' => [
array(
'from' => 'infoSMS',
'destinations' => ['to' => '1st_phone_number'],
'text' => 'This is first message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '2nd_phone_number'],
'text' => 'This is second message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '3rd_phone_number'],
'text' => 'This is third message.',
),
]
];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://qgdg2q.api.infobip.com/sms/2/text/advanced",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"Authorization: App <api_key>",
"Content-Type: application/json",
"Accept: application/json",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
There is also another service which is https://smsedge.com/

Mailgun api response to validate mail

I have been using the mail API to validate emails, but it has not returned the response. I am doing something wrong?
curl_setopt_array($this->curl, array(
CURLOPT_URL => "https://api.mailgun.net/v4/address/validate?address=".$email,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "address=".$email,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
"Authorization: Basic " . base64_encode("api:mikey")
),
));
$result=curl_exec ($this->curl);
error_log("result ". print_r($result, true));
$err = curl_error($this->curl);
curl_close($this->curl);
error_log("url: ".print_r($url, true));
error_log("error: ".print_r($err, true));
error_log("result: ".print_r($result, true));
return $result;
Well, I faced this same problem but using Guzzle 6.
You should put your account domain at the end of the API Base URL:
https://api.mailgun.net/v4/mysite.com
In Guzzle, these are my configurations (scripts in PHP):
$http_client = new Client([
'base_uri' => 'https://api.mailgun.net/v4/mysite.com',
'allow_redirects' => true,
'debug' => true, // for development purposes
'http_errors' => false
]);
This is the GET Request call:
$response = $http_client->request(
'get',
'address/validate',
[
'query' => ['address' => 'mail#mail.com']
'auth' => ['api', 'your_account_api_private_key'];
]
);

Firebase Clooud Messaging Duplicate Push Notifivation

I am using Firebase for push notification in my ionic app. But unfortunately I am getting the same notification twice. I have searched through the net a lot and tried to apply all possible solutions found there but could not get it to work. My codes are as the following -
Web end (PHP)
$message_for_push = array(
"data" => array(
"title" => "New Notification",
"body" => "the message",
"icon" => "firebase-logo.png",
'sound' => 'mySound',
"type" => $message['type'],
"section_id" => $message['section_id'],
"isPush" => 1,
"subdomain" => $subdomain, //dynamiic
"id" => $message['id'],
"other_key" => true
),
/*"notification" => array(
"title" => "New Notification",
"body" => $message['title'],
"icon" => "firebase-logo.png",
'sound' => 'mySound',
"type" => $message['type'],
"section_id" => $message['section_id'],
"isPush" => 1,
"subdomain" => $subdomain, //dynamiic
"id" => $message['id'],
),*/
"registration_ids" => $registrationIds //array of device ids
);
$message_for_push = json_encode($message_for_push);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_SSL_VERIFYHOST=>0,
CURLOPT_SSL_VERIFYPEER=>0,
CURLOPT_POSTFIELDS => $message_for_push,
CURLOPT_HTTPHEADER => array(
"authorization: key=THE_KEY_GIVEN_HERE",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
On the App End
I have saved the device id on my web end at the time of first login. The token is saved only once. It does not change until or unless the app is re-installed.
this.firebase.getToken().then(token => {
this.devicInfo.uuid = token;
console.log( 'device_id>>>>>', token ); ///saved on web end
}).catch(error => console.error('Error getting token', error));
When the notification is received (Do not think any problem here)-
this.firebase.onNotificationOpen().subscribe((pushed_data) => {
let alert = this.alert.create({
title: 'Notification Received!',
message: pushed_data,
buttons: ['OK']
});
alert.present();
});
The list of plugins used -
com-sarriaroman-photoviewer
cordova-plugin-console
cordova-plugin-device
cordova-plugin-file
cordova-plugin-file-opener2
cordova-plugin-file-transfer
cordova-plugin-firebase
cordova-plugin-network-information
cordova-plugin-splashscreen
cordova-plugin-statusbar
cordova-plugin-whitelist
cordova-plugin-youtube-video-player
cordova-sqlite-storage
ionic-plugin-keyboard
Any help is highly appreciable. Thanks.

curl_exec return an XMLFault from Paypal REST Api

I'm currently using the Paypal REST Api for a mobile app.
Here's my code :
$paymentDatas = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => "http://example.com/your_redirect_url/",
"cancel_url" => "http://example.com/your_cancel_url/"
),
"payer" => array("payment_method" => "paypal"),
"transactions" => array(
"transactions" => array(
"total" => ".99",
"currency" => "USD"
)
)
);
$paymentUrl = 'https://api.sandbox.paypal.com/v1/payments/payment';
$initCurl = curl_init();
curl_setopt_array(
$initCurl, array(
CURLOPT_URL => $paymentUrl,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, //todo: For testing purpose, need tp be removed
CURLOPT_POST =>true,
CURLOPT_HTTPHEADER => array(
'Accept-Language: en_US',
'Accept: application/json',
'Authorization: Bearer '.$data['access_token']
),
CURLOPT_POSTFIELDS => json_encode($paymentDatas),
)
);
$initRet = curl_exec($initCurl);
dd($initRet);
curl_close($initCurl);
And the dd gives me this :
string '<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>' (length=196)
I've already made others functions for authentication but I'm pretty new with REST and Paypal Api.
I had the same problem.
When changing the POST request to GET everything worked fine. Hope this will help you.

Categories