Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:

runs-on: ubuntu-latest

env:
TATRAPAY_CLIENT_ID: ${{ secrets.TATRAPAY_CLIENT_ID }}
TATRAPAY_CLIENT_SECRET: ${{ secrets.TATRAPAY_CLIENT_SECRET }}

steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ composer.phar
# PHPUnit cache
.phpunit.result.cache
/logs/
.idea
/lib/ModelBackup
26 changes: 26 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

**
!lib/Model/**
6 changes: 6 additions & 0 deletions ECID_PUBLIC_KEY_2023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcGk6cYrtjOHOjP8KHJ5YPO9t0
lXkR38dfkPbSkG5o873AKQqLiDC3JmMGPkm8gO79M4wWBas7DWo0NWM2Y+rT+zu4
4w+/xHcwDl8K/LmVmDaBkV/irWfmAreDPVJTVt1t4nPK/nhPh+B3LHY1THhfXujV
sMWycfPgHB0nY7wcxQIDAQAB
-----END PUBLIC KEY-----
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# tatrapayplus-php

[![Release](https://img.shields.io/github/v/release/SmartBase-SK/tatrapayplus-php)](https://img.shields.io/github/v/release/SmartBase-SK/tatrapayplus-php)
[![Build status](https://img.shields.io/github/actions/workflow/status/SmartBase-SK/tatrapayplus-php/php.yml?branch=main)](https://github.com/SmartBase-SK/tatrapayplus-php/actions/workflows/php.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/SmartBase-SK/tatrapayplus-php/branch/main/graph/badge.svg)](https://codecov.io/gh/SmartBase-SK/tatrapayplus-php)
[![Commit activity](https://img.shields.io/github/commit-activity/m/SmartBase-SK/tatrapayplus-php)](https://img.shields.io/github/commit-activity/m/SmartBase-SK/tatrapayplus-php)
[![License](https://img.shields.io/github/license/SmartBase-SK/tatrapayplus-php)](https://img.shields.io/github/license/SmartBase-SK/tatrapayplus-php)

PHP SDK for Tatrapay+ payment gateway.

- **Github repository**: <https://github.com/SmartBase-SK/tatrapayplus-php/>
- **Documentation** <https://sdk.tatrabanka.sk/docs/libraries/php/v1.0.0>

## Type generation
To generate new types after OpenAPI structure has been changed please run
```
./generate_openapi_models.sh
```
This command will automatically generate models based on `tatrapayplus_api_sandbox.json` file
and preserve custom Model classes.\
Old models will be backed up in ModelBackup folder.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "tatrapayplus/tatrapayplus_api_client",
"type": "library",
"description": "PHP SDK for Tatrapay+ payment gateway API",
"license": "OSL-3.0",
"scripts": {
"test": "phpunit --bootstrap vendor/autoload.php tests/tests.php"
},
"autoload": {
"psr-4": {
"Tatrapayplus\\TatrapayplusApiClient\\" : "lib/"
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions generate_openapi_models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mkdir tmp-openapi
cp .openapi-generator-ignore ./tmp-openapi

openapi-generator-cli generate -g php -c openapi_generator_config.json -i ./tatrapayplus_api_sandbox.json -o ./tmp-openapi

echo "Backing up existing Model files..."
rm -rf ./lib/ModelBackup
cp -R ./lib/Model ./lib/ModelBackup
echo "Backup done"
rm -rf ./lib/Model
echo "Removed existing Model files"

echo "Copying generated Model files to repo files..."
cp -R ./tmp-openapi/lib/Model ./lib/
echo "Copying finished"
rm -rf ./tmp-openapi

echo "Adding custom Model classes from backup..."
cp ./lib/ModelBackup/TokenSuccessResponseType.php ./lib/Model
cp ./lib/ModelBackup/QRStatus.php ./lib/Model
cp ./lib/ModelBackup/PaymentMethodRules.php ./lib/Model

echo "********************************"
echo "Verify new Model files by running tests -> phpunit --bootstrap vendor/autoload.php tests/tests.php"
echo "Ensure env variables TATRAPAY_CLIENT_ID and TATRAPAY_CLIENT_SECRET are set before running tests"
echo "If successful, remove old Model files backup (dir ./lib/ModelBackup)"

# to revert back to old Model files
# rm -rf ./lib/Model
# cp -R ./lib/ModelBackup ./lib/Model
31 changes: 31 additions & 0 deletions lib/AccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* AccessToken
* PHP version 7.4
*
* @category Class
*/

namespace Tatrapayplus\TatrapayplusApiClient;

class AccessToken
{
private string $access_token;
private int $expires_in;

public function __construct(string $access_token, int $expires_in)
{
$this->access_token = $access_token;
$this->expires_in = $expires_in + time();
}

public function getAccessToken(): string
{
return $this->access_token;
}

public function isExpired(): bool
{
return $this->expires_in < time();
}
}
Loading