Skip to content

Commit

Permalink
Merge pull request #2 from paytic/master
Browse files Browse the repository at this point in the history
refactor: add php8.0 type hints
  • Loading branch information
stevro authored Apr 1, 2024
2 parents ab40bf5 + 9410a7d commit 9d180a5
Show file tree
Hide file tree
Showing 30 changed files with 451 additions and 372 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prefer-stable": true,
"require": {
"ext-json": "*",
"ext-iconv": "*",
"jms/serializer": "^3.29",
"guzzlehttp/guzzle": "^6.5|^7.0",
"alcohol/iso4217": "^4.1",
Expand Down
30 changes: 22 additions & 8 deletions src/BTIPayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Stev\BTIPay\Exceptions\RequiredValueException;
use Stev\BTIPay\Model\Order;
use Stev\BTIPay\Requests\GetOrderStatusExtended;
use Stev\BTIPay\Requests\Register;
Expand All @@ -18,24 +19,24 @@ class BTIPayClient
/**
* @var string
*/
protected $username;
protected string $username;
/**
* @var string
*/
protected $password;
protected string $password;

/**
* @var bool
*/
protected $isTest = true;
protected bool $isTest = true;

/**
* BTIPayClient constructor.
* @param $username
* @param $password
* @param bool $isTest
*/
public function __construct($username, $password, $isTest = true)
public function __construct($username, $password, bool $isTest = true)
{
$this->username = $username;
$this->password = $password;
Expand All @@ -45,8 +46,10 @@ public function __construct($username, $password, $isTest = true)
/**
* @param Order $order
* @return RegisterResponse
* @throws RequiredValueException
* @throws GuzzleException
*/
public function register(Order $order)
public function register(Order $order): RegisterResponse
{
$registerRequest = new Register($this->isTest);

Expand All @@ -61,8 +64,10 @@ public function register(Order $order)
/**
* @param Order $order
* @return RegisterResponse
* @throws RequiredValueException
* @throws GuzzleException
*/
public function registerPreAuth(Order $order)
public function registerPreAuth(Order $order): RegisterResponse
{
$registerRequest = new RegisterPreAuth($this->isTest);

Expand All @@ -80,7 +85,7 @@ public function registerPreAuth(Order $order)
* @throws Exceptions\RequiredValueException
* @throws GuzzleException
*/
public function getOrderStatusExtendedByOrderId($orderId)
public function getOrderStatusExtendedByOrderId($orderId): Responses\GetOrderStatusExtendedResponse
{
$getOrderStatusRequest = new GetOrderStatusExtended($this->isTest);

Expand All @@ -97,7 +102,7 @@ public function getOrderStatusExtendedByOrderId($orderId)
* @throws Exceptions\RequiredValueException
* @throws GuzzleException
*/
public function getOrderStatusExtendedByOrderNumber($orderNumber)
public function getOrderStatusExtendedByOrderNumber($orderNumber): Responses\GetOrderStatusExtendedResponse
{
$getOrderStatusRequest = new GetOrderStatusExtended($this->isTest);

Expand All @@ -108,16 +113,25 @@ public function getOrderStatusExtendedByOrderNumber($orderNumber)
);
}

/**
* @throws Exception
*/
public function refund()
{
throw new Exception("Not implemented yet");
}

/**
* @throws Exception
*/
public function reverse()
{
throw new Exception("Not implemented yet");
}

/**
* @throws Exception
*/
public function deposit()
{
throw new Exception("Not implemented yet");
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace Stev\BTIPay\Exceptions;


class ValidationException extends \Exception
use Exception;

class ValidationException extends Exception
{

/**
Expand Down
78 changes: 44 additions & 34 deletions src/Model/BillingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Stev\BTIPay\Model;

use JMS\Serializer\Annotation as Serializer;
use Stev\BTIPay\Exceptions\InvalidValueException;
use Stev\BTIPay\Util\Countries;
use Stev\BTIPay\Util\Validator;

Expand All @@ -13,47 +14,54 @@ class BillingInfo
* @var string | null
* @Serializer\Type("string")
*/
private $deliveryType;
private ?string $deliveryType;

/**
* @var int
* @Serializer\Type("int")
*/
private $country;
private int $country;

/**
* @var string
* @Serializer\Type("string")
*/
private $city;
private string $city;

/**
* @var string
* @Serializer\Type("string")
*/
private $postAddress;
private string $postAddress;

/**
* @var string | null
* @Serializer\Type("string")
*/
private $postAddress2;
private ?string $postAddress2;

/**
* @var string | null
* @Serializer\Type("string")
*/
private $postAddress3;
private ?string $postAddress3;

/**
* @var string | null
* @Serializer\Type("string")
*/
private $postalCode;
private ?string $postalCode;

/**
* @var string | null
* @Serializer\Type("string")
*/
private $state;
private ?string $state;

/**
* @return string|null
*/
public function getDeliveryType()
public function getDeliveryType(): ?string
{
return $this->deliveryType;
}
Expand All @@ -62,7 +70,7 @@ public function getDeliveryType()
* @param string|null $deliveryType
* @return BillingInfo
*/
public function setDeliveryType($deliveryType)
public function setDeliveryType(?string $deliveryType): static
{
$this->deliveryType = $deliveryType;

Expand All @@ -72,23 +80,27 @@ public function setDeliveryType($deliveryType)
/**
* @return int
*/
public function getCountry()
public function getCountry(): int
{
return $this->country;
}

/**
* @param int $country
* @return BillingInfo
* @throws InvalidValueException
*/
public function setCountry($country)
public function setCountry(int $country): static
{
$this->country = Validator::validateCountry('billingInfo.country',$country);
$this->country = Validator::validateCountry('billingInfo.country', $country);

return $this;
}

public function setCountryAlpha2($countryName)
/**
* @throws InvalidValueException
*/
public function setCountryAlpha2($countryName): static
{
$this->setCountry(Countries::getCountryCodeByAlpha2($countryName));

Expand All @@ -98,7 +110,7 @@ public function setCountryAlpha2($countryName)
/**
* @return string
*/
public function getCity()
public function getCity(): string
{
return $this->city;
}
Expand All @@ -107,7 +119,7 @@ public function getCity()
* @param string $city
* @return BillingInfo
*/
public function setCity($city)
public function setCity(string $city): static
{
$this->city = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $city);

Expand All @@ -117,7 +129,7 @@ public function setCity($city)
/**
* @return string
*/
public function getPostAddress()
public function getPostAddress(): string
{
return $this->postAddress;
}
Expand All @@ -126,12 +138,12 @@ public function getPostAddress()
* @param string $postAddress
* @return BillingInfo
*/
public function setPostAddress($postAddress)
public function setPostAddress(string $postAddress): static
{
$this->postAddress = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $postAddress);

if(strlen($this->postAddress) >= 50){
$this->postAddress = str_replace(array("\n","\r"), ' ', substr($this->postAddress,0,49));
if (strlen($this->postAddress) >= 50) {
$this->postAddress = str_replace(array("\n", "\r"), ' ', substr($this->postAddress, 0, 49));
}

return $this;
Expand All @@ -140,7 +152,7 @@ public function setPostAddress($postAddress)
/**
* @return string|null
*/
public function getPostAddress2()
public function getPostAddress2(): ?string
{
return $this->postAddress2;
}
Expand All @@ -149,12 +161,12 @@ public function getPostAddress2()
* @param string|null $postAddress2
* @return BillingInfo
*/
public function setPostAddress2($postAddress2)
public function setPostAddress2($postAddress2): static
{
$this->postAddress2 = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $postAddress2);

if(strlen($this->postAddress2) >= 50){
$this->postAddress2 = str_replace(array("\n","\r"), ' ', substr($this->postAddress2,0,49));
if (strlen($this->postAddress2) >= 50) {
$this->postAddress2 = str_replace(array("\n", "\r"), ' ', substr($this->postAddress2, 0, 49));
}

return $this;
Expand All @@ -163,7 +175,7 @@ public function setPostAddress2($postAddress2)
/**
* @return string|null
*/
public function getPostAddress3()
public function getPostAddress3(): ?string
{
return $this->postAddress3;
}
Expand All @@ -172,12 +184,12 @@ public function getPostAddress3()
* @param string|null $postAddress3
* @return BillingInfo
*/
public function setPostAddress3($postAddress3)
public function setPostAddress3($postAddress3): static
{
$this->postAddress3 = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $postAddress3);

if(strlen($this->postAddress3) >= 50){
$this->postAddress3 = str_replace(array("\n","\r"), ' ', substr($this->postAddress3,0,49));
if (strlen($this->postAddress3) >= 50) {
$this->postAddress3 = str_replace(array("\n", "\r"), ' ', substr($this->postAddress3, 0, 49));
}

return $this;
Expand All @@ -186,7 +198,7 @@ public function setPostAddress3($postAddress3)
/**
* @return string|null
*/
public function getPostalCode()
public function getPostalCode(): ?string
{
return $this->postalCode;
}
Expand All @@ -195,7 +207,7 @@ public function getPostalCode()
* @param string|null $postalCode
* @return BillingInfo
*/
public function setPostalCode($postalCode)
public function setPostalCode(?string $postalCode): static
{
$this->postalCode = $postalCode;

Expand All @@ -205,7 +217,7 @@ public function setPostalCode($postalCode)
/**
* @return string|null
*/
public function getState()
public function getState(): ?string
{
return $this->state;
}
Expand All @@ -214,12 +226,10 @@ public function getState()
* @param string|null $state
* @return BillingInfo
*/
public function setState($state)
public function setState(?string $state): static
{
$this->state = $state;

return $this;
}


}
Loading

0 comments on commit 9d180a5

Please sign in to comment.