3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Paypal \Model \Payflow ;
8
9
@@ -59,6 +60,11 @@ class Transparent extends Payflowpro implements TransparentInterface
59
60
*/
60
61
private $ paymentExtensionFactory ;
61
62
63
+ /**
64
+ * @var \Magento\Paypal\Model\CartFactory
65
+ */
66
+ private $ payPalCartFactory ;
67
+
62
68
/**
63
69
* @param \Magento\Framework\Model\Context $context
64
70
* @param \Magento\Framework\Registry $registry
@@ -76,6 +82,7 @@ class Transparent extends Payflowpro implements TransparentInterface
76
82
* @param ResponseValidator $responseValidator
77
83
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
78
84
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
85
+ * @param \Magento\Paypal\Model\CartFactory $payPalCartFactory
79
86
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
80
87
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
81
88
* @param array $data
@@ -98,6 +105,7 @@ public function __construct(
98
105
ResponseValidator $ responseValidator ,
99
106
PaymentTokenInterfaceFactory $ paymentTokenFactory ,
100
107
OrderPaymentExtensionInterfaceFactory $ paymentExtensionFactory ,
108
+ \Magento \Paypal \Model \CartFactory $ payPalCartFactory ,
101
109
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
102
110
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
103
111
array $ data = []
@@ -123,9 +131,12 @@ public function __construct(
123
131
$ this ->responseValidator = $ responseValidator ;
124
132
$ this ->paymentTokenFactory = $ paymentTokenFactory ;
125
133
$ this ->paymentExtensionFactory = $ paymentExtensionFactory ;
134
+ $ this ->payPalCartFactory = $ payPalCartFactory ;
126
135
}
127
136
128
137
/**
138
+ * Gets response validator instance.
139
+ *
129
140
* @return ResponseValidator
130
141
*/
131
142
public function getResponceValidator ()
@@ -162,13 +173,19 @@ public function authorize(InfoInterface $payment, $amount)
162
173
$ this ->addRequestOrderInfo ($ request , $ order );
163
174
$ request = $ this ->fillCustomerContacts ($ order , $ request );
164
175
176
+ /** @var \Magento\Paypal\Model\Cart $payPalCart */
177
+ $ payPalCart = $ this ->payPalCartFactory ->create (['salesModel ' => $ order ]);
178
+ $ payPalCart ->getAmounts ();
179
+
165
180
$ token = $ payment ->getAdditionalInformation (self ::PNREF );
166
181
$ request ->setData ('trxtype ' , self ::TRXTYPE_AUTH_ONLY );
167
182
$ request ->setData ('origid ' , $ token );
168
183
$ request ->setData ('amt ' , $ this ->formatPrice ($ amount ));
169
184
$ request ->setData ('currency ' , $ order ->getBaseCurrencyCode ());
170
- $ request ->setData ('taxamt ' , $ this ->formatPrice ($ order ->getBaseTaxAmount ()));
171
- $ request ->setData ('freightamt ' , $ this ->formatPrice ($ order ->getBaseShippingAmount ()));
185
+ $ request ->setData ('itemamt ' , $ this ->formatPrice ($ payPalCart ->getSubtotal ()));
186
+ $ request ->setData ('taxamt ' , $ this ->formatPrice ($ payPalCart ->getTax ()));
187
+ $ request ->setData ('freightamt ' , $ this ->formatPrice ($ payPalCart ->getShipping ()));
188
+ $ request ->setData ('discount ' , $ this ->formatPrice ($ payPalCart ->getDiscount ()));
172
189
173
190
$ response = $ this ->postRequest ($ request , $ this ->getConfig ());
174
191
$ this ->processErrors ($ response );
@@ -178,6 +195,7 @@ public function authorize(InfoInterface $payment, $amount)
178
195
} catch (LocalizedException $ exception ) {
179
196
$ payment ->setParentTransactionId ($ response ->getData (self ::PNREF ));
180
197
$ this ->void ($ payment );
198
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
181
199
throw new LocalizedException (__ ("The payment couldn't be processed at this time. Please try again later. " ));
182
200
}
183
201
@@ -200,10 +218,12 @@ public function getConfigInterface()
200
218
}
201
219
202
220
/**
221
+ * Creates vault payment token.
222
+ *
203
223
* @param Payment $payment
204
224
* @param string $token
205
- * @throws LocalizedException
206
225
* @return void
226
+ * @throws \Exception
207
227
*/
208
228
protected function createPaymentToken (Payment $ payment , $ token )
209
229
{
@@ -222,8 +242,11 @@ protected function createPaymentToken(Payment $payment, $token)
222
242
}
223
243
224
244
/**
245
+ * Generates CC expiration date by year and month provided in payment.
246
+ *
225
247
* @param Payment $payment
226
248
* @return string
249
+ * @throws \Exception
227
250
*/
228
251
private function getExpirationDate (Payment $ payment )
229
252
{
@@ -242,6 +265,8 @@ private function getExpirationDate(Payment $payment)
242
265
}
243
266
244
267
/**
268
+ * Returns payment extension attributes instance.
269
+ *
245
270
* @param Payment $payment
246
271
* @return \Magento\Sales\Api\Data\OrderPaymentExtensionInterface
247
272
*/
0 commit comments