Commit 3fb06325 authored by Jonathan Sacksick's avatar Jonathan Sacksick Committed by Jonathan Sacksick
Browse files

Issue #3270317 by jsacksick: Add a method to the Klarna manager for loading...

Issue #3270317 by jsacksick: Add a method to the Klarna manager for loading the order from the order management API.
parent 22229cbc
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -103,8 +103,14 @@ class KlarnaManager implements KlarnaManagerInterface {
   * {@inheritdoc}
   */
  public function acknowledgeKlarnaOrder(string $klarna_order_id, ?OrderInterface $order = NULL) {
    try {
      // Try getting the order from the Klarna checkout endpoint.
      $klarna_order = (array) $this->loadOrder($klarna_order_id);

    }
    catch (\Exception $exception) {
      // Fallback to loading it from the order management API.
      $klarna_order  = (array) $this->loadCompletedOrder($klarna_order_id);
    }
    if (!$order) {
      $order_storage = $this->entityTypeManager->getStorage('commerce_order');
      $order = $order_storage->load($klarna_order['merchant_reference2']);
@@ -164,6 +170,15 @@ class KlarnaManager implements KlarnaManagerInterface {
    return $klarna_order;
  }

  /**
   * {@inheritdoc}
   */
  public function loadCompletedOrder(string $klarna_order_id) {
    $klarna_order = new KlarnaOrderManagement($this->connector, $klarna_order_id);
    $klarna_order->fetch();
    return $klarna_order;
  }

  /**
   * {@inheritdoc}
   */
+14 −0
Original line number Diff line number Diff line
@@ -99,6 +99,20 @@ interface KlarnaManagerInterface {
   */
  public function loadOrder($klarna_order_id);

  /**
   * Loads an order from the Klarna order management API.
   *
   * Once the customer has completed the purchase, the order should be loaded
   * from this endpoint.
   *
   * @param string $klarna_order_id
   *   The Klarna order ID.
   *
   * @return \Klarna\Rest\OrderManagement\Order
   *   The Klarna order (retrieved from the order management API).
   */
  public function loadCompletedOrder(string $klarna_order_id);

  /**
   * Updates the order in Klarna.
   *