1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Getnet. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See LICENSE for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\PaymentMagento\Gateway\Request; |
10
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\Config; |
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
use Magento\Payment\Gateway\ConfigInterface; |
15
|
|
|
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
16
|
|
|
use Magento\Payment\Gateway\Request\BuilderInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Two Cc Refund Request - Refund data structure. |
20
|
|
|
*/ |
21
|
|
|
class TwoCcRefundRequest implements BuilderInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* External Payments - Block Name. |
25
|
|
|
*/ |
26
|
|
|
public const GETNET_PAYMENTS = 'payments'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* External Payment Id - Block Name. |
30
|
|
|
*/ |
31
|
|
|
public const GETNET_PAYMENT_ID = 'payment_id'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Amount block name. |
35
|
|
|
*/ |
36
|
|
|
public const GETNET_PAYMENT_TAG = 'payment_tag'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ConfigInterface |
40
|
|
|
*/ |
41
|
|
|
protected $config; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Config |
45
|
|
|
*/ |
46
|
|
|
protected $configPayment; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var ConfigCc |
50
|
|
|
*/ |
51
|
|
|
protected $configCc; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param ConfigInterface $config |
55
|
|
|
* @param Config $configPayment |
56
|
|
|
* @param ConfigCc $configCc |
57
|
|
|
*/ |
58
|
|
|
public function __construct( |
59
|
|
|
ConfigInterface $config, |
60
|
|
|
Config $configPayment, |
61
|
|
|
ConfigCc $configCc |
62
|
|
|
) { |
63
|
|
|
$this->config = $config; |
64
|
|
|
$this->configPayment = $configPayment; |
65
|
|
|
$this->configCc = $configCc; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Build. |
70
|
|
|
* |
71
|
|
|
* @param array $buildSubject |
72
|
|
|
*/ |
73
|
|
|
public function build(array $buildSubject) |
74
|
|
|
{ |
75
|
|
|
if (!isset($buildSubject['payment']) |
76
|
|
|
|| !$buildSubject['payment'] instanceof PaymentDataObjectInterface |
77
|
|
|
) { |
78
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
79
|
|
|
} |
80
|
|
|
$result = []; |
81
|
|
|
|
82
|
|
|
$paymentDO = $buildSubject['payment']; |
83
|
|
|
|
84
|
|
|
$payment = $paymentDO->getPayment(); |
85
|
|
|
|
86
|
|
|
$order = $paymentDO->getOrder(); |
87
|
|
|
|
88
|
|
|
$incrementId = $order->getOrderIncrementId(); |
89
|
|
|
|
90
|
|
|
$paymentId = $payment->getAdditionalInformation('payment_id'); |
91
|
|
|
|
92
|
|
|
$tagId = $incrementId.'-1'; |
93
|
|
|
|
94
|
|
|
$paymentIdSecondary = $payment->getAdditionalInformation('payment_id_secondary'); |
95
|
|
|
|
96
|
|
|
$tagIdSecondary = $incrementId.'-2'; |
97
|
|
|
|
98
|
|
|
$result[self::GETNET_PAYMENTS][] = [ |
99
|
|
|
self::GETNET_PAYMENT_ID => $paymentId, |
100
|
|
|
self::GETNET_PAYMENT_TAG => $tagId, |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
$result[self::GETNET_PAYMENTS][] = [ |
104
|
|
|
self::GETNET_PAYMENT_ID => $paymentIdSecondary, |
105
|
|
|
self::GETNET_PAYMENT_TAG => $tagIdSecondary, |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
return $result; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|