This bundle allows to implement a Payment Solution working with SystemPay for your symfony projet. This payment solution uses Systempay. Systempay is a payment gateway proposed by the following bank companies :
- Banque Populaire (Cyberplus)
- Caisse d'épargne (SPPlus)
Using composer :
{
"require": {
"baptiste-dulac/systempay-bundle": "master"
}
}
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Tlconseil\SystempayBundle\TlconseilSystempayBundle(),
);
}
Mandatory fields :
tlconseil_systempay:
# Credentials
site_id: XXXXX
# Keys
key_dev: XXXXX
key_prod: XXXXX
# Return
url_return: http://www.example.com/payment_return
Optionnal fields (here the fields have their default values) :
# Debug values : ON / OFF
debug: ON
# Return mode
return_mode: GET
# Possible values for ctx_mode : TEST / PRODUCTION
ctx_mode: TEST
# Language
language: fr
# Success
redirect_success_timeout: 1
redirect_success_message: Redirection vers Les Annonces de la Seine dans quelques instants
# Error
redirect_error_timeout: 1
redirect_error_message: Redirection vers Les Annonces de la Seine dans quelques instants
To intantiate a new Transaction, you need to create an action in one of your controller and call the tlconseil_systempay
serivce. All mandatory fields are used with their default value. You can configure all the common fields of your transactions in the app/config/config.yml
file.
To see what fields are available see : Systempay Documentation (Chapter 2.3.1)
init($currency = 978, $amount = 1000)
allows you to specify the amount and the currency of the transaction.setOptionnalFields(array)
allows you to specify any field for the System Pay Gateway.
/**
* @Route("/initiate-payment/id-{id}", name="pay_online")
* @Template()
*/
public function payOnlineAction($id)
{
// ...
$systempay = $this->get('tlconseil.systempay')
->init()
->setOptionnalFields(array(
'shop_url' => 'http://www.example.com'
))
;
return array(
'paymentUrl' => $systempay->getPaymentUrl(),
'fields' => $systempay->getResponse(),
);
}
This route will be called by the Systempay service to update you about the payment status. This is the only way to correctly handle payment verfication.
responseHandler(Request)
is used to update the transaction status (in database)
/**
* @Route("/payment/verification")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function paymentVerificationAction(Request $request)
{
// ...
$this->get('tlconseil.systempay')
->responseHandler($request)
;
return new Response();
}
This is how the template for the payOnlineAction()
may look like. You can use the systempayForm
twig function to automatically generate the form based on the fields created in the service and returned by the getResponse()
function.
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="widget widget-white text-center">
<i class="fa fa-refresh fa-spin margin-top margin-bottom" style="font-size: 50px"></i>
<h3>Redirection vers la page de paiement en cours...</h3>
<form action="{{ paymentUrl }}" method="POST" id="systempay-form">
{{ systempayForm(fields) | raw }}
</form>
</div>
</div>
</div>
<script type="text/javascript">
document.getElementById('systempay-form').submit();
</script>