Skip to content

Commit

Permalink
Merge pull request #301 from TransbankDevelopers/feat/kiwan-reports
Browse files Browse the repository at this point in the history
fix: kiwan reports
  • Loading branch information
Matiasnickolas authored Oct 4, 2024
2 parents 7d7d4bf + 4483b1d commit f0cdcae
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 101 deletions.
3 changes: 1 addition & 2 deletions src/Contracts/HttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Transbank\Contracts;

use Psr\Http\Message\ResponseInterface;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

interface HttpClientInterface
{
Expand All @@ -13,7 +12,7 @@ interface HttpClientInterface
* @param array|null $payload
* @param array|null $options
*
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return ResponseInterface
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Contracts/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Transbank\Contracts;

use Transbank\Webpay\Options;
use Transbank\Webpay\Exceptions\WebpayRequestException;
use Psr\Http\Message\ResponseInterface;
use Transbank\Utils\TransbankApiRequest;

Expand All @@ -15,7 +14,7 @@ interface RequestService
* @param array $payload
* @param Options $options
*
* @throws WebpayRequestException
* @throws \Transbank\Webpay\Exceptions\WebpayRequestException
*
* @return array Response from the API as json.
*/
Expand Down
5 changes: 2 additions & 3 deletions src/PatpassComercio/Inscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Transbank\Utils\RequestServiceTrait;
use Transbank\Contracts\RequestService;
use Transbank\PatpassComercio\Options;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

class Inscription
{
Expand Down Expand Up @@ -63,7 +62,7 @@ public function __construct(
* @param string $city
*
* @throws InscriptionStartException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return InscriptionStartResponse
*/
Expand Down Expand Up @@ -123,7 +122,7 @@ public function start(
* @param string $token
*
* @throws InscriptionStatusException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return InscriptionStatusResponse
*/
Expand Down
32 changes: 32 additions & 0 deletions src/Utils/Curl/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Transbank\Utils\Curl;

use Psr\Http\Message\StreamInterface;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

trait MessageTrait
{
Expand Down Expand Up @@ -60,4 +61,35 @@ public function withBody(StreamInterface $body): static
$new->body = $body;
return $new;
}

public function withHeader($name, $value): static
{
$new = clone $this;
$new->headers[$name] = (array) $value;
return $new;
}

public function withAddedHeader($name, $value): static
{
$new = clone $this;
$new->headers[$name][] = $value;
return $new;
}

private function createBody($body = ''): StreamInterface
{
$resource = fopen('php://temp', 'rw+');
if ($resource === false) {
throw new CurlRequestException('Unable to open stream');
}

if (!empty($body)) {
$writtenBytes = fwrite($resource, $body);
if ($writtenBytes === false) {
throw new CurlRequestException('Unable to write to stream');
}
}

return new Stream($resource);
}
}
20 changes: 0 additions & 20 deletions src/Utils/Curl/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,4 @@ public function withUri(UriInterface $uri, $preserveHost = false): RequestInterf

return $new;
}

public function withHeader($name, $value): RequestInterface
{
return clone $this;
}

public function withAddedHeader($name, $value): RequestInterface
{
return clone $this;
}

private function createBody($body = ''): StreamInterface
{
$resource = fopen('php://temp', 'rw+');
if (!empty($body)) {
fwrite($resource, $body);
}

return new Stream($resource);
}
}
24 changes: 0 additions & 24 deletions src/Utils/Curl/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,4 @@ public function getReasonPhrase(): string
{
return $this->reasonPhrase;
}

public function withHeader($name, $value): ResponseInterface
{
$new = clone $this;
$new->headers[$name] = (array) $value;
return $new;
}

public function withAddedHeader($name, $value): ResponseInterface
{
$new = clone $this;
$new->headers[$name][] = $value;
return $new;
}

private function createBody($body = ''): StreamInterface
{
$resource = fopen('php://temp', 'rw+');
if (!empty($body)) {
fwrite($resource, $body);
}

return new Stream($resource);
}
}
4 changes: 2 additions & 2 deletions src/Utils/HttpClientRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Transbank\Utils\Curl\HttpCurlClient;
use Transbank\Webpay\Exceptions\WebpayRequestException;
use Transbank\Webpay\Options;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;
use Psr\Http\Message\ResponseInterface;

class HttpClientRequestService implements RequestService
Expand Down Expand Up @@ -57,7 +56,8 @@ public function setHttpClient(HttpClientInterface $httpClient): void
* @param array $payload
* @param Options $options
*
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
* @throws WebpayRequestException
*
* @return array
Expand Down
3 changes: 1 addition & 2 deletions src/Utils/RequestServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Transbank\Utils;

use Transbank\Contracts\RequestService;
use Transbank\Webpay\Exceptions\WebpayRequestException;

