Payplug integration to symfony2.
{
"require": {
"alcalyn/payplug-bundle": "1.x"
}
}
Update your composer.
php composer.phar update
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Alcalyn\PayplugBundle\AlcalynPayplugBundle(),
);
}
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: /
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.
<?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=..."
}
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 }
- Use TEST mode
- Extend IPN class
- Listen to malformed IPN
- Generate payment Url from command
- Simulate an IPN from command
This bundle is under the MIT license. See the complete license: