Giter Club home page Giter Club logo

2checkout-node's Introduction

DEPRECATED!!! This SDK can only be used with the legacy 2Checkout platform which is depreciated. Please use 2checkout-node-sdk with the current 2Checkout platform.

Full documentation for each binding is provided in the wiki.

This library provides developers with a simple set of bindings to the 2Checkout Payment API, Hosted Checkout, Instant Notification Service and Admin API.

To use, download or clone the repository and install with npm.

git clone https://github.com/craigchristenson/2checkout-node.git
npm install 2checkout-node

Then you can require the module and setup the 2Checkout object with a number of options shown below.

// Require the module
var Twocheckout = require('2checkout-node');

// Pass in your private key and seller ID
var tco = new Twocheckout({
    apiUser: "APIuser1817037",                              // Admin API Username, required for Admin API bindings
    apiPass: "APIpass1817037",                              // Admin API Password, required for Admin API bindings
    sellerId: "1817037",                                    // Seller ID, required for all non Admin API bindings 
    privateKey: "3508079E-5383-44D4-BF69-DC619C0D9811",     // Payment API private key, required for checkout.authorize binding
    secretWord: "tango"                                    // Secret Word, required for response and notification checks
});

Example Payment API Usage

Example Request:

// Setup the authorization object
var params = {
    "merchantOrderId": "123",
    "token": "MWQyYTI0ZmUtNjhiOS00NTIxLTgwY2MtODc3MWRlNmZjY2Jh",
    "currency": "USD",
    "total": "10.00",
    "billingAddr": {
        "name": "Testing Tester",
        "addrLine1": "123 Test St",
        "city": "Columbus",
        "state": "Ohio",
        "zipCode": "43123",
        "country": "USA",
        "email": "[email protected]",
        "phoneNumber": "5555555555"
    }
};

// Make the call using the authorization object and your callback function
tco.checkout.authorize(params, function (error, data) {
    if (error) {
        console.log(error.message);
    } else {
        console.log(JSON.stringify(data));
    }
});

Example Response:

{
    "validationErrors": null,
    "response": {
        "type": "AuthResponse",
        "currencyCode": "USD",
        "lineItems": [
            {
                "description": "",
                "duration": "1 Year",
                "options": [],
                "price": "6.99",
                "quantity": "2",
                "recurrence": "1 Month",
                "startupFee": null,
                "productId": "123",
                "tangible": "N",
                "name": "Demo Item 1",
                "type": "product"
            },
            {
                "description": "",
                "duration": null,
                "options": [
                    {
                        "optName": "Size",
                        "optValue": "Large",
                        "optSurcharge": "1.00"
                    }
                ],
                "price": "1.99",
                "quantity": "1",
                "recurrence": null,
                "startupFee": null,
                "productId": "",
                "tangible": "N",
                "name": "Demo Item 2",
                "type": "product"
            },
            {
                "description": "",
                "duration": null,
                "options": [],
                "price": "3.00",
                "quantity": "1",
                "recurrence": null,
                "startupFee": null,
                "productId": "",
                "tangible": "Y",
                "name": "Shipping Fee",
                "type": "shipping"
            }
        ],
        "transactionId": "205203115673",
        "billingAddr": {
            "addrLine1": "123 Test St",
            "addrLine2": null,
            "city": "Columbus",
            "zipCode": "43123",
            "phoneNumber": "5555555555",
            "phoneExtension": null,
            "email": "[email protected]",
            "name": "Testing Tester",
            "state": "Ohio",
            "country": "USA"
        },
        "shippingAddr": {
            "addrLine1": "123 Test St",
            "addrLine2": "",
            "city": "Columbus",
            "zipCode": "43123",
            "phoneNumber": null,
            "phoneExtension": null,
            "email": null,
            "name": "Testing Tester",
            "state": "OH",
            "country": "USA"
        },
        "merchantOrderId": "123",
        "orderNumber": "205203115664",
        "recurrentInstallmentId": null,
        "responseMsg": "Successfully authorized the provided credit card",
        "responseCode": "APPROVED",
        "total": "19.97",
        "errors": null
    },
    "exception": null
}

