rocketfuel-node-sdk
v0.1.4
Published
JS SDK for RocketFuel Payment Method
Downloads
10
Maintainers
Readme
Rocketfuel JS SDK
JS SDK for RocketFuel Payment Method
- Go to https://merchant-rocketefuelblockchain.com/ or https://merchant-sandbox.rocketefuelblockchain.com/ and register as a Merchant
- Confirm your email
- Connect your e-shop = click Edit in the lower left corner, fill in all the fields, copy your merchantID
- Type in your shop callback/Webhook URL (for example, https://yourshop.com/rocketfuel-callback)
- Generate your clientId and clientSecret from Settings tab.
Payments (via Rocketfuel extension or popup window/iframe)
After a user creates a new order in your shop and clicks Rocketfuel payment method button on a checkout page, order information should be sent to Rocketfuel
Install
$ npm install rocketfuel-node-sdk
Usage
Basic usage
// if you use sdk on browser
import Rocketfuel from 'rocketfuel-node-sdk';
// or
const Rocketfuel = require('rocketfuel-node-sdk').default;
// if you use sdk on nodejs
const Rocketfuel = require('rocketfuel-node-sdk');
// you need to specify the baseUrl to which requests will be sent
// For example: https://stage1.rocketdemo.net/api or 'https://dev.rocketdemo.net/api'
const environment = production || sandbox;
const rocketfuel = new Rocketfuel(environment);
const authData = {
clientId: 'YOUR_CLIENT_ID',
encryptedPayload: 'YOUR_ENCRYPTED_PAYLOAD'
}
const auth = await rocketfuel.auth(authData);
// => {
// "ok": true,
// "result": {
// access: "string",
// refresh: "string",
// status: 0
// }
// }
// set an access token to gain access to private methods
rocketfuel.setAccessToken(auth.result.access);
SDK instance
API
encrypt()
Encrypt is uded for generating secure payload for token generation/ auth. It takes two parameters, tokenInfo and clientSecret to generate encrypted data. Token Info consist of merchantId and totp.
const tokenInfo = {
merchantId,
totp, // Authorization code from google authenticator. Pass it if you have two-factor authentication enabled
}
await rocketfuel.encrypt(tokenInfo, clientSecret);
/*
=> U2FsdGVkX1/6QwJJRTTjYnt/bzMeQO370pjWPakPbNZQw8oXRmC0F3QYG8fM8WeCQbmlTHitMrAVCEP8I5vCQiHFIqSygcwNR3lVB+fTsAw=
*/
decrypt()
Decrypt works opposite of encrypt. It accepts encryptedText and clientSecret as the parameters.
await rocketfuel.decrypt(encryptedText, clientSecret);
/*
=> {
merchantId,
totp, // Authorization code from google authenticator. Pass it if you have two-factor authentication enabled
}
*/
auth()
User authorization. The method accepts data for authorization and returns JWT tokens and user status
const auth = {
clientId,
encryptedPayload
}
await rocketfuel.auth(auth);
/*
=> {
"ok": true,
"result": {
access: "string",
refresh: "string",
status: 0
}
}
*/
setAccessToken()
Access token setting method. You must call this method once before starting to work with the SDK so that you have access to other methods.
After the token expires, you need to call the refreshTokens()
method to get new tokens. After that, call the setAccessToken()
method again.
An access token can be obtained during authorization (auth()
methods) or when refreshing tokens (refreshTokens()
method)
rocketfuel.setAccessToken(access);
// => void
refreshTokens()
Token refresh method. If you receive a 401 Unauthorized
error, then you need to use this method to update tokens.
The method accepts a refresh token that you received after authorization. The method returns new tokens
const refresh = await rocketfuel.refreshTokens(refreshToken);
/*
=> {
"ok": true,
"result": {
access: "string",
refresh: "string",
status: 0
}
}
*/
generateUUID()
Private method
Method for making a purchase.
const options = {
amount: "59.97",
merchant_id: process.env.MERCHANT_ID,
cart: [
{
id: "23",
name: "Tshirt with round nect (L)",
price: "10",
quantity: "1",
},
{
id: "24",
name: "Flower Formal T-shirt (L)",
price: "15",
quantity: "1",
},
{
id: "25",
name: "Printed White Tshirt (L)",
price: "9",
quantity: "1",
},
],
currency: "USD",
order: "390",
redirectUrl: "",
customerInfo: {
name: 'Customer Name',
email: 'Customer Email',
}
}
// options is required
const result = await rocketfuel.generateUUID(options);
/*
=> {
"ok": true,
"result": {
uuid: "string",
url: "string"
}
}
*/
merchant_id - identifier of a shopper.
amount - amount of money to be paid.
currency - currency of the purchase.
order - identifier of a purchase within a shop.
lookup()
Private method
It is used to fetch the currenct stauts of the transaction record.
// options is required
const result = await rocketfuel.lookup(txnId, merchantId);
/*
=> {
"ok": true,
"result": [
{
"id": <Transaction_id>,
"status": <Status>,
"meta": {
"offerId": <Offer_id>
},
"amount": "1.598457239956444619",
"receivedAmount": "0",
"currency": "ETH"
}
]
}
// Values received in response are
1. id – RKFL identifier
2. status – code will be interpreted as follows
1 = RocketFuel received the amount successfully
0 = Amount is Pending to be received by RocketFuel
-1 = RocketFuel didn’t receive the amount, and the transaction is failed
101 = RocketFuel received a partial payment of the total amount
3. meta
3.1 offerId – Unique identifier of the merchant
4. amount - the total price of the complete order.
5. receivedAmount – Amount received by RocketFuel for an order.
6. currency – Unit of currency used by Shopper to make the payment for an order
*/
webhook()
Private method
It is used to match the signature of the webhook received. It accepts the webhook payload received as a paramter.
// options is required
const result = await rocketfuel.webhook(requestBody);
/*
=> // verify webhook
const webhookAuthentic = await rocket.webhook(requestBody); // true false
console.log('Webhook authentic: ', webhookAuthentic);
*/