MerchantPortal.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * This file is part of the Klarna Core module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Core\Model;
  11. use Klarna\Core\Helper\ConfigHelper;
  12. use Klarna\Core\Api\OrderInterface as KlarnaOrder;
  13. use Magento\Sales\Api\Data\OrderInterface as MageOrder;
  14. /**
  15. * Class MerchantPortal
  16. *
  17. * @package Klarna\Core\Model
  18. */
  19. class MerchantPortal
  20. {
  21. const MERCHANT_PORTAL_US = "https://orders.us.portal.klarna.com/";
  22. const MERCHANT_PORTAL_EU = "https://orders.eu.portal.klarna.com/";
  23. /**
  24. * @var \Klarna\Core\Helper\ConfigHelper
  25. */
  26. private $configHelper;
  27. /**
  28. * MerchantPortal Model.
  29. *
  30. * @param ConfigHelper $configHelper
  31. */
  32. public function __construct(ConfigHelper $configHelper)
  33. {
  34. $this->configHelper = $configHelper;
  35. }
  36. /**
  37. * Get Merchant Portal link for order
  38. *
  39. * @param MageOrder $mageOrder
  40. * @param KlarnaOrder $klarnaOrder
  41. * @return string
  42. */
  43. public function getOrderMerchantPortalLink(MageOrder $mageOrder, KlarnaOrder $klarnaOrder)
  44. {
  45. $store = $mageOrder->getStore();
  46. $merchantId = $this->configHelper->getApiConfig('merchant_id', $store);
  47. $apiVersion = $this->configHelper->getApiConfig('api_version', $store);
  48. $url = self::MERCHANT_PORTAL_EU;
  49. if (in_array($apiVersion, ['na', 'kp_na'])) {
  50. $url = self::MERCHANT_PORTAL_US;
  51. }
  52. $merchantIdArray = explode("_", $merchantId);
  53. $url .= "merchants/" . $merchantIdArray[0] . "/orders/" . $klarnaOrder->getKlarnaOrderId();
  54. return $url;
  55. }
  56. }