1. Go to this page and download the library: Download digitapeu/paypal 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/ */
return [
'mode' => 'sandbox', // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
'sandbox' => [
'username' => env('PAYPAL_SANDBOX_API_USERNAME', ''),
'password' => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
'secret' => env('PAYPAL_SANDBOX_API_SECRET', ''),
'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
'app_id' => '', // Used for testing Adaptive Payments API in sandbox mode
],
'live' => [
'username' => env('PAYPAL_LIVE_API_USERNAME', ''),
'password' => env('PAYPAL_LIVE_API_PASSWORD', ''),
'secret' => env('PAYPAL_LIVE_API_SECRET', ''),
'certificate' => env('PAYPAL_LIVE_API_CERTIFICATE', ''),
'app_id' => '', // Used for Adaptive Payments API
],
'payment_action' => 'Sale', // Can only be 'Sale', 'Authorization' or 'Order'
'currency' => 'USD',
'notify_url' => '', // Change this accordingly for your application.
'locale' => '', // force gateway language i.e. it_IT, es_ES, en_US ... (for express checkout only)
'validate_ssl' => true, // Validate SSL when creating api client.
];
// Import the class namespaces first, before using it directly
use Digitap\PayPal\Services\ExpressCheckout;
use Digitap\PayPal\Services\AdaptivePayments;
$provider = new ExpressCheckout; // To use express checkout.
$provider = new AdaptivePayments; // To use adaptive payments.
// Through facade. No need to import namespaces
$provider = PayPal::setProvider('express_checkout'); // To use express checkout(used by default).
$provider = PayPal::setProvider('adaptive_payments'); // To use adaptive payments.
$response = $provider->setExpressCheckout($data);
// Use the following line when creating recurring payment profiles (subscriptions)
$response = $provider->setExpressCheckout($data, true);
// This will redirect user to PayPal
return redirect($response['paypal_link']);
// Note that 'token', 'PayerID' are values returned by PayPal when it redirects to success page after successful verification of user's PayPal info.
$response = $provider->doExpressCheckoutPayment($data, $token, $PayerID);
$response = $provider->refundTransaction($transactionid);
// To issue partial refund, you must provide the amount as well for refund:
$response = $provider->refundTransaction($transactionid, 9.99);
// The $token is the value returned from SetExpressCheckout API call
$response = $provider->createBillingAgreement($token);
// The $token is the value returned from CreateBillingAgreement API call
// $action Can be Order, Sale or Authorization
// $amount to withdraw from the given BillingAgreement defaults to $. To overwrite use $provider->addOptions
$response = $provider->doReferenceTransaction($token,$action,$amount);
// The $token is the value returned from doReferenceTransaction API call
$response = $provider->getTransactionDetails($token);
// The $token is the value returned from SetExpressCheckout API call
$startdate = Carbon::now()->toAtomString();
$profile_desc = !empty($data['subscription_desc']) ?
$data['subscription_desc'] : $data['invoice_description'];
$data = [
'PROFILESTARTDATE' => $startdate,
'DESC' => $profile_desc,
'BILLINGPERIOD' => 'Month', // Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
'BILLINGFREQUENCY' => 1, //
'AMT' => 10, // Billing amount for each billing cycle
'CURRENCYCODE' => 'USD', // Currency code
'TRIALBILLINGPERIOD' => 'Day', // (Optional) Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
'TRIALBILLINGFREQUENCY' => 10, // (Optional) set 12 for monthly, 52 for yearly
'TRIALTOTALBILLINGCYCLES' => 1, // (Optional) Change it accordingly
'TRIALAMT' => 0, // (Optional) Change it accordingly
];
$response = $provider->createRecurringPaymentsProfile($data, $token);
Route::post('ipn/notify','PayPalController@postNotify'); // Change it accordingly in your application
'ipn/notify'
/**
* Retrieve IPN Response From PayPal
*
* @param \Illuminate\Http\Request $request
*/
public function postNotify(Request $request)
{
// Import the namespace Digitap\PayPal\Services\ExpressCheckout first in your controller.
$provider = new ExpressCheckout;
$request->merge(['cmd' => '_notify-validate']);
$post = $request->all();
$response = (string) $provider->verifyIPN($post);
if ($response === 'VERIFIED') {
// Your code goes here ...
}
}
// Always update the code below accordingly to your own > "Monthly Subscription",
'price' => 0,
'qty' => 1,
],
];
$data['subscription_desc'] = "Monthly Subscription #1";
$data['invoice_id'] = 1;
$data['invoice_description'] = "Monthly Subscription #1";
$data['return_url'] = url('/paypal/ec-checkout-success?mode=recurring');
$data['cancel_url'] = url('/');
$total = 0;
foreach ($data['items'] as $item) {
$total += $item['price'] * $item['qty'];
}
$data['total'] = $total;
//give a discount of 10% of the order amount
$data['shipping_discount'] = round((10 / 100) * $total, 2);