/**
* Trait RequestServiceTrait .
Expand All @@ -21,7 +20,7 @@ trait RequestServiceTrait
* @param string $endpoint
* @param array $payload
*
* @throws WebpayRequestException
* @throws \Transbank\Webpay\Exceptions\WebpayRequestException
*
* @return array
*/
Expand Down
7 changes: 3 additions & 4 deletions src/Webpay/Oneclick/MallInscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Transbank\Webpay\Oneclick\Responses\InscriptionDeleteResponse;
use Transbank\Webpay\Oneclick\Responses\InscriptionFinishResponse;
use Transbank\Webpay\Oneclick\Responses\InscriptionStartResponse;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

class MallInscription
{
Expand All @@ -28,7 +27,7 @@ class MallInscription
* @return InscriptionStartResponse
*
* @throws InscriptionStartException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function start(string $username, string $email, string $responseUrl): InscriptionStartResponse
{
Expand Down Expand Up @@ -63,7 +62,7 @@ public function start(string $username, string $email, string $responseUrl): Ins
* @return InscriptionFinishResponse
*
* @throws InscriptionFinishException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function finish(string $token): InscriptionFinishResponse
{
Expand Down Expand Up @@ -93,7 +92,7 @@ public function finish(string $token): InscriptionFinishResponse
* @return InscriptionDeleteResponse
*
* @throws InscriptionDeleteException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function delete(string $tbkUser, string $username): InscriptionDeleteResponse
{
Expand Down
9 changes: 4 additions & 5 deletions src/Webpay/Oneclick/MallTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Transbank\Webpay\Oneclick\Responses\MallTransactionCaptureResponse;
use Transbank\Webpay\Oneclick\Responses\MallTransactionRefundResponse;
use Transbank\Webpay\Oneclick\Responses\MallTransactionStatusResponse;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

class MallTransaction
{
Expand All @@ -31,7 +30,7 @@ class MallTransaction
* @return MallTransactionAuthorizeResponse
*
* @throws MallTransactionAuthorizeException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function authorize(
string $userName,
Expand Down Expand Up @@ -74,7 +73,7 @@ public function authorize(
* @return MallTransactionCaptureResponse
*
* @throws MallTransactionCaptureException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function capture(
string $childCommerceCode,
Expand Down Expand Up @@ -114,7 +113,7 @@ public function capture(
* @return MallTransactionStatusResponse
*
* @throws MallTransactionStatusException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function status(string $buyOrder): MallTransactionStatusResponse
{
Expand Down Expand Up @@ -146,7 +145,7 @@ public function status(string $buyOrder): MallTransactionStatusResponse
* @return MallTransactionRefundResponse
*
* @throws MallRefundTransactionException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*/
public function refund(
string $buyOrder,
Expand Down
3 changes: 1 addition & 2 deletions src/Webpay/TransaccionCompleta/MallTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionStatusResponse;
use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionCaptureResponse;
use Transbank\Utils\InteractsWithWebpayApi;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;
use Transbank\Webpay\Exceptions\WebpayRequestException;

class MallTransaction
Expand Down Expand Up @@ -224,7 +223,7 @@ public function status(string $token)
* @param int|float $captureAmount
*
* @throws MallTransactionCaptureException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return MallTransactionCaptureResponse
*/
Expand Down
13 changes: 6 additions & 7 deletions src/Webpay/TransaccionCompleta/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Transbank\Webpay\TransaccionCompleta\Responses\TransactionCaptureResponse;
use Transbank\Utils\InteractsWithWebpayApi;
use Transbank\Webpay\Exceptions\WebpayRequestException;
use Transbank\Utils\Curl\Exceptions\CurlRequestException;

/**
* Class Transaction.
Expand All @@ -42,7 +41,7 @@ class Transaction
* @param string|null $cvv
*
* @throws TransactionCreateException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionCreateResponse
*/
Expand Down Expand Up @@ -83,7 +82,7 @@ public function create(
* @param int $installmentsNumber
*
* @throws TransactionInstallmentsException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionInstallmentsResponse
*/
Expand Down Expand Up @@ -119,7 +118,7 @@ public function installments(
* @param bool|null $gracePeriod
*
* @throws TransactionCommitException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionCommitResponse
*/
Expand Down Expand Up @@ -157,7 +156,7 @@ public function commit(
* @param int|float $amount
*
* @throws TransactionRefundException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionRefundResponse
*/
Expand Down Expand Up @@ -188,7 +187,7 @@ public function refund(string $token, int|float $amount)
* @param string $token
*
* @throws TransactionStatusException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionStatusResponse
*/
Expand Down Expand Up @@ -218,7 +217,7 @@ public function status($token)
* @param int|float $captureAmount
*
* @throws TransactionCaptureException
* @throws CurlRequestException
* @throws \Transbank\Utils\Curl\Exceptions\CurlRequestException
*
* @return TransactionCaptureResponse
*/
Expand Down
Loading

0 comments on commit f0cdcae

Please sign in to comment.