sinenco/allopasspayment

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

为Symfony提供的Allopass支付

安装: 42

依赖项: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

公开问题: 0

类型:symfony-bundle

1.2 2015-07-08 10:38 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:12:53 UTC


README

(使用 sinenco/allopassapi 包)

Composer中的安装

在composer require中加入:"sinenco/AllopassPayment" : "1.*"

配置

AppKernel

new Sinenco\AllopassPaymentBundle\SinencoAllopassPaymentBundle(),
new Sinenco\AllopassAPIBundle\SinencoAllopassAPIBundle()

参数

AllopassPayment

parameters:
    allopass_payment.site_id: "Your site ID"
    allopass_payment.product_name: "Your Product Name"
    sinenco.allopass_payments.return_route: "Your controller page for return"

当用户使用Allopass支付时,他将被重定向到该页面。带有GET参数:RECALL、data、code、trxid、transaction_id。交易不是通过返回URL检查,而是通过回调URL。

AllopassAPI

parameters:
    allopassAPI.api_key: "your api key"
    allopassAPI.secret_key: "your secret key"

    allopassAPI.default_hash: "sha1"
    allopassAPI.default_format: "xml"
    allopassAPI.network_timeout: "30"
    allopassAPI.network_protocol: "http"
    allopassAPI.network_port: "80"
    allopassAPI.host: "api.allopass.com"

您还可以使用HTTPS和443端口

要添加的服务

services:
    sinenco_allopass_api.init:
        class: Sinenco\AllopassAPIBundle\Model\AllopassApiConf
        arguments: 
            api_key: %allopassAPI.api_key%
            secret_key: %allopassAPI.secret_key%
            default_hash: %allopassAPI.default_hash%
            default_format: %allopassAPI.default_format%
            network_timeout: %allopassAPI.network_timeout%
            network_protocol: %allopassAPI.network_protocol%
            network_port: %allopassAPI.network_port%
            host: %allopassAPI.host%

要添加的路由

sinenco_allopass_payment:
    resource: '@SinencoAllopassPaymentBundle/Resources/config/routing.yml'
    prefix: /

安装和更新

图片

php app/console assets:install

更新价格点

当您设置所有参数时

php app/console allopass:prices:update

如何使用它

转到支付页面

您需要设置数据字段,例如使用发票ID或用户ID

$this->generateUrl(
    "sinenco_allopass_payment_prepare", array(
        'data' => 'your data'
    )
)

此链接将重定向到您服务器上的页面(资源来自此包)

  • 用户选择其国家
  • 然后选择支付方式
  • 然后,他将被重定向到由Allopass API生成的Allopass文档

支付和事件

当支付完成时,您必须通过回调操作处理支付,并通过返回URL重定向您的客户

返回URL

请记住,您在sinenco.allopass_payments.return_route中设置了一个参数

当用户使用Allopass支付时,他将被重定向到该页面。带有GET参数:RECALL、data、code、trxid、transaction_id。交易不是通过返回URL检查,而是通过回调URL,因此您只需向客户显示正确的页面,如发票页面或确认页面。

回调URL

此URL是安全的,用于处理操作。例如,在发票中添加交易。

此URL创建一个交易,并触发一个事件:AllopassPaymentCoreEvents::onAllopassPaymentCallback。该事件是一个AllopassPaymentCallbackEvent对象

事件有isFirstTime()方法,可以知道交易在此支付之前是否存在。事件有getTransaction()方法,可以获取一个Sinenco\AllopassPaymentBundle\Entity\Transaction实体。此实体在触发之前被存储。

因此,您需要创建一个监听器,以下是一个示例

In services.yml

services:
    shop.allopass.listener.callback:
        class: Shop\PaymentBundle\Listeners\AllopassCallbackListener
        arguments: 
            entityManager: "@doctrine.orm.entity_manager"
            container: "@service_container"
        tags:
            - { name: kernel.event_listener, event: "sinenco.allopasspayment.callback", method: onCallbackAllopass }

在Shop\PaymentBundle\Listeners\AllopassCallbackListener中

在我的示例中,我使用发票号设置了数据。

<?php

namespace Shop\PaymentBundle\Listeners;

use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Sinenco\AllopassPaymentBundle\Events\AllopassPaymentCallbackEvent;
use Shop\PaymentBundle\Entity\Invoice;

use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;

class AllopassCallbackListener {

    private $em;
    private $container;

    public function __construct(EntityManager $entityManager, Container $container) {

        $this->em = $entityManager;
        $this->container = $container;
    }

    public function onCallbackAllopass(AllopassPaymentCallbackEvent $event) {
        $repository = $this->em->getRepository("ShopPaymentBundle:Invoice");
        $transaction = $event->getTransaction();

        if ($event->isFirstTime()) {
            $invoice = $repository->find($transaction->getData());

            if ($invoice != null) {
                $payout_amount = $transaction->getPayoutAmount();
                $payout_currency = $transaction->getPayoutCurrency();


                $invoice->addCredit($payout_amount);
                $this->em->persist($invoice);
                $this->em->flush();
            }
        }
    }

}