webfactorybulgaria / laravel-shop-gateway-paypal
Laravel Shop 包的 PayPal 网关。
Requires
- php: >=5.4.0
- illuminate/console: ~5.0
- illuminate/support: ~5.0
- paypal/rest-api-sdk-php: *
Requires (Dev)
- sami/sami: dev-master
This package is not auto-updated.
Last update: 2024-09-14 19:36:44 UTC
README
为 Laravel Shop 提供的 PayPal 网关解决方案。
网关
本包包含
-
直接信用卡支付
-
PayPal Express 支付
内容
安装
为了安装 Laravel Shop,您可以在您的 composer.json 中运行
"amsgames/laravel-shop-gateway-paypal": "v1.0.0"
然后运行 composer install
或 composer update
。
然后在您的 config/shop.php
中添加
'paypal' => Amsgames\LaravelShopGatewayPaypal\GatewayPayPal::class, 'paypalExpress' => Amsgames\LaravelShopGatewayPaypal\GatewayPayPalExpress::class,
到 gateways
数组中。
配置
身份验证
在 config/services.php
中设置您的 PayPal 应用身份验证凭据,例如
'paypal' => [ 'client_id' => env('PAYPAL_CLIENT_ID', ''), 'secret' => env('PAYPAL_SECRET', ''), 'sandbox' => env('PAYPAL_SANDBOX', true), ],
注意:当上线时,将 sandbox
改为 false。
网关使用
直接信用卡
要使此功能正常工作,所需的唯一额外步骤是在 checkout
和 order placement
之前添加信用卡信息,例如
// (1) - Set gateway Shop::setGateway('paypal'); // (2) - Add credit card for validation Shop::gateway()->setCreditCard( $cartType = 'visa', $cardNumber = '4111111111111111', $month = '1', $year = '2019', $cvv = '123', $firstname = 'John', $lastname = 'Doe' ); // (3) - Call checkout if (!Shop::checkout()) { echo Shop::exception()->getMessage(); // echos: card validation error. } // (4) - Create order $order = Shop::placeOrder(); // (5) - Review payment if ($order->hasFailed) { echo Shop::exception()->getMessage(); // echos: payment error. }
注意:如果您在不同于 Shop::placeOrder
的控制器或视图中调用 Shop::checkout()
,请确保在第二个控制器中调用 Shop::placeOrder()
之前调用 setCreditCard()
。此包不存储信用卡数据。
建议:在使用信用卡时,请使用 SSL 保护您的结账流程。
PayPal Express
如果您不想处理信用卡表单和 SSL,则可以使用 PayPal Express。PayPal Express 在您的网站外处理支付过程,并返回结果。
有关此过程的更多信息,请参阅 PayPal 的文档。
配置
PayPal 将回调 Laravel Shop 和此网关,并带有结果。Laravel Shop 将然后重定向客户到 config/shop.php
中设置的路线,并将 Order Id
作为参数传递。在使用此网关之前,请设置此路由。
/* |-------------------------------------------------------------------------- | Redirect route after callback |-------------------------------------------------------------------------- | | Which route to call after the callback has been processed. | */ 'callback_redirect_route' => 'home',
用法
// (1) - Set gateway Shop::setGateway('paypalExpress'); // (2) - Call checkout / OPTIONAL // You can call this to keep a standard flow // Although this step for this gateway is not needed. Shop::checkout(); // (3) - Create order $order = Shop::placeOrder(); // (4) - Review order and redirect to payment if ($order->isPending) { // PayPal URL to redirect to proceed with payment $approvalUrl = Shop::gateway()->getApprovalUrl(); // Redirect to url return redirect($approvalUrl); } // (5) - Callback // You don't have to do anything. // Laravel Shop will handle the callback and redirect the customer to the configured route.
许可
此包是免费软件,根据 MIT 许可证的条款分发。
附加信息
此包使用官方的 PayPal PHP SDK。