Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b506ca4

Browse files
Merge remote-tracking branch 'origin/MAGETWO-71771-Impossible-full-refund-paypal' into BundledPR-Sep7b
2 parents 5e8ed65 + b022fdc commit b506ca4

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

app/code/Magento/Paypal/Model/Api/Nvp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public function callRefundTransaction()
991991
{
992992
$request = $this->_exportToRequest($this->_refundTransactionRequest);
993993
if ($this->getRefundType() === \Magento\Paypal\Model\Config::REFUND_TYPE_PARTIAL) {
994-
$request['AMT'] = $this->getAmount();
994+
$request['AMT'] = $this->formatPrice($this->getAmount());
995995
}
996996
$response = $this->call(self::REFUND_TRANSACTION, $request);
997997
$this->_importFromResponse($this->_refundTransactionResponse, $response);

dev/tests/integration/testsuite/Magento/Paypal/Model/Api/NvpTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,48 @@ public function testRequestTotalsAndLineItemsWithFPT()
118118
$this->nvpApi->callSetExpressCheckout();
119119
}
120120

121+
/**
122+
* Test that the refund request to Paypal sends the correct data
123+
*
124+
* @magentoDataFixture Magento/Paypal/_files/order_express_with_tax.php
125+
*/
126+
public function testCallRefundTransaction()
127+
{
128+
/** @var \Magento\Sales\Model\Order $order */
129+
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
130+
$order->loadByIncrementId('100000001');
131+
132+
/** @var \Magento\Sales\Model\Order\Payment $payment */
133+
$payment = $order->getPayment();
134+
135+
$this->nvpApi->setPayment(
136+
$payment
137+
)->setTransactionId(
138+
'fooTransactionId'
139+
)->setAmount(
140+
$payment->formatAmount($order->getBaseGrandTotal())
141+
)->setCurrencyCode(
142+
$order->getBaseCurrencyCode()
143+
)->setRefundType(
144+
Config::REFUND_TYPE_PARTIAL
145+
);
146+
147+
$httpQuery = 'TRANSACTIONID=fooTransactionId&REFUNDTYPE=Partial'
148+
.'&CURRENCYCODE=USD&AMT=145.98&METHOD=RefundTransaction'
149+
.'&VERSION=72.0&BUTTONSOURCE=Magento_Cart_';
150+
151+
$this->httpClient->expects($this->once())->method('write')
152+
->with(
153+
'POST',
154+
'https://api-3t.paypal.com/nvp',
155+
'1.1',
156+
[],
157+
$httpQuery
158+
);
159+
160+
$this->nvpApi->callRefundTransaction();
161+
}
162+
121163
/**
122164
* Gets quote by reserved order id.
123165
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\ObjectManagerInterface;
8+
use Magento\Sales\Model\OrderRepository;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
require __DIR__ . '/order_express.php';
12+
13+
/** @var ObjectManagerInterface $objectManager */
14+
$objectManager = Bootstrap::getObjectManager();
15+
16+
$subTotal = 121;
17+
$taxRate = .0825;
18+
$taxAmount = $subTotal * $taxRate;
19+
$shippingAmount = 15;
20+
$totalAmount = $subTotal + $taxAmount + $shippingAmount;
21+
22+
$order->setSubtotal($subTotal);
23+
$order->setBaseSubtotal($subTotal);
24+
$order->setGrandTotal($totalAmount);
25+
$order->setBaseGrandTotal($totalAmount);
26+
$order->setTaxAmount($taxAmount);
27+
28+
/** @var OrderRepository $orderRepository */
29+
$orderRepository = $objectManager->get(OrderRepository::class);
30+
$orderRepository->save($order);

0 commit comments

Comments
 (0)