amostajo / laravel-shop-gateway-omnipay
Laravel Shop 包的 Omnipay 网关。
v1.0.2
2015-11-05 06:16 UTC
Requires
- php: >=5.4.0
- illuminate/console: ~5.0
- illuminate/support: ~5.0
- omnipay/common: ~2.4
Requires (Dev)
- sami/sami: dev-master
This package is auto-updated.
Last update: 2024-09-21 20:10:36 UTC
README
为 Laravel Shop 提供的 Omnipay 网关解决方案。
启用多种网关支付,如 PayPal、2Checkout、Stripe 等。请参阅 Omnipay 页面 上的完整列表。
网关
本包包含
- Omnipay
内容
安装
添加
"amostajo/laravel-shop-gateway-omnipay": "1.0.*"
到您的 composer.json
文件中。然后运行 composer install
或 composer update
。
然后在您的 config/shop.php
文件中添加
'omnipay' => Amostajo\LaravelShopGatewayOmnipay\GatewayOmnipay::class,
到 gateways
数组中。
添加服务
安装完成后,下一步将在 composer.json
文件中添加您选择的服务。
可用的服务在此处列出
https://github.com/thephpleague/omnipay#payment-gateways
例如,以下依赖项必须添加以使用 Stripe
"omnipay/stripe": "~2.0"
网关使用
以下示例将展示如何使用和访问 Omnipay
// (1) - Set gateway Shop::setGateway('omnipay'); // (2) - Indicate service to use Shop::gateway()->create('PayPal_Rest'); // (3) - Initialize your service (varies from service) Shop::gateway()->omnipay->initialize([ 'clientId' => '...', 'secret' => '...', 'testMode' => true, ]); // (4) - Add credit card for validation (optional depending service) Shop::gateway()->setCreditCard([ 'number' => '4111111111111111', 'expiryMonth' => '1', 'expiryYear' => '2019', 'cvv' => '123', 'firstName' => 'John', 'lastName' => 'Doe', 'billingAddress1' => '666 grand canyon', 'billingCountry' => 'US', 'billingCity' => 'TX', 'billingPostcode' => '12345', 'billingState' => 'TX', ]); // (5) - Call checkout if (!Shop::checkout()) { echo Shop::exception()->getMessage(); // echos: card validation error. } // (6) - Create order $order = Shop::placeOrder(); // (7) - Review payment if ($order->hasFailed) { echo Shop::exception()->getMessage(); // echos: payment error. }
行数可能因选择的服务而异。
注意:结账和下单不应与标准的 Laravel Shop 流程有所不同。
访问 Omnipay
如果您需要设置或调用服务所需的任何特定方法,可以始终访问 omnipay
对象
// (1) - Set gateway Shop::setGateway('omnipay'); Shop::gateway()->create('Stripe'); // (2) - Setting method / calling specific method Shop::gateway()->omnipay->setSpecific();
添加选项
您可以将更多选项(除 amount
、currency
和 card
外)添加到授权和购买方法中
// (1) - Set gateway Shop::setGateway('omnipay'); Shop::gateway()->create('Stripe'); // (2) - Adding an option Shop::gateway()->addOption('token', $stripetoken); // (3) - Any operation that follows Shop::checkout();
回调
当需要回调时,请使用以下示例
// (1) - Set gateway Shop::setGateway('omnipay'); Shop::gateway()->create('PayPal_Express'); // (2) - Authentication Shop::gateway()->omnipay->setUsername('...'); Shop::gateway()->omnipay->setPassword('...'); // (2) - Call checkout / OPTIONAL 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.
测试服务
- PayPal
- Stripe
许可协议
本软件包是免费软件,根据 MIT 许可协议分发。
附加信息
本软件包使用 Omnipay。