Wallogit.com
2017 © Pedro Peláez
Laravel package for easypay.pt
Laravel Package to work with easypay API, (*1)
Add this to your composer.json file, in the require object:, (*2)
"OrbitPodium/easypay": "dev-master"
After that, run composer install to install the package.
Add the service provider to config/app.php, within the providers array., (*3)
'providers' => array(
// ...
orbitpodium\easypay\EasypayServiceProvider::class,
)
Publish the config file., (*4)
php artisan vendor:publish
After this you might want change config file located at config/easypay.php with your credentials, etc, (*5)
Lastly, run migrate to create easypay_notifications table, (*6)
php artisan migrate
This code will ask easypay for a new reference which can be payed using MB or credit-card, (*7)
$payment_info = [
'o_name' => "Your name",
'o_email' => 'Your email',
't_value' => '29.00',
'o_description' => 'Here is your description',
'o_obs' => 'Here is your observations',
'o_mobile' => 'Here is your mobile',
't_key' => 'Here is the ID of your order'
];
$easypay = new EasyPay($payment_info);
$reference = $easypay->createReference();
if($reference["ep_status"] == "ok0"){
$entidade=$reference["ep_entity"];
$referencia=$reference["ep_reference"];
$valor=$reference["ep_value"];
return view('refMB', ['entidade'=>$entidade, 'referencia'=> $referencia, 'valor' => $valor]);
}
else{
return view('erro');
}
This will return an array with the following :, (*8)
Array ( [ep_status] => ok0 [ep_message] => ep_country and ep_entity and ep_user and ep_cin ok and validation by code;code ok - new reference generated - NEW REFERENCE - [ep_cin] => your CIN [ep_user] => your USER [ep_entity] => your ENTITY [ep_reference] => generated REFERENCE [ep_value] => Asked value [t_key] => Order ID sent [ep_link] => Link to pay using credit-card )
Now you can do what you want with this information, maybe you might want save to database to build user history payments., (*9)
When easypay get his payment they will call the URL that you provided to them which will execute a similiar method like below, for more details see (https://docs.easypay.pt/workflow/payment-notification), (*10)
$easypay = new EasyPay($request->input());
$xml = $easypay->processPaymentInfo();
return \Response::make($xml, '200')->header('Content-Type', 'text/xml');
This block of code will store into database the document number of the payment received from easypay, update with more info sent from them and return xml to easypay. (Step 4 : https://docs.easypay.pt/workflow/payment-notification), (*11)
This will return an array with all of your payments from easypay, (*12)
$easypay = new EasyPay(); $all_payments = $easypay->fetchAllPayments();
and thats it ...., (*13)
Pedro Oliveira, Carlos Neto e Hugo Neto (kanazaca), (*14)