vedatunlu/payment

Laravel的支付系统API集成

v1.4.6 2023-09-17 10:14 UTC

This package is auto-updated.

Last update: 2024-09-20 19:30:07 UTC


README

Laravel Payment

Laravel Payment是一个用于管理支付网关集成的包。此包提供了一个易于使用的接口,将流行的支付网关(如Sipay以及即将推出的Iyzico、Sipay、PayTr、iPara、Paynet等)集成到您的Laravel应用程序中。

特性

  • 与各种支付网关轻松集成
  • 使用Payment客户端类轻松使用
  • 使用可用的支付网关进行钱包使用
  • 轻松验证传入的错误或成功回调请求中的哈希密钥,例如webhooks等。
  • 使用可用的网关及其方法进行多用途。

安装

  1. 使用Composer将Laravel Payment包添加到您的项目中
    composer require vedatunlu/payment
  1. 包服务提供者将由您的laravel项目自动发现。因此,您无需更新您的app/config.php文件以添加包服务提供者。

  2. 发布配置文件到您的项目。

    php artisan vendor:publish --tag=payment-config

上述命令将在配置目录中创建一个名为payment.php的文件。

在使用之前,请在您的.env文件上创建环境变量

将您的支付网关提供的凭据添加到已发布的配置目录中支付配置文件的相应支付网关范围内。如果您还没有,您可以从服务提供商处提供凭据。如果您不打算使用另一个,则不需要定义任何其他凭据。如果需要,您可以通过在支付配置文件的相应范围内定义凭据来使用包支持的每个支付网关。

Payment类使用参考表

在使用之前,请查看下表以了解Payment类的基本行为。

提示:所有方法都接受一个数组作为参数。由于包服务提供者可以自动附加凭据,因此您不需要附加任何凭据,如merchant_id、app_key、secret_key。请检查您的支付网关文档以获取有关端点所需参数的更多信息。

基本用法示例

  1. getCards
    // will return credit card resources
    Payment::gateway('sipay')
        ->getCards([
            'customer_number' => 123123
        ])->toArray();
  1. saveCard
    // will return credit card token
    Payment::gateway('sipay')
        ->saveCard([
            'card_number' => 4508034508034509,
            'customer_number' => 123123,
            'expiry_month' => 12,
            'expiry_year' => 2026,
            'card_holder_name' => 'Vedat Ünlü'
        ])->toArray();
  1. payWith3D
    // will return a html form body and this form will redirect to the 3D verification
    $response = Payment::gateway('sipay')
                    ->payWith3D([
                        'cc_holder_name' => 'Vedat Ünlü',
                        'cc_no' => '4508034508034509',
                        'expiry_month' => '12',
                        'expiry_year' => '2026',
                        'cvv' => '000',
                        'currency_code' => 'TRY',
                        'installments_number' => 1,
                        'invoice_id' => rand(100000, 999999),
                        'invoice_description' => 'invoice_description',
                        'name' => 'Vedat',
                        'surname' => 'Ünlü',
                        'total' => 101.10,
                        'items' => json_encode([
                            [
                                'name' => 'Item 2',
                                'price' => 101.10,
                                'quantity' => 1,
                                'description' => "item description"
                            ]
                        ]),
                        'cancel_url' => 'payment-success-callback-url', // route('payment.callback.success)
                        'return_url' => 'payment-error-callback-url', // route('payment.callback.error)
                        'response_method' => 'POST'
                    ]);
                    
    if ($response->isSuccess() == true) {
        return $response->get3DSForm(); // get response as html form
    }
    
    return $response->toArray(); // get response as array
  1. 验证传入的Sipay哈希密钥

您可以使用Payment::validate($hashKey)轻松验证来自sipay网关返回的哈希密钥。

    $hashKey = $request->input('hash_key');
    
    if (!Payment::validate('sipay', $hashKey)) {
        return back()->with('error', 'Invalid hash key');
    }

如果密钥有效,则此方法返回包含状态、总金额、发票ID、订单ID、货币代码的数组。如果无效,方法将返回false。

为包做出贡献

我们欢迎并感谢您对包的贡献!贡献指南可在此处找到。

许可

此包是开源软件,根据MIT许可许可。