1. Go to this page and download the library: Download sashalenz/novapay-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sashalenz / novapay-api example snippets
use Sashalenz\NovapayApi\NovapayApi;
use Sashalenz\NovapayApi\NovapayCredentials;
// 1. З конфігу (.env)
$auth = NovapayApi::auth()->jwtFromConfig();
// 2. Явно (параметри)
$auth = NovapayApi::auth()->jwt(
refreshToken: 'REFRESH_TOKEN',
login: 'your_login',
publicCertificate: '-----BEGIN RSA PUBLIC KEY-----...',
);
// 3. З DTO NovapayCredentials
$credentials = new NovapayCredentials(
login: $bankAccount->novapay_login,
refreshToken: $bankAccount->novapay_refresh_token,
publicCertificate: $bankAccount->novapay_public_certificate,
);
$auth = NovapayApi::authenticateWith($credentials);
// 4. Напряму з моделі (через HasNovapayCredentials інтерфейс)
$auth = NovapayApi::authenticateAs($bankAccount);
$jwt = $auth->jwt; // токен для API запитів
$newRefreshToken = $auth->refresh_token; // зберегти в БД
$newCertificate = $auth->public_certificate; // зберегти в БД
use Sashalenz\NovapayApi\HasNovapayCredentials;
use Sashalenz\NovapayApi\NovapayApi;
class BankAccount extends Model implements HasNovapayCredentials
{
public function getNovapayLogin(): string
{
return $this->novapay_login;
}
public function getNovapayRefreshToken(): string
{
return $this->novapay_refresh_token;
}
public function getNovapayPublicCertificate(): string
{
return $this->novapay_public_certificate;
}
public function updateNovapayTokens(string $refreshToken, string $publicCertificate): void
{
$this->update([
'novapay_refresh_token' => $refreshToken,
'novapay_public_certificate' => $publicCertificate,
]);
}
/**
* Отримати JWT і одразу оновити токени в БД.
*/
public function refreshNovapayJwt(): string
{
$response = NovapayApi::authenticateAs($this);
$this->updateNovapayTokens(
$response->refresh_token,
$response->public_certificate,
);
return $response->jwt;
}
}