marqant-lab/marqant-pay-stripe

marqant/marqant-pay 包的 Stripe 支付提供商。


README

此包使 Stripe 支付提供商对 marqant/marqant-pay 包可用。

安装

您可以通过 composer 需求此包,如下所示。

composer require marqant-lab/marqant-pay-stripe

然后您必须将服务信息添加到 Laravel 的 services.php 配置文件。为此,更新配置文件如下。

return [
    // other services
    // ...

    'stripe' => [
        'key'    => env('STRIPE_KEY'),
        'secret' => env('STRIPE_SECRET'),
    ],
];

接下来,您需要添加环境变量。转到您的 Stripe 控制面板,获取您的 Stripe 密钥和密钥,然后将其添加到您的 .env 文件中。

STRIPE_KEY=pk_test_iLokikJOvEuI2HlWgH4olf3P
STRIPE_SECRET=sk_test_BQokikJOvBiI2HlWgH4olfQ2

现在,在 marqant-pay.php 配置文件中启用支付提供商。

return [
    /*
     |--------------------------------------------------------------------------
     | Gateways
     |--------------------------------------------------------------------------
     |
     | In this section you can define all payment gateways that you need for
     | your project.
     |
     */

    'gateways' => [
        'stripe' => \Marqant\MarqantPayStripe\StripePaymentGateway::class,
    ],
];

接下来,您需要在 marqant-pay 设置中设置的账单上添加 Stripe 字段。因此,为每个已设置的账单模型(或将要设置的)运行以下操作。

php artisan marqant-pay:migrations:stripe

如果您正在使用 marqant-lab/marqant-pay-subscriptions 包来启用订阅,则需要在所选命令中添加 --subscriptions 标志。

php artisan marqant-pay:migrations:stripe --subscriptions

现在,您可以像往常一样运行迁移。

php artisan migrate

就是这样,现在您应该可以开始了。

### WebHooks

我们使用 spatie/laravel-stripe-webhooks 包来处理 Stripe WebHooks。

##### 配置

STRIPE_WEBHOOK_SECRET 添加到 .env

您可以在 Stripe 控制面板 的 WebHook 配置设置中找到使用的密钥。

如果您之前没有做,运行 $ php artisan migrate

转到您的 your_project/app/Http/Middleware/VerifyCsrfToken.php 并添加以下行

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/stripe/webhook'
    ];

最后,处理路由
在 Stripe 控制面板中,您必须配置 Stripe WebHooks 应该击中您的应用程序的哪个 URL。

您应该将其设置为 '/stripe/webhook'。

端点 URL 的示例
http://your.awesome.site/stripe/webhook

可用的 Stripe 事件

  • payment_intent.succeeded
  • invoice.payment_succeeded
  • payment_intent.payment_failed
  • charge.failed (未完成)

对于 'payment_intent.payment_failed',您应该在配置文件中设置 'marqant-pay.payment_urls.base_url''marqant-pay.payment_urls.payment_sub_url'
描述在配置文件中。
您还需要查看 'marqant-pay.support_emails' 配置。

您还可以将以下键添加到项目/resources/lang中进行翻译

  • "Here"
  • "Payment failed."
  • "Requires payment method."
  • "You needs to update your payment method in the"
    别忘了:它应该是 json 文件。

示例 resources/lang/en.json

{
  "Payment failed.": "Payment failed translation."
}

它们用于 'payment_intent.payment_failed' 事件的电子邮件

这就是您所需要的