alcalyn/payplug-bundle

Payplug integration to symfony2

Installs: 691

Dependents: 0

Suggesters: 0

Security: 0

Stars: 7

Watchers: 5

Forks: 6

Open Issues: 0

Type:symfony-bundle

v1.2.5 2015-12-09 21:44 UTC

README

Payplug integration to symfony2.

Latest Stable Version Scrutinizer Code Quality SensioLabsInsight Build Status License

Installation

Step 1: Download using composer

{
    "require": {
        "alcalyn/payplug-bundle": "1.x"
    }
}

Update your composer.

php composer.phar update

Step 2: Register the Bundle

<?php
// app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Alcalyn\PayplugBundle\AlcalynPayplugBundle(),
        );
    }

Step 3: Import Payplug IPN route

To create payments and process IPNs, the bundle need to have its routes enabled.

Add this to app/config/routing.yml:

# Payplug routing
alcalyn_payplug:
    resource: "@AlcalynPayplugBundle/Resources/config/routing.yml"
    prefix:   /

Step 4: Configure the bundle and your account settings

Add these lines to your config.yml:

# Payplug configuration
alcalyn_payplug:
    account:
        url:                %payplug_account_url%
        amount_min:         %payplug_account_amount_min%
        amount_max:         %payplug_account_amount_max%
        currencies:         %payplug_account_currencies%
        payplugPublicKey:   %payplug_account_payplugPublicKey%
        yourPrivateKey:     %payplug_account_yourPrivateKey%

And these lines into parameters.yml, and optionally into parameters.yml.dist:

    payplug_account_url:                ~
    payplug_account_amount_min:         ~
    payplug_account_amount_max:         ~
    payplug_account_currencies:         ~
    payplug_account_payplugPublicKey:   ~
    payplug_account_yourPrivateKey:     ~

Then run this command to load your Payplug account settings:

php app/console payplug:account:update

(Your Payplug email and password will be prompted)

Warning:

Be sure to never commit your account settings by commiting your parameters.yml

See Payplug documentation for more informations about account configuration.

Note:

This command uses curl to load your account parameters from https://www.payplug.fr/portal/ecommerce/autoconfig

If the command fails, go to https://www.payplug.fr/portal/ecommerce/autoconfig and copy/paste your parameters manually.

Your parameters.yml should looks like this: parameters.yml.example

You can also configure your TEST mode.

Basic usage:

Generating payment url:

<?php
use Alcalyn\PayplugBundle\Model\Payment;

// ...

    public function wtfAction()
    {
        // Create a payment of 16 €
        $payment = new Payment(1600, Payment::EUROS);

        // Get Payplug payment service
        $payplugPayment = $this->get('payplug.payment');

        // Generate url
        $payplugPayment->generateUrl($payment); // returns "https://www.payplug.fr/p/aca8...ef?data=...&sign=..."
    }

Treat IPNs

AlcalynPayplugBundle dispatches PayplugIPNEvent when an IPN is received.

This event contains an instance of IPN that you can access by calling PayplugIPNEvent::getIPN().

So listen it like that:

  • Create the listener class:
<?php
// src/Acme/AcmeBundle/EventListener/PaymentListener.php

namespace Acme\AcmeBundle\EventListener;

use Alcalyn\PayplugBundle\Event\PayplugIPNEvent;

class PaymentListener
{
    /**
     * @param PayplugIPNEvent $event
     */
    public function onPayment(PayplugIPNEvent $event)
    {
        $ipn = $event->getIPN();

        // treat $ipn
    }
}
  • Register your listener:
# src/Acme/AcmeBundle/Resources/services.yml
services:
    acme.listeners.payment:
        class: Acme\AcmeBundle\EventListener\PaymentListener
        tags:
            - { name: kernel.event_listener, event: event.payplug.ipn, method: onPayment }

Advanced usage:

License

This bundle is under the MIT license. See the complete license:

Resources/meta/LICENSE