hakito / cakephp-stuzza-eps-banktransfer-plugin

CakePHP EPS 银行转账支付插件

v5.0 2024-01-04 20:22 UTC

This package is auto-updated.

Last update: 2024-09-04 21:48:31 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

CakePHP-EpsBankTransfer-Plugin

CakePHP 4.x 插件

安装

使用 composer

如果您正在使用 composer,只需使用以下命令添加插件

composer require hakito/cakephp-stuzza-eps-banktransfer-plugin

不使用 composer

将插件下载到 app/Plugin/EpsBankTransfer。同时下载 https://github.com/hakito/PHP-Stuzza-EPS-BankTransfer 并将 PSR-4 兼容的自动加载器添加到您的 bootstrap 中。

加载插件

在您的 bootstrap 中加载插件

public function bootstrap()
{
    // Call parent to load bootstrap from files.
    parent::bootstrap();

    $this->addPlugin(\EpsBankTransfer\Plugin::class, ['routes' => true]);
}

配置

在您的 app.local.php 中为 EpsBankTransfer 添加一个条目

[
    'EpsBankTransfer',
    [
        // required parameters
        'userid' => 'AKLJS231534',           // Eps "Händler" id
        'secret' => 'topSecret',             // Secret for authentication
        'iban' => 'AT611904300234573201',    // IBAN code of bank account where money will be sent to
        'bic' => 'GAWIATW1XXX',              // BIC code of bank account where money will be sent to
        'account_owner' => 'John Q. Public', // Name of the account owner where money will be sent to

        // Encryption key for sending encrypted remittance identifier as encrypted string
        'encryptionKey' => 'A_SECRET_KEY_MUST_BE_32_BYTES_LONG',

        //// optional parameters
        //'ObscuritySuffixLength' => 8,             // Number of hash chars appended to remittance identifier
        //'ObscuritySeed'  => 'SOME RANDOM STRING', // Seed for the random remittance identifier suffix. REQUIRED when ObscuritySuffixLength > 0 provided
        //'TestMode' => true                        // Use EPS test mode URL endpoint
    ]
];

日志

如果您想收集日志流,请将此条目添加到 app_local.php 中的日志配置中

    'Log' =>
    [
        'eps' =>
        [
            'className' => FileLog::class,
            'path' => LOGS,
            'file' => 'eps',
            'scopes' => ['EpsBankTransfer'],
            'levels' => ['warning', 'error', 'critical', 'alert', 'emergency', 'info', 'debug'],
        ],
    ]

使用方法

在您的支付处理控制器中

    // Load the component
    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('EpsBankTransfer.Eps');
    }

    // Sample checkout
    private function _checkoutEPS($orderId)
    {
        // Add all articles
        $this->Eps->AddArticle('Magic dragon', $quantity, $priceInCents);

        // You might also want to add shipping agio as article
        $this->Eps->AddArticle('Shipping agio', 1, $shippingAgioInCents);

        // remittanceIdentifier could be your shopping card id
        // okUrl is the return url if payment is successful
        // nOkUrl is the return url if payment failed / canceled
        // BIC of the bank from GetBanksArray
        $this->Eps->PaymentRedirect($remittanceIdentifier, $okUrl, $nOkUrl, $bic);
    }

事件处理器

您必须实现以下事件处理器中的至少一个

EpsBankTransfer.VitalityCheck

\Cake\Event\EventManager::instance()->on('EpsBankTransfer.VitalityCheck',
function ($event, $args)
{
  // $args =
  // [
  //   'raw' => {string},                  // Raw XML content
  //   'vitalityCheckDetails' => {object}, // Instance of at\externet\eps_bank_transfer\VitalityCheckDetails
  // ]

  return ['handled' => true]; // You have to set this otherwise the EPS call is not successful
});

EpsBankTransfer.Confirmation', $this

\Cake\Event\EventManager::instance()->on('EpsBankTransfer.Confirmation',
function ($event, $args)
{
  // $args =
  // [
  //   'raw' => {string},                     // Raw XML content
  //   'bankConfirmationDetails' => {object}, // Instance of at\externet\eps_bank_transfer\BankConfirmationDetails
  // ]

  return ['handled' => true]; // You have to set this otherwise the EPS call is not successful
});