Skip to content

Commit a0b49fe

Browse files
committed
Set billing address as well.
1 parent 4106522 commit a0b49fe

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Controller/AddressUpdate.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ public function __invoke($orderId, Request $request)
5959
/** @var Cart|Model $cart */
6060
$this->cart = Cart::findOneBy('klarna_order_id', $orderId);
6161

62+
$billingAddress = $data->billing_address;
6263
$shippingAddress = $data->shipping_address;
6364
$checkoutModule = ModuleModel::findById($this->cart->klarna_checkout_module);
6465
if (null === $checkoutModule) {
6566
$this->errorResponse();
6667
}
6768

69+
// Set billing address
70+
$address = $this->cart->getBillingAddress();
71+
$address = $address ?? Address::createForProductCollection($this->cart);
72+
$address = $this->updateAddressByApiResponse($address, (array)$billingAddress);
73+
74+
$this->cart->setBillingAddress($address);
75+
6876
// Set shipping address
6977
$address = $this->cart->getShippingAddress();
7078
$address = $address ?? Address::createForProductCollection($this->cart);
@@ -90,8 +98,8 @@ public function __invoke($orderId, Request $request)
9098

9199
// Update order since shipping method may get updated
92100
$data->shipping_options = $shippingOptions;
93-
$data->order_amount = $this->cart->getTotal() * 100;
94-
$data->order_tax_amount = ($this->cart->getTotal() - $this->cart->getTaxFreeTotal()) * 100;
101+
$data->order_amount = round($this->cart->getTotal() * 100);
102+
$data->order_tax_amount = round(($this->cart->getTotal() - $this->cart->getTaxFreeTotal()) * 100);
95103
$data->order_lines = $this->orderLines();
96104

97105
$response = new JsonResponse($data);

0 commit comments

Comments
 (0)