unified-client v1.0.0
up-client
This module helps to simplify the process of integrating with unified payments platform.
Description
Admittedly, having to deal with XML data has become less common in recent years. But xml is extensively used while integrating with unified payments, so this helps to minimize the effort required to achieve smooth and swift integration.
Installation
For now the module is a local. so to install just copy the module directory to the same as your application and then
type npm link ../up-client
in your projects root folder and your good to go.
or copy the module package up-client-1.0.0.tgz
(note the module version) to any location and then install using npm install path-to-package
.
if in the same location as the project then just type npm install ../up-client-1.0.0.tgz
Configuration
You can pass configuration options into the up client middleware. IMPORTANT: Currently it is advisable to include the approve, decline and cancel url while creating the order instead of adding it globally in the setup.
var opts = {
merchantId: 'MERCHANT ID', // provision by unified payments
endpoint:'Up Endpoint',
port : 'PORT',
path : '/Exec',
key : '/path/to/key',
cert : 'path/to/cert',
approved: 'Approve Url',
canceled: 'Cancel Url',
declined: 'Decline Url'
};
Usage
In using this module you are expected to set the basic none changing options like the unified payments endpoint, path and port.
It is also advisable to include your merchant Id
at this point.
Here is an example of an express application with options:
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
var opts = {
merchantId: 'MERCHANT ID', // provision by unified payments
endpoint:'Up Endpoint',
port : 'PORT',
path : '/Exec',
key : '/path/to/key',
cert : 'path/to/cert',
approved: 'Approve Url',
canceled: 'Cancel Url',
declined: 'Decline Url'
};
// .. other middleware ...
app.use(express.json());
app.use(express.urlencoded());
require('up-client')(app, opts);
// ... other middleware ...
server.listen(1337);
CreateOrder action
the following fields are required to successfully perform the create order. Just pass the amount, description and respective return url and a callback to process the result.
var client = require('up-client').client;
app.post('/createOrder', function(req, res, next) {
client.createOrder({
amount: 200,
description: 'Sample Description',
approved: 'http://......../approved',
declined: 'http://......../declined',
canceled: 'http://......../canceled',
}, function(e, data){
// e is the error, if the process fails or the response status code is not successful '00',
// data is an object of the necessary values, look bellow
});
});
// The object passed into the callback is in the following format:
{
OrderID: '', //The OrderID
SessionID: '', //The sessionID
URL: '', //The base url,
mpi: '', // The Url, concatenated with the session and order ids.
xml: '', // The xml response to the create order.
co_xml: '' //The create order xml
}
8 years ago