From a31311b4132d78c4c5a1aa981e7e9ab5faf33716 Mon Sep 17 00:00:00 2001 From: Costin Soare Date: Tue, 5 Apr 2022 18:26:22 +0200 Subject: [PATCH 1/8] add support for checkout captures endpoint --- src/Adyen/Service/Checkout.php | 17 ++++++++++ .../ResourceModel/Checkout/Captures.php | 31 +++++++++++++++++++ tests/Integration/CheckoutTest.php | 24 ++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/Adyen/Service/ResourceModel/Checkout/Captures.php diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index cf98b4755..3889d7834 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -69,6 +69,11 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService */ protected $reversals; + /** + * @var ResourceModel\Checkout\Captures + */ + protected $captures; + /** * Checkout constructor. * @@ -91,6 +96,7 @@ public function __construct(\Adyen\Client $client) $this->sessions = new \Adyen\Service\ResourceModel\Checkout\Sessions($this); $this->refunds = new \Adyen\Service\ResourceModel\Checkout\Refunds($this); $this->reversals = new \Adyen\Service\ResourceModel\Checkout\Reversals($this); + $this->captures = new \Adyen\Service\ResourceModel\Checkout\Captures($this); } /** @@ -237,4 +243,15 @@ public function reversals($params, $requestOptions = null) { return $this->reversals->request($params, $requestOptions); } + + /** + * @param array $params + * @param array|null $requestOptions + * @return mixed + * @throws \Adyen\AdyenException + */ + public function captures($params, $requestOptions = null) + { + return $this->captures->request($params, $requestOptions); + } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Captures.php b/src/Adyen/Service/ResourceModel/Checkout/Captures.php new file mode 100644 index 000000000..652404919 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/Captures.php @@ -0,0 +1,31 @@ +endpoint = $this->getCheckoutEndpoint($service) . + '/' . $service->getClient()->getApiCheckoutVersion() . '/payments/{paymentPspReference}/captures'; + parent::__construct($service, $this->endpoint, $this->allowApplicationInfo); + } +} diff --git a/tests/Integration/CheckoutTest.php b/tests/Integration/CheckoutTest.php index 4b25d5a33..21c3fab13 100644 --- a/tests/Integration/CheckoutTest.php +++ b/tests/Integration/CheckoutTest.php @@ -358,4 +358,28 @@ public function testReversals() $this->assertEquals('received', $result['status']); } + + public function testCaptures() + { + $this->testPaymentsSuccess(); + + // create Checkout client + $client = $this->createCheckoutAPIClient(); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'paymentPspReference' => $this->pspReference, + 'merchantAccount' => $this->merchantAccount, + 'amount' => [ + 'currency' => "EUR", + 'value' => 1000 + ] + ); + + $result = $service->captures($params); + + $this->assertEquals('received', $result['status']); + } } From 32eba648a0858b0917d1ea95ab3af3d71a4d7638 Mon Sep 17 00:00:00 2001 From: Costin Soare Date: Wed, 6 Apr 2022 09:51:48 +0200 Subject: [PATCH 2/8] support for checkout cancels --- src/Adyen/Service/Checkout.php | 17 ++++++++++ .../ResourceModel/Checkout/Cancels.php | 31 +++++++++++++++++++ tests/Integration/CheckoutTest.php | 20 ++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/Adyen/Service/ResourceModel/Checkout/Cancels.php diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index 3889d7834..b42db22a2 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -74,6 +74,11 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService */ protected $captures; + /** + * @var ResourceModel\Checkout\Cancels + */ + protected $cancels; + /** * Checkout constructor. * @@ -97,6 +102,7 @@ public function __construct(\Adyen\Client $client) $this->refunds = new \Adyen\Service\ResourceModel\Checkout\Refunds($this); $this->reversals = new \Adyen\Service\ResourceModel\Checkout\Reversals($this); $this->captures = new \Adyen\Service\ResourceModel\Checkout\Captures($this); + $this->cancels = new \Adyen\Service\ResourceModel\Checkout\Cancels($this); } /** @@ -254,4 +260,15 @@ public function captures($params, $requestOptions = null) { return $this->captures->request($params, $requestOptions); } + + /** + * @param array $params + * @param array|null $requestOptions + * @return mixed + * @throws \Adyen\AdyenException + */ + public function cancels($params, $requestOptions = null) + { + return $this->cancels->request($params, $requestOptions); + } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Cancels.php b/src/Adyen/Service/ResourceModel/Checkout/Cancels.php new file mode 100644 index 000000000..64f23206a --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/Cancels.php @@ -0,0 +1,31 @@ +endpoint = $this->getCheckoutEndpoint($service) . + '/' . $service->getClient()->getApiCheckoutVersion() . '/payments/{paymentPspReference}/cancels'; + parent::__construct($service, $this->endpoint, $this->allowApplicationInfo); + } +} diff --git a/tests/Integration/CheckoutTest.php b/tests/Integration/CheckoutTest.php index 21c3fab13..87a3248d1 100644 --- a/tests/Integration/CheckoutTest.php +++ b/tests/Integration/CheckoutTest.php @@ -382,4 +382,24 @@ public function testCaptures() $this->assertEquals('received', $result['status']); } + + public function testCancels() + { + $this->testPaymentsSuccess(); + + // create Checkout client + $client = $this->createCheckoutAPIClient(); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'paymentPspReference' => $this->pspReference, + 'merchantAccount' => $this->merchantAccount, + ); + + $result = $service->cancels($params); + + $this->assertEquals('received', $result['status']); + } } From 35b84f53077718c486fdaf63deaddbe66a7a380e Mon Sep 17 00:00:00 2001 From: Costin Soare Date: Wed, 27 Apr 2022 16:55:44 +0200 Subject: [PATCH 3/8] set ssl verify option --- src/Adyen/Client.php | 10 ++++++++++ src/Adyen/Config.php | 10 ++++++++++ src/Adyen/HttpClient/CurlClient.php | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 805b5e7f1..8320cbc0e 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -136,6 +136,16 @@ public function setHttpProxy($proxy) $this->config->set('http-proxy', $proxy); } + /** + * Set the path to a CA bundle file that enables verification using a custom certificate + * + * @param string $certFilePath + */ + public function setSslVerify($certFilePath) + { + $this->config->set('ssl-verify', $certFilePath); + } + /** * Set environment to connect to test or live platform of Adyen * For live please specify the unique identifier. diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index 4bcfd5712..dc1c40351 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -102,6 +102,16 @@ public function getHttpProxy() return !empty($this->data['http-proxy']) ? $this->data['http-proxy'] : null; } + /** + * Get the path to a CA bundle file that enables verification using a custom certificate + * + * @return mixed|null + */ + public function getSslVerify() + { + return !empty($this->data['ssl-verify']) ? $this->data['ssl-verify'] : null; + } + /** * @return mixed|string */ diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 7a71ee5d3..e332b9b36 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -84,6 +84,28 @@ public function curlSetHttpProxy($ch, $httpProxy) } } + /** + * Set the path to a custom CA bundle in the current curl configuration. + * + * @param resource $ch + * @param string $certFilePath + * @throws AdyenException + */ + public function curlSetSslVerify($ch, $certFilePath) + { + if (empty($certFilePath)) { + return; + } + + if (!file_exists($certFilePath)) { + throw new AdyenException("SSL CA bundle not found: {$certFilePath}"); + } + + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($ch, CURLOPT_CAINFO, $certFilePath); + } + /** * Request to Adyen with query string used for Directory Lookup * @@ -102,6 +124,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params) $password = $config->getPassword(); $httpProxy = $config->getHttpProxy(); $environment = $config->getEnvironment(); + $sslVerify = $config->getSslVerify(); // log the request $this->logRequest($logger, $requestUrl, $environment, $params); @@ -113,6 +136,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params) curl_setopt($ch, CURLOPT_POST, 1); $this->curlSetHttpProxy($ch, $httpProxy); + $this->curlSetSslVerify($ch, $sslVerify); // set authorisation curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); @@ -356,6 +380,7 @@ public function requestHttp(\Adyen\Service $service, $requestUrl, $params, $meth $xApiKey = $config->getXApiKey(); $httpProxy = $config->getHttpProxy(); $environment = $config->getEnvironment(); + $sslVerify = $config->getSslVerify(); $jsonRequest = json_encode($params); @@ -382,6 +407,7 @@ public function requestHttp(\Adyen\Service $service, $requestUrl, $params, $meth } $this->curlSetHttpProxy($ch, $httpProxy); + $this->curlSetSslVerify($ch, $sslVerify); //create a custom User-Agent $userAgent = $config->get('applicationName') . " " . From ca391334c6dacd3f09620baed9ab1e5061fda414 Mon Sep 17 00:00:00 2001 From: Costin Soare Date: Wed, 27 Apr 2022 17:03:13 +0200 Subject: [PATCH 4/8] proxy url schema --- src/Adyen/HttpClient/CurlClient.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index e332b9b36..1c9e2f5c4 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -73,7 +73,11 @@ public function curlSetHttpProxy($ch, $httpProxy) throw new AdyenException("Invalid proxy configuration " . $httpProxy); } - $proxy = $urlParts["host"]; + $proxy = ""; + if (isset($urlParts["schema"])) { + $proxy = $urlParts["schema"] . "://"; + } + $proxy .= $urlParts["host"]; if (isset($urlParts["port"])) { $proxy .= ":" . $urlParts["port"]; } From 6ab9c8dfa72d85cecdbe0431731061d17ec25f90 Mon Sep 17 00:00:00 2001 From: Costin Soare Date: Wed, 27 Apr 2022 17:04:08 +0200 Subject: [PATCH 5/8] typo --- src/Adyen/HttpClient/CurlClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 1c9e2f5c4..69ddcb3cb 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -74,8 +74,8 @@ public function curlSetHttpProxy($ch, $httpProxy) } $proxy = ""; - if (isset($urlParts["schema"])) { - $proxy = $urlParts["schema"] . "://"; + if (isset($urlParts["scheme"])) { + $proxy = $urlParts["scheme"] . "://"; } $proxy .= $urlParts["host"]; if (isset($urlParts["port"])) { From 66c9facf23db6ffce9b08ff50d1b4dc638578739 Mon Sep 17 00:00:00 2001 From: Wouter Boereboom <62436079+wboereboom@users.noreply.github.com> Date: Mon, 10 Jul 2023 10:42:42 +0200 Subject: [PATCH 6/8] Remove Capital from Makefile (#517) --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3c58d473f..833443f61 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ Payout: spec=PayoutService-v68 Management: spec=ManagementService-v1 LegalEntityManagement: spec=LegalEntityService-v3 Transfers: spec=TransferService-v3 -Capital: spec=GrantService-v3 # Classic Platforms marketpay/account: spec=AccountService-v6 @@ -55,7 +54,7 @@ $(modelGen): target/spec $(openapi-generator-jar) # Service Generation; split up in to templates based on the size of the service. That is, some services have no subgroups and are thus generated in one single file, others are grouped in a directory. Services:=BalancePlatform Checkout StoredValue Payments Payout Management LegalEntityManagement Transfers -SingleFileServices:=BalanceControl BinLookup DataProtection StoredValue POSTerminalManagement Recurring Capital +SingleFileServices:=BalanceControl BinLookup DataProtection StoredValue POSTerminalManagement Recurring all: $(Services) $(SingleFileServices) @@ -125,4 +124,4 @@ clean: git clean -f -d $(models) -.PHONY: templates models $(services) \ No newline at end of file +.PHONY: templates models $(services) From 172a35c5c9c1e367c764b910da2903a7957c0d9f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:16:25 +0200 Subject: [PATCH 7/8] chore(deps): update dependency dms/phpunit-arraysubset-asserts to v0.5.0 (#507) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c453b9c48..bc065ed39 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "monolog/monolog": "^1.16 || ^2.0 || ^3.0" }, "require-dev": { - "dms/phpunit-arraysubset-asserts": "0.4.0", + "dms/phpunit-arraysubset-asserts": "0.5.0", "friendsofphp/php-cs-fixer": "*", "phpunit/phpunit": "9.6.7", "php-coveralls/php-coveralls": "2.5.3", From efc2ec6859b452ec9347ea7dedbbfe14690f48ca Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:57:50 +0200 Subject: [PATCH 8/8] chore(deps): update dependency phpunit/phpunit to v9.6.10 (#504) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bc065ed39..2e655328f 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require-dev": { "dms/phpunit-arraysubset-asserts": "0.5.0", "friendsofphp/php-cs-fixer": "*", - "phpunit/phpunit": "9.6.7", + "phpunit/phpunit": "9.6.10", "php-coveralls/php-coveralls": "2.5.3", "squizlabs/php_codesniffer": "3.7.2" },