1. Go to this page and download the library: Download henshall/php-paypal-wrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
henshall / php-paypal-wrapper example snippets
return [
/**
* get from https://developer.paypal.com
*/
'client_id' => 'PAYPAL_CLIENT_ID',
/**
* get from https://developer.paypal.com
*/
'secret' => 'PAYPAL_CLIENT_SECRET',
/**
* after a user authorizes the payment, they will be directed to this url. This is where we will place the logic from step 2 below.
*/
'return_url' => 'RETURN_URL',
/**
* // url the user is sent to if they cancel the transaction. Maybe you can bring the user back to your homepage with a message saying they cancelled the transaction.
*/
'cancel_url' => 'CANCEL_URL',
/**
* SDK configuration
*/
'settings' => array(
/**
* Available option 'sandbox' or 'live'
*/
'mode' => "sandbox", // make sure to change this to live!
/**
* Specify the max request time in seconds
*/
'http.ConnectionTimeOut' => 1000,
/**
* Whether want to log to a file
*/
'log.LogEnabled' => false,
/**
* Specify the file that want to write on
*/
'log.FileName' => '/logs/paypal.log',
/**
* Available option 'FINE', 'INFO', 'WARN' or 'ERROR'
*
* Logging is most verbose in the 'FINE' level and decreases as you
* proceed towards ERROR
*/
'log.LogLevel' => 'FINE',
),
];
// Create the class
$paypalWrapper = new PaypalWrapper;
// Set the config file as shown above in the prerequisites section
$config = config('paypal_conf');
$validate = $paypalWrapper->validateConfigFile($config);
$paypalWrapper->setConfigFile($config);
// Set a Parameter - Here you can set a user_id, name, or email address to track which user has paid.
$paypalWrapper->setParam("[email protected]");
// Set the amount and the currency type (currency examples below)
$paypalWrapper->RedirectToPaypal(100, "USD");
if ($paypalWrapper->error) {
// Where to put your logic if there is an error. (Save error to DB, or log file, or email to yourself etc.)
// die($paypalWrapper->error);
}
//NOTE you can also check if any of the individual functions fail by see if they return false.
// $setConfig = $paypalWrapper->setConfigFile($config);
// if (!$setConfig) {
// // LOGIC IF FAILED TO SET CONFIG
// }
// Create the class
$paypalWrapper = new PaypalWrapper;
// Set the config file as shown above in the prerequisites section
$config = config('paypal_conf');
$validate = $paypalWrapper->validateConfigFile($config);
$paypalWrapper->setConfigFile($config);
// Set the payment
$paypalWrapper->setPayment($data["PayerID"], $data["paymentId"] );
// Execute the payment
$executePayment = $paypalWrapper->executePayment();
if ($paypalWrapper->error) {
// Where to put your logic if there is an error with the wrapper itself, or its config
}
if ($executePayment == true) {
// write code for when payment is successful
}
if ($executePayment == false) {
// write code for when payment is NOT successful (ex. insufficient funds, or blocked for some reason)
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.