gabrielextso/paybox-bundle 问题修复 & 功能扩展

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

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

gabrielextso/paybox-bundle

Composer 安装命令:

composer require gabrielextso/paybox-bundle

包简介

LexikPayboxBundle eases the implementation of the Paybox payment system.

README 文档

README

Build Status Latest Stable Version SensioLabsInsight

Important!

This bundle is partially maintained. No new features will be added but some PR will be merged for compatibility or security.

LexikPayboxBundle makes the use of Paybox payment system easier by doing all the boring things for you.

LexikPayboxBundle silently does :

  • hmac hash calculation of parameters during request.
  • server testing before request to be sure it is up.
  • signature verification with openssl on ipn response.
  • triggers an event on response.

You only need to provide parameters of your transaction, customize the response page and wait for the event triggered on ipn response.

Requirements

  • PECL hash >= 1.1
  • openssl enabled

Installation

Installation with composer :

composer require lexik/paybox-bundle

Add this bundle to your app/AppKernel.php :

public function registerBundles()
{
    return array(
        // ...
        new Lexik\Bundle\PayboxBundle\LexikPayboxBundle(),
        // ...
    );
}

Configuration

Your personnal account informations must be set in your config.yml

# Lexik Paybox Bundle
lexik_paybox:
    accounts:
        default:
            parameters:
                production: false        # Switches between Paybox test and production servers (preprod-tpe <> tpe)
                site:        '9999999'   # Site number provided by the bank
                rank:        '99'        # Rank number provided by the bank
                login:       '999999999' # Customer's login provided by Paybox
                hmac:
                    key: '01234...BCDEF' # Key used to compute the hmac hash, provided by Paybox

Additional configuration:

lexik_paybox:
    accounts:
        default:
            parameters:
                currencies:  # Optionnal parameters, this is the default value
                    - '036'  # AUD
                    - '124'  # CAD
                    - '756'  # CHF
                    - '826'  # GBP
                    - '840'  # USD
                    - '978'  # EUR
                hmac:
                    algorithm:      sha512 # signature algorithm
                    signature_name: Sign   # customize the signature parameter name

The routing collection must be set in your routing.yml

# Lexik Paybox Bundle
lexik_paybox:
    resource: '@LexikPayboxBundle/Resources/config/routing.yml'

Usage of Paybox System

The bundle includes a sample controller SampleController.php with two actions.

...
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Sample action to call a payment.
 * It create the form to submit with all parameters.
 */
public function indexAction($account)
{
    $service = sprintf('lexik_paybox.request_handler.%s', $account);

    if (!$this->has($service)) {
        throw new NotFoundHttpException(sprintf('Service %s not found', $service));
    }

    $paybox = $this->get($service);
    $paybox->setParameters(array(
        'PBX_CMD'          => 'CMD'.time(),
        'PBX_DEVISE'       => '978',
        'PBX_PORTEUR'      => 'test@paybox.com',
        'PBX_RETOUR'       => 'Mt:M;Ref:R;Auto:A;Erreur:E',
        'PBX_TOTAL'        => '1000',
        'PBX_TYPEPAIEMENT' => 'CARTE',
        'PBX_TYPECARTE'    => 'CB',
        'PBX_EFFECTUE'     => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'success'), UrlGenerator::ABSOLUTE_URL),
        'PBX_REFUSE'       => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'denied'), UrlGenerator::ABSOLUTE_URL),
        'PBX_ANNULE'       => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'canceled'), UrlGenerator::ABSOLUTE_URL),
        'PBX_RUF1'         => 'POST',
        'PBX_REPONDRE_A'   => $this->generateUrl('lexik_paybox_ipn', array('account' => $account, 'time' => time()), UrlGenerator::ABSOLUTE_URL),
    ));

    return $this->render(
        'LexikPayboxBundle:Sample:index.html.twig',
        array(
            'url'  => $paybox->getUrl(),
            'form' => $paybox->getForm()->createView(),
        )
    );
}
...
/**
 * Sample action of a confirmation payment page on witch the user is sent
 * after he seizes his payment informations on the Paybox's platform.
 * This action must only containts presentation logic.
 */
public function returnAction(Request $request, $status, $account)
{
    return $this->render('LexikPayboxBundle:Sample:return.html.twig', array(
        'status'     => $status,
        'account'    => $account,
        'parameters' => $request->query,
    ));
}
...

The getUrl() method silently does a server check and throws an exception if the destination server does not respond.

The payment confirmation in your business logic must be done when the instant payment notification (IPN) occurs. The plugin contains a controller with an action that manages this IPN and triggers an event. The event contains all data transmetted during the request and a boolean that tells if signature verification was successful.

The bundle contains a listener example that simply create a file on each ipn call.

namespace Lexik\Bundle\PayboxBundle\Listener;

use Lexik\Bundle\PayboxBundle\Event\PayboxResponseEvent;
use Symfony\Component\Filesystem\Filesystem;

/**
 * Sample listener that create a file for each ipn call.
 */
class SampleIpnListener
{
    /**
     * @var string
     */
    private $rootDir;

    /**
     * @var Filesystem
     */
    private $filesystem;

    /**
     * Constructor.
     *
     * @param string     $rootDir
     * @param Filesystem $filesystem
     */
    public function __construct($rootDir, Filesystem $filesystem)
    {
        $this->rootDir = $rootDir;
        $this->filesystem = $filesystem;
    }

    /**
     * Creates a txt file containing all parameters for each IPN.
     *
     * @param PayboxResponseEvent $event
     */
    public function onPayboxIpnResponse(PayboxResponseEvent $event)
    {
        $path = sprintf('%s/../data/%s', $this->rootDir, date('Y\/m\/d\/'));
        $this->filesystem->mkdir($path);

        $content = sprintf('Account : %s%s', $event->getAccount(), PHP_EOL);
        $content .= sprintf('Signature verification : %s%s', $event->isVerified() ? 'OK' : 'KO', PHP_EOL);
        foreach ($event->getData() as $key => $value) {
            $content .= sprintf("%s:%s%s", $key, $value, PHP_EOL);
        }

        file_put_contents(
            sprintf('%s%s.txt', $path, time()),
            $content
        );
    }
}

To create your own listener, you just have to make it wait for the "paybox.ipn_response" event. For example the listener of the bundle:

parameters:
    lexik_paybox.sample_response_listener.class: 'Lexik\Bundle\PayboxBundle\Listener\SampleIpnListener'

services:
    ...
    lexik_paybox.sample_response_listener:
        class: '%lexik_paybox.sample_response_listener.class%'
        arguments: [ '%kernel.root_dir%', '@filesystem' ]
        tags:
            - { name: kernel.event_listener, event: paybox.ipn_response, method: onPayboxIpnResponse }

Resources

All transactions parameters are available in the official documentation.

gabrielextso/paybox-bundle 适用场景与选型建议

gabrielextso/paybox-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 gabrielextso/paybox-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-02