Skip to content

Commit

Permalink
Merge pull request #285 from TransbankDevelopers/feat/upgrade-minimum…
Browse files Browse the repository at this point in the history
…-php-version

feat: upgrade minimum php version
  • Loading branch information
gasspper authored Jul 3, 2024
2 parents b105736 + 76ea663 commit e15926a
Show file tree
Hide file tree
Showing 60 changed files with 1,180 additions and 883 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [7.4]
php-versions: [8.2]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Requisitos:

- PHP 7.0+
- PHP 8.2+

## Dependencias
Para utilizar este SDK, debes tener las siguientes extensiones de PHP instaladas:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Transbank SDK",
"keywords": ["payments", "transbank", "api", "sdk"],
"require": {
"php": ">=7.0",
"php": ">=8.2",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
20 changes: 19 additions & 1 deletion src/Contracts/HttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@

namespace Transbank\Contracts;

use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\GuzzleException;

interface HttpClientInterface
{
public function request($method, $url, $payload = [], $options = null);
/**
* @param string $method
* @param string $url
* @param array|null $payload
* @param array|null $options
*
* @throws GuzzleException
*
* @return ResponseInterface
*/
public function request(
string $method,
string $url,
array|null $payload = [],
array|null $options = null
): ResponseInterface;
}
20 changes: 15 additions & 5 deletions src/Contracts/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
namespace Transbank\Contracts;

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

interface RequestService
{
/**
* @param $method
* @param $endpoint
* @param $payload
* @param string $method
* @param string $endpoint
* @param array $payload
* @param Options $options
*
* @throws Transbank\Webpay\Exceptions\WebpayRequestException
* @throws WebpayRequestException
*
* @return array Response from the API as json.
*/
public function request($method, $endpoint, $payload, Options $options);
public function request(
string $method,
string $endpoint,
array $payload,
Options $options
): array;
public function getLastResponse(): ResponseInterface|null;
public function getLastRequest(): TransbankApiRequest|null;
}
109 changes: 55 additions & 54 deletions src/PatpassComercio/Inscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Transbank\Utils\RequestServiceTrait;
use Transbank\Contracts\RequestService;
use Transbank\PatpassComercio\Options;
use GuzzleHttp\Exception\GuzzleException;

class Inscription
{
Expand All @@ -27,63 +28,62 @@ class Inscription
/**
* @var Options
*/
protected $options;
protected Options $options;

/**
* Transaction constructor.
*
* @param Options $options
* @param RequestService |null $requestService
* @param Options $options
* @param RequestService|null $requestService
*/
public function __construct(
Options $options,
RequestService $requestService = null
RequestService|null $requestService = null
) {
$this->options = $options;

$this->setRequestService($requestService !== null ? $requestService :
new HttpClientRequestService());
}

/**
* @param $url
* @param $name
* @param $lastName
* @param $secondLastName
* @param $rut
* @param $serviceId
* @param $finalUrl
* @param $maxAmount
* @param $phone
* @param $cellPhone
* @param $patpassName
* @param $personEmail
* @param $commerceEmail
* @param $address
* @param $city
* @param string $url
* @param string $name
* @param string $lastName
* @param string $secondLastName
* @param string $rut
* @param string $serviceId
* @param string $finalUrl
* @param string $maxAmount
* @param string $phone
* @param string $cellPhone
* @param string $patpassName
* @param string $personEmail
* @param string $commerceEmail
* @param string $address
* @param string $city
*
* @throws InscriptionStartException
* @throws GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*
* @return InscriptionStartResponse
*/
public function start(
$url,
$name,
$lastName,
$secondLastName,
$rut,
$serviceId,
$finalUrl,
$maxAmount,
$phone,
$cellPhone,
$patpassName,
$personEmail,
$commerceEmail,
$address,
$city
) {
string $url,
string $name,
string $lastName,
string $secondLastName,
string $rut,
string $serviceId,
string $finalUrl,
string $maxAmount,
string $phone,
string $cellPhone,
string $patpassName,
string $personEmail,
string $commerceEmail,
string $address,
string $city
): InscriptionStartResponse {
$payload = [
'url' => $url,
'nombre' => $name,
Expand Down Expand Up @@ -120,15 +120,14 @@ public function start(
}

/**
* @param $token
* @param null $options
* @param string $token
*
* @throws InscriptionStatusException
* @throws GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*
* @return InscriptionStatusResponse
*/
public function status($token)
public function status(string $token): InscriptionStatusResponse
{
$payload = [
'token' => $token,
Expand All @@ -154,46 +153,48 @@ public function status($token)
/**
* @return Options
*/
public function getOptions()
public function getOptions(): Options
{
return $this->options;
}

/**
* @param Options $options
*
* @return void
*/
public function setOptions(Options $options)
public function setOptions(Options $options): void
{
$this->options = $options;
}

/**
* @return string
*/
protected function getBaseUrl()
protected function getBaseUrl(): string
{
return $this->getOptions()->getApiBaseUrl();
}

/**
* @param $commerceCode
* @param $apiKey
* @param string $commerceCode
* @param string $apiKey
*
* @return $this
* @return self
*/
public static function buildForIntegration($commerceCode, $apiKey)
public static function buildForIntegration(string $commerceCode, string $apiKey): self
{
return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION));
return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION));
}

/**
* @param $commerceCode
* @param $apiKey
* @param string $commerceCode
* @param string $apiKey
*
* @return $this
* @return self
*/
public static function buildForProduction($commerceCode, $apiKey)
public static function buildForProduction(string $commerceCode, string $apiKey): self
{
return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION));
return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION));
}
}
6 changes: 4 additions & 2 deletions src/PatpassComercio/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace Transbank\PatpassComercio;

