Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment services #439

Merged
merged 3 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 63 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Xeroizer API Library ![Project status](http://stillmaintained.com/waynerobinson/
**Git**: [git://github.com/waynerobinson/xeroizer.git](git://github.com/waynerobinson/xeroizer.git)
**Github**: [https://github.com/waynerobinson/xeroizer](https://github.com/waynerobinson/xeroizer)
**Author**: Wayne Robinson [http://www.wayne-robinson.com](http://www.wayne-robinson.com)
**Contributors**: See Contributors section below
**Contributors**: See Contributors section below
**Copyright**: 2007-2013
**License**: MIT License

Expand Down Expand Up @@ -34,7 +34,7 @@ client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CON
# Retrieve list of contacts (note: all communication must be made through the client).
contacts = client.Contact.all(:order => 'Name')
```

Authentication
--------------

Expand All @@ -44,13 +44,13 @@ There are three methods of authentication detailed below:

### All: Consumer Key/Secret

All methods of authentication require your OAuth consumer key and secret. This can be found for your application
All methods of authentication require your OAuth consumer key and secret. This can be found for your application
in the API management console at [http://api.xero.com](http://api.xero.com).

### Public Applications

Public applications use a 3-legged authorisation process. A user will need to authorise your
application against each organisation that you want access to. Your application can have access
Public applications use a 3-legged authorisation process. A user will need to authorise your
application against each organisation that you want access to. Your application can have access
to many organisations at once by going through the authorisation process for each organisation.

The access token received will expire after 30 minutes. If you want access for longer you will need
Expand All @@ -75,69 +75,69 @@ redirect_to request_token.authorize_url

# 3. Exchange RequestToken for AccessToken.
# This access token will be used for all subsequent requests but it is stored within the client
# application so you don't have to record it.
# application so you don't have to record it.
#
# Note: This example assumes the callback URL is a Rails action.
client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier])
```

You can now use the client to access the Xero API methods, e.g.

```ruby
contacts = client.Contact.all
```

#### Example Rails Controller

```ruby
class XeroSessionController < ApplicationController

before_filter :get_xero_client

public

def new
request_token = @xero_client.request_token(:oauth_callback => 'http://yourapp.com/xero_session/create')
session[:request_token] = request_token.token
session[:request_secret] = request_token.secret

redirect_to request_token.authorize_url
end

def create
@xero_client.authorize_from_request(
session[:request_token],
session[:request_secret],
session[:request_token],
session[:request_secret],
:oauth_verifier => params[:oauth_verifier] )

session[:xero_auth] = {
:access_token => @xero_client.access_token.token,
:access_key => @xero_client.access_token.secret }

session.data.delete(:request_token)
session.data.delete(:request_secret)
end

def destroy
session.data.delete(:xero_auth)
end

private

def get_xero_client
@xero_client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET)

# Add AccessToken if authorised previously.
if session[:xero_auth]
@xero_client.authorize_from_access(
session[:xero_auth][:access_token],
session[:xero_auth][:access_token],
session[:xero_auth][:access_key] )
end
end
end
```
#### Storing AccessToken

#### Storing AccessToken

You can store the access token/secret pair so you can access the API again without user intervention. Currently these
tokens are only valid for 30 minutes and will raise a `Xeroizer::OAuth::TokenExpired` exception if you try to access
Expand All @@ -152,9 +152,9 @@ access_secret = client.access_token.secret

### Private Applications

Private applications use a 2-legged authorisation process. When you register your application, you will select
the organisation that is authorised to your application. This cannot be changed afterwards, although you can
register another private application if you have multiple organisations.
Private applications use a 2-legged authorisation process. When you register your application, you will select
the organisation that is authorised to your application. This cannot be changed afterwards, although you can
register another private application if you have multiple organisations.

Note: You can only register organisations you are authorised to yourself.

Expand Down Expand Up @@ -188,7 +188,7 @@ Authentication occcurs in 3 steps:
```ruby
client = Xeroizer::PartnerApplication.new(
YOUR_OAUTH_CONSUMER_KEY,
YOUR_OAUTH_CONSUMER_SECRET,
YOUR_OAUTH_CONSUMER_SECRET,
"/path/to/privatekey.pem"
)

Expand All @@ -206,7 +206,7 @@ redirect_to request_token.authorize_url

# 3. Exchange RequestToken for AccessToken.
# This access token will be used for all subsequent requests but it is stored within the client
# application so you don't have to record it.
# application so you don't have to record it.
#
# Note: This example assumes the callback URL is a Rails action.
client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier])
Expand All @@ -221,7 +221,7 @@ session_handle = client.session_handle
access_key = client.access_token.token
access_secret = client.access_token.secret
```

Two other interesting attributes of the PartnerApplication client are:

> **`#expires_at`**: Time this AccessToken will expire (usually 30 minutes into the future).
Expand All @@ -245,6 +245,10 @@ session.

If you lose these details at any stage you can always reauthorise by redirecting the user back to the Xero OAuth gateway.

#### Branding Themes API
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved

Once you are approved as a Xero Partner you can request unofficial documentation to do with customizing Payment Services and Branding Themes using the API. There is more info on that [here]( https://github.com/waynerobinson/xeroizer/pull/439).

Retrieving Data
---------------

Expand All @@ -264,10 +268,10 @@ saved = new_contact.save

### \#all([options])

Retrieves list of all records with matching options.
Retrieves list of all records with matching options.

**Note:** Some records (Invoice, CreditNote) only return summary information for the contact and no line items
when returning them this list operation. This library takes care of automatically retrieving the
when returning them this list operation. This library takes care of automatically retrieving the
contact and line items from Xero on first access however, this first access has a large performance penalty
and will count as an extra query towards your 5,000/day and 60/minute request per organisation limit.

Expand Down Expand Up @@ -305,11 +309,11 @@ You can specify find filters by providing the :where option with a hash. For exa
```ruby
invoices = Xero.Invoice.all(:where => {:type => 'ACCREC', :amount_due_is_not => 0})
```

will automatically create the Xero string:

Type=="ACCREC"&&AmountDue<>0

The default method for filtering is the equality '==' operator however, these can be overridden
by modifying the postfix of the attribute name (as you can see for the :amount\_due field above).

Expand All @@ -318,9 +322,9 @@ by modifying the postfix of the attribute name (as you can see for the :amount\_
\{attribute_name}_is_greater_than_or_equal_to will use '>='
\{attribute_name}_is_less_than will use '<'
\{attribute_name}_is_less_than_or_equal_to will use '<='

The default is '=='

**Note:** Currently, the hash-conversion library only allows for AND-based criteria and doesn't
take into account associations. For these, please use the custom filter method below.

Expand All @@ -332,31 +336,31 @@ in the resulting response, including all nested XML elements.
**Example 1: Retrieve all invoices for a specific contact ID:**

invoices = xero.Invoice.all(:where => 'Contact.ContactID.ToString()=="cd09aa49-134d-40fb-a52b-b63c6a91d712"')

**Example 2: Retrieve all unpaid ACCREC Invoices against a particular Contact Name:**

invoices = xero.Invoice.all(:where => 'Contact.Name=="Basket Case" && Type=="ACCREC" && AmountDue<>0')

**Example 3: Retrieve all Invoices PAID between certain dates**

invoices = xero.Invoice.all(:where => 'FullyPaidOnDate>=DateTime.Parse("2010-01-01T00:00:00")&&FullyPaidOnDate<=DateTime.Parse("2010-01-08T00:00:00")')

**Example 4: Retrieve all Invoices using Paging (batches of 100)**

invoices = xero.Invoice.find_in_batches({page_number: 1}) do |invoice_batch|
invoice_batch.each do |invoice|
...
end
end

**Example 5: Retrieve all Bank Accounts:**

accounts = xero.Account.all(:where => 'Type=="BANK"')

**Example 6: Retrieve all DELETED or VOIDED Invoices:**

invoices = xero.Invoice.all(:where => 'Status=="VOIDED" OR Status=="DELETED"')

**Example 7: Retrieve all contacts with specific text in the contact name:**

contacts = xero.Contact.all(:where => 'Name.Contains("Peter")')
Expand All @@ -376,7 +380,7 @@ invoice.line_items.each do | line_item |
puts "Line Description: #{line_item.description}"
end
```

**belongs\_to example:**

```ruby
Expand Down Expand Up @@ -430,21 +434,21 @@ contact.add_phone(:type => 'DEFAULT', :area_code => '07', :number => '3033 1234'
contact.add_phone(:type => 'MOBILE', :number => '0412 123 456')
contact.save
```

To add to a `has_many` association use the `add_{association}` method. For example:

```ruby
contact.add_address(:type => 'STREET', :line1 => '12 Testing Lane', :city => 'Brisbane')
```

To add to a `belongs_to` association use the `build_{association}` method. For example:

```ruby
invoice.build_contact(:name => 'ABC Company')
```

### Updating

If the primary GUID for the record is present, the library will attempt to update the record instead of
creating it. It is important that this record is downloaded from the Xero API first before attempting
an update. For example:
Expand All @@ -454,8 +458,8 @@ contact = xero.Contact.find("cd09aa49-134d-40fb-a52b-b63c6a91d712")
contact.name = "Another Name Change"
contact.save
```
Have a look at the models in `lib/xeroizer/models/` to see the valid attributes, associations and

Have a look at the models in `lib/xeroizer/models/` to see the valid attributes, associations and
minimum validation requirements for each of the record types.

### Bulk Creates & Updates
Expand Down Expand Up @@ -501,7 +505,7 @@ saved = contact.save

# contact.errors will contain [[:name, "can't be blank"]]
```

\#errors\_for(:attribute\_name) is a helper method to return just the errors associated with
that attribute. For example:

Expand Down Expand Up @@ -582,16 +586,16 @@ trial_balance.rows.each do | row |
case row
when Xeroizer::Report::HeaderRow
# do something with header

when Xeroizer::Report::SectionRow
# do something with section, will need to step into the rows for this section

when Xeroizer::Report::Row
# do something for standard report rows

when Xeroizer::Report::SummaryRow
# do something for summary rows

end
end
```
Expand Down Expand Up @@ -704,6 +708,6 @@ rake test


### Contributors
Xeroizer was inspired by the https://github.com/tlconnor/xero_gateway gem created by Tim Connor
and Nik Wakelin and portions of the networking and authentication code are based completely off
Xeroizer was inspired by the https://github.com/tlconnor/xero_gateway gem created by Tim Connor
and Nik Wakelin and portions of the networking and authentication code are based completely off
this project. Copyright for these components remains held in the name of Tim Connor.
1 change: 1 addition & 0 deletions lib/xeroizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
require 'xeroizer/models/option'
require 'xeroizer/models/organisation'
require 'xeroizer/models/payment'
require 'xeroizer/models/payment_service'
require 'xeroizer/models/prepayment'
require 'xeroizer/models/overpayment'
require 'xeroizer/models/phone'
Expand Down
3 changes: 2 additions & 1 deletion lib/xeroizer/generic_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GenericApplication
record :ManualJournal
record :Organisation
record :Payment
record :PaymentService
record :Prepayment
record :Overpayment
record :PurchaseOrder
Expand Down Expand Up @@ -80,6 +81,6 @@ def payroll(options = {})
xero_client.xero_url = options[:xero_url] || "https://api.xero.com/payroll.xro/1.0"
@payroll ||= PayrollApplication.new(xero_client)
end

end
end
Loading