sakshram/pangalinks

添加了在爱沙尼亚使用Banklink(Pangalink)转账进行支付的功能

安装: 4

依赖: 0

建议: 0

安全性: 0

星标: 0

关注者: 0

分支: 0

类型:symfony-bundle

3.0.2 2020-09-09 08:17 UTC

This package is auto-updated.

Last update: 2024-09-29 05:42:56 UTC


README

添加了在爱沙尼亚使用Banklink(Pangalink)转账进行支付的功能。
目前只实现了支付逻辑。

支持的银行

  • Swedbank
  • SEB
  • Krediidipank
  • Danske
  • Nordea
  • LHV

安装

  • 在 composer.json 中添加依赖

"require": {
  ...
  "sakshram/pangalink-bundle": "2.*@dev"
  ...
  • 运行 "php composer.phar update"
  • 在 app/AppKernel.php 中注册捆绑

$bundles = array(
  ...
  new TFox\PangalinkBundle\TFoxPangalinkBundle(),
  ...
);

配置

PangalinkBundle 的配置存储在 app/config/config.yml 文件中。以下是一个示例


t_fox_pangalink:
    accounts:
        #First bank
        #ID of the first bank. This ID will be used in system. Feel free to write any ID you wish
        swedbank:
            #Type of bank. Possible arguments: swedbank, seb, krediidipank, sampo, nordea, lhv
            bank: swedbank
            #Service URL. Remove in production mode if real bank's URL is necessary
            service_url: "https://pangalink.net/banklink/swedbank"
            #Vendor's bank account number
            account_number: 123456
            #Vendor's name
            account_owner: "Test"
            #Path to file with user's private key. Relative to "app" directory
            private_key: "data/pangalink/swed_user_key.pem"
            #Path to file with certificate of the bank. Relative to "app" directory
            bank_certificate: "data/pangalink/swed_bank_cert.pem"
            #Vendor's ID given by bank
            vendor_id: "222222"
            #Route of the page displayed if payment was successful
            route_return: "acme_demo_pangalink_swedbank_process"
            #Route of the page displayed if payment was cancelled
            route_cancel: "acme_demo_pangalink_swedbank_index"
            #Alternatives to route_return and route_cancel are:
            #url_return: "http://example.com"
            #url_cancel:  "http://example.com"
        #Second bank
        #ID of the second bank. This ID will be used in system. Feel free to write any ID you wish
        seb:
            bank: seb
            account_number: 1234567
            account_owner: "Test2"
            private_key: "data/pangalink/seb_user_key.pem"
            bank_certificate: "data/pangalink/seb_bank_cert.pem"
            vendor_id: "33333333"
            route_return: "acme_demo_pangalink_sebbank_process"
            route_cancel: "acme_demo_pangalink_sebbank_index"
        #Third bank. Yes, you might have multiple accounts for each bank
        seb_second:
            bank: seb
            account_number: 9876545
            account_owner: "Test3"
            private_key: "data/pangalink/seb_user_key2.pem"
            bank_certificate: "data/pangalink/seb_bank_cert2.pem"
            vendor_id: "33333334"
            route_return: "acme_demo_pangalink_sebbanksecond_process"
            route_cancel: "acme_demo_pangalink_sebbanksecond_index"
        #Nordea uses secret instead of key pair based encryption.
        nordea:
            bank: nordea
            account_owner: "Test4"
            secret: "SomeSecretString"
            vendor_id: "33333334"
            route_return: "acme_demo_pangalink_nordea_process"
            route_reject: "acme_demo_pangalink_nordea_index"
            route_cancel: "acme_demo_pangalink_nordea_index"

使用方法

  • 首先,让我们创建一个动作,以便将支付数据保存

//YourBundle/Controller/SomeController.php

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Sensio;

class SomeController extends BaseController
{

    /**
     * @Sensio\Route
     * @Sensio\Template
     */
    public function indexAction()
    {
        //Amount, payment description and some transaction ID
        $amount = 10.0;
        $description = 'Symfony2 pangalink bundle test';
        $transactionId = mt_rand(0, 999999);
        $transactionId = str_pad($transactionId, 6, '0');

        /* @var $service \TFox\PangalinkBundle\Service\PangalinkService */
        $service = $this->get('tfox.pangalink.service');
         // 'swedbank' is ID of the bank from config.yml
        /* @var $connector \TFox\PangalinkBundle\Connector\SwedbankConnector */		
        $connector = $service->getConnector('swedbank');
        $request = $connector->createPaymentRequest();
        $request
            ->setAmount($amount)
            ->setComment($description)
            ->setTransactionId($transactionId)
            ->setLanguage('EST') //Possible values: EST, ENG, RUS
            // Warning: RUS is not applicable for Nordea
        ;

        // Warning: date is not applicable for Solo protocol (Nordea)
        $request->setDateTime(new \DateTime());
            
        //Optional. Warning: don't forget to make a 7 + 3 + 1 check of reference number,
        //otherwise bank might not accept sended data
        //Further info: http://www.pangaliit.ee/et/arveldused/7-3-1meetod
        //->setReferenceNumber('123456')
        ;

        return array('payment_request' => $request);

    }
}
  • 现在您可以渲染您的表单。您有两种方式来实现。第一种方式允许您设计任何您想要的表单


//YourBundle/Resources/views/Some/index.html.twig

{# 'swedbank' is bank ID which was defined in config.yml  #}
<form method="post" action="{{ pangalink_action_url(payment_request) }}">
{{ pangalink_form_data(payment_request) }}

{# Just an argument from controller  #}

<input type="submit" value="Begin payment">
</form>

  • 第二种方式显示一个图形按钮,如果点击则重定向到银行。这里您可以看到五个不同渲染的按钮


//YourBundle/Resources/views/Some/index.html.twig

{# The first argument is a payment request received from controller. The second argument is a button code. Watch the table below.  #}

{{ pangalink_button(payment_request, '88x31') }}

下表提供了 PangalinkBundle 中可用的图像代码。
警告! 所有图像均为各自所有者(银行)的财产。通常禁止修改提供的图像。

  • 最后任务是处理银行发送的响应。让我们再次查看控制器

//YourBundle/Controller/SomeController.php

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Sensio;

class SomeController extends BaseController
{

    /**
     * @Sensio\Route("/process")
     * @Sensio\Template
     */
    public function processAction(Request $request)
    {
            /* @var $service \TFox\PangalinkBundle\Service\PangalinkService */
            $service = $this->get('tfox.pangalink.service');
            // Get a response from bank. 
            // The bundle automatically determines an appropriate connector
            $paymentResponse = $service->getPaymentResponse($request);

            // If no appropriate connector found, the function "getPaymentResponse" returns null
            if(true == is_null($paymentResponse))
                throw new \Exception('Could not determine a bank operator');

            // Check if payment was successful
            if(true == $paymentResponse->isSuccessful()) {
                // Get some properties 
                $paymentResponse->getBankId();
                $paymentResponse->getOrderNumber();
                $paymentResponse->getTransactionId();
                $paymentResponse->getDateTime();
            }

            // Get ID of the connector defined in the Symfony confiruration
            $accountId = $paymentResponse ? $paymentResponse->getConnector()->getAccountId() : 'NONE';
            // Format status
            $status = $paymentResponse && $paymentResponse->isSuccessful() ? 'YES' : 'NO';

            return array(
                'response' => $paymentResponse,
                'account_id' => $accountId,
                'status' => $status
            );
    }
}