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

Commit 7b119d5

Browse files
committed
MAGETWO-71771: imposible perform full refund for Order Paid with PayPal Payments Standard
-Add integration test for Nvp::callRefundTransaction
1 parent 5d2c85d commit 7b119d5

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,49 @@ 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_standard_with_tax_and_invoice.php
125+
*/
126+
public function testCallRefundTransaction()
127+
{
128+
$this->assertTrue(true);
129+
/** @var \Magento\Sales\Model\Order $order */
130+
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
131+
$order->loadByIncrementId('100000001');
132+
133+
/** @var \Magento\Sales\Model\Order\Payment $payment */
134+
$payment = $order->getPayment();
135+
136+
$this->nvpApi->setPayment(
137+
$payment
138+
)->setTransactionId(
139+
'fooTransactionId'
140+
)->setAmount(
141+
$payment->formatAmount($order->getBaseGrandTotal())
142+
)->setCurrencyCode(
143+
$order->getBaseCurrencyCode()
144+
)->setRefundType(
145+
Config::REFUND_TYPE_PARTIAL
146+
);
147+
148+
$httpQuery = 'TRANSACTIONID=fooTransactionId&REFUNDTYPE=Partial'
149+
.'&CURRENCYCODE=USD&AMT=145.98&METHOD=RefundTransaction'
150+
.'&VERSION=72.0&BUTTONSOURCE=Magento_Cart_';
151+
152+
$this->httpClient->expects($this->once())->method('write')
153+
->with(
154+
'POST',
155+
'https://api-3t.paypal.com/nvp',
156+
'1.1',
157+
[],
158+
$httpQuery
159+
);
160+
161+
$this->nvpApi->callRefundTransaction();
162+
}
163+
121164
/**
122165
* Gets quote by reserved order id.
123166
*
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\DB\Transaction;
8+
use Magento\Paypal\Model\Config;
9+
use Magento\Sales\Api\InvoiceManagementInterface;
10+
use Magento\Sales\Api\OrderRepositoryInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\Sales\Model\Order\Item;
13+
use Magento\Sales\Model\Order\Address;
14+
use Magento\Sales\Model\Order\Payment;
15+
use Magento\Sales\Model\Service\InvoiceService;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
18+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
19+
$product->setPrice(121);
20+
21+
$objectManager = Bootstrap::getObjectManager();
22+
23+
$addressData = include __DIR__ . '/address_data.php';
24+
$billingAddress = $objectManager->create(
25+
Address::class,
26+
['data' => $addressData]
27+
);
28+
$billingAddress->setAddressType('billing');
29+
$shippingAddress = clone $billingAddress;
30+
$shippingAddress->setId(null)->setAddressType('shipping');
31+
32+
$payment = $objectManager->create(Payment::class);
33+
$payment->setMethod(Config::METHOD_WPS_EXPRESS);
34+
35+
$taxRate = .0825;
36+
$taxAmount = $product->getPrice() * $taxRate;
37+
38+
/** @var Item $orderItem */
39+
$orderItem = $objectManager->create(Item::class);
40+
$orderItem->setProductId($product->getId())->setQtyOrdered(1);
41+
$orderItem->setBasePrice($product->getPrice());
42+
$orderItem->setPrice($product->getPrice());
43+
$orderItem->setRowTotal($product->getPrice());
44+
$orderItem->setRowTotalInclTax($product->getPrice() + $taxAmount);
45+
$orderItem->setBaseRowTotal($product->getPrice());
46+
$orderItem->setBaseRowTotalInclTax($product->getPrice() + $taxAmount);
47+
$orderItem->setBaseRowInvoiced($product->getPrice() + $taxAmount);
48+
$orderItem->setProductType('simple');
49+
50+
$itemsAmount = $product->getPrice();
51+
$shippingAmount = 15;
52+
$itemsAmountInclTax = $itemsAmount + $taxAmount;
53+
$totalAmount = $itemsAmountInclTax + $shippingAmount;
54+
55+
/** @var Order $order */
56+
$order = $objectManager->create(Order::class);
57+
$order->setCustomerEmail('[email protected]')
58+
->setIncrementId('100000001')
59+
->addItem($orderItem)
60+
->setSubtotal($itemsAmount)
61+
->setBaseSubtotal($itemsAmount)
62+
->setBaseGrandTotal($totalAmount)
63+
->setGrandTotal($totalAmount)
64+
->setTaxAmount($taxAmount)
65+
->setBaseCurrencyCode('USD')
66+
->setCustomerIsGuest(true)
67+
->setStoreId(1)
68+
->setEmailSent(true)
69+
->setState(Order::STATE_PROCESSING)
70+
->setBillingAddress($billingAddress)
71+
->setShippingAddress($shippingAddress)
72+
->setBaseTotalPaid($totalAmount)
73+
->setTotalPaid($totalAmount)
74+
->setData('base_to_global_rate', 1)
75+
->setData('base_to_order_rate', 1)
76+
->setData('shipping_amount', $shippingAmount)
77+
->setData('base_shipping_amount', $shippingAmount)
78+
->setPayment($payment);
79+
80+
/** @var OrderRepositoryInterface $orderRepository */
81+
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
82+
$orderRepository->save($order);
83+
84+
/** @var InvoiceService $invoiceService */
85+
$invoiceService = $objectManager->create(InvoiceManagementInterface::class);
86+
87+
/** @var Transaction $transaction */
88+
$transaction = $objectManager->create(Transaction::class);
89+
90+
$invoice = $invoiceService->prepareInvoice($order, [$orderItem->getId() => 1]);
91+
$invoice->register();
92+
93+
$transaction->addObject($invoice)->addObject($order)->save();

0 commit comments

Comments
 (0)