paypal

所属分类:支付接口
开发工具:PHP
文件大小:0KB
下载次数:0
上传日期:2020-01-28 09:40:41
上 传 者sh-1993
说明:  贝宝,,
(paypal,,)

文件列表:
composer.json (602, 2020-01-28)
config/ (0, 2020-01-28)
config/config.php (1415, 2020-01-28)
lang/ (0, 2020-01-28)
lang/en/ (0, 2020-01-28)
lang/en/error.php (307, 2020-01-28)
lang/fr/ (0, 2020-01-28)
lang/fr/error.php (346, 2020-01-28)
src/ (0, 2020-01-28)
src/Facades/ (0, 2020-01-28)
src/Facades/PayPal.php (426, 2020-01-28)
src/PayPalFacadeAccessor.php (1099, 2020-01-28)
src/Providers/ (0, 2020-01-28)
src/Providers/PayPalServiceProvider.php (1612, 2020-01-28)
src/Services/ (0, 2020-01-28)
src/Services/AdaptivePayments.php (7805, 2020-01-28)
src/Services/ExpressCheckout.php (14612, 2020-01-28)
src/Traits/ (0, 2020-01-28)
src/Traits/PayPalHttpClient.php (3376, 2020-01-28)
src/Traits/PayPalRequest.php (8771, 2020-01-28)
src/Traits/PayPalTransactions.php (1812, 2020-01-28)
src/Traits/RecurringProfiles.php (2626, 2020-01-28)

