digital-link/saferpay
Laravel package for integrating Saferpay payments: create and manage transactions, handle redirects and callbacks, and verify payment status. Provides a clean PHP API to connect your app to Saferpay’s gateway with configurable credentials and endpoints.
Installation
composer require digital-link/saferpay
Add the service provider to config/app.php under providers:
DigitalLink\Saferpay\SaferpayServiceProvider::class,
Configuration Publish the config file:
php artisan vendor:publish --provider="DigitalLink\Saferpay\SaferpayServiceProvider"
Update .env with your Saferpay credentials:
SAFERPAY_MERCHANT_ID=your_merchant_id
SAFERPAY_SECRET_KEY=your_secret_key
SAFERPAY_BASE_URL=https://saferpay-test.saferpay.com/api/v1/
First Use Case: Payment Initialization
use DigitalLink\Saferpay\Facades\Saferpay;
$payment = Saferpay::payment()
->setAmount(1000) // Amount in cents
->setCurrency('EUR')
->setDescription('Test Payment')
->setNotificationUrl(route('saferpay.notification'))
->setSuccessUrl(route('checkout.success'))
->setFailureUrl(route('checkout.failure'))
->create();
return redirect()->to($payment->getRedirectUrl());
Payment Processing
Saferpay::payment()->authorize() for pre-authorizations.Saferpay::payment()->capture().Saferpay::payment()->refund().Webhook Handling Create a route to handle notifications:
Route::post('/saferpay/notification', [SaferpayController::class, 'handleNotification']);
Validate and process notifications in the controller:
public function handleNotification(Request $request)
{
$notification = Saferpay::notification()->validate($request->all());
// Process based on $notification->getType()
}
Recurring Payments Set up subscriptions:
$subscription = Saferpay::subscription()
->setCustomerId($customerId)
->setAmount(500)
->setCurrency('EUR')
->setInterval('monthly')
->create();
$user->newSubscription('default', $plan)->create('saferpay_'.$paymentId);
config/saferpay.php:
'debug' => env('SAFERPAY_DEBUG', false),
SAFERPAY_BASE_URL=https://saferpay-test.saferpay.com/api/v1/).Amount Handling
10.00 EUR → 1000 (not 10).Notification Validation
Saferpay::notification()->validate().Idempotency
Idempotency-Key header for critical operations (e.g., refunds) to avoid duplicate processing:
Saferpay::payment()->refund($paymentId, [], ['Idempotency-Key' => 'unique_key']);
Redirect URLs
successUrl, failureUrl, and notificationUrl are absolute URLs (include https://).'debug' => true in config/saferpay.php to log raw API responses.4xx/5xx errors. Inspect the response body for details:
try {
$response = Saferpay::payment()->create();
} catch (\DigitalLink\Saferpay\Exceptions\SaferpayException $e) {
\Log::error($e->getResponseBody());
}
Custom Request Headers Add headers globally via the config:
'headers' => [
'X-Custom-Header' => 'value',
],
Or per request:
Saferpay::payment()->create([], ['X-Custom-Header' => 'value']);
Override API Client Bind a custom HTTP client (e.g., Guzzle with middleware):
Saferpay::setClient(app()->makeWith(GuzzleHttp\Client::class));
Extend Models Create a custom model to extend functionality:
class CustomPayment extends \DigitalLink\Saferpay\Models\Payment
{
public function customMethod()
{
// Add logic here
}
}
Bind it in a service provider:
Saferpay::extend('payment', function () {
return new CustomPayment();
});
How can I help you explore Laravel packages today?