Skip to content
Open
Show file tree
Hide file tree
Changes from 13 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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ on:
workflow_dispatch: {}

permissions:
contents: read
contents: read

jobs:
php-test:
name: PHP Test
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ '7.3', '8.2', '8.4' ]
php-version: [ '8.2', '8.4' ]
include:
- php-version: '8.2'
validate: true
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
name: Integration Tests
needs: [php-test, php-lint]
runs-on: ubuntu-latest

# Only run integration tests on pull requests with release label and from the main repository
if: |
github.event_name == 'pull_request' &&
Expand Down
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
"homepage": "https://github.com/Adyen/adyen-php-api-library",
"license": "MIT",
"require": {
"php": ">=7.3",
"ext-ctype": "*",
"php": "^8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*"
"guzzlehttp/guzzle": "^7.3",
"guzzlehttp/psr7": "^1.7 || ^2.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "0.5.0",
"friendsofphp/php-cs-fixer": "*",
"phpunit/phpunit": "9.6.33",
"php-coveralls/php-coveralls": "2.7.0",
"phpunit/phpunit": "^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^3.5",
"squizlabs/php_codesniffer": "3.10.2"
},
"autoload": {
Expand Down
92 changes: 92 additions & 0 deletions src/Adyen/BaseService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Adyen;

/**
* Parent class for API services
*/
class BaseService
{
private Configuration $configuration;

/**
* Service constructor.
*
* @param Configuration $configuration
* @throws AdyenException
*/
public function __construct(Configuration $configuration)
{
if (!$configuration->getAdyenApiKey()) {
$msg = 'API Key is undefined';
throw new AdyenException($msg);
}

if (!$configuration->getEnvironment()) {
$msg = 'The Client does not have a correct environment, use ' .
Environment::TEST . ' or ' . Environment::LIVE;
throw new AdyenException($msg);
}

if ($configuration->getEnvironment() == Environment::LIVE && !$configuration->getLiveEndpointUrlPrefix()) {
$msg = 'The live URL prefix is not defined';
throw new AdyenException($msg);
}
$this->configuration = $configuration;
}

/**
* @param string $url
* @return string
* @throws AdyenException
*/
public function createBaseUrl(string $url): string
{
if ($this->configuration->getEnvironment() == Environment::TEST) {
return $url;
}

if (strpos($url, "pal-") !== false) {
// Add live prefix for PAL endpoints
if ($this->configuration->getLiveEndpointUrlPrefix() == null) {
throw new AdyenException(
"Please add your live URL prefix from CA under Developers > API URLs > Prefix"
);
}

// We inject the prefix formatted like "https://{PREFIX}-"
$url = str_replace(
"https://pal-test.adyen.com/pal/servlet/",
"https://" . $this->configuration->getLiveEndpointUrlPrefix() . '-pal-live.adyenpayments.com/pal/servlet/',
$url
);
}
if (strpos($url, "checkout-") !== false) {
// Add live prefix for Checkout endpoints
if ($this->configuration->getLiveEndpointUrlPrefix() == null) {
throw new AdyenException(
"Please add your checkout live URL prefix from CA under Developers > API URLs > Prefix"
);
}

if (strpos($url, "possdk") !== false) {
// PosSdk (PosMobileApi): inject the live prefix like "https://{PREFIX}-" without duplicating `/checkout` in path
$url = str_replace(
"https://checkout-test.adyen.com/",
"https://" . $this->configuration->getLiveEndpointUrlPrefix() . '-checkout-live.adyenpayments.com/',
$url
);
} else {
// Other services: inject the live prefix like "https://{PREFIX}-"
$url = str_replace(
"https://checkout-test.adyen.com/",
"https://" . $this->configuration->getLiveEndpointUrlPrefix() . '-checkout-live.adyenpayments.com/checkout/',
$url
);
}
}

// Replace 'test' in string with 'live' for the other endpoints
return str_replace('-test', '-live', $url);
}
}
Loading
Loading