What is process to integrate paypal payout rest API in php - php

I am working on PayPal Payout API.i am not getting what exactly process should be for a complete payout payment method.everything is working fine but still there are so many bugs. what I and mobile application developer is doing.
Mobile API calls to the server with an amount so that server side a PayPal SDK has been integrated where I make a call on PayPal and make a transaction.
The problem is that whether a payer email register or not in Paypal it returns status PENDING without any transaction id.
And I have set up an IPN listener on PayPal which makes a call whenever payout status update. but it returns transaction_id and I am not getting transaction id while payout made.
I don't know what I need to do with it. Please if you did not understand you can drop a comment.
I am using the simple code for Payouts.
$headers = array(
'Content-Type:application/json',
'Authorization:Bearer '.$accsessToken,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=false");
// curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
$response = json_decode($result, 1);
$payoutBatchId = $response['batch_header']['payout_batch_id'];
$headers = array(
'Content-Type:application/json',
'Authorization:Bearer '.$accsessToken,
);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts/".$payoutBatchId);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$response = json_decode($result, 1);
dd($response);

I think you should use PHP Paypal SDK.
There is some easy examples.
Hope this help.

Related

paypal api curl refund getting error AUTHENTICATION_FAILURE

I am trying to implement paypal refund using php curl.
This is my code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/oauth2/token");
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Accept-Language: en_US'
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
$json = json_decode($result);
$access_token=$json->access_token;
curl_close($ch);
$ch=curl_init();
$headers=array('Content-Type: application/json','Authorization: Bearer '.$access_token);
curl_setopt($ch,CRULOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/payments/sale/".$paypal_transaction_id."/refund");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
$result = curl_exec($ch);
$result_array=json_decode($result,true);
I got the access token successfully.
But, the following error occurs in refund.
"Authentication failed due to invalid authentication credentials or a
missing Authorization header."
What's wrong with my code?
Or
My PayPal account is a business account and there is no problem with receiving money (using php paypal api).
Look at https://developer.paypal.com/docs/platforms/get-started/ it says you need to fill out the PayPal Marketplaces and Platforms form to be approved.
Is this the problem?
Haha, I found the error.
It's just spell error.(curl_setopt($ch,CRULOPT_HTTPHEADER,$headers);)
not CRULOPT_HTTPHEADER , is CURLOPT_HTTPHEADER
and I have change code more simply.(using API v2)
$ch=curl_init();
$headers=array('Content-Type: application/json','Authorization: Basic '.base64_encode($clientId.':'.$secret));
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$refund_url="https://api.paypal.com/v2/payments/captures/".$order['paypal_txn_id']."/refund";
curl_setopt($ch, CURLOPT_URL, $refund_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
$result = curl_exec($ch);
$result_array=json_decode($result,true);
curl_close($ch);

PHP cURL Cancel Subscription PayPal issues

I will admit, I have been on this for 3 days, back and forth through documentation, and even learned how to create my own products and plans through Postman.
So I have a complete working subscription button, now I learned I need to save the Subscription ID in order to cancel the subscription so now that is saving and loading perfectly.
To my sad surprise, I need to get an AuthKey every time someone wants to cancel, so I need to run 2 cURL commands, 1 GET Auth Key, and 1 POST cancel a subscription. How would I do this in PHP?
I don't get any errors when these commands run just no data.
Paypal cURL Example:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel
////////////////////////////// GET TEMP ACCESS TOKEN/////////////////////////////////
$ch = curl_init();
$clientId = "x";
$secret = "x";
$myIDKEY = "";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json->access_token);
$myIDKEY = $json->access_token;
}
curl_close($ch);
/////////////////////////////// SEND CANCEL POST ////////////////////////////////
$ch = curl_init();
$headers = [
'Authorization: Bearer '.$myIDKEY,
'Content-Type: application/json'
];
$postData = [
'reason' => 'clicked cancel subscription button'
];
curl_setopt($ch, CURLOPT_URL,"https://api.sandbox.paypal.com/v1/billing/subscriptions/".$_SESSION['honeybeesubID']."/cancel");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $myIDKEY
Thank you so much!
As documented at https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel , a success response is an HTTP 204 with no data.
So, it will be normal to receive an empty response, along with that status code.

Clickbank API - confirming that order has been successful?

I am new to API's and cURL (sorry).
I am looking to use Clickbank's API to check if an order has been successful - https://api.clickbank.com/rest/1.3/orders2
I understand that what I have here is a basic curl request:
define('CLICKBANK_DEV_KEY','DEV-KEY');
define('CLICKBANK_API_KEY','API-KEY');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/orders/list");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Authorization:".CLICKBANK_DEV_KEY.":".CLICKBANK_API_KEY));
$result = curl_exec($ch);
curl_close($ch);
print $result;
How would I use their API to check if an order is successful?
Any tips or resources are appreciated, thank-you.

How to initiate refund using click bank API

I am trying to initiate a refund using click bank api with below source code.
$ch = curl_init();
$qry_str="?type=rfnd&comment=API refund check&reason=7&refundType=FULL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.clickbank.com/rest/1.3/tickets/N5GNE72J'.$qry_str);
curl_setopt($ch, CURLOPT_HEADER, true);
//curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-xxxxxxxxx:API-yyyyyyyyyyyy"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
I have used below two url for reference:
https://api.clickbank.com/api/api_13_examples/api_example.php
https://api.clickbank.com/rest/1.3/tickets
After executing above code it shows a blank screen nothing is displyed, My error flag is set to 1 still no error shown.
After a long struggle found the solution. Use below code it worked for me.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://api.clickbank.com/rest/1.3/tickets/627JE7CZ/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/**
* ClickBank doesn't allow POST parameters to be sent in; however, for the CURL POST to work correctly, the
* CURL_POSTFIELDS option must be set, so we'll just set it to empty and put all our request parameters on the URL
*/
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/xml",
"Authorization:DEV-enter your dev key here:API-enter your clerk key here"
));
$result = curl_exec($ch);
curl_close($ch);
?>

CURL - get Retrieve all email from Google API

I'm using cURL to get all email from user via Google API. Following https://developers.google.com/admin-sdk/email-audit/#retrieving_all_email_monitors_of_a_source_user.
According this tutorial, the server return '201 Created' status code to successful. But, my result return '200 OK' code.
Here is code Authorization
$data = array(
'accountType' => 'HOSTED_OR_GOOGLE',
'Email' => 'myEmail',
'Passwd' => 'myPassword',
'source'=>'PHP-cUrl-Example',
'service'=>'apps');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
And here is code to Retrieving all email monitors of a source user
preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches);
$auth = $matches[1];
$header = array('Content-Type: application/atom+xml; charset=utf-8',
'Authorization: GoogleLogin auth='.trim($auth),
);
$url_email ="https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/mydomain/username";
curl_setopt($ch, CURLOPT_URL, $url_email);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
$response = curl_exec($ch);
$response = simplexml_load_string($response);
curl_close($ch);
print_r($response);
Help me pls ?
The API allows you to request the status of a single export request with a URL of:
https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/{domain name}/{source user name}/{mailbox requestId}
or of all requests across the domain with a request of:
https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/{domain name}?fromDate={fromDate}
there is no operation to retrieve the status of all requests for a given user like you are trying to do.
I suggest you confirm you've successfully created an audit request by using GAM to create the request. GAM will show you the request ID on success. Then you can try getting the results of the single request with your code.

Categories