Giter VIP home page Giter VIP logo

squarecordovaintegration's Introduction

Cordova Square Reader SDK

A Cordova plugin to interface with the native Square Reader SDK.

Install

$ cordova plugin add cordova-plugin-square-reader

$ cordova platform ios prepare

Install the Square SDK

Currently we only support iOS.

For more details refer Square Reader SDK Documentation.

Sub Step from Step 3 - "Update your Info.plist" can be skipped. Plugin will auto configure this.

Pair the card reader

NOTE: Square SDK needs to be authorized before initiating the pairing.

window['squarereader'].pairCardReaders(function () {
    console.log('Square card reader completed.');
}, function (err) {
    console.error('Square card reader pairing failed.');
    console.error(err);
});

Authorize and checkout

var retrieveAuthParams = {
    "personalAccessToken": "<YOUR PERSONAL ACCESS TOKEN>",
    "locationId": "<LOCATION ID OF>"
};
// Authorization code will be fetched from Square if previous authorization code is expired/empty
window['squarereader'].retrieveAuthorizationCode(retrieveAuthParams, function (response) {
    console.log("Application authorization code: " + response.authorization_code);

    var authorizeParams = {
        "authCode": response.authorization_code
    };

    window['squarereader'].authorizeReaderSDKIfNeeded(authorizeParams, function () {
        console.log("Application is authorized.");

        let checkoutParam = {
            "amount": "<AMOUNT_TO_AUTHORIZE"
        }
        window['squarereader'].startCheckout(checkoutParam, function (response) {
            console.log(response);
            console.log("Checkout completed successfully.");
        }, function (err) {
            console.error("Failed to checkout");
            console.error(err);
        });
    }, function (err) {
        console.log("Failed to authorize with retrieved authorization code.");
    });
}, function (err) {
    console.log('Failed to get the authorization code');
});

NOTE:

Make sure that you are passing the amount in checkout as a string and not number.

squarecordovaintegration's People

Contributors

sudhirdhumal289 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.