Paypal Masspay or Auto payment example PHP code

script async src=”https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”>



<?php

 

$environment = ‘sandbox’; // or ‘beta-sandbox’ or ‘live’
function PPHttpPost($methodName_, $nvpStr_) {
global $environment;

/*
// Set up your API credentials, PayPal end point, and API version.
*/

$API_UserName = ”;
$API_Password =”;
$API_Signature = ”;

// $environment = “sandbox”;
/*
$API_UserName = urlencode(‘my_api_username’);
$API_Password = urlencode(‘my_api_password’);
$API_Signature = urlencode(‘my_api_signature’);

*/ $API_Endpoint = “https://api-3t.paypal.com/nvp”;
if(“sandbox” === $environment || “beta-sandbox” === $environment) {
$API_Endpoint = “https://api-3t.$environment.paypal.com/nvp”;
}
$version = urlencode(‘51.0’);

// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

// Set the API operation, version, and API signature in the request.
$nvpreq = “METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_”;

// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

// Get response from the server.
$httpResponse = curl_exec($ch);

if(!$httpResponse) {
exit(“$methodName_ failed: “.curl_error($ch).'(‘.curl_errno($ch).’)’);
}

// Extract the response details.
$httpResponseAr = explode(“&”, $httpResponse);

$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode(“=”, $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}

if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists(‘ACK’, $httpParsedResponseAr)) {
exit(“Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.”);
}

return $httpParsedResponseAr;
}

// Set request-specific fields.
$emailSubject =urlencode(‘example_email_subject’);
$receiverType = urlencode(‘EmailAddress’);
$currency = urlencode(‘USD’); // or other currency (‘GBP’, ‘EUR’, ‘JPY’, ‘CAD’, ‘AUD’)

// Add request-specific fields to the request string.
$nvpStr=”&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency”;

$receiversArray = array();
$receiverData1 = array( ‘receiverEmail’ => “[email protected]”,
‘amount’ => “7”,
‘uniqueID’ => “100”,
‘note’ => “Testing1”);

$receiverData2 = array( ‘receiverEmail’ => “[email protected]”,
‘amount’ => “6”,
‘uniqueID’ => “200”,
‘note’ => “Testing2”);

$receiversArray[0] = $receiverData1;
$receiversArray[1] = $receiverData2;
/*
for($i = 0; $i < 3; $i++) {
$receiverData = array( ‘receiverEmail’ => “[email protected]”,
‘amount’ => “example_amount”,
‘uniqueID’ => “example_unique_id”,
‘note’ => “example_note”);
$receiversArray[$i] = $receiverData;
}
*/

foreach($receiversArray as $i => $receiverData) {
$receiverEmail = urlencode($receiverData[‘receiverEmail’]);
$amount = urlencode($receiverData[‘amount’]);
$uniqueID = urlencode($receiverData[‘uniqueID’]);
$note = urlencode($receiverData[‘note’]);
$nvpStr .= “&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note”;
}

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost(‘MassPay’, $nvpStr);

if(“SUCCESS” == strtoupper($httpParsedResponseAr[“ACK”]) || “SUCCESSWITHWARNING” == strtoupper($httpParsedResponseAr[“ACK”])) {
exit(‘MassPay Completed Successfully: ‘.print_r($httpParsedResponseAr, true));
} else {
exit(‘MassPay failed: ‘ . print_r($httpParsedResponseAr, true));
}

?>

How to add dynamic PHP page in wordpress

To add dynamic PHP page in wordpress

1) Create a page home_new.php with below content

/* Template Name: home new page */ get_header();
echo “Hello”;

2) Upload this php file into selected Theme home folder

3) Create a new page from admin side

Select home new page (This is what we added in step 1) in the template list from right side

4) Find the newly created page link

you can see the out put ” Hello”

5) whateverv php code you added in home_new.php will come in that link