adyen/php-api-library

A PHP client library for accessing Adyen APIs


README

php

Adyen PHP API Library

This is the officially supported PHP library for using Adyen's APIs.

version

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

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.

See also