Skip to content

Commit 78e8356

Browse files
authored
Merge pull request #40 from pronamic/core-230-payment-line-quantity-type
Update for quantity `Number`.
2 parents abe8886 + a5663bb commit 78e8356

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/PaymentRequestHelper.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
1212

1313
use Pronamic\WordPress\Money\TaxedMoney;
14+
use Pronamic\WordPress\Number\Number;
1415
use Pronamic\WordPress\Pay\Payments\Payment;
1516

1617
/**
@@ -168,9 +169,26 @@ public static function complement( Payment $payment, AbstractPaymentRequest $req
168169

169170
$total_amount = $line->get_total_amount();
170171

172+
$quantity = $line->get_quantity();
173+
174+
if ( null === $quantity ) {
175+
$quantity = new Number( 0 );
176+
}
177+
178+
// Handle decimal quantities.
179+
if ( ! $quantity->is_whole_number() ) {
180+
$description = \sprintf(
181+
'%s × %s',
182+
$quantity->format_i18n_non_trailing_zeros(),
183+
(string) $description
184+
);
185+
186+
$quantity = new Number( 1 );
187+
}
188+
171189
$item = $line_items->new_item(
172190
(string) $description,
173-
(int) $line->get_quantity(),
191+
$quantity->to_int(),
174192
$total_amount->get_minor_units()->to_int()
175193
);
176194

0 commit comments

Comments
 (0)