Skip to content

Commit 86c1aca

Browse files
Class separation
1 parent 09d11f7 commit 86c1aca

File tree

3 files changed

+158
-154
lines changed

3 files changed

+158
-154
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simpaypl/simpay",
33
"description": "Official SimPay API",
44
"type": "library",
5-
"version": "1.2",
5+
"version": "1.3",
66
"license": "MIT",
77
"minimum-stability": "stable",
88
"require": {

src/Directbilling.php

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -327,156 +327,3 @@ private function url($value, $params = array())
327327
return $this->call;
328328
}
329329
}
330-
331-
class DirectbillingTransactions extends Components
332-
{
333-
334-
protected $requestOptions = [
335-
'serviceId' => null,
336-
'amount' => null,
337-
'amount_gross' => null,
338-
'amount_required' => null,
339-
'provider' => null,
340-
'control' => null,
341-
'failure' => null,
342-
'complete' => null,
343-
'sign' => null
344-
];
345-
346-
protected $apiKey = '';
347-
protected $apiSecret = '';
348-
349-
protected $resultInstance = null;
350-
351-
protected $debugMode = false;
352-
353-
public function __construct()
354-
{
355-
$this->components = new Components();
356-
}
357-
358-
public function setDebugMode($value)
359-
{
360-
$this->debugMode = (boolean)$value;
361-
}
362-
363-
private function isDebugMode()
364-
{
365-
return !!$this->debugMode;
366-
}
367-
368-
private function logDebugMode($err)
369-
{
370-
print_r($err);
371-
372-
error_log($err);
373-
}
374-
375-
public function setServiceID($id)
376-
{
377-
$this->requestOptions['serviceId'] = $id;
378-
}
379-
380-
public function setAmount($amount)
381-
{
382-
$this->requestOptions['amount'] = $amount;
383-
384-
$this->requestOptions['amount_gross'] = null;
385-
$this->requestOptions['amount_required'] = null;
386-
}
387-
388-
public function setAmountGross($amount)
389-
{
390-
$this->requestOptions['amount'] = null;
391-
392-
$this->requestOptions['amount_gross'] = $amount;
393-
$this->requestOptions['amount_required'] = null;
394-
}
395-
396-
public function setAmountRequired($amount)
397-
{
398-
$this->requestOptions['amount'] = null;
399-
400-
$this->requestOptions['amount_gross'] = null;
401-
$this->requestOptions['amount_required'] = $amount;
402-
}
403-
404-
public function setProvider($provider)
405-
{
406-
$this->requestOptions['provider'] = $provider;
407-
}
408-
409-
public function setControl($control)
410-
{
411-
$this->requestOptions['control'] = $control;
412-
}
413-
414-
public function setFailureLink($link)
415-
{
416-
$this->requestOptions['failure'] = $link;
417-
}
418-
419-
public function setCompleteLink($link)
420-
{
421-
$this->requestOptions['complete'] = $link;
422-
}
423-
424-
public function setApiKey($key)
425-
{
426-
$this->apiKey = $key;
427-
}
428-
429-
public function setApiSecret($secret)
430-
{
431-
$this->apiSecret = $secret;
432-
}
433-
434-
protected function generateSign()
435-
{
436-
$hash = '';
437-
438-
if ($this->requestOptions['amount']) {
439-
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount'] . $this->requestOptions['control'] . $this->apiKey);
440-
} elseif ($this->requestOptions['amount_gross']) {
441-
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount_gross'] . $this->requestOptions['control'] . $this->apiKey);
442-
} elseif ($this->requestOptions['amount_required']) {
443-
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount_required'] . $this->requestOptions['control'] . $this->apiKey);
444-
}
445-
446-
return $hash;
447-
}
448-
449-
public function getTransactionLink()
450-
{
451-
if (!isset($this->resultInstance->link)) {
452-
return false;
453-
}
454-
455-
return $this->resultInstance->link;
456-
}
457-
458-
public function getResults()
459-
{
460-
return $this->resultInstance;
461-
}
462-
463-
public function generateTransaction()
464-
{
465-
466-
$this->requestOptions['sign'] = $this->generateSign();
467-
468-
try {
469-
$this->resultInstance = $this->components->request($this->requestOptions, "https://simpay.pl/db/api");
470-
} catch (Exception $err) {
471-
if ($this->isDebugMode()) {
472-
$this->logDebugMode($err);
473-
}
474-
}
475-
476-
if ($this->resultInstance->status != 'success') {
477-
if ($this->isDebugMode()) {
478-
$this->logDebugMode($this->resultInstance->message);
479-
}
480-
}
481-
}
482-
}

