3.0.4 • Published 5 years ago

isignthis-psp v3.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

isignthis-psp

UPDATE 2.x.x: Node-style callbacks are deprecated, but can still be found in versions 1.x.x

Module for interfacing with iSignThis as a payment service provider (PSP)

Constructor

Module constructor

Arguments

ArgumentTypeDefaultDescription
settingsObjectRequiredAn object of settings required or supported by the module.
option object
FieldTypeDefaultDescription
clientCertificateBufferRequiredClient certificate used for communication
clientKeyBufferRequiredClient private key used for communication
merchantIdStringRequirediSignThis merchant identifier
logObjectconsole-log-level instanceBunyan-compatible logger
baseUrlString"https://gateway.isignthis.com"Base URL (without trailing slash) to iSignThis to use instead of default
acquirerIdString"node-isignthis-psp"Default acquirer to use if none specified when creating a payment

Example

var fs = require('fs');
var ISignThis = require('isignthis-psp');

var iSignThis = new ISignThis({
  clientCertificate: fs.readFileSync(certFile),
  clientKey: fs.readFileSync(keyFile),
  merchantId: "my_merchant",
  acquirerId: "clearhaus"
});

Payments

Payment object

This section describes the object that is returned on success from createPayment and getPayment.

FieldType Description
idStringPSP-specific identifier for this payment
acquirerIdStringAcquirer used for this payment? (options.acquirerId as passed to the constructor)
stateStringState of the payment. Is one of the following strings: pending - Payment has been initiated, but is waiting for action from the PSP or the end-user.rejected - Payment was rejected before the end-user entered any payment details.declined - Payment was declined after the end-user entered payment details.failed - Payment failed due to an error with the PSP.expired - Payment expired before it was completed.completed - Payment completed successfully.
eventStringThe event field describes an event, a system action that has been triggered either automatically or by an operator.
expiryTimeDateTime when payment expires in ISO-8601 format
redirectUrlStringURL where the payment is processed by the user.
transactionsObjectInformation about the transaction(s) related to the payment
idStringAcquirer-specific identifier for this transaction.
amountIntegerAmount (denominated in sub-unit of currency) of this transaction
currencyStringCurrency denominating amount
identityObjectInformation about the KYC/SCA identity returned with the transaction. If no identity is returned, value will be null
identity.idStringIdentity ID
identity.urlStringURL to get provider specific identity information
rawObjectThe payment object from the PSP. The contents of this object will differ between different PSPs, and should be treated as an opaque blob.
cardObjectInformation about the card
tokenStringThe credit card token to use for a preauthorized card payment
last4StringThe last four digits of the credit card number
binStringThe credit card bin
brandStringThe credit card brand
expiryDateStringThe credit card expiry date (e.g. 1217 for Dec, 2017)
recurringIdStringID to use for recurring payments.

createPayment: Create payment

Initiate a payment

createPayment(options)

options arguments

ArgumentTypeDefaultDescription
workflowStringRequiredWorkflow identifier given by iSignThis.
acquirerIdStringacquirerId from constructorWhat acquirer should be used for this payment?
returnUrlString (URL fragment)RequiredURL to redirect end-user to after a successful payment. Note: The PSP transaction ID will be appended to the URL, so it should be something like https://example.com/payment-complete?transaction_id=
amountIntegerRequiredAmount (denominated in sub-unit of currency) to create a payment for.
currencyStringRequiredCurrency code denominating amount.
clientObjectRequiredObject with information about the client initiating the payment. Only the ip field is required.
initRecurringBoolean(Optional)If payment is the first in a series of recurring payments.
ipStringRequiredIP address of client
nameStringnullFull name of client
dobStringnullDate of birth of client
countryStringnullCountry code (ISO-3166-1 alpha-2) of country of citizenship of client
emailString (Email address)nullEmail address of client
addressStringnullPhysical street address of client
account Object  RequiredObject with information about the account (e.g. the internal user or equivalent)
idStringRequiredUnique identifier for this account (e.g. internal user ID or equivalent)
secretStringnullSecret used by iSignThis
nameStringnullFull name of account owner
transactionObject{}Information about the transaction(s) related to the payment
idStringnullInternal reference
referenceStringnullInternal reference for the transaction(s)

Returns

The function return a Promise which resolves in a payment object.

Example

var options = {
  workflow: 'CORE',
  acquirerId: 'clearhaus',
  returnUrl: 'https://example.com/payment-complete?transaction_id=',
  amount: 5000,
  currency: 'USD', // 50.00 USD
  client: {
    ip: '127.0.0.1',
    userAgent: 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531...'
  },
  account: {
    id: 'user-12345'
  }
};

