Adinots.pl
Karmia
- Joined
- Oct 26, 2018
- Messages
- 25
- Reaction score
- 0
Hello .. I would like to add to Gesior acc new payment method (Getpay)
I have script from Getpay but I can not do it.
I have script from Getpay but I can not do it.
Code:
<?php
class GetPaySMS
{
//Request
private $apiKey;
private $apiSecret;
private $number;
private $code;
private $unlimited;
private $url;
//Response
private $infoCode = null;
private $info = null;
private $response = FALSE;
private $test = FALSE;
//Info enum
private $infoEnum = array(
100 => 'Empty method',
102 => 'Empty params',
104 => 'Wrong length of client API login data (key/secret)',
105 => 'Wrong client API login data (key/secret)',
106 => 'Wrong client status',
107 => 'No method require params',
200 => 'OK',
400 => 'SMS code not found',
401 => 'SMS code already used',
402 => 'System error'
);
public function __construct($apiKey, $apiSecret)
{
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
//URL GetPaySMS API
$this->url = 'https://getpay.pl/panel/app/common/resource/ApiResource.php';
}
public function getStatus($number, $code, $unlimited = FALSE)
{
$this->number = $number;
$this->code = $code;
$this->unlimited = $unlimited;
$bodyJSON = json_encode(array('apiKey' => $this->apiKey, 'apiSecret' => $this->apiSecret, 'number' => $this->number, 'code' => $this->code, 'unlimited' => $this->unlimited));
$options = array(
'http' => array(
'header' => 'Content-Type: application/json',
'method' => 'POST',
'content' => $bodyJSON
)
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($this->url, FALSE, $context));
if ($result === FALSE) {
$this->createResponse(402);
return $this;
} else {
if (isset($result->infoCode)) {
if (isset($result->response) && isset($result->test)) {
$this->createResponse($result->infoCode, $result->response, $result->test);
return $this;
} else {
$this->createResponse($result->infoCode);
return $this;
}
} else {
$this->createResponse(402);
return $this;
}
}
}
private function createResponse($infoCode, $response = null, $test = null)
{
if (isset($response) && isset($test)) {
$this->infoCode = $infoCode;
$this->info = $this->infoEnum[$infoCode];
$this->response = $response;
$this->test;
} else {
$this->infoCode = $infoCode;
$this->info = $this->infoEnum[$infoCode];
}
}
//Getters
public function getNumber()
{
return $this->number;
}
public function getCode()
{
return $this->code;
}
public function getUnlimited()
{
return $this->unlimited;
}
public function getInfoCode()
{
return $this->infoCode;
}
public function getInfo()
{
return $this->info;
}
public function getResponse()
{
return $this->response;
}
public function getTest()
{
return $this->test;
}
}