|
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\Response; |
|
10
|
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\Config; |
|
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigBoleto; |
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
|
15
|
|
|
use Magento\Payment\Gateway\Response\HandlerInterface; |
|
16
|
|
|
use Magento\Sales\Model\Order\Payment\Transaction; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Txn Id Getpay Handler - Handles reading responses for Getpay payment. |
|
20
|
|
|
*/ |
|
21
|
|
|
class TxnIdGetpayHandler implements HandlerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Getpay Link - Payment Addtional Information. |
|
26
|
|
|
*/ |
|
27
|
|
|
public const PAYMENT_INFO_GETPAY_LINK = 'getpay_link'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Getpay Expiration Date - Payment Addtional Information. |
|
31
|
|
|
*/ |
|
32
|
|
|
public const PAYMENT_INFO_GETPAY_EXPIRATION_DATE = 'getpay_expiration_date'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Response Pay Link Id - Block name. |
|
36
|
|
|
*/ |
|
37
|
|
|
public const RESPONSE_LINK_ID = 'link_id'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Response Pay Url - Block name. |
|
41
|
|
|
*/ |
|
42
|
|
|
public const RESPONSE_URL = 'url'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Response Pay Expiration - Block name. |
|
46
|
|
|
*/ |
|
47
|
|
|
public const RESPONSE_GETPAY_EXPIRATION = 'expiration'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Config |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $config; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var ConfigBoleto |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $configBoleto; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param Config $config |
|
61
|
|
|
* @param ConfigBoleto $configBoleto |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct( |
|
64
|
|
|
Config $config, |
|
65
|
|
|
ConfigBoleto $configBoleto |
|
66
|
|
|
) { |
|
67
|
|
|
$this->config = $config; |
|
68
|
|
|
$this->configBoleto = $configBoleto; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Handles. |
|
73
|
|
|
* |
|
74
|
|
|
* @param array $handlingSubject |
|
75
|
|
|
* @param array $response |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function handle(array $handlingSubject, array $response) |
|
80
|
|
|
{ |
|
81
|
|
|
if (!isset($handlingSubject['payment']) |
|
82
|
|
|
|| !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
|
83
|
|
|
) { |
|
84
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$paymentDO = $handlingSubject['payment']; |
|
88
|
|
|
|
|
89
|
|
|
$payment = $paymentDO->getPayment(); |
|
90
|
|
|
|
|
91
|
|
|
$payment->setAdditionalInformation( |
|
92
|
|
|
self::PAYMENT_INFO_GETPAY_LINK, |
|
93
|
|
|
$response[self::RESPONSE_URL] |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$payment->setAdditionalInformation( |
|
97
|
|
|
self::PAYMENT_INFO_GETPAY_EXPIRATION_DATE, |
|
98
|
|
|
$response[self::RESPONSE_GETPAY_EXPIRATION] |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$transactionId = $response[self::RESPONSE_LINK_ID]; |
|
102
|
|
|
$payment->setTransactionId($transactionId); |
|
103
|
|
|
$payment->setIsTransactionPending(1); |
|
104
|
|
|
$payment->setIsTransactionClosed(false); |
|
105
|
|
|
$payment->setAuthorizationTransaction($transactionId); |
|
106
|
|
|
$payment->addTransaction(Transaction::TYPE_AUTH); |
|
107
|
|
|
|
|
108
|
|
|
$order = $payment->getOrder(); |
|
109
|
|
|
$order->setState(\Magento\Sales\Model\Order::STATE_NEW); |
|
110
|
|
|
$order->setStatus('pending'); |
|
111
|
|
|
$comment = __('Awaiting payment of the Getpay.'); |
|
112
|
|
|
$order->addStatusHistoryComment($comment, $payment->getOrder()->getStatus()); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|