# Laravel PayPal (Chained and express checkout) - [Introduction](https://github.com/osingh152/paypal/blob/master/#introduction) - [PayPal API Credentials](https://github.com/osingh152/paypal/blob/master/#paypal-api-credentials) - [Installation](https://github.com/osingh152/paypal/blob/master/#installation) - [Configuration](https://github.com/osingh152/paypal/blob/master/#configuration) - [Usage](https://github.com/osingh152/paypal/blob/master/#usage) - [Override PayPal API Configuration](https://github.com/osingh152/paypal/blob/master/#usage-paypal-api-configuration) - [Set Currency](https://github.com/osingh152/paypal/blob/master/#usage-currency) - [Additional PayPal API Parameters](https://github.com/osingh152/paypal/blob/master/#usage-paypal-params) - [Express Checkout](https://github.com/osingh152/paypal/blob/master/#usage-express-checkout) - [SetExpressCheckout](https://github.com/osingh152/paypal/blob/master/#usage-ec-setexpresscheckout) - [GetExpressCheckoutDetails](https://github.com/osingh152/paypal/blob/master/#usage-ec-getexpresscheckoutdetails) - [DoExpressCheckoutPayment](https://github.com/osingh152/paypal/blob/master/#usage-ec-doexpresscheckoutpayment) - [RefundTransaction](https://github.com/osingh152/paypal/blob/master/#usage-ec-refundtransaction) - [CreateBillingAgreement](https://github.com/osingh152/paypal/blob/master/#usage-ec-createbillingagreement) - [DoReferenceTransaction](https://github.com/osingh152/paypal/blob/master/#usage-ec-doreferencetransaction) - [GetTransactionDetails](https://github.com/osingh152/paypal/blob/master/#usage-ec-gettransactiondetails) - [CreateRecurringPaymentsProfile](https://github.com/osingh152/paypal/blob/master/#usage-ec-createrecurringprofile) - [GetRecurringPaymentsProfileDetails](https://github.com/osingh152/paypal/blob/master/#usage-ec-getrecurringprofiledetails) - [UpdateRecurringPaymentsProfile](https://github.com/osingh152/paypal/blob/master/#usage-ec-updaterecurringprofile) - [ManageRecurringPaymentsProfileStatus](https://github.com/osingh152/paypal/blob/master/#usage-ec-managerecurringprofile) - [Adaptive Payments](https://github.com/osingh152/paypal/blob/master/#usage-adaptive-payments) - [Pay Primary](https://github.com/osingh152/paypal/blob/master/#usage-adaptive-pay) - [Pay Secondary](https://github.com/osingh152/paypal/blob/master/#usage-adaptive-secondary) - [Handling PayPal IPN](https://github.com/osingh152/paypal/blob/master/#paypalipn) - [Creating Subscriptions](https://github.com/osingh152/paypal/blob/master/#create-subscriptions) - [Support](https://github.com/osingh152/paypal/blob/master/#support) ## Introduction By using this plugin you can process or refund payments and handle IPN (Instant Payment Notification) from PayPal in your Laravel application. **Currently only PayPal Express Checkout API Is Supported.** Github repo https://github.com/osingh152/paypal ## PayPal API Credentials This package uses the classic paypal express checkout. Refer to this link on how to create API credentials: https://developer.paypal.com/docs/classic/api/apiCredentials/#create-an-api-signature ## Installation * Use following command to install: ```bash composer require zehntech/paypal ``` * Add the service provider to your `$providers` array in `config/app.php` file like: ```php Zehntech\Paypal\Providers\PayPalServiceProvider::class ``` * Add the alias to your `$aliases` array in `config/app.php` file like: ```php 'PayPal' => Zehntech\PayPal\Facades\PayPal::class ``` * Run the following command to publish configuration: ```bash php artisan vendor:publish --provider "Zehntech\Paypal\Providers\PayPalServiceProvider" ``` ## Configuration * After installation, you will need to add your paypal settings. Following is the code you will find in **config/paypal.php**, which you should update accordingly. ```php 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' => 'APP-80W284485P519543T', // 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. ]; ``` * Add this to `.env.example` and `.env` ``` #PayPal Setting & API Credentials - sandbox PAYPAL_SANDBOX_API_USERNAME= PAYPAL_SANDBOX_API_PASSWORD= PAYPAL_SANDBOX_API_SECRET= PAYPAL_SANDBOX_API_CERTIFICATE= #PayPal Setting & API Credentials - live PAYPAL_LIVE_API_USERNAME= PAYPAL_LIVE_API_PASSWORD= PAYPAL_LIVE_API_SECRET= PAYPAL_LIVE_API_CERTIFICATE= ``` ## Usage Following are some ways through which you can access the paypal provider: ```php // Import the class namespaces first, before using it directly use Srmklive\PayPal\Services\ExpressCheckout; use Srmklive\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. ``` ## Override PayPal API Configuration You can override PayPal API configuration by calling `setApiCredentials` method: ```php $provider->setApiCredentials($config); ``` ## Set Currency By default the currency used is `USD`. If you wish to change it, you may call `setCurrency` method to set a different currency before calling any respective API methods: ```php $provider->setCurrency('EUR')->setExpressCheckout($data); ``` ## Additional PayPal API Parameters By default only a specific set of parameters are used for PayPal API calls. However, if you wish specify any other additional parameters you may call the `addOptions` method before calling any respective API methods: ```php $options = [ 'BRANDNAME' => 'MyBrand', 'LOGOIMG' => 'https://example.com/mylogo.png', 'CHANNELTYPE' => 'Merchant' ]; $provider->addOptions($options)->setExpressCheckout($data); ``` **Warning:** Any parameters should be referenced accordingly to the API call you will perform. For example, if you are performing `SetExpressCheckout`, then you must provide the parameters as documented by PayPal for `SetExpressCheckout` to `addOptions` method. #### Express Checkout ```php $data = []; $data['items'] = [ [ 'name' => 'Product 1', 'price' => 9.99, 'desc' => 'Description for product 1' 'qty' => 1 ], [ 'name' => 'Product 2', 'price' => 4.99, 'desc' => 'Description for product 2', 'qty' => 2 ] ]; $data['invoice_id'] = 1; $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice"; $data['return_url'] = url('/payment/success'); $data['cancel_url'] = url('/cart'); $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); ``` * **SetExpressCheckout** ```php $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']); ``` * **GetExpressCheckoutDetails** ```php $response = $provider->getExpressCheckoutDetails($token); ``` * **DoExpressCheckoutPayment** ```php // 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); ``` * **RefundTransaction** ```php $response = $provider->refundTransaction($transactionid); // To issue partial refund, you must provide the amount as well for refund: $response = $provider->refundTransaction($transactionid, 9.99); ``` * **CreateBillingAgreement** ```php // The $token is the value returned from SetExpressCheckout API call $response = $provider->createBillingAgreement($token); ``` * **DoReferenceTransaction** ```php // 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); ``` * **GetTransactionDetails** ```php // The $token is the value returned from doReferenceTransaction API call $response = $provider->getTransactionDetails($token); ``` * **CreateRecurringPaymentsProfile** ```php // 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); ``` * **GetRecurringPaymentsProfileDetails** ```php $response = $provider->getRecurringPaymentsProfileDetails($profileid); ``` * **UpdateRecurringPaymentsProfile** ```php $response = $provider->updateRecurringPaymentsProfile($data, $profileid); ``` * **ManageRecurringPaymentsProfileStatus** ```php // Cancel recurring payment profile $response = $provider->cancelRecurringPaymentsProfile($profileid); // Suspend recurring payment profile $response = $provider->suspendRecurringPaymentsProfile($profileid); // Reactivate recurring payment profile $response = $provider->reactivateRecurringPaymentsProfile($profileid); ``` #### Adaptive Payments To use adaptive payments, you must set the provider to use Adaptive Payments: ```php PayPal::setProvider('adaptive_payments'); ``` * **Pay Primary** ```php // Change the values accordingly for your application $data = [ 'receivers' => [ [ 'email' => 'johndoe@example.com', 'amount' => 10, 'primary' => true, ], [ 'email' => 'janedoe@example.com', 'amount' => 5, 'primary' => false ] ], 'action_type' => 'PAY_PRIMARY', 'payer' => 'EACHRECEIVER', // (Optional) Describes who pays PayPal fees. Allowed values are: 'SENDER', 'PRIMARYRECEIVER', 'EACHRECEIVER' (Default), 'SECONDARYONLY' 'return_url' => url('payment/success'), 'cancel_url' => url('payment/cancel'), ]; $response = $provider->createPayRequest($data); // The above API call will return the following values if successful: // 'responseEnvelope.ack', 'payKey', 'paymentExecStatus' ``` Next, you need to redirect the user to PayPal to authorize the payment ```php $redirect_url = $provider->getRedirectUrl('approved', $response['payKey']); return redirect($redirect_url); ``` * **Pay Secondary** ```php // Change the values accordingly for your application $payKey='Your payment paykey'; $actioType='Pay'; $response = $provider->approvePayment($payKey, $actioType); ``` ## Handling PayPal IPN You can also handle Instant Payment Notifications from PayPal. Suppose you have set IPN URL to **http://example.com/ipn/notify/** in PayPal. To handle IPN you should do the following: * First add the `ipn/notify` tp your routes file: ```php Route::post('ipn/notify','PayPalController@postNotify'); // Change it accordingly in your application ``` * Open `App\Http\Middleware\VerifyCsrfToken.php` and add your IPN route to `$excluded` routes variable. ```php 'ipn/notify' ``` * Write the following code in the function where you will parse IPN response: ```php /** * Retrieve IPN Response From PayPal * * @param \Illuminate\Http\Request $request */ public function postNotify(Request $request) { // Import the namespace Srmklive\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 ... } } ``` ## Create Subscriptions * For example, you want to create a recurring subscriptions on paypal, first pass data to `SetExpressCheckout` API call in following format: ```php // Always update the code below accordingly to your own requirements. $data = []; $data['items'] = [ [ 'name' => "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); ``` * Next perform the remaining steps listed in [`SetExpressCheckout`](https://github.com/osingh152/paypal/blob/master/#usage-ec-setexpresscheckout). * Next perform the exact steps listed in [`GetExpressCheckoutDetails`](https://github.com/osingh152/paypal/blob/master/#usage-ec-getexpresscheckoutdetails). * Finally do the following for [`CreateRecurringPaymentsProfile`](https://github.com/osingh152/paypal/blob/master/#usage-ec-createrecurringprofile) ```php $amount = 9.99; $description = "Monthly Subscription #1"; $response = $provider->createMonthlySubscription($token, $amount, $description); // To create recurring yearly subscription on PayPal $response = $provider->createYearlySubscription($token, $amount, $description); ``` ## Support This plugin only supports Laravel 5.1 or greater. * In case of any issues, kindly create one on the [Issues](https://github.com/osingh152/paypal/blob/master/https://github.com/zehntech/laravel-paypal/issues) section. * If you would like to contribute: * Fork this repository. * Implement your features. * Generate pull request.

近期下载者

相关文件


收藏者