Rest Getting Started
Rest Getting Started
Started with
REST
REST API
Developer Guide
Cybersource Contact Information
For general information about our company, products, and services, go to https://www.cybersource.com.
For sales questions about any Cybersource service, email [email protected] or call 650-432-7350 or 888-330-2300 (toll free in
the United States).
For support information about any Cybersource service, visit the Support Center: https://www.cybersource.com/support
Copyright
© 2020. Cybersource Corporation. All rights reserved. Cybersource Corporation (“Cybersource”) furnishes this document and the
software described in this document under the applicable agreement between the reader of this document (“You”) and Cybersource
(“Agreement”). You may use this document and/or software only in accordance with the terms of the Agreement. Except as expressly
set forth in the Agreement, the information contained in this document is subject to change without notice and therefore should not
be interpreted in any way as a guarantee or warranty by Cybersource. Cybersource assumes no responsibility or liability for any errors
that may appear in this document. The copyrighted software that accompanies this document is licensed to You for use only in strict
accordance with the Agreement. You should read the Agreement carefully before using the software. Except as permitted by the
Agreement, You may not reproduce any part of this document, store this document in a retrieval system, or transmit this document, in
any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written consent of Cybersource.
For civilian agencies: Use, reproduction, or disclosure is subject to restrictions set forth in suparagraphs (a) through (d) of the
Commercial Computer Software Restricted Rights clause at 52.227-19 and the limitations set forth in Cybersource Corporation's
standard commercial agreement for this software. Unpublished rights reserved under the copyright laws of the United States.
Trademarks
Authorize.Net, eCheck.Net, and The Power of Payment are registered trademarks of Cybersource Corporation. Cybersource,
Cybersource Payment Manager, Cybersource Risk Manager, Cybersource Decision Manager, and Cybersource Connect are trademarks
and/or service marks of Cybersource Corporation. Visa, Visa International, Cybersource, the Visa logo, and the Cybersource logo
are the registered trademarks of Visa International in the United States and other countries. All other trademarks, service marks,
registered marks, or registered service marks are the property of their respective owners.
Condentiality Notice
This document is furnished to you solely in your capacity as a client of Cybersource and as a participant in the Visa payments system.
By accepting this document, you acknowledge that the information contained herein (the “Information”) is condential and subject
to the condentiality restrictions contained in Visa's operating regulations and/or other condentiality agreements, which limity our
use of the Information. You agree to keep the Information condential and not to use the Information for any purpose other than its
intended purpose and in your capacity as a customer of Cybersource or as a participant in the Visa payments system. The Information
may only be disseminated within your organization on a need-to-know basis to enable your participation in the Visa payments system.
Please be advised that the Information may constitute material non-public information under U.S. federal securities laws and that
purchasing or selling securities of Visa Inc. while being aware of material non-public information would constitute a violation of
applicable U.S. federal securities laws.
Revision
Version: 25.01
Contents
Contents
Cybersource Contents 3
Test the Shared Secret Key Pair................................................................................44
Test Endpoints.............................................................................................................. 46
Construct Messages Using HTTP Signature Security..................................................... 46
Elements of an HTTP Message...................................................................................46
Generate a Hash of the Message Body.................................................................... 47
Generate the Signature Hash.................................................................................... 48
Update Header Fields.................................................................................................. 49
Going Live................................................................................................................................50
Create a Merchant ID..................................................................................................50
Activate your Merchant ID...........................................................................................51
Production Endpoints.................................................................................................. 52
VISA Platform Connect: Specications and Conditions for Resellers/Partners...................53
Getting Started with REST
This section describes how to use this developer guide and where to nd further
information.
Visit the Cybersource documentation hub to nd additional technical documentation.
24.10
Fixed error in the JWE token for message level encryption (MLE). See Message-Level
Encryption Using JSON Web Tokens on page 30.
24.09
Fixed signature header parameter "keyid" typo. See Update Header Fields on page 49.
24.08
Removed support for message level encryption (MLE) when setting up an HTTP signature
message. See Set Up HTTP Signature Message on page 37.
24.07
This update contains editorial changes.
24.06
The guide has undergone a major reorganization.
24.05
Corrected typo. Updated the creating validation string
example for generating an HTTP signature
hash using the \n newline switch. For more
information, see Construct Messages Using
HTTP Signature Security on page 46.
24.04
Updated JSON Web Token Construction Updated the Constructing Messages Using
JSON Web Tokens Section.
Minor update to Message Level Encryption Added note to Enabling MLE Encryption
about the P12 certicate.
24.03
Update token signature to use the Key ID Replaced x5c signature with kid when
(kid). creating a token signature.
Added Message Level Encryption Message Level Encryption (MLE) was added
to the guide. See Construct Messages
Using HTTP Signature Security on page
46
24.02
Updated the link to the IETF HTTP Working Group website. See Construct Messages Using
HTTP Signature Security on page 46.
24.01
Message Elements Added the message elements required to
send a successful message. See Elements
of a JSON Web Token Message on page
23
To get started using the Cybersource payment API, you must rst set up your
payment processing system to be REST compliant. Cybersource uses the REST, or
(REpresentational State Transfer), architecture for developing web services. REST
enables communication between a client and server using HTTP protocols.
This guide explains how to set up secure communications between your client and server
using one of these methods:
JSON Web Token JSON Web Tokens (JWTs) are digitally
signed JSON objects based on the open
standard RFC 7519. These tokens provide
a compact, self-contained method for
securely transmitting information between
parties. These tokens are signed with an
RSA-encoded public/private key pair. The
signature is calculated using the header
and body, which enables the receiver to
validate that the content has not been
tampered with. Token-based applications
are best for applications that use browser
and mobile clients.
HTTP Signature Each request is digitally signed, or the
entire request is digitally hashed using
a private key. Both the client and server
will have the same shared secret, which
enables each request to be validated on
either end. If the request transmission is
compromised, the attacker cannot change
the request or act as a user because they
do not have the secret. HTTP signatures
can be used only with API requests. They
Components of REST
A REST message consists of these four components:
• Endpoint: The endpoint is a Uniform Resource Identier (URI) that shows where and
how to nd the resource on the internet. For example, to test an authorization request,
you can send the request to this endpoint: https://apitest.cybersource.com/pts/v2/
payments.
• HTTP Method: The method is the action performed by the resource. There are four
basic HTTP methods:
• POST: Create a resource.
• GET: Retrieve a resource.
• PATCH: Modify a resource.
• DELETE: Delete a resource.
• Headers: The header is a collection of elds and their associated values. It provides
information about the message to the receiver. Think of it as metadata about the
message. The header also contains authentication information that indicates that the
message is legitimate.
• Body: The request in JSON format.
This overview lists the tasks you will need to complete in order to set up your Cybersource
account for sending and receiving REST API messages using either JSON Web Token
messaging or HTTP Signature messaging.
To set up JSON web token messaging, see Set Up a JSON Web Token Message on page
12.
Cybersource Set Up Your Cybersource Account 10
Set Up Your Cybersource Account
To set up HTTP signature messaging, see Set Up HTTP Signature Message on page 37.
Setting up your JSON web token message requires you to complete these tasks:
3. Go to your email and nd a message titled: Merchant Registration Details. Click the Set
up your username and password now link.
Your browser opens the New User Sign Up wizard.
4. Enter the Organization ID and Contact email you supplied previously. Follow the wizard
pages to add your name, a username, and a password.
5. Log in to the Business Center.
When you log in for the rst time, you will be asked to verify your identity through a
system-generated email to your email account.
6. Check your email for a message titled: Cybersource Identication Code. A passcode is
included in the message.
7. Enter the passcode on the Verify your Identity page.
You should be directed to the Business Center home page.
You have successfully signed up for a sandbox account.
4. Under REST APIs, select REST – Certicate and then click Generate key.
5.
Click Download key .
6. Create a password for the certicate by entering the password into the New Password
and Conrm Password elds, and then click Generate key.
Important
If you are using the SDK to establish communication, you do not need to extract
the private key from the P12 certicate.
Prerequisite
You must have a tool such as OpenSSL installed on your system.
8. On the developer center's left navigation panel, navigate to Payments > POST Process a
Payment.
9. Under Request: Live Console click Send.
A message displays conrming that your request was successful with the status code
201.
Test Endpoints
When testing an API outside of the Developer Center's API Reference sandbox, send your
test API request messages to the test server:
https://apitest.cybersource.com
For example, to test an authorization request, you can send the request to this endpoint:
https://apitest.cybersource.com/pts/v2/payments
Headers
Your message header must include these header elds:
Header Fields
Body
The message body. For more information on setting up the body, see Generate a Hash of
the Message Body on page 24.
Token Headers
Token Header
eyJ2LWMtbWVyY2hhbnQtaWQiOiJtZXJjaGFudElEIiwiYWxnIjoiUlMyNTYiLCJraWQiOiI3MDc4NjMzMjg1MjUwMTc3MDQxNDk5In0
import base64
print(stripped)
Headers
iat The date and time of the message origin. Date formatting is
dened by RFC 7231, Section 7.1.1.1.
digest A Base64 encoded hash of the message payload. The
digest field is not included in a GET request.
digestAlgorithm The algorithm used to hash the message payload. The
message payload should be hashed using the SHA-256 al
gorithm. The digestAlgorithm field is not included in a
GET request.
NTk5NWE0ZjI3YjRiOTI1NmE5NGNmNTQ0ODlhOWVmNjkxZDhkYzhhNTkwZDMyMjc4MGQzYjIwMmNmYTJmMDc4Zg==
Token Headers
echo -n "{"kid":"cc34c0a0-bd5a-4a3c-a50d-a2a7db7643df",
"alg":"RS256","v-c-merchant-id":"merchant_id"}"
| shasum -a 256
digest: eyJkaWdlc3QiOiJSQk52bzFXelo0b1JScTBXOStoa25wVDdUOElmNTM2REVNQmc5aHlxLzRvPSIsImRpZ
2VzdEFsZ29yaXRobSI6IlNIQS0yNTYiLCJpYXQiOiIyMDI0LTA0LTA1VDE2OjI1OjE4LjI1OVoifQ
import base64
data = b'{"digest":"RBNvo1WzZ4oRRq0W9+hknpT7T8If536DEMBg9hyq/4o=","digestAlgorithm":"SHA-256",
"iat":"2024-04-05T16:25:18.259Z"}'
encode = base64.urlsafe_b64encode(data)
stripped = encode.decode('ascii').strip('=')
print(stripped)
base64 -i [signature-encoded-le]
Dc4NjMzMjg1MjUwMTc3MDQxNDk5In0.eyJkaWdlc3QiOiJSQk52bzFXelo0b1JScTBXOStoa2
5wVDdUOElmNTM2REVNQmc5aHlxLzRvPSIsImRpZ2VzdEFsZ29yaXRobSI6IlNIQS0yNTYiLCJ
pYXQiOiIyMDI0LTA0LTA1VDE2OjI1OjE4LjI1OVoifQ.YjgwNGIxOTMxMzQ2NzhlYjdiMDdhM
WZmYjZiYzUzNzliMTk5NzFmNjAzNWRmMThlNzk0N2NhY2U0YTEwNzYyYQ
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.0</version>
</dependency>
2. Prepare the API request payload. This example is hard-coded for demonstration.
4. Loop through the Java KeyStore to extract the private key from merchant p12 le
and extract the public key for Cybersource. You must use the Cybersource SJC
(CyberSource_SJC_US) to encrypt the payload.
while (enumKeyStore.hasMoreElements()) {
merchantKeyAlias = (String) enumKeyStore.nextElement();
if (merchantKeyAlias.contains("test_merchant")) {
KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) merchantKeyStore.getEntry(
merchantKeyAlias, new KeyStore.PasswordProtection(
"test_merchant".toCharArray()));
//Extract the merchant certicate to sign the payload.
x509Certicate = (X509Certicate) keyEntry.getCerticate();
rsaPrivateKey = (RSAPrivateKey) keyEntry.getPrivateKey();
5. Update the custom headers to include "iat" with the current timestamp:
6. Generate the JWE token (the encrypted payload) using the supported algorithm and
the Cybersource public certicate. Include the JSON payload as the input.
.keyID(serialNumber)
.customParams(customHeaders)
.build(),
new Payload(content));
7. Build the JSON request body for calling the Cybersource API.
8. Generate the body digest to validate that the payload has not been compromised.
10.Sign the payload and create the JWT token that is passed in the request header.
}
protected static String extractSerialNumberFromDN(X509Certicate x509Certicate) {
String serialNumber = null;
String serialNumberPrex = "SERIALNUMBER=";
String principal = x509Certicate.getSubjectDN().getName().toUpperCase();
int beg = principal.indexOf(serialNumberPrex);
if (beg >= 0) {
int end = principal.indexOf(",", beg);
if (end == -1) end = principal.length();
serialNumber = principal.substring(beg + serialNumberPrex.length(), end);
} else
serialNumber = x509Certicate.getSerialNumber().toString();
return serialNumber;
}
11. Send the JWT as the Bearer token in the header and send the JWE as the body.
Going Live
When you are ready to process payments in a live environment, you must transition your
account to a live status with a valid conguration for your chosen payment processor.
When live, your transaction data ows through the production Cybersource gateway, to
your processor, and on to the appropriate payment network.
To transition your account:
1. Sign up for a merchant account.
2. Contact sales to establish a contract with Cybersource that enables you to process
real transactions and receive support.
3. Submit a merchant ID (MID) activation request.
It may take up to three business days to complete a MID activation request.
Create a Merchant ID
The merchant ID (MID) is used to identify you and your transactions and is included in
the header of each transaction request. When you signed up for a sandbox account, you
received a merchant ID for testing purposes. If you choose, you can use that merchant ID
as your production ID.
Follow these steps to sign up for a merchant account in order to create a production MID:
1. Navigate to the Business Center Evaluation Account Sign-up page, enter the required
information, and click Create Account.
Choose your merchant ID name carefully. It cannot be changed. This name is not visible
to your customers.
2. Review your information entered, especially your business email address. Your merchant
ID registration information will be sent to the email entered on this form.
3. Check your email from customer support titled: Cybersource Merchant Evaluation
Account.
This email will include the Organization ID and contact email associated with your MID.
4. Go to your email and nd a message titled: Merchant Registration Details. Click the Set
up your username and password now link.
Your browser opens the New User Sign Up wizard.
5. Enter the Organization ID and Contact email you supplied previously. Follow the wizard
pages to add your name, a username, and password.
6. Log into the Business Center.
When you log in for the rst time, you will be asked to identify your identity through a
system-generated email that is sent to your email account.
7. Check your email for a message titled: Cybersource Identication Code.
Note the passcode.
8. Enter the passcode on the Verify your Identity page.
You should be directed to the Business Center home page.
You have successfully created a merchant ID and merchant account.
Production Endpoints
When sending API request messages using your production account, send your requests
to the production server:
https://api.cybersource.com
For example, to send a live authorization request, you can send the request to this
endpoint:
https://api.cybersource.com/pts/v2/payments
Setting up your HTTP signature message requires you to follow these steps.
2. Create a shared secret key. See Create a Shared Secret Key Pair on page 40.
3. Construct a message using HTTP signature security. See Construct Messages Using
HTTP Signature Security on page 46.
4. Go live by transitioning your sandbox account into a production account. Going Live on
page 34.
3. Go to your email and nd a message titled: Merchant Registration Details. Click the Set
up your username and password now link.
Your browser opens the New User Sign Up wizard.
4. Enter the Organization ID and Contact email you supplied previously. Follow the wizard
pages to add your name, a username, and a password.
5. Log in to the Business Center.
When you log in for the rst time, you will be asked to verify your identity through a
system-generated email to your email account.
6. Check your email for a message titled: Cybersource Identication Code. A passcode is
included in the message.
7. Enter the passcode on the Verify your Identity page.
You should be directed to the Business Center home page.
You have successfully signed up for a sandbox account.
4. Under REST APIs, select REST – Shared Secret and then click Generate key.
When you generate one or more keys, you can view the keys on the Key Management page.
A message displays conrming that your request was successful with the status code
201.
Test Endpoints
When testing an API outside of the Developer Center's API Reference sandbox, send your
test API request messages to the test server:
https://apitest.cybersource.com
For example, to test an authorization request, you can send the request to this endpoint:
https://apitest.cybersource.com/pts/v2/payments
Headers
Your message header must include these header elds:
Body
The message body. For more information on setting up the body, see Generate a Hash of
the Message Body on page 47.
echo -n "{"clientReferenceInformation":{"code":"TC50171_3"},"paymentInformation":{"card":{"number":
"4111111111111111","expirationMonth":"12","expirationYear":"2031"}},"orderInformation":{"amountDetails":
{"totalAmount":"102.21","currency":"USD"},"billTo”:{“rstName":"John","lastName":"Doe","address1":
"1MarketSt","locality":"sanfrancisco","administrativeArea":"CA","postalCode":"94105","country":"US",
"email":"[email protected]","phoneNumber":"4158880000"}}}" | shasum -a 256
digest:
SHA-256=NmFlNTQ1OWJjOGE3ZDZhNGIyMDNlOGE3MzRkNmE2MTY3MjUxMzQwODhlMTMyNjFmNWJiY2VmYzE0MjRmYzk1Ng==
Header Fields
Date From the header, the date and time in the RFC1123 format
. For example: Date: Thu, 18 Jul 2023, 22:18:03.
Digest The Base64-encoded SHA-256 hash of the message body
. For more information, see Generate a Hash of the Messa
ge Body. For example: Digest: SHA-256=gXWufV4Zc7
VkN9Wkv9jh/JuAVclqDusx3vkyo3uJFWU=. Do not include
the digest with GET requests.
Host From the header, the endpoint host. For example: api
test.cybersource.com.
v-c-merchant-id From the header, the merchant ID associated with the re
quest. For example: v-c-merchant-id: mymerchantid.
request-target The HTTP method and endpoint resource path. For ex
ample: request-target: post /pts/v2/payments/.
signature=”OuKeDxj+Mg2Bh9cBnZ/25IXJs5n+qj93FvPKYpnqtTE=”
host: apitest.cybersource.com\n
date: Thu, 18 Jul 2019 00:18:03 GMT\n
request-target: post /pts/v2/payments/\n
digest: SHA-256=gXWufV4Zc7VkN9Wkv9jh/JuAVclqDusx3vkyo3uJFWU=\n
v-c-merchant-id: mymerchantid
Signatures
Going Live
When you are ready to process payments in a live environment, you must transition your
account to a live status with a valid conguration for your chosen payment processor.
When live, your transaction data ows through the production Cybersource gateway, to
your processor, and on to the appropriate payment network.
To transition your account:
1. Sign up for a merchant account.
2. Contact sales to establish a contract with Cybersource that enables you to process
real transactions and receive support.
3. Submit a merchant ID (MID) activation request.
It may take up to three business days to complete a MID activation request.
Create a Merchant ID
The merchant ID (MID) is used to identify you and your transactions and is included in
the header of each transaction request. When you signed up for a sandbox account, you
received a merchant ID for testing purposes. If you choose, you can use that merchant ID
as your production ID.
Follow these steps to sign up for a merchant account in order to create a production MID:
1. Navigate to the Business Center Evaluation Account Sign-up page, enter the required
information, and click Create Account.
Choose your merchant ID name carefully. It cannot be changed. This name is not visible
to your customers.
2. Review your information entered, especially your business email address. Your merchant
ID registration information will be sent to the email entered on this form.
3. Check your email from customer support titled: Cybersource Merchant Evaluation
Account.
This email will include the Organization ID and contact email associated with your MID.
4. Go to your email and nd a message titled: Merchant Registration Details. Click the Set
up your username and password now link.
Your browser opens the New User Sign Up wizard.
5. Enter the Organization ID and Contact email you supplied previously. Follow the wizard
pages to add your name, a username, and password.
6. Log into the Business Center.
When you log in for the rst time, you will be asked to identify your identity through a
system-generated email that is sent to your email account.
7. Check your email for a message titled: Cybersource Identication Code.
Note the passcode.
8. Enter the passcode on the Verify your Identity page.
You should be directed to the Business Center home page.
You have successfully created a merchant ID and merchant account.
If you are unsure of your processor name, contact your merchant service provider or
your merchant acquiring bank.
7. Select the environments that this change applies (test or production).
8. Select Service Enablement and list the products and services that you intend to use.
9. Select Submit.
Production Endpoints
When sending API request messages using your production account, send your requests
to the production server:
https://api.cybersource.com
For example, to send a live authorization request, you can send the request to this
endpoint:
https://api.cybersource.com/pts/v2/payments
The following are specications and conditions that apply to a Reseller/Partner enabling
its merchants through Cybersource for Visa Platform Connect (“VPC”) processing. Failure
to meet any of the specications and conditions below is subject to the liability provisions
and indemnication obligations under Reseller/Partner’s contract with Visa/Cybersource.
1. Before boarding merchants for payment processing on a VPC acquirer’s connection,
Reseller/Partner and the VPC acquirer must have a contract or other legal agreement
that permits Reseller/Partner to enable its merchants to process payments with the
acquirer through the dedicated VPC connection and/or traditional connection with
such VPC acquirer.
2. Reseller/Partner is responsible for boarding and enabling its merchants in accordance
with the terms of the contract or other legal agreement with the relevant VPC acquirer.
3. Reseller/Partner acknowledges and agrees that all considerations and fees associated
with chargebacks, interchange downgrades, settlement issues, funding delays, and
other processing related activities are strictly between Reseller and the relevant VPC
acquirer.
4. Reseller/Partner acknowledges and agrees that the relevant VPC acquirer is
responsible for payment processing issues, including but not limited to, transaction
declines by network/issuer, decline rates, and interchange qualication, as may be
agreed to or outlined in the contract or other legal agreement between Reseller/
Partner and such VPC acquirer.
DISCLAIMER: NEITHER VISA NOR CYBERSOURCE WILL BE RESPONSIBLE OR LIABLE
FOR ANY ERRORS OR OMISSIONS BY THE VISA PLATFORM CONNECT ACQUIRER IN
PROCESSING TRANSACTIONS. NEITHER VISA NOR CYBERSOURCE WILL BE RESPONSIBLE
OR LIABLE FOR RESELLER/PARTNER BOARDING MERCHANTS OR ENABLING MERCHANT
PROCESSING IN VIOLATION OF THE TERMS AND CONDITIONS IMPOSED BY THE RELEVANT
VISA PLATFORM CONNECT ACQUIRER.