ibrows/saferpay-bundle

A simple saferpay implementation

Installs: 41

Dependents: 0

Suggesters: 0

Stars: 1

Watchers: 11

Forks: 0

Open Issues: 0

Type:symfony-bundle

dev-master 2012-09-06 07:58 UTC

README

a simple inofficial implementation of the saferpay payment service as a symfony bundle

installation

composer.json

{
    "require": {
        "ibrows/saferpay-bundle": "master"
    }
}

app/AppKernel.php

new Ibrows\Bundle\SaferpayBundle\IbrowsSaferpayBundle(),

app/config/config.yml

ibrows_saferpay:
  parameters:
    ACCOUNTID: 99867-xxxxxxxx

usage

try
{
    // get saferpay service
    $objSaferpay = $this->container->get('ibrows_saferpay');
    /** @var \Ibrows\Bundle\SaferpayBundle\Util\Saferpay $objSaferpay */

    // restore session information
    $objSaferpay->setSessionInformation($this->container->get('session')->get('ibrows_saferpay', serialize(array())));

    // get status
    switch($this->container->get('request')->query->get('status'))
    {
        case 'success':

            // confirm payment
            if($objSaferpay->verfifyPayConfirm(
                $this->container->get('request')->query->get('DATA'),
                $this->container->get('request')->query->get('SIGNATURE')
            ))
            {
                // complete payment
                if($objSaferpay->createPayComplete())
                {
                    // reset session data
                    $this->container->get('session')->remove('ibrows.saferpay');

                    // redirect
                    return new RedirectResponse(
                        'http://<nextstep>.<com>',
                        302
                    );
                }
            }
            break;
        default:

            // get saferpay url
            $strToCallUrl = $objSaferpay->createPayInit(
                array(
                    'AMOUNT' => 10250,
                    'DESCRIPTION' => sprintf('Bestellnummer %s', '000001'),
                    'ORDERID' => '000001',
                    'SUCCESSLINK' => 'http://<thisstep>.<com>?status=success',
                    'FAILLINK' => 'http://<thisstep>.<com>?status=fail',
                    'BACKLINK' => 'http://<thisstep>.<com>',
                )
            );

            // store data in session
            $this->container->get('session')->set('ibrows_saferpay', $objSaferpay->getSessionInformation());

            // return redirect response
            return new RedirectResponse($strToCallUrl, 302);
    }
}
catch(\Exception $e)
{
    echo $e->getMessage();
}