use Transbank\Webpay\Options as WebpayOptions;

/**
* Class Options.
*/
class Options extends \Transbank\Webpay\Options
class Options extends WebpayOptions
{
const BASE_URL_PRODUCTION = 'https://www.pagoautomaticocontarjetas.cl/';
const BASE_URL_INTEGRATION = 'https://pagoautomaticocontarjetasint.transbank.cl/';

/**
* @return array
*/
public function getHeaders()
public function getHeaders(): array
{
return [
'commercecode' => $this->getCommerceCode(),
Expand Down
6 changes: 3 additions & 3 deletions src/PatpassComercio/PatpassComercio.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* @category
*/

namespace Transbank\PatpassComercio;
namespace Transbank\PatpassComercio;


class PatpassComercio
{
const INTEGRATION_API_KEY = 'cxxXQgGD9vrVe4M41FIt';
const INTEGRATION_COMMERCE_CODE = '28299257';
public const INTEGRATION_API_KEY = 'cxxXQgGD9vrVe4M41FIt';
public const INTEGRATION_COMMERCE_CODE = '28299257';
}
16 changes: 8 additions & 8 deletions src/PatpassComercio/Responses/InscriptionFinishResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

class InscriptionFinishResponse
{
public $status;
public $code;
public string|null $status;
public int $code;

public function __construct($httpCode)
public function __construct(int $httpCode)
{
$this->code = $httpCode;
$this->status = null;

if ($httpCode == 204) {
$this->status = 'OK';
Expand All @@ -26,19 +27,18 @@ public function __construct($httpCode)
}

/**
* @return mixed
* @return string|null
*/
public function getStatus()
public function getStatus(): string|null
{
return $this->status;
}

/**
* @return mixed
* @return int
*/
public function getCode()
public function getCode(): int
{
return $this->code;
}

}
17 changes: 8 additions & 9 deletions src/PatpassComercio/Responses/InscriptionStartResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,33 @@

class InscriptionStartResponse
{
public $token;
public $urlWebpay;
public string|null $token;
public string|null $urlWebpay;

/**
* InscriptionStartResponse constructor.
*
* @param $token
* @param array $json
*/
public function __construct($json)
public function __construct(array $json)
{
$this->token = Utils::returnValueIfExists($json, 'token');
$this->urlWebpay = Utils::returnValueIfExists($json, 'url');
}

/**
* @return mixed
* @return string|null
*/
public function getToken()
public function getToken(): string|null
{
return $this->token;
}

/**
* @return mixed
* @return string|null
*/
public function getUrlWebpay()
public function getUrlWebpay(): string|null
{
return $this->urlWebpay;
}

}
Loading

0 comments on commit e15926a

Please sign in to comment.