noweh/laravel-payzen

轻松创建Payzen支付表单。

1.3.0 2023-07-13 15:31 UTC

This package is auto-updated.

Last update: 2024-09-20 00:38:25 UTC


README

Payzen Laravel Run Tests MIT Licensed last version Downloads

该库提供了一种简单快捷的Payzen表单创建方式。这有助于实例化所有必需的参数并创建表单以访问支付界面。要了解必需的参数,请访问 https://payzen.io/en-EN/form-payment/quick-start-guide/sending-a-payment-form-via-post.html

安装

首先,您需要将组件添加到您的composer.json中

composer require noweh/laravel-payzen

使用composer update更新您的包或使用composer install安装。

Laravel使用包自动发现,因此不需要您手动添加ServiceProvider。

Laravel没有自动发现

Noweh\Payzen\PayzenServiceProvider::class,

要使用外观,请在app.php中添加以下内容

'Payzen' => Noweh\Payzen\PayzenFacade::class,

ServiceProvider

更新composer后,将ServiceProvider添加到config/app.php中的providers数组中

配置文件

接下来,您必须迁移config

php artisan vendor:publish --provider="Noweh\Payzen\PayzenServiceProvider"

创建支付表单

现在我们终于可以使用这个包了!这里有一个简单的示例

     $blocks_html = \Payzen::set_amount(300)
        ->set_trans_id(123456)
        ->set_order_info(\Payzen::ascii_transcode('an information', 'an', 255, true))
        ->set_order_info2(\Payzen::ascii_transcode('another information', 'an', 255, true))
        ->set_url_return(request()->fullUrl())
        ->set_return_mode('POST')
        ->set_signature()
        ->get_form('<div><input id="spSubmit" type="submit" value="Pay" class="Button Button--black"></div>')
    ;

检查Payzen响应签名

     $payzen = \Payzen::set_params(\Arr::where(request()->all(), function($value, $key) {
                 	return strrpos($key, 'vads_', -5) !== false;
             	}))
     			->set_signature()
     		;
             return (request()->input('signature') && ($payzen::get_signature() === request()->input('signature')));
    ;

其他有用的函数

add_product

将产品添加到订单中

参数

array $product ,必须包含以下键: 'label,amount,type,ref,qty

示例

    \Payzen::add_product(
        [
            'label' => 'Concert Coldplay 2016',
            'amount' => 235.00,
            'type' => 'ENTERTAINMENT',
            'ref' => 'COLD016',
            'qty' => 3
        ]
    );

注意:每个产品的价格数量 不得 乘以100

set_amount

定义订单的总金额。如果您没有在参数中提供金额,它将自动通过您篮子中的产品总和来计算。

参数

[可选] int $amount,Payzen格式。例如:对于一个价格为150€的产品,给出15000

示例

   $payzen = \Payzen::add_product(
       [
           'label' => 'Concert Coldplay 2016',
           'amount' => 235.00,
           'type' => 'ENTERTAINMENT',
           'ref' => 'COLD016',
           'qty' => 3
       ]
   );
   $payzen->set_amount();
   echo $payzen->get_amount(); //will display 705.00 (3*235.00)

get_amount

获取订单的总金额

参数

[可选] bool $decimal 如果为true,则返回小数,否则返回标准的Payzen金额格式(int)。默认值为true。

示例

  $payzen = \Payzen::add_product(
      [
          'label' => 'Concert Coldplay 2016',
          'amount' => 235.00,
          'type' => 'ENTERTAINMENT',
          'ref' => 'COLD016',
          'qty' => 3
      ]
  );
  $payzen->set_amount();
  echo $payzen->get_amount(); //will display 705.00 (3*235.00)
  echo $payzen->get_amount(false); //will display 70500 (3*235.00)

set_params

用于进行大量参数赋值的方法

参数

array $params 关联数组,包含Payzen参数

示例

   \Payzen::set_params(
       [
           'vads_page_action' => 'PAYMENT',
           'vads_action_mode' => 'INTERACTIVE',
           'vads_payment_config' => 'SINGLE',
           'vads_version' => 'V2',
           'vads_trans_date' => gmdate('YmdHis'),
           'vads_currency' => '978'
       ]
   );

ascii_transcode

将输入转换为Payzen兼容的方法

参数

string $input,要转换的文本

string $allow,n|a|an|ans

int $length 1..255

boolean $truncate 允许返回截断的结果,如果转码后的$input长度超过$length

示例

    \Payzen::ascii_transcode('123nd', 'n', 5, true);

在响应中检查签名

检查Payzen响应签名

示例

    \Payzen::isResponseSignatureValid();