Download the SDK
Download the Paysafe Node.js SDK from GitHub
Before You Begin
Before you use an SDK, you’ll need the API credentials (API Key) that it uses to make JSON requests to our server via the Paysafe REST API.
- Your Paysafe API Key Username
- Your Paysafe API Key Password
- Your Paysafe Account Number
To get your test account, if you intend to use the Direct Debit SDK, contact Paysafe support, otherwise click Sign Up above. Once logged in to the Back Office you can retrieve your Account Number (choose Accounts and copy it from the Account column) and your API Key User name and Password (choose Settings > API Key). See More about Authentication for more information.
- Download Node.js from https://nodejs.org/download/.
The sections that follow include commands you should enter at the command prompt.
- Navigate to the sample_application folder.
- Update the following parameters in config.js with your own credentials, ensuring that each value is enclosed within matching quotes.
Key Value currency_base_units_multiplier
Transactions are actually measured in fractions of the currency specified in the currency_code; for example, USD transactions are measured in cents. This multiplier is how many of these smaller units make up one of the specified currency. For example, with the currency_code USD the value is 100 but for Japanese YEN the multiplier would be 1 as there is no smaller unit.
currency_code The currency for your account, such as USD paysafeAccountNumber
Your Paysafe Account Number
Your Paysafe API Key username
Your Paysafe API Key password
TEST or LIVE. See Initializing the SDK in Your Application for details.
- Use the package manager, npm, to install the Request module to use for HTTP calls by executing the following:
npm install request
- Use npm to install the Node Express web application framework by executing the following:
npm install express
- By default the server uses port 3000. If you do not want to use this port, execute the following:
- Type the following command to start the server:
- If your Node.js server is running on port 3000, open a browser and navigate to the sample URLs below, substituting actual attribute values for the placeholders delimited by angle brackets, <>. If you changed the port number in the step above also substitute your chosen number for 3000.
- http://localhost:3000/createProfile – for creating a profile using dummy data
- http://localhost:3000/createCard?profileId=<profile_id>&cardNumber=<card_number> – for creating a card using dummy data
- http://localhost:3000/silentHosted – for executing a Silent Post using dummy data
- http://localhost:3000/simpleHosted – for executing a Hosted Payment order using dummy data
- http://localhost:3000/cardPayment?cardNumber=<card_number> – for processing a card payment using dummy data
- http://localhost:3000/cardCustomer?paymentToken=<card_payment_token> – for processing a payment using a dummy token
For the Paysafe Node.js SDK to work with your merchant application, the server hosting the application must be able to connect to the relevant Paysafe server, either:
- TEST – The Paysafe Test server
- LIVE – The Paysafe Production server
The URLs of these servers, and the following environment configuration parameters for both, are defined in the script file, /bin/Environment.js.
|host||https://api.paysafe.com||Paysafe REST API Endpoint.|
|maxSockets||10||The maximum number of connections per connection pool.|
|timeOut||30000||The maximum time (in ms) the SDK will wait for a response from the Paysafe Servers.|
To initialize the Paysafe SDK in your application use the following commands:
- Import the Paysafe SDK:
var paysafeApiClient = require("PaysafeApiClient");
- Import the configuration file containing your API key, etc.
var config = require("./config");
- Create the Paysafe API Client object.
var paysafeApiClient = new paysafeApiClient(config.paysafeApiKeyId, config.paysafeApiKeySecret, config.paysafeEnvironment, config.paysafeAccountNumber);
To change the environment configuration settings use:
paysafeApiClient.updateConfig(host, maxSockets, timeOut);
The following topics contain example code for each API:
- Card Payments API – Process all major credit cards through the Paysafe payment gateway.
- Direct Debit API – Process purchases and credits through a variety of bank schemes.
- Customer Vault API – Make repeat payments without having to directly access the cardholder information.
- 3D Secure API – Mitigate fraud while providing additional security for customers using their cards online.
- Exceptions – Handle various exceptions to ensure accurate payment processing.
The above examples do not include initialization.