The library provides an easy and fast Payzen form creation. This helps to instanciate all required parameters and create the form to access to payment interface. To know required parameters, go to https://payzen.io/en-EN/form-payment/quick-start-guide/sending-a-payment-form-via-post.html
First you need to add the component to your composer.json
composer require noweh/laravel-payzen
Update your packages with composer update or install with composer install.
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
Noweh\Payzen\PayzenServiceProvider::class,
To use the facade, add this in app.php:
'Payzen' => Noweh\Payzen\PayzenFacade::class,
After updating composer, add the ServiceProvider to the providers array in config/app.php
Next, you must migrate config :
php artisan vendor:publish --provider="Noweh\Payzen\PayzenServiceProvider"
Now we are finally ready to use the package! Here is a little example:
$blocks_html = \Payzen::set_amount(300)
->set_trans_id(123456)
->set_order_info(\Payzen::ascii_transcode('an information', 'an', 255, true))
->set_order_info2(\Payzen::ascii_transcode('another information', 'an', 255, true))
->set_url_return(request()->fullUrl())
->set_return_mode('POST')
->set_signature()
->get_form('<div><input id="spSubmit" type="submit" value="Pay" class="Button Button--black"></div>')
;
$payzen = \Payzen::set_params(\Arr::where(request()->all(), function($value, $key) {
return strrpos($key, 'vads_', -5) !== false;
}))
->set_signature()
;
return (request()->input('signature') && ($payzen::get_signature() === request()->input('signature')));
;
Add a product to the order
array $product , must have the following keys : 'label,amount,type,ref,qty
\Payzen::add_product(
[
'label' => 'Concert Coldplay 2016',
'amount' => 235.00,
'type' => 'ENTERTAINMENT',
'ref' => 'COLD016',
'qty' => 3
]
);
Note : the amount of each products price must not be multiplied by 100
Defines the total amount of the order. If you doesn't give the amount in parameter, it will be automaticly calculated by the sum of products you've got in your basket.
[optional] int $amount, Payzen format. ex : for a product with a price of 150€, give 15000
$payzen = \Payzen::add_product(
[
'label' => 'Concert Coldplay 2016',
'amount' => 235.00,
'type' => 'ENTERTAINMENT',
'ref' => 'COLD016',
'qty' => 3
]
);
$payzen->set_amount();
echo $payzen->get_amount(); //will display 705.00 (3*235.00)
Get total amount of the order
[optional] bool $decimal if true, you get a decimal otherwise you get standard Payzen amount format (int). Default value is true.
$payzen = \Payzen::add_product(
[
'label' => 'Concert Coldplay 2016',
'amount' => 235.00,
'type' => 'ENTERTAINMENT',
'ref' => 'COLD016',
'qty' => 3
]
);
$payzen->set_amount();
echo $payzen->get_amount(); //will display 705.00 (3*235.00)
echo $payzen->get_amount(false); //will display 70500 (3*235.00)
Method to do massive assignement of parameters
array $params associative array of Payzen parameters
\Payzen::set_params(
[
'vads_page_action' => 'PAYMENT',
'vads_action_mode' => 'INTERACTIVE',
'vads_payment_config' => 'SINGLE',
'vads_version' => 'V2',
'vads_trans_date' => gmdate('YmdHis'),
'vads_currency' => '978'
]
);
Method to convert an input in a compatible for Payzen
string $input, text to convert
string $allow, n|a|an|ans
int $length 1..255
boolean $truncate allow returning truncated result if the transcoded $input length is over $length
\Payzen::ascii_transcode('123nd', 'n', 5, true);
Checking Payzen response signature
\Payzen::isResponseSignatureValid();