-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add payments class and upgrade depences (#1)
* update dependencies version * Add reload! method for bin/console * Add params support to get method request * Add params support to get method request to invoices class * Add Payments class * Add create payment * update README * update version gem * add comment params and update payments functionality * Add delete payments * changes styles code
- Loading branch information
Showing
15 changed files
with
424 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in alegra.gemspec | ||
gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,11 +158,44 @@ Send that invoice by email: | |
params = { emails: ['[email protected]', '[email protected]'], send_copy_to_user: true, invoice_type: 'copy'} | ||
client.invoices.send_by_email(1, params) | ||
``` | ||
|
||
### Payments | ||
|
||
You can get all payments: | ||
```ruby | ||
client.payments.list() | ||
``` | ||
|
||
Or get a specific payment by id: | ||
```ruby | ||
client.payments.find(1) # the parameter is the payment id | ||
``` | ||
|
||
Also you are able to create a new payments, as follows: | ||
```ruby | ||
params = { | ||
date: "2015-12-13", | ||
invoices: [ | ||
{ | ||
id: 6, | ||
amount: 150 | ||
}, | ||
{ | ||
id: 200, | ||
amount: 500 | ||
} | ||
], | ||
bank_account: 1 | ||
} | ||
|
||
client.payments.create(params) | ||
``` | ||
|
||
## Development | ||
|
||
This gem is under construction and I'm writing it with the goal that it will easy to use. However, if you have any recommendation is well received. | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
|
||
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). | ||
|
||
|
@@ -178,6 +211,10 @@ The next endpoints are pending: | |
- Retentions | ||
- Categories | ||
- Sellers | ||
- payments | ||
- cancel payment(void) | ||
- open payment convert https://developer.alegra.com/docs/convertir-pago-a-abierto | ||
- Add attachment https://developer.alegra.com/docs/adjuntar-archivos-a-pagos | ||
|
||
## License | ||
|
||
|
@@ -186,4 +223,4 @@ The gem is available as open source under the terms of the [MIT License](http:// | |
## Contributors | ||
|
||
- Diego Gomez | ||
|
||
- Nicolas Mena |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module Alegra | ||
class Payments | ||
attr_reader :client | ||
|
||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
# @param id [ Integer ] | ||
# @return [ Hash ] | ||
def find(id) | ||
client.get("payments/#{id}") | ||
end | ||
|
||
# Returs all payments | ||
# @param params [ Hash ] | ||
# - start [ Integer ] | ||
# - limit [ Integer ] | ||
# - order_direction [ String ] | ||
# - order_field [ string ] | ||
# - type [ Integer ] | ||
# - metadata [ Boolean ] | ||
# - id [ Integer ] | ||
# @return [ Array ] | ||
def list(params = {}) | ||
client.get('payments', params) | ||
end | ||
|
||
# Creates a payment | ||
# @param params [ Hash ] | ||
# - date [ String ] | ||
# - bank_account [ Integer ] or [ Hash ] | ||
# - payment_method [ String ] | ||
# - observations [ String ] | ||
# - anotation [ String ] | ||
# - type [ String ] | ||
# - client [ Integer ] or [ Hash ] | ||
# - invoices [ Array ] | ||
# - bills [ Array ] | ||
# - categories [ Array ] | ||
# - retentions [ Array ] | ||
# - currency [ Array ] | ||
# @return [ Hash ] | ||
def create(params) | ||
sanitize_params = params.deep_camel_case_lower_keys | ||
client.post('payments', sanitize_params) | ||
end | ||
|
||
# Update a payment | ||
# @param id [ Integer ] | ||
# @param params [ Hash ] | ||
# - date [ String ] | ||
# - bank_account [ Integer ] or [ Hash ] | ||
# - payment_method [ String ] | ||
# - observations [ String ] | ||
# - anotation [ String ] | ||
# - type [ String ] | ||
# - client [ Integer ] or [ Hash ] | ||
# - invoices [ Array ] | ||
# - bills [ Array ] | ||
# - categories [ Array ] | ||
# - retentions [ Array ] | ||
# - currency [ Array ] | ||
# @return [ Hash ] | ||
def update(id, params) | ||
sanitize_params = params.deep_camel_case_lower_keys | ||
client.put("payments/#{id}", sanitize_params) | ||
end | ||
|
||
# @param id [ Integer ] | ||
# @return [ Hash ] | ||
def delete(id) | ||
client.delete("payments/#{id}") | ||
end | ||
end | ||
end |
Oops, something went wrong.