PHPackages                             spatie/payment - 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. [Payment Processing](/categories/payments)
4. /
5. spatie/payment

AbandonedArchivedLibrary[Payment Processing](/categories/payments)

spatie/payment
==============

A Laravel 5 package to verify and accept payments from payment gateways

2.0.2(10y ago)12380642MITPHPPHP ^5.6|^7.0

Since Aug 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/spatie/payment)[ Packagist](https://packagist.org/packages/spatie/payment)[ Docs](https://github.com/spatie/payment)[ RSS](/packages/spatie-payment/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (0)

**THIS PACKAGE IS NOT MAINTAINED ANYMORE**

Accept payments from payment gateways
=====================================

[](#accept-payments-from-payment-gateways)

[![Latest Version](https://camo.githubusercontent.com/a468e6cc3878af8187015916486f89c3524f8783cb805ccdbd7c67bce623051d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7370617469652f7061796d656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/spatie/payment/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/99c66bca89f646d2df0dcf1df37c80e4ac1f7f1c8120fa7752e9d80f7956a62f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7061796d656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/payment)

This Laravel package enables you to accept payments from payment gateways. Currently the only implementation is [Europabank](https://www.europabank.be/ecommerce-professioneel).

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

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

[](#installation)

The package can be installed through Composer:

```
composer require spatie/payment

```

This service provider must be installed:

```
//for laravel  [
    ...
    'Spatie\Payment\PaymentServiceProvider'
    ...
];
```

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

[](#configuration)

You can publish the configuration file using this command:

```
php artisan config:publish spatie/payment

```

A configuration-file with some sensible defaults will be placed in your config/packages directory:

```
return
    [
        'form' =>
            [
                /*
                 * The class or classes that you want to put on the submit button
                 * of the payment form
                 */
                'submitButtonClass' => 'test'
            ],

        'europabank' =>
            [
                'clientSecret' => getenv('EUROPABANK_CLIENT_SECRET'),
                'serverSecret' => getenv('EUROPABANK_SERVER_SECRET'),

                /*
                 * MPI Account number
                 */
                'uid' => getenv('EUROPABANK_UID'),

                /*
                 * The url to where the payment will take place
                 */
                'mpiUrl' => '',

                /*
                 * The name of the route where Europabank will redirect to
                 * after the payment has been made
                 *
                 */
                'paymentLandingPageRoute' => 'verifyPayment',

                /*
                 * Optional url of the css which must be applied on the payment form
                 */
                'formCss'=> '',

                /*
                 * Url of the template which will be applied on  Europabank pages
                 */
                'template'=> '',

                /*
                 * Optional title of the payment form
                 */
                'formTitle' => '',

                /*
                 * Optional e-mail address of the merchant
                 */
                'merchantEmail' => '',

                /*
                 * Optional e-mail address to use as sender for the second chance
                 * or payment link e-mail
                 */
                'secondChanceEmailSender' => '',
            ]
    ];
```

General payment flow
--------------------

[](#general-payment-flow)

Though there are multiple ways to pay an order, most payment gateways except you to follow the following flow in your checkout process:

### 1. The customer is redirected to the payment provider

[](#1-the-customer-is-redirected-to-the-payment-provider)

After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider.

The redirection is accomplished by submitting a form with some hidden fields. The form must post to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash.

The hash is calculated using the hidden form fields and a non-public secret. The hash used by the payment provider to verify if the request is valid.

### 2. The customer pays on the site of the payment provider

[](#2-the-customer-pays-on-the-site-of-the-payment-provider)

The customer arrived on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider.

### 3. The customer gets redirected back

[](#3-the-customer-gets-redirected-back)

After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a paymentresult and a hash.

The hash is calculated out of some of the fields returned and a secret non-public value. This hash is used to verify if the request is valid and comes from the payment provider. It is paramount that this hash is thoroughly checked.

The payment result can be something like "payment ok", "customer cancelled payment" or "payment declined".

Usage
-----

[](#usage)

This package can greatly help you with step 1. and 3. of the general flow

### 1. Redirecting to customer to the payment provider

[](#1-redirecting-to-customer-to-the-payment-provider)

Let's get technical. In the controller in which you will present a view to redirect to user to the payment provider you must inject the payment gateway like so:

```
use Spatie\Payment\PaymentGateway;

class CheckoutConfirmOrderController extends BaseController {

    /**
     * @var PaymentGateway
     */
    protected $paymentGateway;

    public function __construct(.. PaymentGateway $paymentGateway ...)
    {
        ...
        $this->paymentGateway = $paymentGateway;
        ...
    }
```

In the same controller in the method in which you present the view you must set the `$order` that you've probably build up during the checkout-process.

```
public function showOrderDetails()
    {
        $order = $this->orderRepo->getCurrentOrder();
        $paymentGateway = $this->paymentGateway->setOrder($order);

        return View::make('front.checkout.confirmOrder')->with(compact('order', 'paymentGateway'));
    }
```

The `$order` you pass to the payment gateway must adhere to the `PayableOrder`-interface:

```
interface PayableOrder {

    /**
     * @return string
     */
    public function getPaymentOrderId();

    /**
     * @return double
     */
    public function getPaymentAmount();

    /**
     * @return string
     */
    public function getPaymentDescription();

    /**
     * @return string
     */
    public function getCustomerEmail();

    /**
     * @return string
     */
    public function getCustomerLanguage();

}
```

So your Order-model should look something like

```
....
use Spatie\Payment\PayableOrder;

class Order extends Eloquent implements PayableOrder
{

...

    /**
     * @return string
     */
    public function getPaymentOrderId()
    {
        return $this->id;
    }

    /**
     * Should be in eurocents for most payments providers
     * @return double
     */
    public function getPaymentAmount()
    {
        return $this->getTotal() * 100;
    }

    /**
     * @return string
     */
    public function getPaymentDescription()
    {
        return 'Order ' . $this->id;
    }

    /**
     * @return string
     */
    public function getCustomerEmail()
    {
        return $this->email;
    }

    /**
     * @return string
     */
    public function getCustomerLanguage()
    {
        return App::getLocale();
    }
}
```

Please note that for most payment providers the result of `getPaymentAmount()`should be specified in eurocents.

After you've taken care of all steps above you can generate the form that will redirect the customer to the payment provider.

In your view you can simply use the `getPaymentForm()`-method

```
{{ $paymentGateway->getPaymentForm() }}

```

The result of this form is something like:

```

```

When clicking the submit button the customer gets redirected to the site of payment provider.

You can also pass html attributes for the form element as an array.

```
{{ $paymentGateway->getPaymentForm(['class' => 'form']) }}

```

```

```

### 2. Verifying the payment

[](#2-verifying-the-payment)

So now we've redirected the customer to the payment provider. The customer did some actions there (hopefully he or she paid the order) and now gets redirected back to our shop site.

The payment provider will redirect the customer to the url of the route that is specified in the `paymentLandingPageRoute`-option of the config-file.

We must validate if the redirect to our site is a valid request (we don't want imposters to wrongfully place non-paid order).

In the controller that handles the request coming from the payment provider inject the `PaymentGateway`

```
use Spatie\Payment\PaymentGateway;

class CheckoutPaymentVerificationController extends BaseController {

    protected $paymentGateway;

    public function __construct(PaymentGateway $paymentGateway)
    {
        $this->paymentGateway = $paymentGateway;
    }

    ...
```

Then, in the same controller, in the method you use to handle the request coming from the payment provider, use the `validateGatewayResponse`-method:

```
  public function verifyPayment()
    {
        $this->paymentGateway->validateGatewayResponse(Checkout::getCurrentOrderId());
    }
```

That method requires the order id that you are expecting a payment for. Usually you should have stored that order id in session prior to redirecting to user to the site of payment provider.

Notice that in previous example `Checkout::getCurrentOrderId()` is used. If you want such an elegant syntax check out the [spatie/checkout-package](https://github.com/spatie/checkout).

If the `validateGatewayResponse`-method concludes that the request was not valid a `Spatie\Payment\Exceptions\PaymentVerificationFailedException`-exception is thrown.

### 3. Getting the payment result

[](#3-getting-the-payment-result)

After you've verified that the redirect from the payment provider to your site is valid you can determine the result of the payment.

To determine the result you can use the `getPaymentResult()`-method. It can return these constants:

- `Spatie\Payment\PaymentGateway::PAYMENT_RESULT_OK`: all is well, the order has been paid
- `Spatie\Payment\PaymentGateway::PAYMENT_RESULT_CANCELLED_BY_CARDHOLDER`: the customer has cancelled the payment
- `Spatie\Payment\PaymentGateway::PAYMENT_RESULT_DECLINED`: the customer tried to pay, but his payment got declined by that financial institution that handles the payment
- `Spatie\Payment\PaymentGateway::PAYMENT_RESULT_FAILED`: an unexpected error occured.

Here is an example controller in which we verify the payment-request and determine the result:

```
use Spatie\Payment\PaymentGateway;

class CheckoutPaymentVerificationController extends BaseController {

    protected $paymentGateway;

    public function __construct(PaymentGateway $paymentGateway)
    {

        $this->paymentGateway = $paymentGateway;
    }

    public function verifyPayment()
    {
        $this->paymentGateway->validateGatewayResponse(Checkout::getCurrentOrderId());

        switch($this->paymentGateway->getPaymentResult())
        {
            case PaymentGateway::PAYMENT_RESULT_OK:
                //take necessary actions to mark order as confirmed
                break;

            case PaymentGateway::PAYMENT_RESULT_CANCELLED_BY_CARDHOLDER:
                //take necessary actions to mark order as failed
                break;

            case PaymentGateway::PAYMENT_RESULT_DECLINED:
                //take necessary actions to mark order as failed
                break;

            case PaymentGateway::PAYMENT_RESULT_FAILED:
                //take necessary actions to mark order as failed
                break;

            case PaymentGateway::PAYMENT_TIMED_OUT:
                //take necessary actions to mark order as failed
                break;

            default:
                throw new Exception('Unknown payment gateway answer');
                break;

        }
    }
}
```

Remarks
-------

[](#remarks)

Currently the only implemented gateway provider is Europabank. They can give feedback on a payment in many different ways, but this package only supports the 'DIRECT'-redirecttype.

The [Europabank API](https://www.europabank.be/ecommerce-professioneel) has many more options than this package currently provides.

All the examples above are coded to an interface: it should be fairly easy to swap out Europabank and use an other provider like [Ingenico](http://payment-services.ingenico.com/). You most certainly are welcome to send pull requests to implement other providers.

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 82.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~81 days

Total

12

Last Release

3666d ago

Major Versions

0.1.6 → 1.0.02015-05-24

1.1.1 → 2.0.02016-04-22

PHP version history (2 changes)0.1.1PHP &gt;=5.4.0

2.0.0PHP ^5.6|^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (56 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (7 commits)")[![vmitchell85](https://avatars.githubusercontent.com/u/1248035?v=4)](https://github.com/vmitchell85 "vmitchell85 (1 commits)")[![wanghanlin](https://avatars.githubusercontent.com/u/2937647?v=4)](https://github.com/wanghanlin "wanghanlin (1 commits)")[![willemvb](https://avatars.githubusercontent.com/u/1336390?v=4)](https://github.com/willemvb "willemvb (1 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (1 commits)")[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (1 commits)")

---

Tags

laravelpaymentgatewaywebshope-commercefinancialeuropabank

### Embed Badge

![Health badge](/badges/spatie-payment/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-payment/health.svg)](https://phpackages.com/packages/spatie-payment)
```

###  Alternatives

[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)[dena-a/iran-payment

a Laravel package to handle Internet Payment Gateways for Iran Banking System

312.4k1](/packages/dena-a-iran-payment)[parsisolution/gateway

A Laravel package for connecting to all Iraninan payment gateways

231.7k](/packages/parsisolution-gateway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
