yproximite/payum-system-pay
Composer 安装命令:
composer require yproximite/payum-system-pay
包简介
SP Plus gateway for Payum
README 文档
README
A Payum gateway to use SystemPay (a French payment system)
Requirements
- PHP 7.2+
- Payum
- Optionally PayumBundle and Symfony 3 or 4+
Installation
$ composer require yproximite/payum-system-pay
Configuration
With PayumBundle (Symfony)
First register the gateway factory in your services definition:
# config/services.yaml or app/config/services.yml services: yproximite.system_pay_gateway_factory: class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder arguments: [Yproximite\Payum\SystemPay\SystemPayGatewayFactory] tags: - { name: payum.gateway_factory_builder, factory: system_pay }
Then configure the gateway:
# config/packages/payum.yaml or app/config/config.yml payum: gateways: system_pay: factory: system_pay vads_site_id: 'change it' # required certif_prod: 'change it' # required certif_test: 'change it' # required sandbox: true hash_algorithm: 'algo-sha1' # or 'algo-hmac-sha256'
With Payum
<?php //config.php use Payum\Core\PayumBuilder; use Payum\Core\Payum; /** @var Payum $payum */ $payum = (new PayumBuilder()) ->addDefaultStorages() ->addGateway('gatewayName', [ 'factory' => 'system_pay', 'vads_site_id' => 'change it', // required 'certif_prod' => 'change it', // required 'certif_test' => 'change it', // required 'sandbox' => true, 'hash_algorithm' => 'algo-sha1' // or 'algo-hmac-sha256' ]) ->getPayum() ;
Why hash_algorithm is prefixed by algo-?
We wanted to use sha1 or hmac-256, but there is currently a Payum limitation which try to call sha1 because it's a valid callable.
As a workaround, the only easy solution we thought was to prefix them with algo-.
Since algo-sha1 is not a valid callable, there is no Payum issues and everything works well.
Usage
Make sure your Payment entity overrides getNumber() method like this:
<?php namespace App\Entity\Payment; use Doctrine\ORM\Mapping as ORM; use Payum\Core\Model\Payment as BasePayment; /** * @ORM\Table * @ORM\Entity */ class Payment extends BasePayment { /** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * * @var int */ protected $id; /** * {@inheritdoc} */ public function getNumber() { return (string) $this->id; } }
By doing this, the library will be able to pick the payment's id and use it for the payment with System Pay (we should send a transaction id between 000000 and 999999).
Payment in several instalments
If you planned to support payments in several instalments, somewhere in your code you will need to call Payment#setPartialAmount to keep a trace of the amount per payment:
<?php class Payment extends BasePayment { // ... /** * @ORM\Column(type="integer", nullable=true) */ protected $partialAmount; public function getPartialAmount(): ?int { return $this->partialAmount; } public function setPartialAmount(?int $partialAmount): void { $this->partialAmount = $partialAmount; } }
Usage
<?php use App\Entity\Payment; use Yproximite\Payum\SystemPay\Api; use Yproximite\Payum\SystemPay\PaymentConfigGenerator; // Define the periods $periods = [ ['amount' => 1000, 'date' => new \DateTime()], ['amount' => 2000, 'date' => (new \DateTime())->add(new \DateInterval('P1M'))], ['amount' => 3000, 'date' => (new \DateTime())->add(new \DateInterval('P2M'))], ]; // Compute total amount $totalAmount = array_sum(array_column($periods, 'amount')); // Compute `paymentConfig` fields that will be sent to the API // It will generates something like this: MULTI_EXT:20190102=1000;20190202=2000;20190302=3000 $paymentConfig = (new PaymentConfigGenerator())->generate($periods); // Then create payments $storage = $payum->getStorage(Payment::class); $payments = []; foreach ($periods as $period) { $payment = $storage->create(); $payment->setTotalAmount($totalAmount); $payment->setPartialAmount($period['amount']); $details = $payment->getDetails(); $details[Api::FIELD_VADS_PAYMENT_CONFIG] = $generatedPaymentConfig; $payment->setDetails($details); $storage->update($payment); $payments[] = $payment; }
yproximite/payum-system-pay 适用场景与选型建议
yproximite/payum-system-pay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.5k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2019 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「payum」 「sp plus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yproximite/payum-system-pay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yproximite/payum-system-pay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yproximite/payum-system-pay 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Payum integration for Symfony e-commerce applications.
Quickpay payment plugin for Sylius
Secure payment processing via PayU MEA for Magento 2.3
Library to validate and parse social media profile URLs
Saferpay Payum plugin providing Ecommerce and Business features
Rich payment solutions for zend framework2. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
统计信息
- 总下载量: 6.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-08