Skip to content

Commit 90205dc

Browse files
committed
MC-37649: Paypal Duplicate Orders
- Fixes the issue when duplicated orders were created after unexpected http request termination during order submit
1 parent 4aa2f11 commit 90205dc

File tree

7 files changed

+15
-20
lines changed

7 files changed

+15
-20
lines changed

app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ protected function _processPaypalApiError($exception)
174174
$this->_redirectSameToken();
175175
break;
176176
case ApiProcessableException::API_ADDRESS_MATCH_FAIL:
177+
case ApiProcessableException::API_TRANSACTION_HAS_BEEN_COMPLETED:
177178
$this->redirectToOrderReviewPageAndShowError($exception->getUserMessage());
178179
break;
179180
case ApiProcessableException::API_UNABLE_TRANSACTION_COMPLETE:

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,15 +1286,6 @@ protected function _handleCallErrors($response)
12861286
);
12871287
$this->_logger->critical($exceptionLogMessage);
12881288

1289-
/**
1290-
* The response code 10415 'Transaction has already been completed for this token'
1291-
* must not fails place order. The old Paypal interface does not lock 'Send' button
1292-
* it may result to re-send data.
1293-
*/
1294-
if (in_array((string)ProcessableException::API_TRANSACTION_HAS_BEEN_COMPLETED, $this->_callErrors)) {
1295-
return;
1296-
}
1297-
12981289
$exceptionPhrase = __('PayPal gateway has rejected request. %1', $errorMessages);
12991290

13001291
/** @var \Magento\Framework\Exception\LocalizedException $exception */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public function getUserMessage()
6767
. ' Please contact us so we can assist you.'
6868
);
6969
break;
70+
case self::API_TRANSACTION_HAS_BEEN_COMPLETED:
71+
$message = __(
72+
'A successful payment transaction has already been completed.'
73+
. ' Please, check if the order has been placed.'
74+
);
75+
break;
7076
case self::API_ADDRESS_MATCH_FAIL:
7177
$message = __(
7278
'A match of the Shipping Address City, State, and Postal Code failed.'

app/code/Magento/Paypal/Model/Express.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ protected function _setApiProcessableErrors()
276276
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
277277
ApiProcessableException::API_OTHER_FILTER_DECLINE,
278278
ApiProcessableException::API_ADDRESS_MATCH_FAIL,
279+
ApiProcessableException::API_TRANSACTION_HAS_BEEN_COMPLETED,
279280
self::$authorizationExpiredCode
280281
]
281282
);

app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ public function testGetDebugReplacePrivateDataKeys()
305305

306306
/**
307307
* Tests case if obtained response with code 10415 'Transaction has already
308-
* been completed for this token'. It must does not throws the exception and
309-
* must returns response array.
308+
* been completed for this token'. It must throw the ProcessableException.
310309
*/
311310
public function testCallTransactionHasBeenCompleted()
312311
{
@@ -317,15 +316,10 @@ public function testCallTransactionHasBeenCompleted()
317316
->method('read')
318317
->willReturn($response);
319318
$this->model->setProcessableErrors($processableErrors);
320-
$this->customLoggerMock->expects($this->once())
321-
->method('debug');
322-
$expectedResponse = [
323-
'ACK' => 'Failure',
324-
'L_ERRORCODE0' => '10415',
325-
'L_SHORTMESSAGE0' => 'Message.',
326-
'L_LONGMESSAGE0' => 'Long Message.'
327-
];
328319

329-
$this->assertEquals($expectedResponse, $this->model->call('some method', ['data' => 'some data']));
320+
$this->expectExceptionMessageMatches('/PayPal gateway has rejected request/');
321+
$this->expectException(ProcessableException::class);
322+
323+
$this->model->call('DoExpressCheckout', ['data' => 'some data']);
330324
}
331325
}

app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ExpressTest extends TestCase
5353
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
5454
ApiProcessableException::API_OTHER_FILTER_DECLINE,
5555
ApiProcessableException::API_ADDRESS_MATCH_FAIL,
56+
ApiProcessableException::API_TRANSACTION_HAS_BEEN_COMPLETED
5657
];
5758

5859
/**

app/code/Magento/Paypal/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,4 @@ User,User
737737
"Please enter at least 0 and at most 65535","Please enter at least 0 and at most 65535"
738738
"Order is suspended as an account verification transaction is suspected to be fraudulent.","Order is suspended as an account verification transaction is suspected to be fraudulent."
739739
"Payment can't be accepted since transaction was rejected by merchant.","Payment can't be accepted since transaction was rejected by merchant."
740+
"A successful payment transaction has already been completed. Please, check if the order has been placed.","A successful payment transaction has already been completed. Please, check if the order has been placed."

0 commit comments

Comments
 (0)