diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 585895f9d..1610eedfe 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @AlexandrosMor @acampos1916 @peterojo @rikterbeek @morerice @michaelpaul @candemiralp +* @AlexandrosMor @acampos1916 @peterojo @rikterbeek @morerice @michaelpaul @candemiralp @RokPopov \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4e07ec21..ee7ce9a18 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,6 +36,7 @@ jobs: INTEGRATION_PASSWORD: ${{ secrets.INTEGRATION_PASSWORD }} INTEGRATION_X_API_KEY: ${{ secrets.INTEGRATION_X_API_KEY }} INTEGRATION_MERCHANT_ACCOUNT: ${{ secrets.INTEGRATION_MERCHANT_ACCOUNT }} + INTEGRATION_DONATION_ACCOUNT: ${{ secrets.INTEGRATION_DONATION_ACCOUNT }} INTEGRATION_SKIN_CODE: ${{ secrets.INTEGRATION_SKIN_CODE }} INTEGRATION_HMAC_SIGNATURE: ${{ secrets.INTEGRATION_HMAC_SIGNATURE }} INTEGRATION_STORE_PAYOUT_USERNAME: ${{ secrets.INTEGRATION_STORE_PAYOUT_USERNAME }} diff --git a/README.md b/README.md index 6ee119bab..85a77747c 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@ This is the officially supported PHP library for using Adyen's APIs. +[![version](https://img.shields.io/badge/version-13.0.0-blue.svg)](https://docs.adyen.com/development-resources/libraries) + ## Integration The library supports all APIs under the following services: -* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v68/overview): Our latest integration for accepting online payments. Current supported version: **v68** +* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v69/overview): Our latest integration for accepting online payments. Current supported version: **v69** * [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v51/overview): Our classic integration for online payments. Current supported version: **v51** * [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v49/overview): Endpoints for managing saved payment details. Current supported version: **v49** * [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v51/overview): Endpoints for sending funds to your customers. Current supported version: diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 805b5e7f1..be8aef99b 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -10,7 +10,7 @@ class Client { - const LIB_VERSION = "12.2.0"; + const LIB_VERSION = "13.0.0"; const LIB_NAME = "adyen-php-api-library"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com"; @@ -22,7 +22,7 @@ class Client const API_BIN_LOOKUP_VERSION = "v50"; const API_PAYOUT_VERSION = "v51"; const API_RECURRING_VERSION = "v49"; - const API_CHECKOUT_VERSION = "v68"; + const API_CHECKOUT_VERSION = "v69"; const API_CHECKOUT_UTILITY_VERSION = "v1"; const API_NOTIFICATION_VERSION = "v6"; const API_ACCOUNT_VERSION = "v6"; diff --git a/src/Adyen/Service/ResourceModel/Management/MerchantAccount.php b/src/Adyen/Service/ResourceModel/Management/MerchantAccount.php index 94e0dc9a6..e3eb35d07 100644 --- a/src/Adyen/Service/ResourceModel/Management/MerchantAccount.php +++ b/src/Adyen/Service/ResourceModel/Management/MerchantAccount.php @@ -33,4 +33,16 @@ public function get($merchantId) $url = $this->managementEndpoint . "/merchants/" . $merchantId; return $this->requestHttp($url, 'get'); } + + /** + * @param $merchantId + * @param array $queryParams + * @return mixed + * @throws \Adyen\AdyenException + */ + public function paymentMethodSettings($merchantId, array $queryParams = []) + { + $url = $this->managementEndpoint . "/merchants/" . $merchantId . "/paymentMethodSettings"; + return $this->requestHttp($url, 'get', $queryParams); + } } diff --git a/src/Adyen/Service/ResourceModel/Management/MerchantWebhooks.php b/src/Adyen/Service/ResourceModel/Management/MerchantWebhooks.php index f20370ce5..3fefe4cf2 100644 --- a/src/Adyen/Service/ResourceModel/Management/MerchantWebhooks.php +++ b/src/Adyen/Service/ResourceModel/Management/MerchantWebhooks.php @@ -4,9 +4,13 @@ namespace Adyen\Service\ResourceModel\Management; use Adyen\AdyenException; +use Adyen\Service\AbstractResource; -class MerchantWebhooks extends \Adyen\Service\AbstractResource +class MerchantWebhooks extends AbstractResource { + const MERCHANTS = "/merchants/"; + const WEBHOOKS = "/webhooks"; + /** * Include applicationInfo key in the request parameters * @@ -14,6 +18,17 @@ class MerchantWebhooks extends \Adyen\Service\AbstractResource */ protected $allowApplicationInfo = false; + /** + * @param $merchantId + * @return mixed + * @throws AdyenException + */ + public function list($merchantId) + { + $url = $this->managementEndpoint . self::MERCHANTS . $merchantId . self::WEBHOOKS; + return $this->requestHttp($url, 'get'); + } + /** * @param $merchantId * @param $params @@ -22,7 +37,7 @@ class MerchantWebhooks extends \Adyen\Service\AbstractResource */ public function create($merchantId, $params) { - $url = $this->managementEndpoint . "/merchants/" . $merchantId . "/webhooks"; + $url = $this->managementEndpoint . self::MERCHANTS . $merchantId . self::WEBHOOKS; return $this->requestHttp($url, 'post', $params); } @@ -35,7 +50,7 @@ public function create($merchantId, $params) */ public function update($merchantId, $webhookId, $params) { - $url = $this->managementEndpoint . "/merchants/" . $merchantId . "/webhooks/" . $webhookId; + $url = $this->managementEndpoint . self::MERCHANTS . $merchantId . self::WEBHOOKS . "/" . $webhookId; return $this->requestHttp($url, 'patch', $params); } @@ -47,7 +62,21 @@ public function update($merchantId, $webhookId, $params) */ public function generateHmac($merchantId, $webhookId) { - $url = $this->managementEndpoint . "/merchants/" . $merchantId . "/webhooks/" . $webhookId . "/generateHmac"; + $url = $this->managementEndpoint . self::MERCHANTS . $merchantId . self::WEBHOOKS . "/" + . $webhookId . "/generateHmac"; return $this->requestHttp($url, 'post'); } + + /** + * @param $merchantId + * @param $webhookId + * @param $params + * @return mixed + * @throws AdyenException + */ + public function test($merchantId, $webhookId, $params) + { + $url = $this->managementEndpoint . self::MERCHANTS . $merchantId . self::WEBHOOKS . "/" . $webhookId . "/test"; + return $this->requestHttp($url, 'post', $params); + } } diff --git a/tests/Integration/CheckoutTest.php b/tests/Integration/CheckoutTest.php index 87a3248d1..ff6d63851 100644 --- a/tests/Integration/CheckoutTest.php +++ b/tests/Integration/CheckoutTest.php @@ -280,7 +280,7 @@ public function testDonationsSuccess() 'reference' => "Your order number", 'donationToken' => $paymentResult['donationToken'], 'donationOriginalPspReference' => $paymentResult['pspReference'], - 'donationAccount' => $this->merchantAccount, + 'donationAccount' => $this->donationAccount, 'returnUrl' => self::RETURN_URL, 'shopperInteraction' => "Ecommerce" ); diff --git a/tests/Integration/ManagementTest.php b/tests/Integration/ManagementTest.php index 03b64272f..27de7e1f9 100644 --- a/tests/Integration/ManagementTest.php +++ b/tests/Integration/ManagementTest.php @@ -209,6 +209,33 @@ public function testGenerateHmac() $this->assertNotEmpty($response['hmacKey']); } + /** + * post /merchants/{id}/webhooks/{webhookId}/test + * + * @throws \Adyen\AdyenException + */ + public function testMerchantWebhooksTest() + { + if (empty($this->settings['merchantAccount']) || + $this->settings['merchantAccount'] == self::YOUR_MERCHANT_ACCOUNT) { + $this->skipTest(self::SKIP_TEST_MESSAGE); + return null; + } + $listWebhooksResponse = $this->management->merchantWebhooks->list($this->settings['merchantAccount']); + $this->assertNotEmpty($listWebhooksResponse); + + if (isset($listWebhooksResponse['data'][0]['id'])) { + $params = ['types' => ['AUTHORISATION']]; + $testWebhook = $this->management->merchantWebhooks->test( + $this->settings['merchantAccount'], + $listWebhooksResponse['data'][0]['id'], + $params + ); + $this->assertNotEmpty($testWebhook); + } else { + $this->fail("Unable to retrieve the webhooks"); + } + } /** * Get /me/allowedOrigins @@ -248,6 +275,18 @@ public function testCreateAllowedOrigins() } } + /** + * Get /merchants/{id}/paymentMethodSettings + */ + public function testGetPaymentMethodSettings() + { + $response = $this->management->merchantAccount->paymentMethodSettings($this->settings['merchantAccount']); + $this->assertNotEmpty($response['data']); + $this->assertNotEmpty($response['data'][0]['PaymentMethod']); + $this->assertNotEmpty($response['data'][0]['PaymentMethod']['id']); + $this->assertNotEmpty($response['data'][0]['PaymentMethod']['type']); + } + /** * @param $e */ diff --git a/tests/TestCase.php b/tests/TestCase.php index c8e9d696a..39373b8dc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,6 +30,7 @@ class TestCase extends \PHPUnit\Framework\TestCase { protected $merchantAccount; + protected $donationAccount; protected $skinCode; protected $hmacSignature; @@ -45,6 +46,7 @@ public function __construct($name = null, array $data = [], $dataName = '') parent::__construct($name, $data, $dataName); $this->settings = $this->loadConfig(); $this->merchantAccount = $this->getMerchantAccount(); + $this->donationAccount = $this->getDonationAccount(); $this->skinCode = $this->getSkinCode(); $this->hmacSignature = $this->getHmacSignature(); @@ -70,20 +72,17 @@ private function setDefaultsDuringDevelopment() */ protected function createClient() { - // load settings from .ini file - $settings = $this->settings; - // validate username, password and MERCHANTAccount - if (!empty($settings['username']) && - $settings['username'] != "YOUR USERNAME" && - !empty($settings['password']) && - $settings['password'] != "YOUR PASSWORD" + if (!empty($this->settings['username']) && + $this->settings['username'] != "YOUR USERNAME" && + !empty($this->settings['password']) && + $this->settings['password'] != "YOUR PASSWORD" ) { $client = new Client(); $client->setApplicationName("My Test Application"); - $client->setUsername($settings['username']); - $client->setPassword($settings['password']); + $client->setUsername($this->settings['username']); + $client->setPassword($this->settings['password']); $client->setEnvironment(Environment::TEST); return $client; @@ -117,16 +116,13 @@ protected function createClientWithoutTestIni() */ protected function createPayoutClient() { - // load settings from .ini file - $settings = $this->settings; - // validate username, password and MERCHANTAccount - if (isset($settings['storePayoutUsername']) && isset($settings['storePayoutPassword'])) { - if ($settings['storePayoutUsername'] == "YOUR STORE PAYOUT USERNAME" - || $settings['storePayoutUsername'] == "" - || $settings['storePayoutPassword'] == "YOUR STORE PAYOUT PASSWORD" - || $settings['storePayoutPassword'] == "") { + if (isset($this->settings['storePayoutUsername']) && isset($this->settings['storePayoutPassword'])) { + if ($this->settings['storePayoutUsername'] == "YOUR STORE PAYOUT USERNAME" + || $this->settings['storePayoutUsername'] == "" + || $this->settings['storePayoutPassword'] == "YOUR STORE PAYOUT PASSWORD" + || $this->settings['storePayoutPassword'] == "") { $client = new Client(); $client->setApplicationName("My Test Application"); $client->setEnvironment(Environment::TEST); @@ -137,8 +133,8 @@ protected function createPayoutClient() } else { $client = new Client(); $client->setApplicationName("My Test Application"); - $client->setUsername($settings['storePayoutUsername']); - $client->setPassword($settings['storePayoutPassword']); + $client->setUsername($this->settings['storePayoutUsername']); + $client->setPassword($this->settings['storePayoutPassword']); $client->setEnvironment(Environment::TEST); return $client; } @@ -154,16 +150,13 @@ protected function createPayoutClient() */ protected function createReviewPayoutClient() { - // load settings from .ini file - $settings = $this->settings; - // validate username, password and MERCHANTAccount - if (isset($settings['reviewPayoutUsername']) && isset($settings['reviewPayoutPassword'])) { - if ($settings['reviewPayoutUsername'] == "YOUR REVIEW PAYOUT USERNAME" - || $settings['reviewPayoutUsername'] == "" - || $settings['reviewPayoutPassword'] == "YOUR REVIEW PAYOUT PASSWORD" - || $settings['reviewPayoutPassword'] == "") { + if (isset($this->settings['reviewPayoutUsername']) && isset($this->settings['reviewPayoutPassword'])) { + if ($this->settings['reviewPayoutUsername'] == "YOUR REVIEW PAYOUT USERNAME" + || $this->settings['reviewPayoutUsername'] == "" + || $this->settings['reviewPayoutPassword'] == "YOUR REVIEW PAYOUT PASSWORD" + || $this->settings['reviewPayoutPassword'] == "") { $client = new Client(); $client->setApplicationName("My Test Application"); $client->setEnvironment(Environment::TEST); @@ -174,8 +167,8 @@ protected function createReviewPayoutClient() } else { $client = new Client(); $client->setApplicationName("My Test Application"); - $client->setUsername($settings['reviewPayoutUsername']); - $client->setPassword($settings['reviewPayoutPassword']); + $client->setUsername($this->settings['reviewPayoutUsername']); + $client->setPassword($this->settings['reviewPayoutPassword']); $client->setEnvironment(Environment::TEST); return $client; } @@ -188,16 +181,13 @@ protected function createReviewPayoutClient() protected function createTerminalCloudAPIClient() { - // load settings from .ini file - $settings = $this->settings; - - if (empty($settings['x-api-key']) || $settings['x-api-key'] == 'YOUR X-API KEY') { + if (empty($this->settings['x-api-key']) || $this->settings['x-api-key'] == 'YOUR X-API KEY') { $this->skipTest("Skipped the test. Configure your x-api-key in the config"); } else { $client = new Client(); $client->setApplicationName("My Test Terminal API App"); $client->setEnvironment(Environment::TEST); - $client->setXApiKey($settings['x-api-key']); + $client->setXApiKey($this->settings['x-api-key']); return $client; } } @@ -206,15 +196,12 @@ protected function createClientWithMerchantAccount() { $client = $this->createClient(); - // load settings from .ini file - $settings = $this->settings; - - if (empty($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { + if (empty($this->settings['merchantAccount']) || $this->settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { $this->skipTest("Skipped the test. Configure your MerchantAccount in the config"); return null; } - $client->setMerchantAccount($settings['merchantAccount']); + $client->setMerchantAccount($this->settings['merchantAccount']); return $client; } @@ -222,59 +209,58 @@ protected function createCheckoutAPIClient() { $client = $this->createClientWithMerchantAccount(); - // load settings from .ini file - $settings = $this->settings; - - if (empty($settings['x-api-key']) || $settings['x-api-key'] == 'YOUR X-API KEY') { + if (empty($this->settings['x-api-key']) || $this->settings['x-api-key'] == 'YOUR X-API KEY') { $this->skipTest("Skipped the test. Configure your x-api-key"); } else { - $client->setXApiKey($settings['x-api-key']); + $client->setXApiKey($this->settings['x-api-key']); return $client; } } protected function getMerchantAccount() { - $settings = $this->settings; + if (empty($this->settings['merchantAccount']) || $this->settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { + return null; + } + + return $this->settings['merchantAccount']; + } - if (empty($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') { + protected function getDonationAccount() + { + if (empty($this->settings['donationAccount']) || + $this->settings['donationAccount'] == 'YOUR DONATION MERCHANT ACCOUNT') { return null; } - return $settings['merchantAccount']; + return $this->settings['donationAccount']; } protected function getSkinCode() { - $settings = $this->settings; - - if (empty($settings['skinCode']) || $settings['skinCode'] == 'YOUR SKIN CODE') { + if (empty($this->settings['skinCode']) || $this->settings['skinCode'] == 'YOUR SKIN CODE') { return null; } - return $settings['skinCode']; + return $this->settings['skinCode']; } protected function getHmacSignature() { - $settings = $this->settings; - - if (empty($settings['hmacSignature'])|| $settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') { + if (empty($this->settings['hmacSignature'])|| $this->settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') { return null; } - return $settings['hmacSignature']; + return $this->settings['hmacSignature']; } protected function getPOIID() { - $settings = $this->settings; - - if (empty($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') { + if (empty($this->settings['POIID']) || $this->settings['POIID'] == 'MODEL-SERIALNUMBER') { return null; } - return $settings['POIID']; + return $this->settings['POIID']; } protected function loadConfig() @@ -287,6 +273,7 @@ protected function loadConfig() 'password' => getenv('INTEGRATION_PASSWORD'), 'x-api-key' => getenv('INTEGRATION_X_API_KEY'), 'merchantAccount' => getenv('INTEGRATION_MERCHANT_ACCOUNT'), + 'donationAccount' => getenv('INTEGRATION_DONATION_ACCOUNT'), 'skinCode' => getenv('INTEGRATION_SKIN_CODE'), 'hmacSignature' => getenv('INTEGRATION_HMAC_SIGNATURE'), 'storePayoutUsername' => getenv('INTEGRATION_STORE_PAYOUT_USERNAME'), diff --git a/tests/Unit/TestCaseMock.php b/tests/Unit/TestCaseMock.php index 20adcdd0e..147010b39 100644 --- a/tests/Unit/TestCaseMock.php +++ b/tests/Unit/TestCaseMock.php @@ -53,7 +53,11 @@ protected function createMockClient($jsonFile, $httpStatus, $errno = null, $envi ->willReturn(array($errno, null)); $curlClient->method('requestJson') ->willReturnCallback(function (Service $service, $requestUrl, $params) use ($json, $client, $errno) { - $result = json_decode($json, true); + if (!is_null($json)) { + $result = json_decode($json, true); + } else { + $result = null; + } if ($client->getLogger()) { $client->getLogger()->info(json_encode($params)); $client->getLogger()->info($json); diff --git a/tests/config/test.ini.sample b/tests/config/test.ini.sample index f1946c6d9..a0d6a2ac5 100644 --- a/tests/config/test.ini.sample +++ b/tests/config/test.ini.sample @@ -2,6 +2,7 @@ username = YOUR USERNAME password = "YOUR PASSWORD" merchantAccount = YOUR MERCHANT ACCOUNT +donationAccount = YOUR DONATION MERCHANT ACCOUNT skinCode = YOUR SKIN CODE hmacSignature = YOUR HMAC SIGNATURE x-api-key = YOUR X-API KEY