1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Omnipay\Redsys\Message; |
6
|
|
|
|
7
|
|
|
class AuthorizeRequest extends AbstractRequest |
8
|
|
|
{ |
9
|
|
|
use RedirectionTrait; |
10
|
|
|
|
11
|
|
|
public function getData() |
12
|
|
|
{ |
13
|
|
|
$this->validate('merchantId', 'terminalId', 'amount', 'currency'); |
14
|
|
|
|
15
|
|
|
return [ |
16
|
|
|
// mandatory fields |
17
|
|
|
'Ds_Merchant_MerchantCode' => $this->getMerchantId(), |
18
|
|
|
'Ds_Merchant_Terminal' => $this->getTerminalId(), |
19
|
|
|
'Ds_Merchant_TransactionType' => '1', // Authorisation |
20
|
|
|
'Ds_Merchant_Amount' => $this->getAmountInteger(), |
21
|
|
|
'Ds_Merchant_Currency' => $this->getCurrencyNumeric(), // uses ISO-4217 codes |
22
|
|
|
'Ds_Merchant_Order' => $this->getTransactionId(), |
23
|
|
|
'Ds_Merchant_MerchantUrl' => $this->getNotifyUrl(), |
24
|
|
|
// optional fields |
25
|
|
|
'Ds_Merchant_ProductDescription' => $this->getDescription(), |
26
|
|
|
'Ds_Merchant_Cardholder' => $this->getCardholder(), |
27
|
|
|
'Ds_Merchant_UrlOK' => $this->getReturnUrl(), |
28
|
|
|
'Ds_Merchant_UrlKO' => $this->getReturnUrl(), |
29
|
|
|
'Ds_Merchant_MerchantName' => $this->getMerchantName(), |
30
|
|
|
'Ds_Merchant_ConsumerLanguage' => $this->getConsumerLanguage(), |
31
|
|
|
'Ds_Merchant_MerchantData' => $this->getMerchantData(), |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function sendData($data) |
36
|
|
|
{ |
37
|
|
|
// Avoid sending null parameters, as Redsys will read the keyword null as a string "null" |
38
|
|
|
foreach ($data as $dataKey => $dataValue) { |
39
|
|
|
if (null === $dataValue) { |
40
|
|
|
unset($data[$dataKey]); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$security = new Security(); |
45
|
|
|
|
46
|
|
|
$encoded_data = $security->encodeMerchantParameters($data); |
47
|
|
|
|
48
|
|
|
$response_data = [ |
49
|
|
|
'Ds_SignatureVersion' => Security::VERSION, |
50
|
|
|
'Ds_MerchantParameters' => $encoded_data, |
51
|
|
|
'Ds_Signature' => $security->createSignature( |
52
|
|
|
$encoded_data, |
53
|
|
|
$data['Ds_Merchant_Order'], |
54
|
|
|
$this->getHmacKey() |
55
|
|
|
), |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
return $this->response = new PurchaseResponse($this, $response_data); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|