obydul/larapal
Composer 安装命令:
composer require obydul/larapal
包简介
LaraPal is a laravel plugin for processing payments through PayPal.
README 文档
README
Introduction
By using this plugin you can process or refund payments from PayPal in your Laravel application.
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:
composer require obydul/larapal
- Laravel 5.5 uses package auto-discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery, add the service provider to your
$providersarray inconfig/app.phpfile like:
Obydul\LaraPal\LarapalServiceProvider::class
- Run the following command to publish configuration:
php artisan vendor:publish --provider="Obydul\LaraPal\LarapalServiceProvider"
Installation completed.
Configuration
- After installation, you need to set paypal credentialsin .env file.
LARAPAL_MODE=sandbox # sandbox or live LARAPAL_API_USERNAME= # paypal api username LARAPAL_API_PASSWORD= # paypal api password LARAPAL_API_SIGNATURE= # paypal api signature
- Now optimize the app:
php artisan optimize && php artisan config:clear.
Usage
Following are some ways through which you can access the LaraPal provider:
// Import the class namespaces first, before using it directly use Obydul\LaraPal\Services\ExpressCheckout; // Create object instance $paypal = new ExpressCheckout(); // Redirect user to PayPal to obtain charging permissions $paypal->doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD'); // single payment $paypal->doExpressMultipleCheckout($items, 'invoice_id', 'USD', false, $customFields); // multiple items // Perform payment, token and PayerID are being returned with GET response from PayPal $paypal->doSinglePayment($_GET['token'], $_GET['PayerID']; // single payment $paypal->doMultiplePayment($_GET['token'], $_GET['PayerID']; // multiple payment // Perform refund based on transaction ID $paypal->doRefund($transactionId, 'invoice_id', false, 0, 'USD', ''); // full refund $paypal->doRefund($transactionId, 'invoice_id', true, 5.15, 'USD', ''); // partial refund // Get transaction details $details = $paypal->getTransactionDetails($transactionId);
doExpressCheckout
// Structure - invoice ID must be unique doExpressCheckout(AMOUNT, 'DESCRIPTION', 'INVOICE', 'CURRENCY', SHIPPING, CUSTOMFIELDS); doExpressMultipleCheckout(ITEMS, 'INVOICE', 'CURRENCY', SHIPPING, CUSTOMFIELDS); // Normal call doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD'); // Pass custom fields to your order $customFields = array( 'identifier' => "Example.com/ID", 'customerEmail' => "customer@email.com", ); // Now do the express checkout. If you don't like to pass custom fields, then remove $customFields. $paypal->doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD', false, $customFields); // multiple items payment $items = array( array( "name" => "Product 1", "price" => "12.25", "quantity" => "1", "product_id" => 111 ), array( "name" => "Product 2", "price" => "25.50", "quantity" => "1", "product_id" => 112 ) ); $paypal->doExpressMultipleCheckout($items, $invoice_id, 'USD', false, $customFields);
doRefund
// Structure doExpressCheckout(TRANSACTION_ID, 'INVOICE_ID', 'IS_PARTIAL', PARTIAL_AMOUNT, CURRENCY, NOTE); // Full refund doRefund($transactionId, 'invoice_id', false, 0, 'USD', '') // Partial refund doRefund($transactionId, 'invoice_id', true, 12.25, 'USD', '') // you can pass note also
Example
After installing LaraPal, create routes and create a controller named 'PayPalController':
// Routes Route::get('payment-status', 'PayPalController@paymentStatus')->name('payment-status'); Route::get('single-payment', 'PayPalController@singlePayment'); Route::get('multiple-payment', 'PayPalController@multipleItemsPayment'); Route::get('do-the-payment', 'PayPalController@doThePayment'); Route::get('refund-payment', 'PayPalController@doRefund'); Route::get('cancel-payment', 'PayPalController@cancelPayment'); // Controller php artisan make:controller PayPalController
Now in your PayPalController add this: PayPalController.php
Now just visit the URL to make an action:
http://example.com/single-payment http://example.com/multiple-payment http://example.com/refund-payment
After successful payment, you will be redirected to http://example.com/payment-status and will see a message like: Success! Transaction ID: 9TR987531T2702301.
License
The MIT License (MIT). Please see License File for more information.
Others
Inspired by paypal-express-checkout and thank you, romaonthego.
In case of any issues, kindly create one on the Issues section.
Thank you for installing LaraPal.
obydul/larapal 适用场景与选型建议
obydul/larapal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.77k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 obydul/larapal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 obydul/larapal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-20