fullpipe/payum-flexidengi

v1.0 2015-06-11 07:31 UTC

This package is auto-updated.

Last update: 2024-11-27 01:37:04 UTC


README

Instalation (with symfony2 payum bundle)

add to your composer json

{
    "require": {
        "payum/payum-bundle": "0.14.*",
        "fullpipe/payum-flexidengi": "dev-master"
    }
}

Add FlexidengiPaymentFactory to payum:

<?php

// src/Acme/PaymentBundle/AcmePaymentBundle.php

namespace Acme\PaymentBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Fullpipe\Payum\Flexidengi\Bridge\Symfony\FlexidengiPaymentFactory;

class AcmePaymentBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $extension = $container->getExtension('payum');
        $extension->addPaymentFactory(new FlexidengiPaymentFactory());
    }
}

Since Flexidengi does not supports callback urls. You will require to implement notifyAction

<?php
// /src/Acme/PaymentBundle/Controller/PaymentController.php

namespace Acme\PaymentBundle\Controller;

use Payum\Bundle\PayumBundle\Controller\PayumController;
use Symfony\Component\HttpFoundation\Request;
use Payum\Core\Request\Notify;
use Payum\Core\Request\GetHumanStatus;
use Fullpipe\Payum\Flexidengi\Api;

class PaymentController extends PayumController
{
    public function notifyAction(Request $request)
    {
        $gateway = $this->getPayum()->getPayment('flexidengi_gateway');
        $payment = $this->getPayum()
            ->getStorage('Acme\PaymentBundle\Entity\Payment')
            ->findBy(array(
                'number' => $request->query->get(Api::ORDER_ID_PARAM_NAME),
            ));

        if ($reply = $gateway->execute(new Notify($payment), true)) {
            if ($reply instanceof HttpResponse) {
                $gateway->execute($status = new GetHumanStatus($payment));

                if ($status->isCaptured()) {
                    // Payment is done
                    // Notify your app here
                }

                throw $reply;
            }

            throw new \LogicException('Unsupported reply', null, $reply);
        }
        return new Response('', 204);
    }
}

and you in routing.yml

acme_payment_notify:
    path:     /payment_notify
    defaults: { _controller: AcmePaymentBundle:Payment:notify }

Configuration (using symfony2 payum bundle)

payum:
    security:
        token_storage:
            Acme\PaymentBundle\Entity\PaymentToken: { doctrine: orm }
    storages:
        Acme\PaymentBundle\Entity\Payment: { doctrine: orm }
    payments:
        ...
        flexidengi_gateway:
            flexidengi:
                service_id: 123
                payment_method_id: 45
                secret: SECRET_KEY
                sandbox: true
        ...

Usage

<?php

namespace Acme\PaymentBundle\Controller;

use Payum\Bundle\PayumBundle\Controller\PayumController;
use Symfony\Component\HttpFoundation\Request;
use Payum\Core\Request\Notify;
use Payum\Core\Request\GetHumanStatus;
use Fullpipe\Payum\Uniteller\Api;

class PaymentController extends PayumController
{
    public function prepareAction()
    {
        $order = ...;
        $user = ...;

        $paymentName = 'flexidengi_gateway';

        $storage = $this->get('payum')
            ->getStorage('Acme\PaymentBundle\Entity\Payment');

        $payment = $storage->create();
        $payment->setNumber($order->getId());
        $payment->setCurrencyCode('RUB');
        $payment->setTotalAmount(14025); // 140 руб, 25 коп.

        $storage->update($payment);

        $captureToken = $this->get('payum.security.token_factory')
            ->createCaptureToken(
                $paymentName,
                $payment,
                'acme_payment_done'
            );

        return $this->redirect($captureToken->getTargetUrl());
    }
}