2Checkout APIv2 Node Library
Requirements
- Node v0.8+
- request v2.0+
Setup
$ npm install
Using the bindings
Require the dependency.
var tco = ;
Setup your credentials:
tco; // pass true as third argument to use the sandbox
Sales
Create
var params = amount: 100 merchant_order_id: '123' auth_only: true customer: phone: '555-555-5556' currency: 'USD' lang: 'en' email: 'nobody@example.com' 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' ; tcosales;
Find
tcosales;
List
params = page: 1 page_size: 5 tcosales;
Invoices
Find
tcoinvoices;
List
params = page: 1 page_size: 5 tcoinvoices;
Capture
tcosales;
Refund
invoice = twocheckoutInvoice # twocheckoutinvoiceInvoice params = amount: 100 currency_type: "vendor" comment: "Refund Issued" tcoinvoices;
Customers
Create
params = phone: '555-555-5556' currency: 'USD' lang: 'en' email: 'nobody@example.com' 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' ; tcocustomers;
Find
tcocustomers;
List
params = page: 1 page_size: 5 tcocustomers;
Update
tcocustomers;
Delete
tcocustomers;
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' tcopayment_methods;
Find
tcopayment_methods;
List
tcopayment_methods;
Set Default
tcopayment_methods;
Delete
tcopayment_methods;
Subscriptions
Subscriptions (recurring items) can be created when creating a sale by passing a recurrence and optionally a duration.
Stop
tcosubscriptions;
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.
tcosales;
Running the tests
$ mocha --timeout 10000