|
|
@@ -84,13 +84,13 @@ class Klarna extends Payment
|
|
|
foreach ($order->items as $item) {
|
|
|
$data = [
|
|
|
'name' => $item->name,
|
|
|
- 'unit_price' => (float) $item->price,
|
|
|
- 'quantity' => $item->qty_ordered,
|
|
|
- 'total_amount' => $item->qty_ordered * $item->price
|
|
|
+ 'unit_price' => $this->toMinorUnits((float) $item->price),
|
|
|
+ 'quantity' => (int) $item->qty_ordered,
|
|
|
+ 'total_amount' => $this->toMinorUnits((float) $item->price * (float) $item->qty_ordered),
|
|
|
];
|
|
|
array_push($products, $data);
|
|
|
}
|
|
|
- $grandTotal = round($order->grand_total, 2);
|
|
|
+ $grandTotal = $this->toMinorUnits((float) $order->grand_total);
|
|
|
$data = [
|
|
|
'order_amount' => $grandTotal,
|
|
|
'merchant_reference1' => $override['merchantOrderId'],
|
|
|
@@ -151,6 +151,14 @@ class Klarna extends Payment
|
|
|
return $prefix . $uuid;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Convert a decimal currency amount to minor units (cents).
|
|
|
+ */
|
|
|
+ protected function toMinorUnits(float $amount): int
|
|
|
+ {
|
|
|
+ return (int) round($amount * 100);
|
|
|
+ }
|
|
|
+
|
|
|
public function captureAndVerify($order, $authorizationToken)
|
|
|
{
|
|
|
if ($order->status != Order::STATUS_PENDING) {
|
|
|
@@ -165,9 +173,9 @@ class Klarna extends Payment
|
|
|
foreach ($order->items as $item) {
|
|
|
$data = [
|
|
|
'name' => $item->name,
|
|
|
- 'unit_price' => (float) $item->price,
|
|
|
- 'quantity' => $item->qty_ordered,
|
|
|
- 'total_amount' => $item->qty_ordered * $item->price
|
|
|
+ 'unit_price' => $this->toMinorUnits((float) $item->price),
|
|
|
+ 'quantity' => (int) $item->qty_ordered,
|
|
|
+ 'total_amount' => $this->toMinorUnits((float) $item->price * (float) $item->qty_ordered),
|
|
|
];
|
|
|
array_push($products, $data);
|
|
|
}
|
|
|
@@ -176,7 +184,7 @@ class Klarna extends Payment
|
|
|
'billing_address' => [
|
|
|
'given_name' => $bill->first_name,
|
|
|
'family_name' => $bill->last_name,
|
|
|
- 'email' => $bill->customer_email,
|
|
|
+ 'email' => $order->customer_email,
|
|
|
'phone' => $bill->phone,
|
|
|
'street_address' => $bill->address,
|
|
|
'city' => $bill->city,
|
|
|
@@ -184,7 +192,7 @@ class Klarna extends Payment
|
|
|
'region' => $bill->state,
|
|
|
'country' => $bill->country
|
|
|
],
|
|
|
- 'order_amount' => round($order->grand_total, 2),
|
|
|
+ 'order_amount' => $this->toMinorUnits((float) $order->grand_total),
|
|
|
'purchase_country' => $bill->country,
|
|
|
'purchase_currency' => $order->order_currency_code,
|
|
|
'order_lines' => $products
|