> For the complete documentation index, see [llms.txt](https://l-shop-en.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://l-shop-en.gitbook.io/documentation/software-api/purchasing/integration-with-payment-systems.md).

# Integration with payment systems

## Introduction <a href="#vvedenie" id="vvedenie"></a>

L-Shop allows you to quickly add integration with payment systems that are different from standard ones.

## Steps <a href="#khod" id="khod"></a>

In order to add integration with the payment system you need:

* Create a class and implement an interface `App\Services\Purchasing\Payers\Payer`.
* Write implementation for 5 methods: `paymentUrl()`, `validate()`, `successAnswer()`, `name()`, `enabled()`.

{% code title="/app/Services/Purchasing/Payers/CustomPayer.php" %}

```php
<?php
declare(strict_types = 1);​
namespace App\Services\Purchasing\Payers;​

use App\Entity\Purchase;

class CustomPayer implements Payer
{
    /**
     * This method returns the url, which the user should go to for payment.
     */
    public function paymentUrl(Purchase $purchase): string
    {
        //
    }
    
    /**
     * Validates an array of incoming data and returns true - in case the
     * data is valid and false otherwise. This method is called when the
     * payment system makes a request to notify the L-Shop of the status
     * of payment.
     */
    public function validate(array $data): bool
    {
        //
    }
    
    /**
     * Returns the string of the successful response. This answer expects
     * to see the payment system on the request to notify the store of a
     * successful payment.
     */
    public function successAnswer(Purchase $purchase): string
    {
        //
    }
    
    /**
     * Returns the internal name of the payment service. Used only by L-Shop.
     */
    public function name(): string
    {
        //
    }​
    
    /**
     * Returns true if the payment system is turned on and false if it is off.
     */
    public function enabled(): bool
    {
        //
    }
}
```

{% endcode %}

* Register the implementation of this payment system.
  * Go to file `/config/purchasing.php` .
  * Add the full name of the new payer class to the array element `payers`.

{% code title="/config/purchasing.php" %}

```php
'payers' => [
    // Builtin payers...
    \App\Services\Purchasing\Payers\RobokassaPayer::class,
    \App\Services\Purchasing\Payers\InterkassaPayer::class,
    
    // Custom payers...
    \App\Services\Purchasing\Payers\CustomPayer::class
],
```

{% endcode %}

* Reset application cache to apply new configuration.

## Specification

{% hint style="info" %}
&#x20;The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "NOT SHALL", "RECOMMENDED", "MAY" must be interpreted in the same way as described in [RFC 2119](http://www.ietf.org/rfc/rfc2119.txt).
{% endhint %}

* Payer class *MUST* implements interface `App\Services\Purchasing\Payers\Payer`.
* It is *RECOMMENDED* to add a *Payer* suffix to the class name so that the class can be identified by name.
* It is *RECOMMENDED* to place payers in the namespace `App\Services\Purchasing\Payer`.
* The implementation of the `paymentUrl()` method *MUST* return a string that is a URL for which the user will need to go to make payment.
* The implementation of the `validate()` method *MUST* return the validation result of the received data that the payment service has generated for the payment status message. A Boolean value of `true` means that the received data is valid, `false` is invalid.
* The implementation of the `validate()` method *MAY* throw an exception of the type `App\Exceptions\Payer\InvalidPaymentDataException` if the received data is invalid.
* The implementation of the `successAnswer()` method *MUST* return a string that will be returned to the payment service in the case of the validity of the data passed to the `validate()` method in response to a request for a payment status message.
* The implementation of the `name()` method *MUST* return a string that is the name of the payment system. This value will be visible to the user when interacting with the system.
* Implementing the `enabled()` method *MUST* return a Boolean value that indicates whether the given payer implementation is available for work or not.

​
