@paciolan/cybersource-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

Cybersource SDK for NodeJS

A modern fork of Cybersource's official Node SDK — generated from Cybersource's own API source code

Motivation

Tl;dr — This is Cybersource's official SDK, generated using a newer (Typescript compatible) version of Swagger Codegen.

Cybersource's official NodeJS SDK is automatically generated using Swagger Codegen v2.3.0. Cybersource feeds the code generator a swagger 2.0 specification file generated from their API's source code and a customized code-gen template.

Unfortunately v2.3 of Swagger Codegen does not support Typescript, and takes a lot of inspiration from the Java code generator, resulting in an unintuitive and clunky user experience. This project feeds the same swagger 2.0 specification file into a newer Typescript-compatible version of Swagger Codegen (v3).

This results in a strongly typed SDK which reflects the types generated by Cybersource's official API source code; much less room for human error.

Differences

The overall functionality of the new SDK should remain similar to the old SDK since they are both generated using the same OpenAPI specification file.

  • Uses Typescript

  • Doesn't require logging settings to be set up.

  • Only supports Cybersource's HTTP authentication method for now.

  • HTTP library has been switched from superagent to Axios.

  • Endpoints now return Promises instead of error-first callbacks.

Usage

While Cybersource's official examples likely won't work as-is, the method names should remain the same and the added types should provide the necessary information to determine which parameters methods should be called with and what data the methods return. We encourage you to still view Cybersource's official documentation for SDK usage, but know that the method signatures may have changed slightly.

Example usage can be found in the payment-ms's CybersourceClientApiWrapper.

Installation

$ npm install @paciolan/cybersource-sdk

Example Payment

import { PaymentsApi, V2PaymentsBody } from '@paciolan/cybersource-sdk';
const requestBody: V2PaymentsBody = {
  paymentInformation: {
    card: {
      number: '4242424242424242',
      expirationMonth: '09',
      expirationYear: '24',
    },
  },
  orderInformation: {
    amountDetails: {
      currency: 'USD',
      totalAmount: '123.45',
    },
  },
};
const apiResponse = await PaymentsApi.createPayment(
  requestBody,
  merchantConfig,
);

Globally Exported Members

  • BASE_PATH (Previously new require('cybersource-rest-client').ApiClient().basePath)

Contributing

This repository is meant to maintain 2 minimal patch sets, one for the custom authentication code from Cybersource, and one for the customized code-gen template to add support for the authentication code.

If, for example, you're looking to add support for another authentication scheme, you would likely want to start in the /src folder to add support there first, and then add any necessary hooks in to the /template to call your custom code.

Generating the SDK

To regenerate the SDK with your changes, simply run ./scripts/develop.sh

Trying your updates locally

Now that you've got the SDK generated, you can try using it locally by using NPM's link command in whatever project you want the consume the SDK with.

Updating base versions

To update the base version of our dependencies, simply change the tag specified in /scripts/lib/variables.sh

Dependency Variable Name
cybersource-rest-client cybersource_rest_client_version
Swagger code-gen binary swagger_codegen_version
Swagger code-gen template swagger_codegen_templates_version

Then, simply refer to Generating the SDK to rebuild.

Readme

Keywords

Package Sidebar

Install

npm i @paciolan/cybersource-sdk

Weekly Downloads

3

Version

0.4.0

License

Cybersource

Unpacked Size

5.86 MB

Total Files

2963

Last publish

Collaborators

  • paciolan