### Install Composer Dependencies Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Install the library and its development dependencies using Composer. This is a standard setup step for PHP projects. ```bash composer install ``` -------------------------------- ### General API Usage with API Key (Live Environment) Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md Configure the Adyen client for the live environment using your API key and live URL prefix. This snippet shows the client setup for live transactions. ```php $client = new \Adyen\Client(); $client->setXApiKey("YOUR API KEY"); $client->setEnvironment(\Adyen\Environment::LIVE, 'Your live URL prefix'); $client->setTimeout(30); ... ``` -------------------------------- ### Install Adyen PHP API Library with Composer Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md Use Composer to add the Adyen PHP API library to your project dependencies. Ensure you have Composer installed and follow its documentation for setup. ```bash composer require adyen/php-api-library ``` -------------------------------- ### General API Usage with API Key (Test Environment) Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md Configure the Adyen client with your API key and set it to the test environment. This example demonstrates creating a payment request with payment method, amount, and merchant details. ```php $client = new \Adyen\Client(); $client->setXApiKey("YOUR API KEY"); $client->setEnvironment(\Adyen\Environment::TEST); $client->setTimeout(30); $service = new \Adyen\Service\Checkout\PaymentsApi($client); // Create PaymentMethod object $paymentMethod = new \Adyen\Model\Checkout\CheckoutPaymentMethod(); $paymentMethod ->setType("scheme") ->setEncryptedBankAccountNumber("test_4111111111111111") ->setEncryptedExpiryMonth("test_03") ->setEncryptedExpiryYear("test_2030") ->setEncryptedSecurityCode("test_737"); // Creating Amount Object $amount = new \Adyen\Model\Checkout\Amount(); $amount ->setValue(1500) ->setCurrency("EUR"); // Create the actual Payments Request $paymentRequest = new \Adyen\Model\Checkout\PaymentRequest(); $paymentRequest ->setMerchantAccount("YOUR MERCHANT ACCOUNT") ->setPaymentMethod($paymentMethod) ->setAmount($amount) ->setReference("payment-test") ->setReturnUrl("https://your-company.com/..."); $result = $service->payments($paymentRequest); ``` -------------------------------- ### Instantiate Request Objects Using ArrayAccess Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md This example shows how to create request objects for the PaymentLinks API using associative arrays, which can be helpful for migrating from older implementations. The library also supports strongly typed objects. ```php $service = new \Adyen\Service\Checkout\PaymentLinksApi($client); $params = array( 'merchantAccount' => "YourMerchantAccount", 'reference' => '12345', 'amount' => array('currency' => "BRL", 'value' => 1250), 'countryCode' => "BR", 'shopperReference' => "YourUniqueShopperId", 'shopperEmail' => "test@email.com", 'shopperLocale' => "pt_BR", 'billingAddress' => array(...), 'deliveryAddress' => array(...), ); $createPaymentLinkRequest = new \Adyen\Model\Checkout\PaymentLinkRequest($params); $result = $service->paymentLinks($createPaymentLinkRequest); $paymentLink = $result->getUrl(); // or use $result['url'] if you want to use arrayAccess ``` -------------------------------- ### Include Composer Autoloader in PHP Script Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md After installing via Composer, include the autoloader file in your PHP script to make the Adyen library classes available. ```php require __DIR__ . '/vendor/autoload.php'; ``` -------------------------------- ### Validate and Parse Management Webhooks Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md This example shows how to validate a management webhook using an HMAC key and signature, followed by parsing the JSON payload to extract the webhook information. ```php $jsonString = 'webhook_payload'; $isValid = $hmac->validateHMAC("YOUR_HMAC_KEY", "YOUR_HMAC_SIGN", $jsonString); if ($isValid) { $webhookParser = new \Adyen\Service\ManagementWebhookParser($jsonString); $result = $webhookParser->getGenericWebhook(); } ``` -------------------------------- ### Generate All PHP Services Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Run the Gradle command to generate all services for the PHP library. This command is part of the local code generation process. ```bash ./gradlew :php:services ``` -------------------------------- ### Run Unit Tests Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Execute the unit tests for the library using PHPUnit. Ensure your test credentials are configured if necessary. ```bash vendor/bin/phpunit --testsuite unit ``` -------------------------------- ### Clean Repository and Generate PHP Service Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Clean the repository and generate a specific service, like Checkout. This ensures a fresh generation process. ```bash ./gradlew :php:cleanRepo :php:checkout ``` -------------------------------- ### Link Local Adyen PHP API Library to Automation Project Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Link your local clone of the Adyen PHP API Library to the automation project. This ensures that the generator targets your local code. ```bash rm -rf php/repo ln -s ../adyen-php-api-library php/repo ``` -------------------------------- ### General API Usage with Basic Authentication Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md Configure the Adyen client using basic authentication with your username and password for the test environment. This is an alternative to API key authentication. ```php $client = new \Adyen\Client(); $client->setUsername("YOUR USERNAME"); $client->setPassword("YOUR PASSWORD"); $client->setEnvironment(\Adyen\Environment::TEST); $client->setTimeout(30); ... ``` -------------------------------- ### Generate Specific PHP Service (e.g., Checkout) Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Generate a specific service, such as Checkout, for the PHP library. This is useful for targeted development or testing. ```bash ./gradlew :php:checkout ``` -------------------------------- ### Clone Adyen SDK Automation Repository Source: https://github.com/adyen/adyen-php-api-library/blob/main/AGENTS.md Clone the repository used for automating SDK code generation. This is a prerequisite for local code generation. ```bash git clone https://github.com/Adyen/adyen-sdk-automation.git ``` -------------------------------- ### Validate and Parse Banking Webhooks Source: https://github.com/adyen/adyen-php-api-library/blob/main/README.md This snippet demonstrates how to validate an incoming banking webhook using an HMAC key and signature, and then parse the JSON payload to retrieve webhook data. ```php $jsonString = 'webhook_payload'; $isValid = $hmac->validateHMAC("YOUR_HMAC_KEY", "YOUR_HMAC_SIGN", $jsonString); if ($isValid) { $webhookParser = new \Adyen\Service\BankingWebhookParser($jsonString); $result = $webhookParser->getGenericWebhook(); } ``` -------------------------------- ### Validate Banking Webhook HMAC Signature Source: https://github.com/adyen/adyen-php-api-library/blob/main/tools/hmac/README.md Use this script to calculate and validate the HMAC signature for banking webhooks. Provide your HMAC key and the path to the payload JSON file. ```bash php tools/hmac/HMACValidatorBanking.php {hmacKey} {path to JSON file} ``` ```bash php tools/hmac/HMACValidatorBanking.php 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB tools/hmac/payload2.json ``` -------------------------------- ### Validate Payments Webhook HMAC Signature Source: https://github.com/adyen/adyen-php-api-library/blob/main/tools/hmac/README.md Use this script to calculate and validate the HMAC signature for payments webhooks. Provide your HMAC key and the path to the payload JSON file. ```bash php tools/hmac/HMACValidatorPayments.php {hmacKey} {path to JSON file} ``` ```bash php tools/hmac/HMACValidatorPayments.php 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB tools/hmac/payload.json ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.