This library has no dependencies on other php
libraries. It provides easy-to-use API for communication with GoPay REST API v3
, known as GoPay Inline.
Install Markette/GopayInline over composer.
$ composer require markette/gopay-inline
From GoPay you need:
- GoID
- ClientID
- ClientSecret
On server you need:
- PHP >= 5.5
- cURL
- Webpage (https://www.gopaygate.com)
- Offical resources in EN (https://doc.gopay.com/en/)
- Offical resources in CZ (https://doc.gopay.com/cs/)
All you can find in examples folder.
There are 3 main parts of this library.
A core class holding credentials, token, authenticator and http client. It could make authentication and requests to endpoints.
Delegates all requests / responses to IO. All requests go over cURL
. There is a place for other implementation, go for it.
Services provide easy-to-use API for creating and verifying payments.
- Verify payments (
$client->payments->verify(..)
) - Standard payments (
$client->payments->createPayment(..)
) - Recurrent payments (
$client->payments->createRecurrentPayment(..)
) - Preauthorized payments (
$client->payments->createPreauthorizedPayment(..)
)
First you need set up client with credentials.
use Markette\GopayInline\Client;
use Markette\GopayInline\Config;
$goId = '***FILL***';
$goClient = '***FILL***';
$goSecret = '***FILL***';
// TEST MODE
$client = new Client(new Config($goId, $goClient, $goSecret));
$client = new Client(new Config($goId, $goClient, $goSecret, $mode = Config::TEST));
// PROD MODE
$client = new Client(new Config($goId, $goClient, $goSecret, $mode = Config::PROD));
Then you have to authenticate with oauth2 authority server on GoPay.
For only creating payments use Scope::PAYMENT_CREATE
, for the rest Scope::PAYMENT_ALL
.
use Markette\GopayInline\Api\Lists\Scope;
$token = $client->authenticate(Scope::PAYMENT_CREATE);
Heureka! We have token, let's make some API request.
This example of payment data was copied from official documentation.
// Payment data
$paymentData = [
'payer' => [
'default_payment_instrument' => 'BANK_ACCOUNT',
'allowed_payment_instruments' => ['BANK_ACCOUNT'],
'default_swift' => 'FIOBCZPP',
'allowed_swifts' => ['FIOBCZPP', 'BREXCZPP'],
'contact' => [
'first_name' => 'Zbynek',
'last_name' => 'Zak',
'email' => '[email protected]',
'phone_number' => '+420777456123',
'city' => 'C.Budejovice',
'street' => 'Plana 67',
'postal_code' => '373 01',
'country_code' => 'CZE',
],
],
'amount' => 150,
'currency' => 'CZK',
'order_number' => '001',
'order_description' => 'pojisteni01',
'items' => [
['name' => 'item01', 'amount' => 50],
['name' => 'item02', 'amount' => 100],
],
'additional_params' => [
array('name' => 'invoicenumber', 'value' => '2015001003')
],
'return_url' => 'http://www.your-url.tld/return',
'notify_url' => 'http://www.your-url.tld/notify',
'lang' => 'cs',
];
// Create payment request
$response = $client->payments->createPayment(PaymentFactory::create($paymentData));
$data = $response->getData();
$client->payments
returns PaymentsService
, you can create this service also by $client->createPaymentsService()
.
PaymentsService::createPayment
need object of Payment
, you can set-up it manually by yourself or via PaymentFactory
. But over PaymentFactory, there is parameters validation and price validation.
Now we have a response with payment information. There's same data as we send it before and also new $gw_url
. It's in response data.
$url = $response->data['gw_url'];
// Redirect to URL
// ...
// Send over AJAX to inline variant
// ...
In case of inline variant you can use prepared javascript.
@TODO
All you need is $paymentId
. Response is always the same.
// Verify payment
$response = $client->payments->verify($paymentId);
Fill your credentials in config.
extensions:
gopay: Markette\GopayInline\Bridges\Nette\GopayExtension
gopay:
goId: ***
clientId: ***
clientSecret: ***
test: on / off
Inject Client
into your services / presenters;
use Markette\GopayInline\Client;
/** @var Client @inject */
public $gopay;
It contains information for cURL.
$url
$headers
$options
$data
It contains information after execution request. It could be success or failed.
$data
$headers
$code
$error