From 0906332b76206c85f507ef27d37726c96bd73d61 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Mon, 20 Sep 2021 10:56:34 +0200 Subject: [PATCH 1/2] Force decimal precission on create order --- spec/Api/CreateOrderApiSpec.php | 96 ++++++++++---------- spec/Provider/PayPalItemDataProviderSpec.php | 68 +++++++------- src/Api/CreateOrderApi.php | 6 +- src/Provider/PayPalItemDataProvider.php | 8 +- 4 files changed, 91 insertions(+), 87 deletions(-) diff --git a/spec/Api/CreateOrderApiSpec.php b/spec/Api/CreateOrderApiSpec.php index 0e09e6b4..fc5922fe 100644 --- a/spec/Api/CreateOrderApiSpec.php +++ b/spec/Api/CreateOrderApiSpec.php @@ -63,7 +63,7 @@ function it_creates_pay_pal_order_based_on_given_payment( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90, + 'value' => 90.0, 'currency_code' => 'PLN', ], 'quantity' => 1, @@ -73,7 +73,7 @@ function it_creates_pay_pal_order_based_on_given_payment( ], ], ], - 'total_item_value' => 90, + 'total_item_value' => 90.0, 'total_tax' => 0, ]); @@ -93,13 +93,13 @@ function it_creates_pay_pal_order_based_on_given_payment( return $data['intent'] === 'CAPTURE' && $data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' && - $data['purchase_units'][0]['amount']['value'] === 100 && + $data['purchase_units'][0]['amount']['value'] === 100.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === 10 && + $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === 10.0 && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -138,7 +138,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90, + 'value' => 90.0, 'currency_code' => 'PLN', ], 'quantity' => 1, @@ -148,7 +148,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( ], ], ], - 'total_item_value' => 90, + 'total_item_value' => 90.0, 'total_tax' => 0, ]); @@ -168,7 +168,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( return $data['intent'] === 'CAPTURE' && $data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' && - $data['purchase_units'][0]['amount']['value'] === 100 && + $data['purchase_units'][0]['amount']['value'] === 100.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -177,7 +177,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -216,7 +216,7 @@ function it_creates_pay_pal_order_with_more_than_one_product( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90, + 'value' => 90.0, 'currency_code' => 'PLN', ], 'quantity' => 1, @@ -228,7 +228,7 @@ function it_creates_pay_pal_order_with_more_than_one_product( [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40, + 'value' => 40.0, 'currency_code' => 'PLN', ], 'quantity' => 2, @@ -238,7 +238,7 @@ function it_creates_pay_pal_order_with_more_than_one_product( ], ], ], - 'total_item_value' => 170, + 'total_item_value' => 170.0, 'total_tax' => 0, ]); @@ -257,7 +257,7 @@ function it_creates_pay_pal_order_with_more_than_one_product( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 200 && + $data['purchase_units'][0]['amount']['value'] === 200.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -266,11 +266,11 @@ function it_creates_pay_pal_order_with_more_than_one_product( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][1]['quantity'] === 2 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40.0 && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -309,30 +309,30 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 50, + 'value' => 50.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 10, + 'value' => 10.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 50, + 'value' => 50.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 10, + 'value' => 10.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 100, - 'total_tax' => 20, + 'total_item_value' => 100.0, + 'total_tax' => 20.0, ]); $payment->getMethod()->willReturn($paymentMethod); @@ -350,7 +350,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 130 && + $data['purchase_units'][0]['amount']['value'] === 130.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -359,15 +359,15 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 50 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 50.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][0]['tax']['value'] === 10 && + $data['purchase_units'][0]['items'][0]['tax']['value'] === 10.0 && $data['purchase_units'][0]['items'][0]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][1]['quantity'] === 1 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 50 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 50.0 && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][1]['tax']['value'] === 10 && + $data['purchase_units'][0]['items'][1]['tax']['value'] === 10.0 && $data['purchase_units'][0]['items'][1]['tax']['currency_code'] === 'PLN' ; }) @@ -406,42 +406,42 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90, + 'value' => 90.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40, + 'value' => 40.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40, + 'value' => 40.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 170, - 'total_tax' => 4, + 'total_item_value' => 170.0, + 'total_tax' => 4.0, ]); $payment->getMethod()->willReturn($paymentMethod); @@ -459,7 +459,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 204 && + $data['purchase_units'][0]['amount']['value'] === 204.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -468,21 +468,21 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][0]['tax']['value'] === 2 && + $data['purchase_units'][0]['items'][0]['tax']['value'] === 2.0 && $data['purchase_units'][0]['items'][0]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][1]['quantity'] === 1 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40.0 && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][1]['tax']['value'] === 1 && + $data['purchase_units'][0]['items'][1]['tax']['value'] === 1.0 && $data['purchase_units'][0]['items'][1]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][2]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][2]['quantity'] === 1 && - $data['purchase_units'][0]['items'][2]['unit_amount']['value'] === 40 && + $data['purchase_units'][0]['items'][2]['unit_amount']['value'] === 40.0 && $data['purchase_units'][0]['items'][2]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][2]['tax']['value'] === 1 && + $data['purchase_units'][0]['items'][2]['tax']['value'] === 1.0 && $data['purchase_units'][0]['items'][2]['tax']['currency_code'] === 'PLN' ; }) @@ -515,7 +515,7 @@ function it_allows_to_create_digital_order( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 200, + 'value' => 200.0, 'currency_code' => 'PLN', ], 'quantity' => 1, @@ -525,7 +525,7 @@ function it_allows_to_create_digital_order( ], ], ], - 'total_item_value' => 200, + 'total_item_value' => 200.0, 'total_tax' => 0, ]); @@ -546,7 +546,7 @@ function it_allows_to_create_digital_order( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 200 && + $data['purchase_units'][0]['amount']['value'] === 200.0 && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['application_context']['shipping_preference'] === 'NO_SHIPPING' ; @@ -579,7 +579,7 @@ function it_creates_pay_pal_order_with_promotion( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 25, + 'value' => 25.0, 'currency_code' => 'PLN', ], 'quantity' => 1, @@ -589,7 +589,7 @@ function it_creates_pay_pal_order_with_promotion( ], ], ], - 'total_item_value' => 25, + 'total_item_value' => 25.0, 'total_tax' => 0, ]); @@ -614,12 +614,12 @@ function it_creates_pay_pal_order_with_promotion( $data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' && $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === 7.49 && $data['purchase_units'][0]['amount']['breakdown']['item_total']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['item_total']['value'] === 25 && + $data['purchase_units'][0]['amount']['breakdown']['item_total']['value'] === 25.0 && $data['purchase_units'][0]['amount']['breakdown']['discount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['amount']['breakdown']['discount']['value'] === 2.5 && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 25 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 25.0 && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) diff --git a/spec/Provider/PayPalItemDataProviderSpec.php b/spec/Provider/PayPalItemDataProviderSpec.php index 124a4962..59c736b3 100644 --- a/spec/Provider/PayPalItemDataProviderSpec.php +++ b/spec/Provider/PayPalItemDataProviderSpec.php @@ -37,18 +37,18 @@ function it_returns_array_of_items_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 20, - 'total_tax' => 2, + 'total_item_value' => 20.0, + 'total_tax' => 2.0, ] ); } @@ -73,42 +73,42 @@ function it_returns_array_of_items_with_different_quantities_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 60, - 'total_tax' => 6, + 'total_item_value' => 60.0, + 'total_tax' => 6.0, ], ); } @@ -133,18 +133,18 @@ function it_returns_array_of_items_with_different_quantities_without_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 3, 'tax' => [ - 'value' => 0, + 'value' => 0.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 60, - 'total_tax' => 0, + 'total_item_value' => 60.0, + 'total_tax' => 0.0, ], ); } @@ -176,30 +176,30 @@ function it_returns_array_of_different_items_with_different_quantities_without_t [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 3, 'tax' => [ - 'value' => 0, + 'value' => 0.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10, + 'value' => 10.0, 'currency_code' => 'PLN', ], 'quantity' => 2, 'tax' => [ - 'value' => 0, + 'value' => 0.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 80, - 'total_tax' => 0, + 'total_item_value' => 80.0, + 'total_tax' => 0.0, ], ); } @@ -230,66 +230,66 @@ function it_returns_array_of_different_items_with_different_quantities_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20, + 'value' => 20.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10, + 'value' => 10.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2, + 'value' => 2.0, 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10, + 'value' => 10.0, 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1, + 'value' => 1.0, 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 80, - 'total_tax' => 6, + 'total_item_value' => 80.0, + 'total_tax' => 6.0, ], ); } diff --git a/src/Api/CreateOrderApi.php b/src/Api/CreateOrderApi.php index 3f0c8717..f300c078 100644 --- a/src/Api/CreateOrderApi.php +++ b/src/Api/CreateOrderApi.php @@ -69,11 +69,11 @@ public function create(string $token, PaymentInterface $payment, string $referen 'invoice_number' => $this->paymentReferenceNumberProvider->provide($payment), 'amount' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => (int) $payment->getAmount() / 100, + 'value' => (float) number_format((int) $payment->getAmount() / 100, 2), 'breakdown' => [ 'shipping' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => $order->getShippingTotal() / 100, + 'value' => (float) number_format($order->getShippingTotal() / 100, 2), ], 'item_total' => [ 'currency_code' => $order->getCurrencyCode(), @@ -85,7 +85,7 @@ public function create(string $token, PaymentInterface $payment, string $referen ], 'discount' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => abs($order->getOrderPromotionTotal()) / 100, + 'value' => (float) number_format(abs($order->getOrderPromotionTotal()) / 100, 2), ], ], ], diff --git a/src/Provider/PayPalItemDataProvider.php b/src/Provider/PayPalItemDataProvider.php index c7fdc0a3..cc777673 100644 --- a/src/Provider/PayPalItemDataProvider.php +++ b/src/Provider/PayPalItemDataProvider.php @@ -42,18 +42,22 @@ public function provide(OrderInterface $order): array $itemData['items'][] = [ 'name' => $orderItem->getProductName(), 'unit_amount' => [ - 'value' => $itemValue / 100, + 'value' => (float) number_format($itemValue / 100, 2), 'currency_code' => $order->getCurrencyCode(), ], 'quantity' => $displayQuantity, 'tax' => [ - 'value' => $nonNeutralTax / 100, + 'value' => (float) number_format($nonNeutralTax / 100, 2), 'currency_code' => $order->getCurrencyCode(), ], ]; + } } + $itemData['total_item_value'] = (float) number_format($itemData['total_item_value'], 2); + $itemData['total_tax'] = (float) number_format($itemData['total_tax'], 2); + return $itemData; } } From a4758dd74bae93d84c7a13d71e245a6562a0367c Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 21 Sep 2021 12:00:24 +0200 Subject: [PATCH 2/2] use paypal amounts as a string --- spec/Api/CreateOrderApiSpec.php | 124 +++++++++---------- spec/Provider/PayPalItemDataProviderSpec.php | 68 +++++----- src/Api/CreateOrderApi.php | 6 +- src/Provider/PayPalItemDataProvider.php | 8 +- 4 files changed, 103 insertions(+), 103 deletions(-) diff --git a/spec/Api/CreateOrderApiSpec.php b/spec/Api/CreateOrderApiSpec.php index fc5922fe..4474ba67 100644 --- a/spec/Api/CreateOrderApiSpec.php +++ b/spec/Api/CreateOrderApiSpec.php @@ -63,18 +63,18 @@ function it_creates_pay_pal_order_based_on_given_payment( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90.0, + 'value' => '90.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 90.0, - 'total_tax' => 0, + 'total_item_value' => '90.00', + 'total_tax' => '0.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -93,13 +93,13 @@ function it_creates_pay_pal_order_based_on_given_payment( return $data['intent'] === 'CAPTURE' && $data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' && - $data['purchase_units'][0]['amount']['value'] === 100.0 && + $data['purchase_units'][0]['amount']['value'] === '100.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === 10.0 && + $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === '10.00' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -138,18 +138,18 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90.0, + 'value' => '90.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 90.0, - 'total_tax' => 0, + 'total_item_value' => '90.00', + 'total_tax' => '0.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -168,7 +168,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( return $data['intent'] === 'CAPTURE' && $data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' && - $data['purchase_units'][0]['amount']['value'] === 100.0 && + $data['purchase_units'][0]['amount']['value'] === '100.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -177,7 +177,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -216,30 +216,30 @@ function it_creates_pay_pal_order_with_more_than_one_product( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90.0, + 'value' => '90.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40.0, + 'value' => '40.00', 'currency_code' => 'PLN', ], 'quantity' => 2, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 170.0, - 'total_tax' => 0, + 'total_item_value' => '170.00', + 'total_tax' => '0.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -257,7 +257,7 @@ function it_creates_pay_pal_order_with_more_than_one_product( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 200.0 && + $data['purchase_units'][0]['amount']['value'] === '200.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -266,11 +266,11 @@ function it_creates_pay_pal_order_with_more_than_one_product( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][1]['quantity'] === 2 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40.0 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === '40.00' && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' ; }) @@ -309,30 +309,30 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 50.0, + 'value' => '50.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 10.0, + 'value' => '10.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 50.0, + 'value' => '50.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 10.0, + 'value' => '10.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 100.0, - 'total_tax' => 20.0, + 'total_item_value' => '100.00', + 'total_tax' => '20.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -350,7 +350,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 130.0 && + $data['purchase_units'][0]['amount']['value'] === '130.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -359,15 +359,15 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity( $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 50.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '50.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][0]['tax']['value'] === 10.0 && + $data['purchase_units'][0]['items'][0]['tax']['value'] === '10.00' && $data['purchase_units'][0]['items'][0]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][1]['quantity'] === 1 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 50.0 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === '50.00' && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][1]['tax']['value'] === 10.0 && + $data['purchase_units'][0]['items'][1]['tax']['value'] === '10.00' && $data['purchase_units'][0]['items'][1]['tax']['currency_code'] === 'PLN' ; }) @@ -406,42 +406,42 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 90.0, + 'value' => '90.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40.0, + 'value' => '40.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 40.0, + 'value' => '40.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 170.0, - 'total_tax' => 4.0, + 'total_item_value' => '170.00', + 'total_tax' => '4.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -459,7 +459,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 204.0 && + $data['purchase_units'][0]['amount']['value'] === '204.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' && $data['purchase_units'][0]['shipping']['address']['address_line_1'] === 'Hobbit St. 123' && @@ -468,21 +468,21 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_ $data['purchase_units'][0]['shipping']['address']['country_code'] === 'US' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 90.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][0]['tax']['value'] === 2.0 && + $data['purchase_units'][0]['items'][0]['tax']['value'] === '2.00' && $data['purchase_units'][0]['items'][0]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][1]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][1]['quantity'] === 1 && - $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === 40.0 && + $data['purchase_units'][0]['items'][1]['unit_amount']['value'] === '40.00' && $data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][1]['tax']['value'] === 1.0 && + $data['purchase_units'][0]['items'][1]['tax']['value'] === '1.00' && $data['purchase_units'][0]['items'][1]['tax']['currency_code'] === 'PLN' && $data['purchase_units'][0]['items'][2]['name'] === 'PRODUCT_TWO' && $data['purchase_units'][0]['items'][2]['quantity'] === 1 && - $data['purchase_units'][0]['items'][2]['unit_amount']['value'] === 40.0 && + $data['purchase_units'][0]['items'][2]['unit_amount']['value'] === '40.00' && $data['purchase_units'][0]['items'][2]['unit_amount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['items'][2]['tax']['value'] === 1.0 && + $data['purchase_units'][0]['items'][2]['tax']['value'] === '1.00' && $data['purchase_units'][0]['items'][2]['tax']['currency_code'] === 'PLN' ; }) @@ -515,18 +515,18 @@ function it_allows_to_create_digital_order( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 200.0, + 'value' => '200.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 200.0, - 'total_tax' => 0, + 'total_item_value' => '200.00', + 'total_tax' => '0.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -546,7 +546,7 @@ function it_allows_to_create_digital_order( Argument::that(function (array $data): bool { return $data['intent'] === 'CAPTURE' && - $data['purchase_units'][0]['amount']['value'] === 200.0 && + $data['purchase_units'][0]['amount']['value'] === '200.00' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['application_context']['shipping_preference'] === 'NO_SHIPPING' ; @@ -579,18 +579,18 @@ function it_creates_pay_pal_order_with_promotion( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 25.0, + 'value' => '25.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 25.0, - 'total_tax' => 0, + 'total_item_value' => '25.00', + 'total_tax' => '0.00', ]); $payment->getMethod()->willReturn($paymentMethod); @@ -609,17 +609,17 @@ function it_creates_pay_pal_order_with_promotion( return $data['intent'] === 'CAPTURE' && $data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' && - $data['purchase_units'][0]['amount']['value'] === 29.99 && + $data['purchase_units'][0]['amount']['value'] === '29.99' && $data['purchase_units'][0]['amount']['currency_code'] === 'PLN' && $data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === 7.49 && + $data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === '7.49' && $data['purchase_units'][0]['amount']['breakdown']['item_total']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['item_total']['value'] === 25.0 && + $data['purchase_units'][0]['amount']['breakdown']['item_total']['value'] === '25.00' && $data['purchase_units'][0]['amount']['breakdown']['discount']['currency_code'] === 'PLN' && - $data['purchase_units'][0]['amount']['breakdown']['discount']['value'] === 2.5 && + $data['purchase_units'][0]['amount']['breakdown']['discount']['value'] === '2.50' && $data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' && $data['purchase_units'][0]['items'][0]['quantity'] === 1 && - $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === 25.0 && + $data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '25.00' && $data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN' ; }) diff --git a/spec/Provider/PayPalItemDataProviderSpec.php b/spec/Provider/PayPalItemDataProviderSpec.php index 59c736b3..d4e0430e 100644 --- a/spec/Provider/PayPalItemDataProviderSpec.php +++ b/spec/Provider/PayPalItemDataProviderSpec.php @@ -37,18 +37,18 @@ function it_returns_array_of_items_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 20.0, - 'total_tax' => 2.0, + 'total_item_value' => '20.00', + 'total_tax' => '2.00', ] ); } @@ -73,42 +73,42 @@ function it_returns_array_of_items_with_different_quantities_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 60.0, - 'total_tax' => 6.0, + 'total_item_value' => '60.00', + 'total_tax' => '6.00', ], ); } @@ -133,18 +133,18 @@ function it_returns_array_of_items_with_different_quantities_without_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 3, 'tax' => [ - 'value' => 0.0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 60.0, - 'total_tax' => 0.0, + 'total_item_value' => '60.00', + 'total_tax' => '0.00', ], ); } @@ -176,30 +176,30 @@ function it_returns_array_of_different_items_with_different_quantities_without_t [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 3, 'tax' => [ - 'value' => 0.0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10.0, + 'value' => '10.00', 'currency_code' => 'PLN', ], 'quantity' => 2, 'tax' => [ - 'value' => 0.0, + 'value' => '0.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 80.0, - 'total_tax' => 0.0, + 'total_item_value' => '80.00', + 'total_tax' => '0.00', ], ); } @@ -230,66 +230,66 @@ function it_returns_array_of_different_items_with_different_quantities_with_tax( [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_ONE', 'unit_amount' => [ - 'value' => 20.0, + 'value' => '20.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10.0, + 'value' => '10.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 2.0, + 'value' => '2.00', 'currency_code' => 'PLN', ], ], [ 'name' => 'PRODUCT_TWO', 'unit_amount' => [ - 'value' => 10.0, + 'value' => '10.00', 'currency_code' => 'PLN', ], 'quantity' => 1, 'tax' => [ - 'value' => 1.0, + 'value' => '1.00', 'currency_code' => 'PLN', ], ], ], - 'total_item_value' => 80.0, - 'total_tax' => 6.0, + 'total_item_value' => '80.00', + 'total_tax' => '6.00', ], ); } diff --git a/src/Api/CreateOrderApi.php b/src/Api/CreateOrderApi.php index f300c078..12270026 100644 --- a/src/Api/CreateOrderApi.php +++ b/src/Api/CreateOrderApi.php @@ -69,11 +69,11 @@ public function create(string $token, PaymentInterface $payment, string $referen 'invoice_number' => $this->paymentReferenceNumberProvider->provide($payment), 'amount' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => (float) number_format((int) $payment->getAmount() / 100, 2), + 'value' => number_format((int) $payment->getAmount() / 100, 2, '.', ''), 'breakdown' => [ 'shipping' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => (float) number_format($order->getShippingTotal() / 100, 2), + 'value' => number_format($order->getShippingTotal() / 100, 2, '.', ''), ], 'item_total' => [ 'currency_code' => $order->getCurrencyCode(), @@ -85,7 +85,7 @@ public function create(string $token, PaymentInterface $payment, string $referen ], 'discount' => [ 'currency_code' => $order->getCurrencyCode(), - 'value' => (float) number_format(abs($order->getOrderPromotionTotal()) / 100, 2), + 'value' => number_format(abs($order->getOrderPromotionTotal()) / 100, 2, '.', ''), ], ], ], diff --git a/src/Provider/PayPalItemDataProvider.php b/src/Provider/PayPalItemDataProvider.php index cc777673..643703e6 100644 --- a/src/Provider/PayPalItemDataProvider.php +++ b/src/Provider/PayPalItemDataProvider.php @@ -42,12 +42,12 @@ public function provide(OrderInterface $order): array $itemData['items'][] = [ 'name' => $orderItem->getProductName(), 'unit_amount' => [ - 'value' => (float) number_format($itemValue / 100, 2), + 'value' => number_format($itemValue / 100, 2, '.', ''), 'currency_code' => $order->getCurrencyCode(), ], 'quantity' => $displayQuantity, 'tax' => [ - 'value' => (float) number_format($nonNeutralTax / 100, 2), + 'value' => number_format($nonNeutralTax / 100, 2, '.', ''), 'currency_code' => $order->getCurrencyCode(), ], ]; @@ -55,8 +55,8 @@ public function provide(OrderInterface $order): array } } - $itemData['total_item_value'] = (float) number_format($itemData['total_item_value'], 2); - $itemData['total_tax'] = (float) number_format($itemData['total_tax'], 2); + $itemData['total_item_value'] = number_format($itemData['total_item_value'], 2, '.', ''); + $itemData['total_tax'] = number_format($itemData['total_tax'], 2, '.', ''); return $itemData; }