Example Admin API Usage

Example Request:

tco.sales.retrieve({sale_id: 205203115664}, function (error, data) {
    if (error) {
        console.log(error);
    } else {
        console.log(data);
    }
});

Example Checkout Usage:

Example Request:

// Setup checkout params
var params = {
    mode: '2CO',
    li_0_name: 'Test Product',
    li_0_price: '0.01'
};

// Get a URL encoded payment link
var link = tco.checkout.link(params);

Example Response:

https://www.2checkout.com/checkout/purchase?mode=2CO&li_0_name=Test%20Product&li_0_price=0.01&sid=1817037

Example Return Usage:

Example Request (Using Express):

if (tco.response.valid(request.body), 0.01) {
    response.send("Valid");
} else {
    response.send("Invalid");
}

Example INS Notifications Usage:

Example Usage (Using Express):

if (tco.notification.valid(request.body)) {
    response.send("Valid");
} else {
    response.send("Invalid");
}

Exceptions:

Errors are returned as the first argument to your callback if they occur. It is best to always check for these before attempting to work with the response.

Example

tco.checkout.authorize(params, function (error, data) {
    if (error) {
        console.log(error.message);
    } else {
        console.log(JSON.stringify(data));
    }
});

Full documentation for each binding is provided in the wiki.

2checkout-node's People

Contributors

andrei-popa88 avatar craigchristenson avatar jmcconnell91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

2checkout-node's Issues

Response has a problem with src causing failure of loading of javascript file.

I am receiving this response:

<form id="2checkout" action="https://www.2checkout.com/checkout/purchase" method="post"><input type="hidden" name="mode" value="2CO"/><input type="hidden" name="li_0_name" value="Test Product"/><input type="hidden" name="li_0_price" value="0.01"/><input type="hidden" name="card_holder_name" value="Testing Tester"/><input type="hidden" name="email" value="[email protected]"/><input type="hidden" name="street_address" value="123 test st"/><input type="hidden" name="city" value="Columbus"/><input type="hidden" name="state" value="Ohio"/><input type="hidden" name="zip" value="43123"/><input type="hidden" name="country" value="USA"/><input type="hidden" name="sid" value="202798592"/><input type="submit" value="Checkout" /></form><script src=https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>

Note

<script src=https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>

Last script tag is missing " after src= but has a " after min.js

Nothing fancy just a demo

    var tco = new Twocheckout({
        sellerId: ""
    });

    var params = {
        'mode': '2CO',
        'li_0_name': 'Test Product',
        'li_0_price': '0.01',
        'card_holder_name': 'Testing Tester',
        'email': '[email protected]',
        'street_address': '123 test st',
        'city': 'Columbus',
        'state': 'Ohio',
        'zip': '43123',
        'country': 'USA'
    };

    var form = tco.checkout.direct(params, 'Checkout');
    console.log(form)

2co.js should check if params are parsed before parsing

2co.js' requestToken method aggressively parses it's params. If the client passes credit card or cvv number as type Number, the library will fail:

a.cvv.replace is not a function

2co.js should check if params are of type Number before parsing, then validate.

A typo in the docs

There is a typo in the docs related to Response_Valid, in the README "Return Usage" section, and in the wiki page https://github.com/2Checkout/2checkout-node/wiki/Response_Valid.
The second parameter on tco.response.valid is the total price, in the docs that parameter not placed correctly.
if (tco.response.valid(request.body), 0.01) {
should be
if (tco.response.valid(request.body, 0.01)) {

BTW the total price must be a string ('20.10') and not a Number(20.1).

token

you are using here token......where u have generated it ...where is the post api to create a sale? how sale is created in nodejs?

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.