Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

card token payments #2

Merged
merged 1 commit into from
May 1, 2024
Merged
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
65 changes: 65 additions & 0 deletions src/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Payment extends RequestBuilder
{
private \MonoPay\Client $client;

const TOKEN_PAYMENT_INIT_KIND_MERCHANT = 'merchant';
const TOKEN_PAYMENT_INIT_KIND_CLIENT = 'client';

public function __construct(\MonoPay\Client $client)
{
$this->client = $client;
Expand Down Expand Up @@ -161,4 +164,66 @@ public function items(int $fromTimestamp, int $toTimestamp=null): array
return $data['list']??[];
}

/**
* Оплата по токену
* Створення платежу за токеном картки
* @param string $cartToken Токен карти
* @param int $amount Сума оплати у мінімальних одиницях (копійки для гривні)
* @param array $options Додаткові параметри (Див. посилання)
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1wallet~1payment/post
*/
public function createWithCardToken(string $cartToken, int $amount, array $options=[]): array
{
if($amount < 1){
throw new \Exception('Amount must be a natural number',500);
}
$options['amount']=$amount;
$options['cardToken']=$cartToken;
$response = $this->client->getClient()->request('POST','/api/merchant/wallet/payment',[
\GuzzleHttp\RequestOptions::JSON => $options
]);

return $this->getDataFromGuzzleResponse($response);
}

/**
* Список карт у гаманці
* @param string $walletId Ідетифікатор гаманція покупця
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1wallet/get
*/
public function listCardTokens(string $walletId): array
{
$query = [
'walletId' => $walletId
];
$response = $this->client->getClient()->request('GET','/api/merchant/statement',[
\GuzzleHttp\RequestOptions::QUERY => $query
]);

$data = $this->getDataFromGuzzleResponse($response);
return $data['wallet']??[];
}

/**
* Видалення токенізованої картки
* @param string $cardToken Токен картки
* @return void
* @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1wallet~1card/delete
*/
public function deleteCardToken(string $cardToken): void
{
$query = [
'cardToken' => $cardToken
];
$response = $this->client->getClient()->request('DELETE','/api/merchant/wallet/payment',[
\GuzzleHttp\RequestOptions::QUERY => $query
]);

$this->getDataFromGuzzleResponse($response);
}

}