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
17 changes: 6 additions & 11 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
check:
Expand All @@ -30,18 +31,12 @@ jobs:
- run: mkdir sdk && unzip tpay-openapi-php.zip -d sdk

- uses: actions/upload-artifact@v4
id: plugin-upload
id: sdk-upload
with:
name: 'tpay-woocommerce'
name: 'tpay-openapi'
path: 'sdk/'

- uses: actions/github-script@v6
- uses: mshick/add-pr-comment@v2
with:
github-token: ${{ secrets.TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Tpay OpenAPI SDK - ${{ steps.plugin-upload.outputs.artifact-url }}'
})
message: |
Tpay Open API SDK - ${{ steps.sdk-upload.outputs.artifact-url }}
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,25 @@ The [`src/Loader.php`](src/Loader.php) file handles all required class loading,

All methods described in [Tpay OpenAPI documentation](https://openapi.tpay.com) can be easily executed by running one of the library methods like:
```php
$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`](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==
```
You can obtain sandbox credentials by registering on https://register.sandbox.tpay.com/ website.

### Examples of usage

Expand Down
11 changes: 7 additions & 4 deletions examples/ExamplesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class ExamplesConfig
// Ask Tpay to get Partner access
const PARTNER_CLIENT_ID = '';
const PARTNER_CLIENT_SECRET = '';
const MERCHANT_CLIENT_ID = '1010-e5736adfd4bc5d8c';
const MERCHANT_CLIENT_SECRET = '493e01af815383a687b747675010f65d1eefaeb42f63cfe197e7b30f14a556b7';
const MERCHANT_CONFIRMATION_CODE = 'demo';
const MERCHANT_RSA_KEY = 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0NCk1JR2ZNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0R05BRENCaVFLQmdRQ2NLRTVZNU1Wemd5a1Z5ODNMS1NTTFlEMEVrU2xadTRVZm1STS8NCmM5L0NtMENuVDM2ekU0L2dMRzBSYzQwODRHNmIzU3l5NVpvZ1kwQXFOVU5vUEptUUZGVyswdXJacU8yNFRCQkxCcU10TTVYSllDaVQNCmVpNkx3RUIyNnpPOFZocW9SK0tiRS92K1l1YlFhNGQ0cWtHU0IzeHBhSUJncllrT2o0aFJDOXk0WXdJREFRQUINCi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ==';
const MERCHANT_CLIENT_ID = '--put--your--client--id--here';
const MERCHANT_CLIENT_SECRET = '--put--your--client--secret--here';
const MERCHANT_CONFIRMATION_CODE = '--put--your--confirmation-code--here';
const MERCHANT_RSA_KEY = '--put--your--RSA-key--here';

public function __construct()
{
Expand All @@ -22,6 +22,9 @@ public function __construct()
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$this->loadLibrary();
if (self::MERCHANT_CLIENT_ID === '--put--your--client--id--here') {
exit('Please fill your API credentials in file: '.__DIR__);
}
}

private function loadLibrary()
Expand Down