noweh/laravel-payzen 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

noweh/laravel-payzen

Composer 安装命令:

composer require noweh/laravel-payzen

包简介

Easily create a Payzen payment form.

README 文档

README

Payzen Laravel Run Tests MIT Licensed last version Downloads

The library provides an easy and fast Payzen form creation. This helps to instanciate all required parameters and create the form to access to payment interface. To know required parameters, go to https://payzen.io/en-EN/form-payment/quick-start-guide/sending-a-payment-form-via-post.html

Installation

First you need to add the component to your composer.json

composer require noweh/laravel-payzen

Update your packages with composer update or install with composer install.

Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Laravel without auto-discovery

Noweh\Payzen\PayzenServiceProvider::class,

To use the facade, add this in app.php:

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

Service Provider

After updating composer, add the ServiceProvider to the providers array in config/app.php

Configuration file

Next, you must migrate config :

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

Create a payment form

Now we are finally ready to use the package! Here is a little example:

     $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>')
    ;

Check Payzen response signature

     $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')));
    ;

Other useful functions

add_product

Add a product to the order

Parameters

array $product , must have the following keys : 'label,amount,type,ref,qty

Example

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

Note : the amount of each products price must not be multiplied by 100

set_amount

Defines the total amount of the order. If you doesn't give the amount in parameter, it will be automaticly calculated by the sum of products you've got in your basket.

Parameters

[optional] int $amount, Payzen format. ex : for a product with a price of 150€, give 15000

Example

   $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

Get total amount of the order

Parameters

[optional] bool $decimal if true, you get a decimal otherwise you get standard Payzen amount format (int). Default value is true.

Example

  $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

Method to do massive assignement of parameters

Parameters

array $params associative array of Payzen parameters

Example

   \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

Method to convert an input in a compatible for Payzen

Parameters

string $input, text to convert

string $allow, n|a|an|ans

int $length 1..255

boolean $truncate allow returning truncated result if the transcoded $input length is over $length

Example

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

check signature in response

Checking Payzen response signature

Example

    \Payzen::isResponseSignatureValid();

noweh/laravel-payzen 适用场景与选型建议

noweh/laravel-payzen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.47k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2021 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「payzen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 noweh/laravel-payzen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 noweh/laravel-payzen 我们能提供哪些服务?
定制开发 / 二次开发

基于 noweh/laravel-payzen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-06