1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Empatix\OmnipaySwedbank\Messages; |
4
|
|
|
|
5
|
|
|
use Empatix\OmnipaySwedbank\Gateway; |
6
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
7
|
|
|
use Empatix\OmnipaySwedbank\Messages\Response; |
8
|
|
|
|
9
|
|
|
class PurchaseRequest extends AbstractRequest |
10
|
|
|
{ |
11
|
|
|
protected $resource = '/psp/creditcard/payments'; |
12
|
|
|
protected $productionEndpoint = 'https://api.payex.com'; |
13
|
|
|
protected $testEndpoint = 'https://api.externalintegration.payex.com'; |
14
|
|
|
|
15
|
|
|
public function setPassword($value) |
16
|
|
|
{ |
17
|
|
|
$this->setParameter('password', $value); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getPassword() |
21
|
|
|
{ |
22
|
|
|
return $this->getParameter('password'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function setLanguage($value) |
26
|
|
|
{ |
27
|
|
|
$this->setParameter('language', $value); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getLanguage() |
31
|
|
|
{ |
32
|
|
|
return $this->getParameter('language'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function setMetaData($value) |
36
|
|
|
{ |
37
|
|
|
$this->setParameter('metadata', $value); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getMetaData() |
41
|
|
|
{ |
42
|
|
|
return $this->getParameter('metadata'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function setAfterUrl($value) |
46
|
|
|
{ |
47
|
|
|
$this->setParameter('afterUrl', $value); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getAfterUrl() |
51
|
|
|
{ |
52
|
|
|
return $this->getParameter('afterUrl'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setMerchantId($value) |
56
|
|
|
{ |
57
|
|
|
return $this->setParameter('merchantId', $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getMerchantId() |
61
|
|
|
{ |
62
|
|
|
return $this->getParameter('merchantId'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setVatAmount($value) |
66
|
|
|
{ |
67
|
|
|
$this->setParameter('vatAmount', $value); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getVatAmount() |
71
|
|
|
{ |
72
|
|
|
return $this->getParameter('vatAmount'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setUserAgent($value) |
76
|
|
|
{ |
77
|
|
|
$this->setParameter('userAgent', $value); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getUserAgent() |
81
|
|
|
{ |
82
|
|
|
return $this->getParameter('userAgent'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setPayeeId($value) |
86
|
|
|
{ |
87
|
|
|
$this->setParameter('payeeId', $value); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getPayeeId() |
91
|
|
|
{ |
92
|
|
|
return $this->getParameter('payeeId'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setPayeeReference($value) |
96
|
|
|
{ |
97
|
|
|
$this->setParameter('payeeReference', $value); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getPayeeReference() |
101
|
|
|
{ |
102
|
|
|
return $this->getParameter('payeeReference'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function sendData($data) |
106
|
|
|
{ |
107
|
|
|
$result = $this->httpClient->request( |
108
|
|
|
'POST', |
109
|
|
|
$this->getEndpoint() . $this->resource, |
110
|
|
|
[ |
111
|
|
|
'Authorization' => 'Bearer ' . $this->getPassword(), |
112
|
|
|
'Content-Type' => 'application/json; charset=utf-8', |
113
|
|
|
'Accept' => 'application/problem+json; q=1.0, application/json; q=0.9', |
114
|
|
|
], |
115
|
|
|
json_encode($data) |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$this->response = new Response( |
119
|
|
|
$this, |
120
|
|
|
json_decode($result->getBody()->getContents(), true) |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
return $this->response; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getData() |
127
|
|
|
{ |
128
|
|
|
return [ |
129
|
|
|
'payment' => [ |
130
|
|
|
'operation' => 'Purchase', |
131
|
|
|
'intent' => 'AutoCapture', |
132
|
|
|
'currency' => $this->getCurrency(), |
133
|
|
|
'prices' => [ |
134
|
|
|
[ |
135
|
|
|
'type' => 'CreditCard', |
136
|
|
|
'vatAmount' => $this->getVatAmount(), |
137
|
|
|
'amount' => $this->getAmountInteger(), |
138
|
|
|
] |
139
|
|
|
], |
140
|
|
|
'language' => $this->getLanguage(), |
141
|
|
|
'userAgent' => $this->getUserAgent(), |
142
|
|
|
'description' => $this->getDescription(), |
143
|
|
|
'urls' => [ |
144
|
|
|
'cancelUrl' => $this->getCancelUrl(), |
145
|
|
|
'completeUrl' => $this->getReturnUrl(), |
146
|
|
|
'callbackUrl' => $this->getNotifyUrl(), |
147
|
|
|
], |
148
|
|
|
'payeeInfo' => [ |
149
|
|
|
'payeeId' => $this->getPayeeId(), |
150
|
|
|
'payeeReference' => $this->getPayeeReference(), |
151
|
|
|
], |
152
|
|
|
'metadata' => $this->getMetaData(), |
153
|
|
|
], |
154
|
|
|
]; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
protected function getEndpoint() |
158
|
|
|
{ |
159
|
|
|
return $this->getTestMode() ? $this->testEndpoint : $this->productionEndpoint; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|