Git Product home page Git Product logo

sips-sdk-nodejs's Introduction

SIPS Payment SDK npm version

This package provides a Node.js implementation for SIPS, the Worldline e-payments gateway.

โš ๏ธ This library was written for SIPS 2.0 and is not compatible with SIPS 1.0!

Installing

This library is provided as two separate packages on NPM . To install it, simply run:

npm install sips-payment-sdk

Or if you prefer Yarn, run:

yarn add sips-payment-sdk

Usage

๐Ÿ’ก Currently this library only supports SIPS in pay page mode.

Initialization

First, create a client for the desired environment using your merchant ID, key version & secret key:

const { Environment, PaypageClient } = require('@worldline/sips-payment-sdk');

const paypageClient = new PaypageClient(
  Environment.TEST,
  '002001000000001',
  1, // This shouldn't be hardcoded here...
  '002001000000001_KEY1'); // ...and neither should this.

Then set up a request to initialize a session on the SIPS server:

const { PaymentRequest, Currency, OrderChannel } = require('@worldline/sips-payment-sdk');

const paymentRequest = new PaymentRequest();
paymentRequest.amount = 2;
paymentRequest.currency = Currency.EUR;
paymentRequest.orderChannel = OrderChannel.INTERNET;

Add unique reference for the transaction:

paymentRequest.transactionReference = 'unique-transaction-ref';

And initialize your session on the server:

const initializationResponse = await paypageClient.initializePayment(paymentRequest);

The initializationResponse you'll receive from the server contains all information needed to continue handling your transaction. If you're initialization was successful, your response will contain a RedirectionStatusCode.TRANSACTION_INITIALIZED.

Making the payment

In case your initialization was successful, you have to use the redirectionUrl received to perform a POST request with both the redirectionData and seal as parameters. Since this should redirect the customer the SIPS payment page, the cleanest example is a simple HTML form:

<form method="post" action="redirectionUrl">
    <input name="redirectionData" type="hidden" value="..." />
    <input name="seal" type="hidden" value="..." />
    <input type="submit" value="Proceed to checkout"/>
</form>

Verifying the payment

When your customer is done, he will be able to return to your application. This is done via a form, making a POST request to the normalReturnUrl provided during the initialization of your payment. This POST request contains details on the payment. You can simply decode these responses, providing the parameters included in the received request to your paypageClient:

const paypageResponse = paypageClient.decodeResponse(request.data);

โš ๏ธ Since the customer is not always redirecting back (e.g. he closes the confirmation page), it's a a good practice to include an automaticReturnUrl. SIPS will always POST details on the transaction on this URL, even if a customer doesn't redirect back to your application.

sips-sdk-nodejs's People

Contributors

crlh avatar dependabot[bot] avatar qtomasicchio avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sips-sdk-nodejs's Issues

Provided example in README has paymentRequest.currency instead of paymentRequest.currencyCode

As per the title.

Provided example in README has paymentRequest.currency instead of paymentRequest.currencyCode.
const paymentRequest = new PaymentRequest();
paymentRequest.amount = 2;
paymentRequest.currency = Currency.EUR; // should be paymentRequest.currencyCode = Currency.EUR
paymentRequest.orderChannel = OrderChannel.INTERNET;

When following the example in the README, the server responds with
The server respond with {"responseCode":"12","errorFieldName":"currency"}.

Correcting the example would be helpful.

Regards

Following the readme tutorial, errorFieldName: Currency

Following the tutorial (simulation user) I'm seeing the following error:
InitializationResponse { responseCode: 12, errorFieldName: 'currency' }

Code used:

const Dom = require('sips-payment-dom');
const SDK = require('sips-payment-sdk');

const Environment = Dom.Environment;
const PaymentRequest = Dom.PaymentRequest;
const Currency = Dom.Currency;
const OrderChannel = Dom.OrderChannel;
const PaypageClient = SDK.PaypageClient;

const paypageClient = new PaypageClient(
  Environment.SIMU,
  '002001000000002',
  1,                          // This shouldn't be hardcoded here...
  '002001000000002_KEY1',     // ...and neither should this.
);

process.env.NODE_ENV = 'development';

const paymentRequest = new PaymentRequest();
paymentRequest.amount = 1;
paymentRequest.currency = paymentRequest.currencyCode = parseInt(Currency.EUR);
paymentRequest.orderChannel = OrderChannel.INTERNET;
paymentRequest.transactionReference = 'TestTransactionDevelopment-' + new Date().getTime();

const initializationResponse = paypageClient.initializePayment(paymentRequest);

const test = async () => {
  console.log(await initializationResponse);
}

test();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.