transact-payments
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

transact-payments

This is a library for use with transact.io

See an example on package transact-payments-demo with a live demo

Working with this package

Add transact-payments package to your package.json file

Usage

Require transact-payments library

let transactIo = require('transact-payments');

Instantiate a new instance of the TransactIoMsg class

let transactToken = new transactIo.TransactIoMsg(); // get new instance

Required: Set the secret that is in the Developer Settings / Keys of the transact publisher menu

transactToken.setSecret('Signing Secret'); // secret key

Required: Set the Account ID of who recieves the funds

transactToken.setRecipient('5206507264147456'); // Account ID to pay

Required: set the URL of what is being purchased.

// Note that the host name MUST match the real name for cross site 
// messaging to work. 
transactToken.setURL($_REQUEST['url']);

Required: Set the price in pences of the sale

transactToken.setPrice(2);

Required: Set an item or product code. This can be something unique to the article or content you are selling. The buyer will see this as part of the name of the charge

transactToken.setItem('ItemCode1'); // item code

Optional: Set a Unique ID associated with this sale.

transactToken.setUid('UniqueSaleID');

Optional: Set meta data you want to save with this sale.

// Set your own meta data
// Note you must keep this short to avoid going over the 1024 byte limt
// of the token URL
transactToken.setMeta({
	'your' : 'data',
	'anything' : 'you want'
});

Get token for normal purchase

Get a token that will be passed to transact.js after all paramateres are set. There are two ways to generate a token.

Using callback

function getTokenCb(error,token) {
	if (error) {
		console.log("Failed to create the token with error:",error);
	} else {
		console.log("Token created successfully:",token);
	}
}

transactToken.getToken(getTokenCb);

Using promise

let promise = transactToken.getToken();

promise.then(function(token) {
	console.log("Token created successfully:",token);
).catch(function(error) {
	console.log("Failed to create the token with error:",error);
});

Verifying a token

To verify a token the signing secret needs to match the one used when creating the token. There are two ways to verify a token.

Using callback

let transactIo = require('transact-payments');
let token = 'token generated previously';
let secret = 'Signing Secret';

function tokenVerification(error,verifiedToken) {
	if (error) {
		console.log("Failed to verify the token with error:",error);
	} else {
		console.log("Token verified successfully:",verifiedToken);
	}
}

transactIo.TransactIoMsg.verify(token,secret,tokenVerification);

Using promise

let transactIo = require('transact-payments');
let token = 'token generated previously';
let secret = 'Signing Secret';

let promise = transactIo.TransactIoMsg.verify(token,secret);
promise.then(function(verifiedToken) {
	console.log("Token verified successfully:",verifiedToken);
}).catch(function(error) {
	console.log("Failed to verify the token with error:",error);
});

Package Sidebar

Install

npm i transact-payments

Weekly Downloads

28

Version

1.4.0

License

Apache-2.0

Unpacked Size

46.7 kB

Total Files

23

Last publish

Collaborators

  • therudo
  • karl_transact