adyen / php-api-library
A PHP client library for accessing Adyen APIs
Installs: 10 453 555
Dependents: 14
Suggesters: 0
Security: 0
Stars: 157
Watchers: 20
Forks: 106
Open Issues: 9
Requires
- php: >=7.3
- ext-ctype: *
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
Requires (Dev)
- dms/phpunit-arraysubset-asserts: 0.5.0
- friendsofphp/php-cs-fixer: *
- php-coveralls/php-coveralls: 2.7.0
- phpunit/phpunit: 9.6.19
- squizlabs/php_codesniffer: 3.10.2
- dev-main
- dev-develop
- v23.0.0
- v22.1.0
- v22.0.0
- v21.1.0
- v21.0.0
- v20.4.0
- v20.3.0
- v20.2.0
- v20.1.0
- v20.0.0
- v19.1.0
- v19.0.0
- v18.2.1
- v18.2.0
- v18.1.0
- v18.0.0
- v17.5.0
- v17.4.0
- v17.3.0
- v17.2.0
- v17.1.1
- v17.1.0
- v17.0.0
- v16.1.0
- v16.0.0
- v16.0.0-beta
- v15.5.1
- v15.5.0
- v15.4.0
- v15.3.0
- v15.2.0
- v15.1.0
- v15.0.0
- 15.0.0-beta
- 14.0.1
- 14.0.0
- 13.0.5
- 13.0.4
- 13.0.3
- 13.0.2
- 13.0.1
- 13.0.0
- 12.2.0
- 12.1.0
- 12.0.0
- 11.0.0
- 10.1.0
- 10.0.0
- 9.0.0
- 8.1.1
- 8.1.0
- 8.0.0
- 7.1.0
- 7.0.0
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.1
- 6.0.0
- 5.0.1
- 5.0.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.1.0
- 3.0.0
- 2.1.0
- 2.0.0
- 1.6.1
- 1.6.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-renovate/phpunit-phpunit-11.x
- dev-sdk-automation/models
- dev-renovate/squizlabs-php_codesniffer-3.x
- dev-renovate/phpunit-phpunit-9.x
- dev-automation/services
- dev-fix-delete-version
- dev-automation/models
- dev-AlexandrosMor-patch-3
- dev-AlexandrosMor-patch-2
- dev-AlexandrosMor-patch-1
- dev-releases/v15
- dev-fix-empty-response
This package is auto-updated.
Last update: 2024-12-18 14:43:23 UTC
README
Adyen PHP API Library
This is the officially supported PHP library for using Adyen's APIs.
Supported API versions
The library supports all APIs under the following services:
Supported Webhook versions
The library supports all webhooks under the following model directories:
For more information, refer to our documentation or the API Explorer.
Prerequisites
- Adyen test account
- API key. For testing, your API credential needs to have the API PCI Payments role.
- PHP 7.3 or later
- cURL with SSL support.
- The PHP extensions: ctype, curl, json, mbstring and openssl.
- See composer require list for the complete list of dependencies.
Legacy version support
If using PHP versions 7.2 or lower, download our library version 6.3.0.
Installation
You can use Composer. Follow the installation instructions if you do not already have composer installed.
composer require adyen/php-api-library
In your PHP script, make sure you include the autoloader:
require __DIR__ . '/vendor/autoload.php';
Alternatively, you can download the release on GitHub.
Using the library
General use with API key
Set up the client as a singleton resource; you'll use it for the API calls that you make to Adyen:
$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);
General use with API key for live environment
$client = new \Adyen\Client(); $client->setXApiKey("YOUR API KEY"); $client->setEnvironment(\Adyen\Environment::LIVE, 'Your live URL prefix'); $client->setTimeout(30); ...
General use with basic auth
$client = new \Adyen\Client(); $client->setUsername("YOUR USERNAME"); $client->setPassword("YOUR PASSWORD"); $client->setEnvironment(\Adyen\Environment::TEST); $client->setTimeout(30); ...
Instantiating the request objects through the arrayAccess implementation (for easy migration)
... $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
Using Banking Webhooks
... $jsonString = 'webhook_payload'; $isValid = $hmac->validateHMAC("YOUR_HMAC_KEY", "YOUR_HMAC_SIGN", $jsonString); if ($isValid) { $webhookParser = new \Adyen\Service\BankingWebhookParser($jsonString); $result = $webhookParser->getGenericWebhook(); }
Using Management Webhooks
... $jsonString = 'webhook_payload'; $isValid = $hmac->validateHMAC("YOUR_HMAC_KEY", "YOUR_HMAC_SIGN", $jsonString); if ($isValid) { $webhookParser = new \Adyen\Service\ManagementWebhookParser($jsonString); $result = $webhookParser->getGenericWebhook(); }
Example integration
For a closer look at how our PHP library works, clone our Laravel example integration. This includes commented code, highlighting key features and concepts, and examples of API calls that can be made using the library.
Running the tests
For the test cases you need the PCI permission enabled on you account. There are no test cases for CSE because credit card data is encrypted through our javascript library. By default the test will then be skipped. If you have these permissions fill in your account details in the config/test.ini file to let the test work. To make the automatic testing cases work for your account change the credentials in the config/test.ini file.
Feedback
We value your input! Help us enhance our API Libraries and improve the integration experience by providing your feedback. Please take a moment to fill out our feedback form to share your thoughts, suggestions or ideas.
Contributing
We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements. Have a look at our contributing guidelines to find out how to raise a pull request.
Support
If you have a feature request, or spotted a bug or a technical problem, create an issue here.
For other questions, contact our Support Team.
Licence
This repository is available under the MIT license.