1. Go to this page and download the library: Download code16/laravel-systempay library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use SystemPay;
class PaymentCallbackController extends Controller
{
public function __invoke(Request $request)
{
// 1. Retrieve the webhook data
$payload = SystemPay::formatWebhookPayload($request);
// 2. Validate the signature
if (! $payload->validateSignature()) {
abort(403, 'Invalid signature');
}
// 3. Check if the payment is valid (status is ACCEPTED, CAPTURED, or AUTHORISED)
if (! $payload->isValidPayment()) {
// Payment refused or cancelled
abort(400, 'Invalid payment');
}
// 4. Verify the paid amount and currency
abort_unless(Order::find($payload->orderId)->amount == $payload->amount, 400, 'Invalid amount');
// Update your database...
return response()->json(['status' => 'ok']);
}
}
namespace App\Http\Controllers;
use SystemPay; // Facade
class PaymentController extends Controller
{
public function create()
{
$systemPay = SystemPay::set([
'amount' => 1234, // 12.34€, in cents
'trans_id' => 123456
]);
return view('payment', compact('systemPay'));
}
}
use SystemPay;
// Cancel a transaction, with an optional comment
SystemPay::cancel($uuid, 'Order cancelled by customer');
// Refund a transaction in full
SystemPay::refund($uuid);
// Refund a transaction partially: amount in the smallest currency unit (e.g. cents for EUR)
SystemPay::refund($uuid, amount: 1000, currency: 'EUR');
$transaction = SystemPay::getTransaction($uuid);
$transaction['status']; // e.g. "CAPTURED"
$transaction['amount']; // in the smallest currency unit (e.g. cents for EUR)