Getting Started With PrivacyGate on NodeJS

If you are planning to start accepting cryptocurrency payments and are not yet familiar with how PrivacyGate works, it is worth spending 5 minute of your time.

List of available cryptocurrencies: Bitcoin, Bitcoin Cash, Ethereum, Litecoin, USD Coin, Tether (ERC20), Dai, Chainlink.

View sample project at: https://github.com/privacyshore/privacygate-node-sample

So let’s get started.

Before anything proceed by

  1. Registering an PrivacyGate account
  2. Navigating to the “settings” page
  3. Generating an API key
  4. Keep track of this API key as it will be needed in this tutorial

After you’ve done this, proceed to your development environment and execute the following commands: In case you have no project to work with as of right now, check out our sample project at https://github.com/privacyshore/privacygate-node-sample

npm install privacygate

This will install the privacygate nodejs library.

var privacygate = require('privacygate');
var Client = privacygate.Client;

var clientObj = Client.init('<API_KEY>');
clientObj.setRequestTimeout(3000);

This will create an client object that we can use to interact with the privacygate API.

This will allow us to do several things. For example (regarding Checkouts):

  1. Retrieve
var Checkout = privacygate.resources.Checkout;
Checkout.retrieve(<checkout_id>, function (error, response) {
  console.log(error);
  console.log(response);
});
  1. Create
var checkoutData = {
    'name': 'The Sovereign Individual',
    'description': 'Mastering the Transition to the Information Age',
    'pricing_type': 'fixed_price',
    'local_price': {
        'amount': '100.00',
        'currency': 'USD'
    },
    'requested_info': ['name', 'email']
};
Checkout.create(checkoutData, function (error, response) {
  console.log(error);
  console.log(response);
});

// or

var checkoutObj = new Checkout();

checkoutObj.name = 'The Sovereign Individual';
checkoutObj.description = 'Mastering the Transition to the Information Age';
checkoutObj.pricing_type = 'fixed_price';
checkoutObj.local_price = {
    'amount': '100.00',
    'currency': 'USD'
};
checkoutObj.requested_info = ['name', 'email'];

checkoutObj.save(function (error, response) {
  console.log(error);
  console.log(response);
});
  1. Update
var checkoutObj = new Checkout();

checkoutObj.id = <checkout_id>;
checkoutObj.name = 'new name';

checkoutObj.save(function (error, response) {
  console.log(error);
  console.log(response);
});
// or
var newParams = {
    'name': 'New name'
};

Checkout.updateById(<checkout_id>, newParams, function (error, response) {
  console.log(error);
  console.log(response);
});
  1. Delete
var checkoutObj = new Checkout();

checkoutObj.id = <checkout_id>;
checkoutObj.delete(function (error, response) {
 console.log(error);
 console.log(response);
});

// or

Checkout.deleteById(<checkout_id>, function (error, response) {
 console.log(error);
 console.log(response);  
});

View https://github.com/privacyshore/privacygate-node/tree/master/examples/resources for more examples