Skip to content

Xencov/squareup-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Square Up library provides an easy and convinent access to Square UP API from server-side applications.

Please keep in mind that this package can be used only in the server-side Node applications that uses Square Up access token. This package should not be used for front-end applications.

Installation:

Install the package with:

npm install squareup --save

Squareup Introduction:

Squareup provides up with a list of API that can be used to connect to square up, register customers, store their credit cards details, paying to the merchant and handling refunds from them.

This library allows us methods to use the Square Up APIs for :

  • Initialise Square Up module with its access token.
  • Add a new customer.
  • Adding new card for the customer.
  • Deleting the card from customer's cards list.
  • Charging the customer.
  • Making refunds.
Usage:

The package needs to be configured with your access token which is available in your Square up Dashboard. It can be either sandbox or actual access token. Require it with the token's value:

var SquareUp = require('squareup');
var squareUp = new SquareUp('your token here ..');     //Initialize square up by passing token here
 
var customerObj = {
		"given_name": '',           //required
		"family_name": '',          //required
		"email_address": '',        //required
		"address": {                //object us required, can be emply object
	     	"address_line_1": "",   //can be empty string
			"address_line_2": "",   //can be empty string
			"locality": "",         //can be empty string
			"postal_code": "",      //can be empty string
			"country": ""           //can be empty string
		},
		"phone_number": "",           //can be empty string
		"reference_id": ""            //any random string, min 32 characters
};
squareUp.createCustomer(
  customerObj,
  function(err, customer) {
    err; // null if no error occurred 
    customer; // the created customer object 
  }
);
For adding customer cards:
var cardObj = {
	"card_nonce": string,      //Generated by client-side square up library used for adding customer card details
	"billing_address": {    
	    "address_line_1": Joi.string(),      //Can be emppty string
	    "address_line_2": Joi.string(),     //Can be emppty string
	    "locality": Joi.string(),           //Can be emppty string
	    "administrative_district_level_1": Joi.string(), //Can be emppty string
    	"postal_code": Joi.string(),        //Required and should be the same as entered in client-side square up library to generate nonce
    	"country": Joi.string()             //Required
	},
	"cardholder_name": Joi.string().required()      //Required
};

squareUp.createCustomerCard(
  customerId,
  cardObj,
  function(err, card) {
    err; // null if no error occurred 
    card; // the created card object 
  }
);

Other methods used are :

  1. createCustomer(customer_details_obj, function(err, customerInfo)): For adding new customer
  2. createCustomerCard(customerId, card_details_obj, function(err, cardDetails)): For adding new card to the customer
  3. deleteCustomerCard(customerId, cardId, function(err, result)): For deleting card from the customer's cards list
  4. charge(charge_details_obj, function(err, result)):
var charge_details_obj = {
			"shipping_address": {
				"address_line_1": string,
				"address_line_2": string,
				"administrative_district_level_1": string,
				"locality": string,
				"postal_code": string,
				"country": string
			},
			"billing_address": {
				"address_line_1": string,
				"address_line_2": string,
				"administrative_district_level_1": string,
				"locality": string,
				"postal_code": string,
				"country": string
			},
			"amount_money": ({
				"amount": number,    //required
				"currency": string      //required
			}),
			"customer_card_id": string,         //required
			"customer_id": string,          //required
			"note": string,
			"delay_capture": false     //required
		};

either of the billing_address or shipping_address must be provided for making transaction with chargeback protection.

The above method provides an idempotency_key which is unique for every transaction and can be used to uniquely identify the transaction.

  1. refund(transactionId, details_obj, function(err, result)) : For making a refund for customer's card.

All methods return a Promise, so they are compatible with async-await.

More Information

Square Up Rest API Documentation Square Up Connection

About

Square up API layer for node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published