Catalog npm
Back to packageRELEASE DETAILS

0.0.2

npm

2checkout-nodejs

A node.js wrapper for the 2Checkout Payment API.

Published10 Dec 2018
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

2Checkout Node.js Library

Full documentation for each binding is provided in the wiki.

This library is forked from the original 2Checkout Node.js Library. The difference is that you don't need to clone and then install (which will install to local file)

To use just install with npm.

npm install 2checkout-nodejs --save

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
    demo: true,                                             // Set to true if testing response with demo sales
    sandbox: false                                          // Uses 2Checkout sandbox URL for all bindings
});

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": "example@2co.com",
        "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": "example@2co.com",
            "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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
request
Environment
{
  "local_name": "request",
  "alias": false,
  "peer_metadata": null
}
2.x.xruntime
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
~1.13.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-jq0ixfZJOxDJe3FQo8LiFBrpU5MxjhlqAxYSEvK8WfM0xNlw12WCnpUzxnoku7MiabLR+PhXPp2vShSGcp4fqg==",
  "shasum": "3bacdd29b87122fabcf68cb2d1319944b875b2c6",
  "tarball": "https://registry.npmjs.org/2checkout-nodejs/-/2checkout-nodejs-0.0.2.tgz",
  "fileCount": 24,
  "unpackedSize": 34612,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcDpUvCRA9TVsSAnZWagAAlokP/2xDIkZqGc0hBPiwXJuY\nmldQAcnFH7VyFdaWTGXOOj+J3SzuN+PHgvbwjVB5DQPT9m1nCLKLkoS7XgKb\nnlUWE9xySoQhdfvMtjF1G/WYUV7+Gy6jmJk+oiiFLI6xndi4N1aiOZ0Lr9AT\nvWUCaAtHcPFt8FGBxZPh9NJf7BwT136OWGuzcs4V2ubstFzrJnjkW7+Fw3Ao\nFYg+dsCspVnQVGedTPFKrkSL2UwHOxrWY1EgEqUV5cYWx12oyQx0tyxEns5X\nXv7HzDgQeDmqGDnV+JpV+UMVkUEz4rDivuwHU2+17kzB5wFQdR1d7ZrtrZvJ\no7TkKahnS4qYP6hRdBCs5cADcVSnFdWUKS/qsUPvmn/BN1WJo0Wp20J4M5XY\numBph1kEhPAK0f1cZP/g+KMh6fBUu4mUWgGNeAC+PfJmK3ZGfblCvFjFP5H/\nCpDq5mYr17aXl6Nl5ZKB3SL2Ko/ZDfAEqbDUrEgv+1E85S4Ewny9gcF7jJWz\ncX+txSPL+T7pp320fas6r55onV7BX9oT3tJOqjBsSFS8RcRiFT3bVOCFSTi4\nRqKvvHLIk836j04sIDrZvmPQWTh6+BkJuJWrL3MnRDSDqJuG1vQxY0cu3/z2\nrQ93bYFuBn8W8/ntDUX8cfOO5/ep2eMXKqyq1amNrnCUB2+QKooBOnv+ulmf\nrXe0\r\n=0JXX\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCf2CVneGTufUy5BTaYQWicWRHjSXiU2HEFL9lurRcczgIgV5jTr1kzwDKg7O8aLJW0albnUN5d4kBDigKrpXHMe5o="
    }
  ]
}

Repository

PENDING
2checkout/2checkout-node

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:09 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:ca594c0d81bb546f6ea2d00c2c6102e4d8b769e4cd17a3e131b32e6b1ae0c511

Other collected versions

0.0.110 DecView all collected versions →