Skip to content

Commit e4ee93c

Browse files
authored
[UPMERGE] 1.7 -> 2.0 (#375)
This PR has been generated automatically. For more details see [upmerge_pr.yaml](/Sylius/PayPalPlugin/blob/1.7/.github/workflows/upmerge_pr.yaml). **Remember!** The upmerge should always be merged with using `Merge pull request` button. In case of conflicts, please resolve them manually with usign the following commands: ``` git fetch upstream gh pr checkout <this-pr-number> git merge upstream/2.0 -m "Resolve conflicts between 1.7 and 2.0" ``` If you use other name for the upstream remote, please replace `upstream` with the name of your remote pointing to the `Sylius/PayPalPlugin` repository. Once the conflicts are resolved, please run `git merge --continue` and push the changes to this PR.
2 parents 9ca9691 + 1c505a9 commit e4ee93c

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/Controller/ProcessPayPalOrderAction.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Sylius\Abstraction\StateMachine\StateMachineInterface;
1818
use Sylius\Component\Core\Factory\AddressFactoryInterface;
1919
use Sylius\Component\Core\Model\CustomerInterface;
20+
use Sylius\Component\Core\Model\OrderInterface;
2021
use Sylius\Component\Core\Model\PaymentInterface;
2122
use Sylius\Component\Core\Model\PaymentMethodInterface;
2223
use Sylius\Component\Core\OrderCheckoutTransitions;
@@ -62,9 +63,18 @@ public function __invoke(Request $request): Response
6263
{
6364
$orderId = $request->request->getInt('orderId');
6465
$order = $this->orderProvider->provideOrderById($orderId);
65-
/** @var PaymentInterface $payment */
66+
67+
if ($order->getState() !== OrderInterface::STATE_NEW) {
68+
return new JsonResponse(['orderID' => $orderId]);
69+
}
70+
71+
/** @var PaymentInterface|null $payment */
6672
$payment = $order->getLastPayment(PaymentInterface::STATE_CART);
6773

74+
if (null === $payment) {
75+
return new JsonResponse(['orderID' => $orderId]);
76+
}
77+
6878
$data = $this->getOrderDetails((string) $request->request->get('payPalOrderId'), $payment);
6979

7080
/** @var CustomerInterface|null $customer */
@@ -119,13 +129,13 @@ public function __invoke(Request $request): Response
119129
} catch (PaymentAmountMismatchException) {
120130
$this->paymentStateManager->cancel($payment);
121131

122-
return new JsonResponse(['orderID' => $order->getId()]);
132+
return new JsonResponse(['orderID' => $orderId]);
123133
}
124134

125135
$this->paymentStateManager->create($payment);
126136
$this->paymentStateManager->process($payment);
127137

128-
return new JsonResponse(['orderID' => $order->getId()]);
138+
return new JsonResponse(['orderID' => $orderId]);
129139
}
130140

131141
private function getOrderCustomer(array $customerData): CustomerInterface

src/Verifier/PaymentAmountVerifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private function getTotalPaymentAmountFromPaypal(PaymentInterface $payment, arra
4141

4242
foreach ($paypalOrderDetails['purchase_units'] as $unit) {
4343
$stringAmount = $unit['amount']['value'] ?? '0';
44-
$totalAmount += (int) ($stringAmount * 100);
44+
$totalAmount += (int) round((float) $stringAmount * 100, 0);
4545
}
4646

4747
return $totalAmount;

tests/Unit/PaymentAmountVerifierTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function testVerifySucceedsWhenAmountsMatch(): void
3333
$payment = $this->createMock(PaymentInterface::class);
3434
$order = $this->createMock(OrderInterface::class);
3535
$payment->method('getOrder')->willReturn($order);
36-
$order->method('getTotal')->willReturn(1500);
36+
$order->method('getTotal')->willReturn(4398);
3737

3838
$paypalOrderDetails = [
3939
'purchase_units' => [
40-
['amount' => ['value' => '10.00']],
40+
['amount' => ['value' => '38.98']],
4141
['amount' => ['value' => '5.00']],
4242
],
4343
];
@@ -52,11 +52,11 @@ public function testVerifyThrowsExceptionWhenAmountsDoNotMatch(): void
5252
$payment = $this->createMock(PaymentInterface::class);
5353
$order = $this->createMock(OrderInterface::class);
5454
$payment->method('getOrder')->willReturn($order);
55-
$order->method('getTotal')->willReturn(1000);
55+
$order->method('getTotal')->willReturn(4500);
5656

5757
$paypalOrderDetails = [
5858
'purchase_units' => [
59-
['amount' => ['value' => '10.00']],
59+
['amount' => ['value' => '38.98']],
6060
['amount' => ['value' => '5.00']],
6161
],
6262
];

0 commit comments

Comments
 (0)