PHPackages                             limetools/swedbank\_laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. limetools/swedbank\_laravel

ActiveLibrary[API Development](/categories/api)

limetools/swedbank\_laravel
===========================

Laravel package for Swedbank Payment Initiation API V3 integration

v1.0.3(4mo ago)014MITPHPPHP ^8.1

Since Dec 15Pushed 4mo agoCompare

[ Source](https://github.com/LimeTools/swedbank_laravel)[ Packagist](https://packagist.org/packages/limetools/swedbank_laravel)[ Docs](https://github.com/LimeTools/swedbank_laravel)[ RSS](/packages/limetools-swedbank-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

Swedbank Laravel Payment API
============================

[](#swedbank-laravel-payment-api)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://www.php.net/)[![GitHub](https://camo.githubusercontent.com/f3f33fc0dc8dea6fe99a9d712003a0bf40a9596ca8422c4b52068314916cfc01/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4c696d65546f6f6c732f7377656462616e6b5f6c61726176656c3f696e636c7564655f70726572656c6561736573)](https://github.com/LimeTools/swedbank_laravel)

A Laravel package for integrating with Swedbank Payment Initiation API V3. This package provides a clean and easy-to-use interface for initiating payments, checking payment status, and retrieving payment providers using Swedbank's Payment Initiation API.

Features
--------

[](#features)

- ✅ **Swedbank Payment Initiation API V3** support
- ✅ **JWS (JSON Web Signature)** authentication
- ✅ **Sandbox and Production** environments
- ✅ **Payment Provider** management
- ✅ **Payment Status** checking
- ✅ **Comprehensive logging** support
- ✅ **Laravel 9, 10, and 11** compatible

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9.0
- OpenSSL extension (for JWS signing)

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

You can install the package via Composer:

```
composer require limetools/swedbank_laravel
```

### Publish Configuration

[](#publish-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=swedbank-config
```

This will create a `config/swedbank.php` file in your Laravel application.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add the following environment variables to your `.env` file:

```
# Environment (sandbox or production)
SWEDBANK_ENVIRONMENT=production

# Sandbox credentials
SWEDBANK_SANDBOX_ENABLED=false
SWEDBANK_SANDBOX_CLIENT_ID=your_sandbox_client_id
SWEDBANK_SANDBOX_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"

# Production credentials
SWEDBANK_PRODUCTION_ENABLED=true
SWEDBANK_PRODUCTION_CLIENT_ID=your_production_client_id
SWEDBANK_PRODUCTION_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"

# Optional: Logging configuration
SWEDBANK_LOGGING_ENABLED=true
SWEDBANK_LOG_LEVEL=info
SWEDBANK_LOG_CHANNEL=swedbank
```

**Important:** When storing the private key in `.env`, make sure to:

- Wrap it in double quotes
- Use `\n` for newlines
- Keep the entire key on a single line

Example:

```
SWEDBANK_PRODUCTION_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC...\n-----END PRIVATE KEY-----"
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

The package provides a `SwedbankPaymentApi` class that can be used in several ways:

#### Using Dependency Injection

[](#using-dependency-injection)

```
use LimeTools\Swedbank\SwedbankPaymentApi;

class PaymentController extends Controller
{
    public function __construct(
        protected SwedbankPaymentApi $swedbankApi
    ) {}
}
```

#### Using the Facade

[](#using-the-facade)

```
use LimeTools\Swedbank\Facades\SwedbankPayment;

class PaymentController extends Controller
{
    public function initiatePayment()
    {
        $providers = SwedbankPayment::getPaymentProviders(
            'LT',
            config('swedbank.production.client_id'),
            config('swedbank.production.private_key')
        );
    }
}
```

#### Using the Service Container

[](#using-the-service-container)

```
$swedbankApi = app(LimeTools\Swedbank\SwedbankPaymentApi::class);
```

Step-by-step integration guide
------------------------------

[](#step-by-step-integration-guide)

This is a minimal, end-to-end example to get you from a fresh Laravel install to a working Swedbank payment redirect.

### 1. Install the package

[](#1-install-the-package)

#### a) From GitHub (recommended now)

[](#a-from-github-recommended-now)

In your application `composer.json`:

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/LimeTools/swedbank_laravel"
        }
    ],
    "require": {
        "limetools/swedbank_laravel": "dev-main"
    }
}
```

Then install:

```
composer require limetools/swedbank_laravel:dev-main
```

### 2. Publish and configure

[](#2-publish-and-configure)

Publish the config file:

```
php artisan vendor:publish --tag=swedbank-config
```

This creates `config/swedbank.php`.

Add environment variables to `.env` (start with sandbox):

```
SWEDBANK_ENVIRONMENT=sandbox

SWEDBANK_SANDBOX_ENABLED=true
SWEDBANK_SANDBOX_CLIENT_ID=your_sandbox_client_id
SWEDBANK_SANDBOX_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"

SWEDBANK_PRODUCTION_ENABLED=false

SWEDBANK_LOGGING_ENABLED=true
SWEDBANK_LOG_LEVEL=info
SWEDBANK_LOG_CHANNEL=swedbank
```

Optionally, configure a log channel in `config/logging.php`:

```
'channels' => [
    // ...
    'swedbank' => [
        'driver' => 'daily',
        'path' => storage_path('logs/swedbank.log'),
        'level' => env('SWEDBANK_LOG_LEVEL', 'info'),
        'days' => 14,
    ],
],
```

### 3. Create routes

[](#3-create-routes)

In `routes/web.php`:

```
use App\Http\Controllers\SwedbankPaymentController;

Route::get('/pay/{order}', [SwedbankPaymentController::class, 'start'])->name('swedbank.pay');
Route::get('/pay/{order}/callback', [SwedbankPaymentController::class, 'callback'])->name('swedbank.callback');
```

### 4. Create a simple controller

[](#4-create-a-simple-controller)

Create `app/Http/Controllers/SwedbankPaymentController.php`:

```