src/DirectbillingTransactions.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
namespace simpay;
4+
5+
use simpay\Components;
6+
7+
class DirectbillingTransactions extends Components
8+
{
9+
protected $requestOptions = [
10+
'serviceId' => null,
11+
'amount' => null,
12+
'amount_gross' => null,
13+
'amount_required' => null,
14+
'provider' => null,
15+
'control' => null,
16+
'failure' => null,
17+
'complete' => null,
18+
'sign' => null
19+
];
20+
21+
protected $apiKey = '';
22+
protected $apiSecret = '';
23+
24+
protected $resultInstance = null;
25+
26+
protected $debugMode = false;
27+
28+
public function __construct()
29+
{
30+
$this->components = new Components();
31+
}
32+
33+
public function setDebugMode($value)
34+
{
35+
$this->debugMode = (boolean)$value;
36+
}
37+
38+
private function isDebugMode()
39+
{
40+
return !!$this->debugMode;
41+
}
42+
43+
private function logDebugMode($err)
44+
{
45+
print_r($err);
46+
47+
error_log($err);
48+
}
49+
50+
public function setServiceID($id)
51+
{
52+
$this->requestOptions['serviceId'] = $id;
53+
}
54+
55+
public function setAmount($amount)
56+
{
57+
$this->requestOptions['amount'] = $amount;
58+
59+
$this->requestOptions['amount_gross'] = null;
60+
$this->requestOptions['amount_required'] = null;
61+
}
62+
63+
public function setAmountGross($amount)
64+
{
65+
$this->requestOptions['amount'] = null;
66+
67+
$this->requestOptions['amount_gross'] = $amount;
68+
$this->requestOptions['amount_required'] = null;
69+
}
70+
71+
public function setAmountRequired($amount)
72+
{
73+
$this->requestOptions['amount'] = null;
74+
75+
$this->requestOptions['amount_gross'] = null;
76+
$this->requestOptions['amount_required'] = $amount;
77+
}
78+
79+
public function setProvider($provider)
80+
{
81+
$this->requestOptions['provider'] = $provider;
82+
}
83+
84+
public function setControl($control)
85+
{
86+
$this->requestOptions['control'] = $control;
87+
}
88+
89+
public function setFailureLink($link)
90+
{
91+
$this->requestOptions['failure'] = $link;
92+
}
93+
94+
public function setCompleteLink($link)
95+
{
96+
$this->requestOptions['complete'] = $link;
97+
}
98+
99+
public function setApiKey($key)
100+
{
101+
$this->apiKey = $key;
102+
}
103+
104+
public function setApiSecret($secret)
105+
{
106+
$this->apiSecret = $secret;
107+
}
108+
109+
protected function generateSign()
110+
{
111+
$hash = '';
112+
113+
if ($this->requestOptions['amount']) {
114+
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount'] . $this->requestOptions['control'] . $this->apiKey);
115+
} elseif ($this->requestOptions['amount_gross']) {
116+
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount_gross'] . $this->requestOptions['control'] . $this->apiKey);
117+
} elseif ($this->requestOptions['amount_required']) {
118+
$hash = hash('sha256', $this->requestOptions['serviceId'] . $this->requestOptions['amount_required'] . $this->requestOptions['control'] . $this->apiKey);
119+
}
120+
121+
return $hash;
122+
}
123+
124+
public function getTransactionLink()
125+
{
126+
if (!isset($this->resultInstance->link)) {
127+
return false;
128+
}
129+
130+
return $this->resultInstance->link;
131+
}
132+
133+
public function getResults()
134+
{
135+
return $this->resultInstance;
136+
}
137+
138+
public function generateTransaction()
139+
{
140+
141+
$this->requestOptions['sign'] = $this->generateSign();
142+
143+
try {
144+
$this->resultInstance = $this->components->request($this->requestOptions, "https://simpay.pl/db/api");
145+
} catch (Exception $err) {
146+
if ($this->isDebugMode()) {
147+
$this->logDebugMode($err);
148+
}
149+
}
150+
151+
if ($this->resultInstance->status != 'success') {
152+
if ($this->isDebugMode()) {
153+
$this->logDebugMode($this->resultInstance->message);
154+
}
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)