webtopay/webtopay-bundle

该包的最新版本(1.8.0)没有可用的许可证信息。

为WebToPay提供服务的Symfony包

1.8.0 2021-01-07 10:35 UTC

This package is auto-updated.

Last update: 2024-09-07 18:51:34 UTC


README

#WebToPayBundle

##什么是WebToPayBundle? WebToPayBundle是一个小型的bundle,可以作为您的Symfony框架和原始webtopay库之间的桥梁。

我们鼓励您首先查看原始库

##章节

##要求

  • Symfony 2.0+
  • 原始libwebtopay库(可以在这里找到)

##安装

###Symfony 2.1安装(供应商)

  • 执行以下命令
    composer require webtopay/libwebtopay 1.6.*@dev
    composer require webtopay/webtopay-bundle dev-master
  • 在kernel中启用bundle
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //... your existing bundles here
        new Evp\Bundle\WebToPayBundle\EvpWebToPayBundle(),
    );
}
  • 配置您的app/config/config.yml
evp_web_to_pay:    
   credentials:    
       project_id: your_project_id    
       sign_password: your_password    

不要忘记将your_project_idyour_password替换为实际的凭据。

这就完成了,现在您可以开始使用WebToPayBundle了。

##代码示例 ###控制器示例

请查看下面的Symfony 2控制器示例,其中包含每种支付案例和回调验证的方法

namespace Vendor\Bundle\PaymentsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class PayseraPaymentsController extends Controller
{
    /**
     * @Route("/payments/paysera/pay", name="paysera.pay")
     */
    public function redirectToPaymentAction()
    {
        $acceptUrl = $this->generateUrl('paysera.accept');
        $cancelUrl = $this->generateUrl('paysera.cancel');
        $callbackUrl = $this->generateUrl('paysera.callback');

        $url = $this->container->get('evp_web_to_pay.request_builder')->buildRequestUrlFromData(array(
            'orderid' => 0,
            'amount' => 1000,
            'currency' => 'EUR',
            'country' => 'LT',
            'accepturl' => $acceptUrl,
            'cancelurl' => $cancelUrl,
            'callbackurl' => $callbackUrl,
            'test' => 0,
        ));

        return new RedirectResponse($url);
    }

    /**
     * @Route("/payments/paysera/accept", name="paysera.accept")
     */
    public function acceptAction()
    {
        // payment was successful
    }

    /**
     * @Route("/payments/paysera/cancel", name="paysera.cancel")
     */
    public function cancelAction()
    {
        // payment was unsuccessful
    }

    /**
     * @Route("/payments/paysera/callback", name="paysera.callback")
     */
    public function callbackAction()
    {
        try {
            $callbackValidator = $this->get('evp_web_to_pay.callback_validator');
            $data = $callbackValidator->validateAndParseData($this->getRequest()->query->all());
            if ($data['status'] == 1) {
                // Provide your customer with the service

                return new Response('OK');
            }
        } catch (\Exception $e) {
            //handle the callback validation error here

            return new Response($e->getTraceAsString(), 500);
        }
    }
}

请注意测试参数:您可以将它设置为1来进行测试支付,而不实际支付。

##使用沙盒 ###为什么使用我们的沙盒?使用test参数是查看您的project_idsign_password设置是否正确的好方法。它还将允许您在支付被接受后测试用户返回和支付回调到您的应用程序。

然而,在您的应用程序的开发阶段,我们建议您使用我们的沙盒环境。在沙盒环境中,您可以通过与您的客户在真实支付中相同的步骤,而不实际使用任何真实货币。

###在配置中启用沙盒 要在配置中启用沙盒,请将以下行添加到您的app/config/config.yml中

evp_web_to_pay:
   credentials:
       project_id: your_project_id
       sign_password: your_password
   use_sandbox: true

use_sandbox参数可以设置为truefalse

##联系方式 如果您有任何其他问题,请随时联系我们

"EVP International", UAB
Mėnulio g. 7
LT-04326 Vilnius
电子邮箱:pagalba@mokejimai.lt
电话:+370 (5) 2 03 27 19
传真:+370 (5) 2 63 91 79