npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tco-node-api

v0.0.1

Published

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

Downloads

5

Readme

2Checkout APIv2 Node Library

Requirements

  • Node v0.8+
  • request v2.0+

Setup

$ npm install

Using the bindings

Require the dependency.

var tco = require('twocheckout');

Setup your credentials:

tco.config(SELLER_ID, PRIVATE_KEY, BOOL(SANDBOX)); // pass true as third argument to use the sandbox

Sales

Create

var params = {
  amount: 1.00,
  merchant_order_id: '123',
  auth_only: true,
  customer: {
    phone: '555-555-5556',
    currency: 'USD',
    lang: 'en',
    email: '[email protected]',
    payment_method: {
      credit_card: {
        number: '4111111111111111',
        exp_month: 12,
        exp_year: 2019,
        cvv: '123'
      },
      address: {
        name: 'Testing Tester',
        address_1: '123 Test St',
        address_2: 'the attic',
        city: 'Columbus',
        state: 'OH',
        country_code: 'US',
        postal_code: '43123'
      }
    }
  }
};

tco.sales.create(params, function (error, sale) {
  console.log(sale.id);  //sale_id
  console.log(sale.invoices[0].id);  //invoice_id
});

Find

tco.sales.find(SALE_ID, function (error, sale) {
  console.log(sale.id); //sale_id
  console.log(sale.invoices[0].id);  //invoice_id
});

List

params = {page: 1, page_size: 5}

tco.sales.list(params, function (error, data) {
  console.log(data.sales[0].id);  // first sale_id
  console.log(data.pagenation.next);  // next page
});

Invoices

Find

tco.invoices.find(INVOICE_ID, function (error, invoice) {
  console.log(invoice.id);  // invoice_id
});

List

params = {page: 1, page_size: 5}

tco.invoices.list(null, function (error, data) {
  console.log(data.invoices[0]);
});

Capture

tco.sales.capture(INVOICE_ID, function (error, invoice) {
  console.log(invoice.id);    // invoice_id
  console.log(invoice.needs_captured);   // false
});

Refund

invoice = twocheckout.Invoice.find(INVOICE_ID)    # twocheckout.invoice.Invoice

params = {
  amount: 1.00,
  currency_type: "vendor",
  comment: "Refund Issued"
}

tco.invoices.refund(sale.invoices[0].id, params,function (error, invoice) {
  console.log(invoice.id);    // invoice_id
  console.log(invoice.refunds[0].id);    // refund_id
});

Customers

Create

params = {
  phone: '555-555-5556',
  currency: 'USD',
  lang: 'en',
  email: '[email protected]',
  payment_method: {
    credit_card: {
      number: '4111111111111111',
      exp_month: 12,
      exp_year: 2019,
      cvv: '123'
    },
    address: {
      name: 'Testing Tester',
      address_1: '123 Test St',
      address_2: 'the attic',
      city: 'Columbus',
      state: 'OH',
      country_code: 'US',
      postal_code: '43123'
    }
  }
};

tco.customers.create(params, function (error, customer) {
  console.log(customer.id);    // customer_id
  console.log(customer.payment_methods[0].id);    // payment_method_id
});

Find

tco.customers.find(CUSTOMER_ID, function (error, customer) {
  console.log(customer.id);    // customer_id
  console.log(customer.payment_methods[0].id);    // payment_method_id
});

List

params = {page: 1, page_size: 5}

tco.customers.list(params, function (error, data) {
  console.log(data.customers[0].id);    // first customer_id
});

Update

tco.customers.update(CUSTOMER_ID, {email: "[email protected]"},function (error, customer) {
  console.log(customer.id);    // customer_id
});

Delete

tco.customers.delete(CUSTOMER_ID,function (error, result) {
  console.log(result.code); // OK
});

Payment Methods

Create

params = {
  credit_card: {
    number: '4111111111111111',
    exp_month: 12,
    exp_year: 2019,
    cvv: '123'
  },
  address: {
    name: 'Testing Tester',
    address_1: '123 Test St',
    address_2: 'the attic',
    city: 'Columbus',
    state: 'OH',
    country_code: 'US',
    postal_code: '43123'
  }
}

tco.payment_methods.create(CUSTOMER_ID, params, function (error, payment_method) {
  console.log(payment_method.id);   // payment_method_id
  console.log(payment_method.brand);    // VS
});

Find

tco.payment_methods.find(CUSTOMER_ID, PAYMENT_METHOD_ID, function (error, payment_method) {
  console.log(payment_method.id);   // payment_method_id
  console.log(payment_method.brand);    // VS
});

List

tco.payment_methods.list(CUSTOMER_ID, null, function (error, data) {
  console.log(data.payment_methods[0].id);    //first payment_method_id
});

Set Default

tco.payment_methods.default(CUSTOMER_ID, PAYMENT_METHOD_ID, function (error, payment_method) {
  console.log(payment_method.default);    //true
});

Delete

tco.payment_methods.delete(CUSTOMER_ID, PAYMENT_METHOD_ID, function (error, result) {
  console.log(result.code);    // OK
});

Subscriptions

Subscriptions (recurring items) can be created when creating a sale by passing a recurrence and optionally a duration.

Stop

tco.subscriptions.stop(SUBSCRIPTION_ID, function (error, subscription) {
  console.log(subscription.id);    // subscription_id
  console.log(subscription.active)    // false
});

Handling Exceptions

Errors will be thrown if the request is not successful. You should always check the error object in your callback so that you can cleanly handle exceptions.

tco.sales.create(params, function (error, sale) {
  if(data === undefined) {
    console.log(error.message)
  } else {
    console.log(data)
  }
});

Running the tests

$ mocha --timeout 10000