Skip to content

Commit

Permalink
Merge pull request #1 from inxy-payments/v2.0
Browse files Browse the repository at this point in the history
FEATURE: release for php7
  • Loading branch information
inxy-payments authored Sep 13, 2022
2 parents 31fecdf + 2d12081 commit ce5f537
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 49 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^5.6",
"php": "^7.0",
"guzzlehttp/guzzle": "^6.5",
"ext-json": "*"
},
Expand Down
10 changes: 5 additions & 5 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ class Config
* @param string $apiKey
* @param string|null $apiVersion
*/
public function __construct($environment, $apiKey, $apiVersion = null)
public function __construct(string $environment, string $apiKey, string $apiVersion = null)
{
$this->url = $environment === Environment::Production ? ApiUrl::Production : ApiUrl::Sandbox;
$this->apiKey = $apiKey;
$this->apiVersion = $apiVersion === null ? ApiVersion::v1 : $apiVersion;
$this->apiVersion = $apiVersion ?? ApiVersion::v1;
}

/**
* @return string
*/
public function getUrl()
public function getUrl(): string
{
return $this->url;
}

/**
* @return string
*/
public function getApiKey()
public function getApiKey(): string
{
return $this->apiKey;
}

/**
* @return string
*/
public function getApiVersion()
public function getApiVersion(): string
{
return $this->apiVersion;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Api/Sessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Sessions extends ApiResource
* @param SessionRequest $request
* @return SessionResponse
*/
public function create(SessionRequest $request)
public function create(SessionRequest $request): SessionResponse
{
$response = $this->client->post(Route::SessionsCreate, [
'json' => $request->toArray()
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Client extends GuzzleClient
* @param string $apiToken
* @param string $apiVersion
*/
public function __construct($url, $apiToken, $apiVersion)
public function __construct(string $url, string $apiToken, string $apiVersion)
{
$this->apiVersion = $apiVersion;

Expand All @@ -38,7 +38,7 @@ public function __construct($url, $apiToken, $apiVersion)
* @param array $options
* @return ResponseInterface
*/
public function post($uri, array $options = [])
public function post($uri, array $options = []): ResponseInterface
{
return parent::post(self::ApiPrefix . $this->apiVersion . $uri, $options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Factories/ApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ApiFactory
* @param Config $config
* @return Api
*/
public static function createApi(Config $config)
public static function createApi(Config $config): Api
{
$client = new Client($config->getUrl(), $config->getApiKey(), $config->getApiVersion());

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/Dto/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Customer implements Arrayable
* @param string|null $firstName
* @param string|null $secondName
*/
public function __construct($email, $firstName = null, $secondName = null)
public function __construct(string $email, string $firstName = null, string $secondName = null)
{
$this->email = $email;
$this->firstName = $firstName;
Expand All @@ -34,7 +34,7 @@ public function __construct($email, $firstName = null, $secondName = null)
/**
* @return array
*/
public function toArray()
public function toArray(): array
{
return [
'email' => $this->email,
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Requests/SessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SessionRequest extends Request
* @param float $fiatAmount
* @param string $orderName
*/
public function __construct($fiatAmount, $orderName)
public function __construct(float $fiatAmount, string $orderName)
{
$this->fiatAmount = $fiatAmount;
$this->orderName = $orderName;
Expand All @@ -52,7 +52,7 @@ public function __construct($fiatAmount, $orderName)
/**
* @param string $orderId
*/
public function setOrderId($orderId)
public function setOrderId(string $orderId)
{
$this->orderId = $orderId;
}
Expand All @@ -68,23 +68,23 @@ public function setCryptocurrencies(array $cryptocurrencies)
/**
* @param string $postbackUrl
*/
public function setPostbackUrl($postbackUrl)
public function setPostbackUrl(string $postbackUrl)
{
$this->postbackUrl = $postbackUrl;
}

/**
* @param string $successUrl
*/
public function setSuccessUrl($successUrl)
public function setSuccessUrl(string $successUrl)
{
$this->successUrl = $successUrl;
}

/**
* @param string $cancelUrl
*/
public function setCancelUrl($cancelUrl)
public function setCancelUrl(string $cancelUrl)
{
$this->cancelUrl = $cancelUrl;
}
Expand All @@ -100,7 +100,7 @@ public function setCustomer(Customer $customer)
/**
* @return array
*/
public function toArray()
public function toArray(): array
{
return [
'fiat_amount' => $this->fiatAmount,
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Responses/SessionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class SessionResponse
/**
* @param string $redirectUri
*/
public function __construct($redirectUri)
public function __construct(string $redirectUri)
{
$this->redirectUri = $redirectUri;
}

/**
* @return string
*/
public function getRedirectUri()
public function getRedirectUri(): string
{
return $this->redirectUri;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/Arrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface Arrayable
/**
* @return array
*/
public function toArray();
public function toArray(): array;
}
2 changes: 1 addition & 1 deletion src/MerchantSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Config $config)
* @param SessionRequest $request
* @return SessionResponse
*/
public function createSession(SessionRequest $request)
public function createSession(SessionRequest $request): SessionResponse
{
return $this->api->sessions->create($request);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Webhooks/Dto/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class Webhook
public $name;

/**
* @param $id
* @param $object
* @param $name
* @param int $id
* @param string $object
* @param string $name
*/
public function __construct($id, $object, $name)
public function __construct(int $id, string $object, string $name)
{
$this->id = $id;
$this->object = $object;
Expand Down
8 changes: 0 additions & 8 deletions src/Webhooks/Dto/WebhookData.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Webhooks/Factories/Dto/CustomersFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomersFactory
* @param stdClass $customer
* @return Customer
*/
public static function create(stdClass $customer)
public static function create(stdClass $customer): Customer
{
if (!property_exists($customer, 'object') || $customer->object !== ObjectName::Customer) {
throw new InvalidArgumentException('Customer param must be object with name customer');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/Dto/PaymentIntentsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PaymentIntentsFactory
* @param stdClass $paymentIntent
* @return PaymentIntent
*/
public static function create(stdClass $paymentIntent)
public static function create(stdClass $paymentIntent): PaymentIntent
{
if (!property_exists($paymentIntent, 'object') || $paymentIntent->object !== ObjectName::PaymentIntent) {
throw new InvalidArgumentException('Payment intent param must be object with name payment_intent');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/Dto/PaymentsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PaymentsFactory
* @param stdClass $payment
* @return Payment
*/
public static function create(stdClass $payment)
public static function create(stdClass $payment): Payment
{
if (!property_exists($payment, 'object') || $payment->object !== ObjectName::Payment) {
throw new InvalidArgumentException('Payment param must be object with name payment');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/Dto/SessionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SessionsFactory
* @param stdClass $session
* @return Session
*/
public static function create(stdClass $session)
public static function create(stdClass $session): Session
{
if (!property_exists($session, 'object') || $session->object !== ObjectName::Session) {
throw new InvalidArgumentException('Session param must be object with name session');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/PaymentsCanceledWebhookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PaymentsCanceledWebhookFactory
* @param stdClass $webhook
* @return PaymentCanceledWebhook
*/
public static function create(stdClass $webhook)
public static function create(stdClass $webhook): PaymentCanceledWebhook
{
if (!property_exists($webhook, 'object') || $webhook->object !== ObjectName::Webhook) {
throw new InvalidArgumentException('Webhook param must be object with name webhook');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/PaymentsExpiredWebhookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PaymentsExpiredWebhookFactory
* @param stdClass $webhook
* @return PaymentExpiredWebhook
*/
public static function create(stdClass $webhook)
public static function create(stdClass $webhook): PaymentExpiredWebhook
{
if (!property_exists($webhook, 'object') || $webhook->object !== ObjectName::Webhook) {
throw new InvalidArgumentException('Webhook param must be object with name webhook');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/PaymentsInitWebhookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PaymentsInitWebhookFactory
* @param stdClass $webhook
* @return PaymentInitWebhook
*/
public static function create(stdClass $webhook)
public static function create(stdClass $webhook): PaymentInitWebhook
{
if (!property_exists($webhook, 'object') || $webhook->object !== ObjectName::Webhook) {
throw new InvalidArgumentException('Webhook param must be object with name webhook');
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks/Factories/PaymentsReceivedWebhookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PaymentsReceivedWebhookFactory
* @param stdClass $webhook
* @return PaymentCanceledWebhook
*/
public static function create(stdClass $webhook)
public static function create(stdClass $webhook): PaymentCanceledWebhook
{
if (!property_exists($webhook, 'object') || $webhook->object !== ObjectName::Webhook) {
throw new InvalidArgumentException('Webhook param must be object with name webhook');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PaymentsWaitingConfirmationsWebhookFactory
* @param stdClass $webhook
* @return PaymentWaitingConfirmationsWebhook
*/
public static function create(stdClass $webhook)
public static function create(stdClass $webhook): PaymentWaitingConfirmationsWebhook
{
if (!property_exists($webhook, 'object') || $webhook->object !== ObjectName::Webhook) {
throw new InvalidArgumentException('Webhook param must be object with name webhook');
Expand Down
12 changes: 6 additions & 6 deletions src/Webhooks/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class Validator
/**
* @param string $secretKey
*/
public function __construct($secretKey)
public function __construct(string $secretKey)
{
$this->secretKey = $secretKey;
}

/**
* @param $payload
* @param $signedHash
* @param string $payload
* @param string $signedHash
* @return bool
*/
public function isValid($payload, $signedHash)
public function isValid(string $payload, string $signedHash): bool
{
return hash_equals($signedHash, $this->hash($payload));
}

/**
* @param $payload
* @param string $payload
* @return string
*/
private function hash($payload)
private function hash(string $payload): string
{
return hash_hmac('sha256', $payload, $this->secretKey);
}
Expand Down

0 comments on commit ce5f537

Please sign in to comment.