amsgames/laravel-shop-gateway-paypal

Laravel Shop 包的 PayPal 网关。

v1.0.1 2015-09-19 04:10 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:42:52 UTC


README

Latest Stable Version Total Downloads License

Laravel Shop 提供的 PayPal 网关解决方案。

网关

本包包含

  • 直接信用卡付款

  • PayPal Express 付款

内容

安装

为了安装 Laravel Shop,您可以在 composer.json 中运行

"amsgames/laravel-shop-gateway-paypal": "v1.0.0"

然后运行 composer installcomposer 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