Butik
Search…
Payment Gateway
In case you want to implement your own Payment Gateway.

Create a new gateway

Use our command to create a gateway boilerplate.
1
php please butik:gateway NewGatewayName
Copied!
This will give you the following boilerplate.
1
<?php
2
3
namespace DummyNamespace;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Collection;
7
use Jonassiewertsen\StatamicButik\Checkout\Customer;
8
use Jonassiewertsen\StatamicButik\Http\Controllers\PaymentGateways\PaymentGateway;
9
use Jonassiewertsen\StatamicButik\Http\Controllers\PaymentGateways\PaymentGatewayInterface;
10
use Jonassiewertsen\StatamicButik\Http\Traits\MoneyTrait;
11
12
class DummyClass extends PaymentGateway implements PaymentGatewayInterface
13
{
14
use MoneyTrait;
15
16
/**
17
* We want to handle the payment process.
18
*
19
* You'll find one example here:
20
* Jonassiewertsen\StatamicButik\Http\Controllers\PaymentGateways\MolliePaymentGateway.php line 26
21
*/
22
public function handle(Customer $customer, Collection $items, string $totalPrice, Collection $shippings)
23
{
24
$orderNumber = $this->createOrderNumber();
25
26
// handle the payment
27
28
// Shall we create the order for you?
29
$this->createOrder(
30
$payment->id,
31
$items,
32
$orderNumber,
33
$customer,
34
$totalPrice,
35
$payment->method,
36
$shippings,
37
);
38
39
// What to do after the payment has been handled?
40
}
41
42
/**
43
* If you want, you can use webhooks. This is optional and can be left empty.
44
*
45
* You'll find one example here:
46
* Jonassiewertsen\StatamicButik\Http\Controllers\PaymentGateways\MolliePaymentGateway.php line 53
47
*/
48
public function webhook(Request $request): void
49
{
50
// Do nothing.
51
}
52
}
Copied!

Use your own payment gateway

Swap the payment gateway class in your config file to use your own gateway.

Webhooks

You can use webhooks if you want.
With our Mollie integration, our webhook does look like this. Maybe you'll find some inspiration:
1
public function webhook(Request $request): void
2
{
3
if (! $request->has('id')) {
4
return;
5
}
6
7
$payment = Mollie::api()->orders()->get($request->id);
8
9
$order = $this->findOrder($payment->id);
10
11
switch ($payment->status) {
12
case 'paid':
13
$this->isPaid($order, Carbon::parse($payment->paidAt), $payment->method);
14
break;
15
case 'authorized':
16
$this->isAuthorized($order, Carbon::parse($payment->authorizedAt), $payment->method);
17
break;
18
case 'completed':
19
$this->isCompleted($order, Carbon::parse($payment->completedAt), $payment->method);
20
break;
21
case 'expired':
22
$this->isExpired($order, Carbon::parse($payment->expiredAt));
23
break;
24
case 'canceled':
25
$this->isCanceled($order, Carbon::parse($payment->canceledAt));
26
break;
27
}
28
}
Copied!
Methods like $this->isPaid() will be provided for you, but you don't need to use them.
Last modified 6mo ago