Skip to content

Commit

Permalink
added init
Browse files Browse the repository at this point in the history
  • Loading branch information
avorontsov committed Feb 11, 2020
0 parents commit 3273eeb
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 0 deletions.
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "sch-group/ips-payment",
"keywords": ["IPS-payment", "payment", "gateway", "ips", "php"],
"homepage": "https://github.com/sch-group/ips-payment",
"description": "Package to connect IPS-PAYMENT gateway",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Anton Vorontsov",
"email": "[email protected]",
"role": "Creator"
}
],
"require": {
"php": ">=7.2",
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"phpunit/phpunit": "^6.3"
},
"autoload": {
"psr-4": {
"SchGroup\\IpsPayment\\" : "src/"
}
},
"autoload-dev": {
"psr-4": {
"SchGroup\\IpsPayment\\Tests\\": "tests/"
}
}
}
35 changes: 35 additions & 0 deletions src/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace SchGroup\IpsPayment;

class Customer
{
/**
* @var string
*/
public $customerName;
/**
* @var string
*/
public $customerEmail;
/**
* @var string
*/
public $customerPhone;

/**
* Customer constructor.
* @param string $customerName
* @param string|null $customerEmail
* @param string|null $customerPhone
*/
public function __construct(
string $customerName,
?string $customerEmail = null,
?string $customerPhone = null
) {
$this->customerName = $customerName;
$this->customerEmail = $customerEmail;
$this->customerPhone = $customerPhone;
}
}
50 changes: 50 additions & 0 deletions src/IpsPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace SchGroup\IpsPayment;

use GuzzleHttp\Exception\GuzzleException;
use Psr\Log\{NullLogger, LoggerInterface};
use GuzzleHttp\ClientInterface;

class IpsPayment
{
/**
* @var NullLogger
*/
private $logger;

const API_URL = "https://wws.ips-payment.com";
/**
* @var string
*/
private $apiKey;
/**
* @var ClientInterface
*/
private $client;

/**
* IpsPayment constructor.
* @param string $apiKey
* @param ClientInterface $client
*/
public function __construct(string $apiKey, ClientInterface $client, LoggerInterface $logger)
{
$this->apiKey = $apiKey;
$this->client = $client;
$this->logger = $logger;
}


/**
* @param Transaction $transaction
* @return string
*/
public function buildLink(Transaction $transaction): string
{
return self::API_URL .'?'. http_build_query($transaction->toArray());
}

}
42 changes: 42 additions & 0 deletions src/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace SchGroup\IpsPayment;

class Order
{
/**
* @var float
*/
public $amount;
/**
* @var string
*/
public $Subscribe_Period;
/**
* @var string
*/
public $RefOrder;
/**
* @var string
*/
public $Subscribe;

/**
* Order constructor.
* @param string $RefOrder
* @param float $amount
* @param string|null $Subscribe
* @param string|null $Subscribe_Period
*/
public function __construct(
string $RefOrder,
float $amount,
?string $Subscribe = null,
?string $Subscribe_Period = null
) {
$this->RefOrder = $RefOrder;
$this->Subscribe = $Subscribe;
$this->Subscribe_Period = $Subscribe_Period;
$this->amount = $amount;
}
}
43 changes: 43 additions & 0 deletions src/ShopSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace SchGroup\IpsPayment;

class ShopSettings
{
/**
* @var string
*/
public $urlIPN;
/**
* @var string
*/
public $Integrated;
/**
* @var string
*/
public $urlOK;
/**
* @var string
*/
public $lang;

/**
* ShopSettings constructor.
* @param string $urlIPN
* @param string $urlOK
* @param string|null $Integrated
* @param string $lang
*/
public function __construct(
string $urlIPN,
string $urlOK,
?string $Integrated = null,
string $lang = 'en'
) {
$this->urlIPN = $urlIPN;
$this->urlOK = $urlOK;
$this->Integrated = $Integrated;

$this->lang = $lang;
}
}
52 changes: 52 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace SchGroup\IpsPayment;

class Transaction
{
/**
* @var Customer
*/
private $customer;
/**
* @var Order
*/
private $order;
/**
* @var ShopSettings
*/
private $shopSettings;

/**
* Transaction constructor.
* @param Order $order
* @param Customer $customer
* @param ShopSettings $shopSettings
*/
public function __construct(
Order $order,
Customer $customer,
ShopSettings $shopSettings
) {
$this->customer = $customer;
$this->order = $order;
$this->shopSettings = $shopSettings;
}

/**
* @return array
*/
public function toArray(): array
{
return [
"MerchantKey"=> '8545e3aa27ba62e0API5e3aa27ba62e1',
"RefOrder" => $this->order->RefOrder,
"amount" => $this->order->amount,
"Customer_Name" => $this->customer->customerName,
"Customer_Email" => $this->customer->customerEmail,
"Customer_Phone" => $this->customer->customerPhone,
"Integrated" => $this->shopSettings->Integrated,
"lang" => $this->shopSettings->lang
];
}
}

0 comments on commit 3273eeb

Please sign in to comment.