1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Omnipay\Paylike; |
4
|
|
|
|
5
|
|
|
use ByTIC\Omnipay\Paylike\Message\CaptureRequest; |
6
|
|
|
use ByTIC\Omnipay\Paylike\Message\CompletePurchaseRequest; |
7
|
|
|
use ByTIC\Omnipay\Paylike\Message\PurchaseRequest; |
8
|
|
|
//use ByTIC\Omnipay\Paylike\Message\ServerCompletePurchaseRequest; |
9
|
|
|
use ByTIC\Omnipay\Paylike\Traits\HasKeysTrait; |
10
|
|
|
use Omnipay\Common\AbstractGateway; |
11
|
|
|
use Omnipay\Common\Message\NotificationInterface; |
12
|
|
|
use Omnipay\Common\Message\RequestInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Gateway |
16
|
|
|
* @package ByTIC\Omnipay\Paylike |
17
|
|
|
* |
18
|
|
|
* @method RequestInterface authorize(array $options = []) |
19
|
|
|
* @method RequestInterface completeAuthorize(array $options = []) |
20
|
|
|
* @method RequestInterface refund(array $options = []) |
21
|
|
|
* @method RequestInterface void(array $options = []) |
22
|
|
|
* @method RequestInterface createCard(array $options = []) |
23
|
|
|
* @method RequestInterface updateCard(array $options = []) |
24
|
|
|
* @method RequestInterface deleteCard(array $options = []) |
25
|
|
|
* @method RequestInterface fetchTransaction(array $options = []) |
26
|
|
|
* @method NotificationInterface acceptNotification(array $options = array()) |
27
|
|
|
*/ |
28
|
|
|
class Gateway extends AbstractGateway |
29
|
|
|
{ |
30
|
|
|
use HasKeysTrait; |
31
|
|
|
|
32
|
|
|
public const VERSION = '1.0'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $prodApiHost = 'https://api.Paylike.com'; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
|
|
public function getName() |
44
|
|
|
{ |
45
|
|
|
return 'Paylike'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// ------------ REQUESTS ------------ // |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
* @return PurchaseRequest |
53
|
|
|
*/ |
54
|
|
|
public function purchase(array $parameters = []): RequestInterface |
55
|
|
|
{ |
56
|
|
|
return $this->createRequest( |
57
|
|
|
PurchaseRequest::class, |
58
|
|
|
array_merge($this->getDefaultParameters(), $parameters) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection |
63
|
|
|
* |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function getDefaultParameters() |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
|
|
'testMode' => true, // Must be the 1st in the list! |
70
|
|
|
'publicKey' => $this->getPublicKey(), |
71
|
|
|
'privateKey' => $this->getPrivateKey(), |
72
|
|
|
'apiUrl' => $this->getApiUrl() |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// ------------ PARAMETERS ------------ // |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param boolean $value |
80
|
|
|
* @return $this|AbstractGateway |
81
|
|
|
*/ |
82
|
|
|
public function setTestMode($value) |
83
|
|
|
{ |
84
|
|
|
$this->parameters->remove('apiUrl'); |
85
|
|
|
$this->parameters->remove('secureUrl'); |
86
|
|
|
return parent::setTestMode($value); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// ------------ Getter'n'Setters ------------ // |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get live- or testURL. |
93
|
|
|
*/ |
94
|
|
|
public function getApiUrl() |
95
|
|
|
{ |
96
|
|
|
$defaultUrl = $this->getTestMode() === false |
97
|
|
|
? $this->prodApiHost |
98
|
|
|
: $this->prodApiHost; |
99
|
|
|
return $this->parameters->get('apiUrl', $defaultUrl); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
* @return CompletePurchaseRequest |
105
|
|
|
*/ |
106
|
|
|
public function completePurchase(array $parameters = []): RequestInterface |
107
|
|
|
{ |
108
|
|
|
return $this->createRequest( |
109
|
|
|
CompletePurchaseRequest::class, |
110
|
|
|
array_merge($this->getDefaultParameters(), $parameters) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @inheritdoc |
116
|
|
|
* @return CaptureRequest |
117
|
|
|
*/ |
118
|
|
|
public function capture(array $parameters = []): RequestInterface |
119
|
|
|
{ |
120
|
|
|
return $this->createRequest( |
121
|
|
|
CaptureRequest::class, |
122
|
|
|
array_merge($this->getDefaultParameters(), $parameters) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
|
|
// public function serverCompletePurchase(array $parameters = []): RequestInterface |
130
|
|
|
// { |
131
|
|
|
// return $this->createRequest( |
132
|
|
|
// ServerCompletePurchaseRequest::class, |
133
|
|
|
// array_merge($this->getDefaultParameters(), $parameters) |
134
|
|
|
// ); |
135
|
|
|
// } |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param $value |
139
|
|
|
* @return $this |
140
|
|
|
*/ |
141
|
|
|
public function setApiUrl($value) |
142
|
|
|
{ |
143
|
|
|
return $this->setParameter('apiUrl', $value); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|