ttrig/laravel-billmate is a Laravel package for laravel package for working with billmate api.
It currently has 1 GitHub stars and 247 downloads on Packagist (latest version v3.0.0).
Install it with composer require ttrig/laravel-billmate.
Discover more Laravel packages by ttrig
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package for interacting with Billmate API.
composer require ttrig/laravel-billmate
Publish the configuration file using this command:
php artisan vendor:publish --provider="Ttrig\Billmate\ServiceProvider"
Add a Billmate ID and key in .env.
BILLMATE_ID=123
BILLMATE_KEY=abc
BILLMATE_TEST=true
Update config/billmate.php to use your own controller(s).
'accept_action' => 'App\Http\Controllers\BillmateController@accept',
'cancel_action' => 'App\Http\Controllers\BillmateController@cancel',
'callback_action' => \Ttrig\Billmate\Controllers\CallbackController::class,
use Ttrig\Billmate\Article as BillmateArticle;
use Ttrig\Billmate\Service as BillmateService;
class CheckoutController extends Controller
{
public function index(BillmateService $billmate)
{
$articles = collect()->push(new BillmateArticle([
'title' => '1kg potatoes',
'price' => 30,
]));
$checkout = $billmate->initCheckout($articles);
return view('checkout', compact('checkout'));
}
}
You can view or update the data to be sent to Billmate by passing a callback
as second argument to initCheckout.
$billmate->initCheckout($articles, function (&$data) {
data_set($data, 'PaymentData.autoactivate', '1');
});
To render the Billmate Checkout iframe you can use $checkout->iframe() in
your blade template or write your own iframe and pass $checkout->url to its src
attribute.
To update height of the Checkout when it updates, we need this JavaScript.
window.addEventListener('message', function (event) {
if (event.origin !== 'https://checkout.billmate.se') {
return
}
try {
var json = JSON.parse(event.data)
} catch (e) {
return
}
if (json.event === 'content_height') {
$('#checkout').height(json.data)
}
})
You need your own controller(s) for handling the accept and cancel redirections.
use Ttrig\Billmate\Order as BillmateOrder;
use Ttrig\Billmate\Service as BillmateService;
class YourRedirectController extends Controller
{
public function accept(BillmateService $billmate)
{
$order = new BillmateOrder(request()->data);
$paymentInfo = $billmate->getPaymentInfo($order);
return view('payment.accept');
}
public function cancel()
{
return view('payment.cancel');
}
}
If you use Ttrig\Billmate\Controllers\CallbackController::class as your
"callback_action" in config/billmate.php, you need to listen to the
Ttrig\Billmate\Events\OrderCreated event in your EventServiceProvider
to handle the order.
protected $listen = [
\Ttrig\Billmate\Events\OrderCreated::class => [
\App\Listeners\DoSomething::class,
],
];
Read more about events at https://laravel.com/docs/8.x/events.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b amazing-feature)git commit -m 'Add some amazing feature)git push origin amazing-feature)laravel-billmate is open-sourced software licensed under the MIT license.