PHP code example of code16 / laravel-systempay

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/ */

    

code16 / laravel-systempay example snippets


return [
    'default' => [
        'site_id' => 'YOUR_SITE_ID',
        'key'     => env('SYSTEMPAY_SITE_KEY', 'YOUR_KEY'),
        'env'     => env('SYSTEMPAY_ENV', 'PRODUCTION'),

        'rest' => [
            // Only 

return [
    'default' => [
        // ...
        'params'  => [
            'currency' => '826'
        ]
    ]
];

return [
    'default' => [
       // ...
    ],
    'store_uk' => [
        'site_id' => '123456',
        'key'     => env('SYSTEMPAY_UK_SITE_KEY', '12345678'),
        'env'     => env('SYSTEMPAY_UK_ENV', 'PRODUCTION'),   
    ]
];
 
$systemPay = SystemPay::config('store_uk')->set([
    'amount' => 1234, // 12.34€, in cents
    'trans_id' => 123456
]);

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']);
    }
}

SystemPay::formatWebhookPayload($request, 'store_uk')->validateSignature();

$payload->isValidPayment(['CAPTURED']);

 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');

use Code16\Systempay\Exceptions\SystempayApiException;

try {
    SystemPay::refund($uuid);
} catch (SystempayApiException $e) {
    logger()->error($e->getMessage(), $e->response());
}

SystemPay::cancelOrRefund($uuid, amount: 1000, currency: 'EUR', resolutionMode: 'REFUND_ONLY');

SystemPay::refund($uuid, config: 'store_uk');

$transaction = SystemPay::getTransaction($uuid);

$transaction['status']; // e.g. "CAPTURED"
$transaction['amount']; // in the smallest currency unit (e.g. cents for EUR)

SystemPay::getTransaction($uuid, 'store_uk');

php artisan vendor:publish --tag="systempay-config"