https://github.com/gnapse/twocheckout
Ruby wrapper for 2Checkout API
https://github.com/gnapse/twocheckout
Last synced: about 2 months ago
JSON representation
Ruby wrapper for 2Checkout API
- Host: GitHub
- URL: https://github.com/gnapse/twocheckout
- Owner: gnapse
- License: mit
- Created: 2012-08-23T17:15:45.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-04T16:49:39.000Z (over 12 years ago)
- Last Synced: 2025-02-05T23:01:07.315Z (4 months ago)
- Language: Ruby
- Size: 122 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Twocheckout
This gem aims at providing an ORM-like interface to access the [2Checkout API](https://www.2checkout.com/documentation/api/) from Ruby code.
## Installation
Add this line to your application's Gemfile:
gem 'twocheckout'
And then execute:
$ bundle
Or install it yourself as:
$ gem install twocheckout
## Usage
The first step is to define your credentials to access the API:
Twcocheckout::API.credentials = { :username => 'api.user', :password => 'secret' }
Then you can start making things like this:
sale = Twocheckout::Sale.find(:sale_id => '4769044324')
puts "#{sale.sale_id} has #{sale.invoices.count} invoices"You can work on child objects too, like invoices and lineitems:
last_invoice = sale.invoices.last
specific_invoice = sale.invoice['4769044335']
puts "Invoice #{last_invoice.invoice_id} has #{last_invoice.lineitems.count} lineitems..."
puts "...and #{last_invoice.active_lineitems.count} of them are active"You can perform actions on them too, not just query their attributes:
last_lineitem = last_invoice.lineitems.last
last_lineitem.refund!
sale.stop_recurring!Sales and invoices are not everything. You can easily query the company info and contact details:
company = Twocheckout::Company.instance
contact_info = company.contact_info
puts "Company: #{company.vendor_name}"
puts "City: #contact_info.mailing_city"And this is just the beginning. We plan to provide an interface to every single 2Checkout API call available.
### Direct API calls
ORM-like interfaces are not a panacea. Sometimes it may be more convenient to perform low-level API calls directly:
sales = Twocheckout::API.request(:get, 'sales/list_sales')
first_sale = sales['sale_summary'].firstIn this case, the resulting object is a hash containing the parsed JSON response obtained from the call.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request