File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Core/Payment/Methods/WompiApi/WompiApiClient.php
<?php
declare(strict_types=1);
namespace App\Core\Payment\Methods\WompiApi;
use App\Core\Payment\Entities\Payment;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\RequestOptions;
class WompiApiClient
{
private $parameters;
private $client;
public function __construct($parameters)
{
$this->parameters = $parameters;
$this->client = new Client([
'base_uri' => $this->parameters->gw_url_prd
]);
}
public function retrieve(Payment $payment)
{
$response = $this->client->get(
'transactions/?reference=' . $payment->reference(),
[
'headers' => [
'Authorization' => 'Bearer ' . $this->parameters->client_secret
]
]
);
return json_decode($response->getBody()->getContents());
}
public function merchant()
{
$response = $this->client->get(
'merchants/' . $this->parameters->client_public
);
return json_decode($response->getBody()->getContents());
}
public function pseFinancialInstitutions()
{
$response = $this->client->get(
"pse/financial_institutions",
[
'headers' => [
'Authorization' => 'Bearer ' . $this->parameters->client_secret
]
]
);
return json_decode($response->getBody()->getContents());
}
public function createTransaction($transactionRequest)
{
try {
$response = $this->client->post(
'transactions',
[
'headers' => [
'Authorization' => 'Bearer ' . $this->parameters->client_secret,
],
RequestOptions::JSON => $transactionRequest
]
);
return json_decode($response->getBody()->getContents());
} catch (ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
throw new WompiApiException("Ha sucedido un error.", 1);
}
}
public function tokenizeCard($cardRequest)
{
$response = $this->client->post(
'tokens/cards',
[
'headers' => [
'Authorization' => 'Bearer ' . $this->parameters->client_public,
],
RequestOptions::JSON => $cardRequest
]
);
return json_decode($response->getBody()->getContents());
}
public function createPaymentSource($paymentSourceRequest)
{
$response = $this->client->post(
'payment_sources',
[
'headers' => [
'Authorization' => 'Bearer ' . $this->parameters->client_secret,
],
RequestOptions::JSON => $paymentSourceRequest
]
);
return json_decode($response->getBody()->getContents());
}
}