PHP Client SDK for CyberSource REST APIs
Important: PHP security notice
PHP released security updates on October 21, 2026, addressing critical vulnerabilities in PHP itself.
Cybersource advises its customers to upgrade their PHP installation to the patched releases: PHP 8.5.12, 8.4.27, 8.3.36, or 8.2.35 — or a later patched release.
PHP 8.1 and earlier are no longer supported upstream; upgrade to a supported branch or check with your operating-system or hosting provider for a patched build.
Description
The CyberSource PHP client provides convenient access to the CyberSource REST API from your PHP application.
System Requirements
- PHP 8.0.0+
- cURL PHP Extension
- JSON PHP Extension
- OpenSSL PHP Extension
- Zip PHP Extension
- MBString PHP Extension
- Hash PHP Extension
- GMP PHP Extension (required for message-level encryption (MLE) / JWE support)
- Sodium PHP Extension
- PHP_APCU PHP Extension. You will need to download it for your platform (Windows/Linux/Mac)
Installation
Composer
We recommend using Composer. (Note: we never recommend you
override the new secure-http default setting).
Update your composer.json file as per the example below and then run
composer update.
{
"require": {
"php": ">=8.0.0",
"cybersource/rest-client-php": "0.0.78"
}
}
Account Registration & Configuration
Follow the first step mentioned in Getting Started with CyberSource REST SDKs to create a sandbox account.
Follow the second step mentioned in Getting Started with CyberSource REST SDKs to configure the SDK by inputting your credentials.
Please note that this is for reference only. Ensure to store the credentials in a more secure manner.
How to Use
To get started using this SDK, it is highly recommended to download our sample code repository:
In that repository, we have comprehensive sample code for all common uses of our API:
Additionally, you can find details and examples of how our API is structured in our API Reference Guide:
The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK.
To learn more about how to use CyberSource's REST API SDKs, please use Developer Center REST API SDKs.
Security Guidance
- It is strongly recommended to use HTTPS for any proxy servers in your environment to protect secrets during transit.
Example using Sample Code Application
For more detailed examples, refer to the cybersource-rest-samples-php repository.
Switching between the sandbox environment and the production environment
CyberSource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, set the appropriate property in Resources\ExternalConfiguration.php.
For example:
// For TESTING use
// $this->runEnv = "apitest.cybersource.com";
// For PRODUCTION use
$this->runEnv = "api.cybersource.com";
The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK.
Logging
Since v0.0.24, a new logging framework has been introduced in the SDK. This new logging framework makes use of Monolog, and standardizes the logging so that it can be integrated with the logging in the client application.
More information about this new logging framework can be found in this file : Logging.md
Features
Message Level Encryption (MLE) Feature
This feature provides an implementation of Message Level Encryption (MLE) for APIs provided by CyberSource, integrated within our SDK. This feature ensures secure communication by encrypting messages at the application level before they are sent over the network.
More information about this new MLE feature can be found in this file : MLE.md
JWT Authentication with Symmetric Key (Shared Secret / HS256 HMAC-SHA256) Support
⚠️ HTTP Signature Deprecation Notice: HTTP Signature authentication (HTTP_SIGNATURE) is being deprecated. JWT with Shared Secret (HS256 / HMAC-SHA256) is the recommended migration path — it uses the same merchantKeyId and merchantsecretKey credentials, requires only two property changes, and enables MLE (Message Level Encryption) support that HTTP Signature does not provide.
JWT authentication now supports two key types, configurable via the jwtKeyType property:
jwtKeyType |
Algorithm |
Credentials Required |
P12 (default) |
RS256 (asymmetric, RSA-SHA256) |
keysDirectory, keyFileName, keyAlias, keyPass |
SHARED_SECRET |
HS256 (symmetric, HMAC-SHA256) |
merchantKeyId, merchantsecretKey |
The default value is P12, which preserves full backward compatibility with existing configurations.
Configuration for JWT with P12 (default — no changes needed)
$config = new CyberSource\Authentication\Core\MerchantConfiguration();
$config->setAuthenticationType('JWT');
$config->setMerchantID('your_merchant_id');
$config->setRunEnvironment('apitest.cybersource.com');
// jwtKeyType defaults to P12 if omitted
$config->setKeyAlias('your_merchant_id');
$config->setKeyPassword('your_merchant_id');
$config->setKeyFileName('your_merchant_id');
$config->setKeysDirectory('/path/to/p12/directory');
Configuration for JWT with Shared Secret
$config = new CyberSource\Authentication\Core\MerchantConfiguration();
$config->setAuthenticationType('JWT');
$config->setMerchantID('your_merchant_id');
$config->setRunEnvironment('apitest.cybersource.com');
$config->setJwtKeyType('SHARED_SECRET');
$config->setApiKeyID('your_key_id');
$config->setSecretKey('your_base64_encoded_shared_secret');
Note: When jwtKeyType is set to SHARED_SECRET, the P12-related properties (keysDirectory, keyFileName, keyAlias, keyPass) are not required and will be ignored. Conversely, when using P12, the merchantKeyId and merchantsecretKey properties are not required for JWT authentication.
JSON Configuration for JWT with P12
{
"authenticationType": "jwt",
"merchantID": "your_merchant_id",
"runEnvironment": "apitest.cybersource.com",
"keyAlias": "your_merchant_id",
"keyPass": "your_merchant_id",
"keyFileName": "your_merchant_id",
"keysDirectory": "path/to/p12/directory"
}
JSON Configuration for JWT with Shared Secret
{
"authenticationType": "jwt",
"merchantID": "your_merchant_id",
"runEnvironment": "apitest.cybersource.com",
"jwtKeyType": "SHARED_SECRET",
"merchantKeyId": "your_key_id",
"merchantsecretKey": "your_base64_encoded_shared_secret"
}
Migrating from HTTP Signature to JWT with Shared Secret (HS256 / HMAC-SHA256)
If you are currently using HTTP Signature authentication, migrating to JWT with Shared Secret (symmetric key, HS256 / HMAC-SHA256) requires only two property changes — your credentials remain the same:
// BEFORE (HTTP Signature — deprecated)
$config->setAuthenticationType('HTTP_SIGNATURE');
$config->setApiKeyID('your_key_id');
$config->setSecretKey('your_shared_secret');
// AFTER (JWT with Shared Secret / HS256 HMAC-SHA256 — recommended)
$config->setAuthenticationType('JWT'); // changed
$config->setJwtKeyType('SHARED_SECRET'); // added — uses HS256 (HMAC-SHA256)
$config->setApiKeyID('your_key_id'); // same
$config->setSecretKey('your_shared_secret'); // same
Using MLE with Shared Secret Credentials
MLE (Message Level Encryption) is fully supported with the SHARED_SECRET key type. This allows merchants who use shared secret credentials (instead of a P12 certificate) to still leverage MLE for secure communication.
When using jwtKeyType=SHARED_SECRET with MLE, you must provide the MLE public certificate separately via the mleForRequestPublicCertPath property, since there is no P12 file to auto-extract the MLE certificate from. The request MLE public certificate can be downloaded from the CyberSource Business Center:
$config = new CyberSource\Authentication\Core\MerchantConfiguration();
$config->setAuthenticationType('JWT');
$config->setMerchantID('your_merchant_id');
$config->setRunEnvironment('apitest.cybersource.com');
$config->setJwtKeyType('SHARED_SECRET');
$config->setApiKeyID('your_key_id');
$config->setSecretKey('your_base64_encoded_shared_secret');
// Request MLE configuration
$config->setEnableRequestMLEForOptionalApisGlobally(true);
$config->setMleForRequestPublicCertPath('/path/to/mle/public/cert.pem');
// Response MLE is also supported — see MLE.md for full configuration
// $config->setEnableResponseMleGlobally(true);
// $config->setResponseMlePrivateKeyFilePath('/path/to/private/key.p12');
// $config->setResponseMlePrivateKeyFilePassword('password');
For more details on MLE configuration options (including Response MLE), see MLE.md.
MetaKey Support
A Meta Key is a single key that can be used by one, some, or all merchants (or accounts, if created by a Portfolio user) in the portfolio.
The Portfolio or Parent Account owns the key and is considered the transaction submitter when a Meta Key is used, while the merchant owns the transaction.
MIDs continue to be able to create keys for themselves, even if a Meta Key is generated.
MetaKey works with all three authentication types: HTTP Signature, JWT (P12), and JWT with Shared Secret.
MetaKey with HTTP Signature (⚠️ Deprecated)
$config->setAuthenticationType('HTTP_SIGNATURE');
$config->setMerchantID('your_transacting_merchant_id');
$config->setApiKeyID('your_metakey_portfolio_KeyId');
$config->setSecretKey('your_metakey_portfolio_shared_secret_key');
$config->setPortfolioID('your_portfolio_id');
$config->setUseMetaKey(true);
MetaKey with JWT (P12)
$config->setAuthenticationType('JWT');
$config->setMerchantID('your_transacting_merchant_id');
$config->setKeyAlias('your_portfolio_id');
$config->setKeyPassword('your_metakey_portfolio_p12File_password');
$config->setKeyFileName('your_metakey_portfolio_p12FileName');
$config->setKeysDirectory('/path/to/p12/directory');
$config->setPortfolioID('your_portfolio_id');
$config->setUseMetaKey(true);
MetaKey with JWT Shared Secret (Recommended)