HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/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());
    }
}