return PSP.createPayment(options)
  .then(payment => {
    // Handle payment creation success
  })
  .catch(err => {
    // Handle error
  });
});

processRecurringPayment: Process recurring payment

Process a recurring payment using a recurringId from a succeded payment with initRecurring: true

processRecurringPayment(options)

options arguments

ArgumentTypeDefaultDescription
workflowStringRequiredWorkflow identifier given by iSignThis.
acquirerIdStringacquirerId from constructorWhat acquirer should be used for this payment?
recurringIdStringRequiredIf payment is the first in a series of recurring payments. https://example.com/payment-complete?transaction_id=
clientObjectRequiredObject with information about the client initiating the payment. Only the ip field is required.
ipStringRequiredIP address of client
nameStringnullFull name of client
dobStringnullDate of birth of client
countryStringnullCountry code (ISO-3166-1 alpha-2) of country of citizenship of client
emailString (Email address)nullEmail address of client
addressStringnullPhysical street address of client
account Object  RequiredObject with information about the account (e.g. the internal user or equivalent)
idStringRequiredUnique identifier for this account (e.g. internal user ID or equivalent)
secretStringnullSecret used by iSignThis
nameStringnullFull name of account owner
transactionObject{}Information about the transaction(s) related to the payment
idStringnullInternal reference
referenceStringnullInternal reference for the transaction(s)

Returns

The function return a Promise which resolves in a payment object.

Example

const options = {
  acquirerId: 'clearhaus',
  recurringId: 'recurring-id-string',
  client: {
    ip: '127.0.0.1',
    userAgent: 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531...'
  },
  account: {
    id: 'user-12345'
  }
};

return PSP.processRecurringPayment(options)
  .then(payment => {
    // Handle payment creation success
  })
  .catch(err => {
    // Handle error
  });
});

getPayment: Read payment

Get updated information about an existing payment

getPayment(paymentId);

Arguments

ArgumentTypeDefaultDescription
paymentIdStringRequiredID of payment to query. Comes from the id property of the payment object.

Returns

The function return a Promise which resolves in a payment object.

Example

const paymentId = '12345678-4321-2345-6543-456787656789';
return PSP.getPayment(paymentId)
  .then(payment => {
    // Handle payment creation success
  })
  .catch(err => {
    // Handle error
  });
});

isCallbackValid: Validate callback

Validate a callback sent from iSignThis.

isCallbackValid(request);

Arguments

ArgumentTypeDefaultDescription
requestObjectRequiredWhole request object with headers and body.

Returns

Returns true if callback is valid

Example

const request = {
  headers: {
  	 'content-type': 'application/json',
	  accept: 'application/json',
	  host: 'example.com',
	  authorization: 'Bearer token_value',
	  'content-length': '1297',
	  connection: 'close',
  },
  body: {}
};

// Result is either true or false
const result = isCallbackValid(request);

parsePayment: Read payment

Get updated information about an existing payment

parsePayment(requestBody);

Arguments

ArgumentTypeDefaultDescription
requestBodyObjectRequiredBody of the request object. In this case its a payment object from iSignThis.

Result

This function returns a payment object.

Example

const requestBody = {
  id: "c97f0bfc-c1ac-46c3-96d8-6605a63d380d",
  uid: "c97f0bfc-c1ac-46c3-96d8-6605a63d380d",
  secret: "f8fd310d-3755-4e63-ae98-ab3629ef245d",
  mode: "registration",
  original_message: {
    merchant_id: merchantId,
    transaction_id: transactionId,
    reference: transactionReference
  },
  expires_at: "2016-03-06T13:36:59.196Z",
  transactions: [
    {
      acquirer_id: acquirerId,
      bank_id: "2774d451-5499-41a6-a37e-6a90f2b8673c",
      response_code: "20000",
      success: true,
      amount: "0.70",
      currency: "DKK",
      message_class: "authorization-and-capture",
      status_code: "20000"
    },
    {
      acquirer_id: acquirerId,
      bank_id: "73f63c0b-7c59-416f-89e5-17dcc38b64ac",
      response_code: "20000",
      success: true,
      amount: "0.30",
      currency: "DKK",
      message_class: "authorization-and-capture",
      status_code: "20000"
    }
  ],
  state: "PENDING",
  compound_state: "PENDING.AWAIT_SECRET"
}

// result is a payment object
const payment = PSP.parsePayment(requestBody);
3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago