tpay-com/tpay-openapi-php

Tpay OpenAPI library

1.7.3 2024-03-28 12:27 UTC

This package is auto-updated.

Last update: 2024-03-28 12:28:24 UTC


README

Library for all methods available via OpenAPI Tpay.

Latest stable version PHP version License CI status Type coverage

Polish version 🇵🇱 wersja polska

Installation

Install via Composer:

composer require tpay-com/tpay-openapi-php

Install via Git over SSH:

git clone git@github.com:tpay-com/tpay-openapi-php.git

Install via Git over HTTPS:

git clone https://github.com/tpay-com/tpay-openapi-php.git

Manual download: https://github.com/tpay-com/tpay-openapi-php/archive/master.zip

Configuration

The only thing you need to do is to set your OAuth credentials like in example config file (see example). You can generate access keys in Tpay's merchant panel.

The src/Loader.php file handles all required class loading, so you can include this file to any file you are editing.

All methods described in Tpay OpenAPI documentation can be easily executed by running one of the library methods like:

$tpayApi = new TpayApi($clientId, $clientSecret, true, 'read');
$transactions = $tpayApi->Transactions->getTransactions();

All currently available API methods have an example usage in Examples directory.

Example credentials

for all API calls:

  Client id: 1010-e5736adfd4bc5d8c
  Client secret: 493e01af815383a687b747675010f65d1eefaeb42f63cfe197e7b30f14a556b7

for notifications validation:

  Confirmation code: demo

for credit card encrypting:

  Public Key: LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0NCk1JR2ZNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0R05BRENCaVFLQmdRQ2NLRTVZNU1Wemd5a1Z5ODNMS1NTTFlEMEVrU2xadTRVZm1STS8NCmM5L0NtMENuVDM2ekU0L2dMRzBSYzQwODRHNmIzU3l5NVpvZ1kwQXFOVU5vUEptUUZGVyswdXJacU8yNFRCQkxCcU10TTVYSllDaVQNCmVpNkx3RUIyNnpPOFZocW9SK0tiRS92K1l1YlFhNGQ0cWtHU0IzeHBhSUJncllrT2o0aFJDOXk0WXdJREFRQUINCi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ==

Examples of usage

Frontend forms and payment handlers:

Payment method choice form, BLIK method form, simple credit card form, extended credit card form, recurrent payment example, payment notification webhook.

Merchant accounts registration (for partners only)

Example of usages.

Logs

Library has own logging system to save all API calls, responses, webhook notifications, and exceptions. Make sure that Logs directory is writable and add rule to Apache .htaccess or NGINX to deny access to this area from browser. The log files are created for each day separately.

The logging is enabled by default, but you can disable this feature by command:

Logger::disableLogging();

You can also set your own logging path by this command:

Logger::setLogPath('/my/own/path/Logs/');

The logs file names will be assigned automatically.

You can replace the logging system above by setting up your own implementation of Psr\Log\LoggerInterface with:

Logger::setLogger($logger);

Custom templates and static files path

You can set your own templates path, so you can copy and modify the phtml template files from this library.

Util::$customTemplateDirectory = '/my/own/templates/path/';

You can set your own static files path, so you can copy and modify the css and js files from this library. By default, the path is based on $_SERVER['REQUEST_URI'] value.

Util::$libraryPath = '/my/own/path/';

Language

The library supports two languages (English and Polish). Default language is English. Change language example:

// Any time you construct the class providing payment forms, you can pass the language in constructor
$paymentForms = new PaymentForms('pl');
// After this line all static messages (input labels, buttons titles etc.) will be displayed in Polish

// If you want to access translations manually, use:
$lang = new Lang();
$lang->setLang('pl'); // for setting language
$lang->lang('pay'); // to echo translated key

License

This library is released under the MIT License.