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