Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PW-7170] - Add region based endpoints for terminal api #400

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Client
const API_HOP_VERSION = "v6";
const ENDPOINT_TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_US_LIVE = "https://terminal-api-live-us.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_AU_LIVE = "https://terminal-api-live-au.adyen.com";
const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com/checkout";
const ENDPOINT_CHECKOUT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
const ENDPOINT_PROTOCOL = "https://";
Expand Down Expand Up @@ -493,4 +495,17 @@ protected function createDefaultLogger()

return $logger;
}

/**
* @param string $region
* @return void
*/
public function setRegion(string $region): void
{
if (!array_key_exists($region, Region::TERMINAL_API_ENDPOINTS_MAPPING)) {
throw new AdyenException('Trying to set invalid region!');
}

$this->config->set('region', $region);
}
}
16 changes: 16 additions & 0 deletions src/Adyen/Region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Adyen;

class Region
{
const EU = "eu";
const US = "us";
const AU = "au";

const TERMINAL_API_ENDPOINTS_MAPPING = [
self::EU => Client::ENDPOINT_TERMINAL_CLOUD_LIVE,
self::US => Client::ENDPOINT_TERMINAL_CLOUD_US_LIVE,
self::AU => Client::ENDPOINT_TERMINAL_CLOUD_AU_LIVE,
];
}
17 changes: 16 additions & 1 deletion src/Adyen/Service/PosPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Adyen\Service;

use Adyen\Client;
use Adyen\Environment;
use Adyen\Region;

class PosPayment extends \Adyen\ApiKeyAuthenticatedService
{
/**
Expand Down Expand Up @@ -30,9 +34,20 @@ class PosPayment extends \Adyen\ApiKeyAuthenticatedService
* @param \Adyen\Client $client
* @throws \Adyen\AdyenException
*/
public function __construct(\Adyen\Client $client)
public function __construct(Client $client)
{
parent::__construct($client);

$region = $this->getClient()->getConfig()->get('region');
$environment = $this->getClient()->getConfig()->get('environment');

if (isset($region) && $environment == Environment::LIVE) {
$this->getClient()->getConfig()->set(
'endpointTerminalCloud',
Region::TERMINAL_API_ENDPOINTS_MAPPING[$region]
);
}

$this->runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false);
$this->runTenderAsync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, true);
$this->connectedTerminals = new \Adyen\Service\ResourceModel\Payment\ConnectedTerminals($this);
Expand Down