tpay-com / tpay-openapi-php
Tpay OpenAPI library
Installs: 125 443
Dependents: 4
Suggesters: 0
Security: 0
Stars: 8
Watchers: 5
Forks: 12
Open Issues: 0
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
- phpseclib/phpseclib: ^2 || ^3
- psr/log: ^1 || ^2 || ^3
Requires (Dev)
- php-parallel-lint/php-parallel-lint: ^1.3.2
- phpunit/phpunit: ^5.7.27 || ^9.6.10
README
Library for all methods available via OpenAPI Tpay.
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:
$cache = /*Your Cache Implementation. Preferably PSR\Cache implementation, because it will be used in future by this library. */; $tpayApiKey = $cache->get('example_YOUR_TPAY_API_TOKEN_KEY'); $tpayApi = new TpayApi($clientId, $clientSecret, true, 'read'); //if your cache returned a token, set it to TpayApi if($tpayApiKey !== null){ $tpayApiKey->setCustomToken(unserialize($tpayApiKey)); } else { //if not, get new token and cache it for given time //as you can notice, we slightly shorten token validity time to avoid using almost invalid token $tpayApi->authorization(); $cache->set('example_YOUR_TPAY_API_TOKEN_KEY', serialize($tpayApi->getToken()), $tpayApiKey->getToken()->expires_in->getValue() - 10); } $transactions = $tpayApi->Transactions->getTransactions();
Credentials
All currently available API methods have an example usage in Examples
directory.
You can obtain sandbox credentials by registering on https://register.sandbox.tpay.com/ website.
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)
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.