Add account balance REPP

This commit is contained in:
Martin Lensment 2015-04-16 11:46:18 +03:00
parent 35513b83bf
commit 4a6c1f4166
17 changed files with 111 additions and 27 deletions

View file

@ -0,0 +1,16 @@
module Repp
class AccountV1 < Grape::API
version 'v1', using: :path
resource :accounts do
desc 'Return current cash account balance'
get 'balance' do
@response = {
balance: current_user.registrar.cash_account.balance,
currency: current_user.registrar.cash_account.currency
}
end
end
end
end

View file

@ -39,5 +39,6 @@ module Repp
mount Repp::DomainV1 mount Repp::DomainV1
mount Repp::ContactV1 mount Repp::ContactV1
mount Repp::AccountV1
end end
end end

View file

@ -7,7 +7,7 @@
= link_to(t('add_deposit'), new_registrar_deposit_path, class: 'btn btn-default') = link_to(t('add_deposit'), new_registrar_deposit_path, class: 'btn btn-default')
%hr %hr
= t('your_current_account_balance_is', balance: current_user.registrar.cash_account.balance) = t('your_current_account_balance_is', balance: current_user.registrar.cash_account.balance, currency: current_user.registrar.cash_account.currency)
%h1= t('invoices') %h1= t('invoices')
%hr %hr

View file

@ -652,7 +652,7 @@ en:
prepayment: 'Prepayment' prepayment: 'Prepayment'
vat: 'VAT (%{vat_prc}%)' vat: 'VAT (%{vat_prc}%)'
unpaid: 'Unpaid' unpaid: 'Unpaid'
your_current_account_balance_is: 'Your current account balance is %{balance} EUR' your_current_account_balance_is: 'Your current account balance is %{balance} %{currency]'
billing: 'Billing' billing: 'Billing'
your_account: 'Your account' your_account: 'Your account'
pay_by_bank_link: 'Pay by bank link' pay_by_bank_link: 'Pay by bank link'

View file

@ -0,0 +1,7 @@
class AddCurrencyToAccount < ActiveRecord::Migration
def change
add_column :accounts, :currency, :string
Account.update_all(currency: 'EUR')
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150415075408) do ActiveRecord::Schema.define(version: 20150416080828) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -32,6 +32,7 @@ ActiveRecord::Schema.define(version: 20150415075408) do
t.decimal "balance", default: 0.0, null: false t.decimal "balance", default: 0.0, null: false
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "currency"
end end
create_table "addresses", force: :cascade do |t| create_table "addresses", force: :cascade do |t|

View file

@ -9,4 +9,5 @@ Production API endpoint: https://repp.todo.ee/repp/v1
Main communication specification through Restful EPP (REPP): Main communication specification through Restful EPP (REPP):
[Contact related functions](repp/v1/contact.md) [Contact related functions](repp/v1/contact.md)
[Domain related functions](repp/v1/domain.md) [Domain related functions](repp/v1/domain.md)
[Account related functions](repp/v1/account.md)

25
doc/repp/v1/account.md Normal file
View file

@ -0,0 +1,25 @@
## GET /repp/v1/accounts/balance
Returns domains of the current registrar.
#### Request
```
GET /repp/v1/accounts/balance HTTP/1.1
Accept: application/json
Authorization: Basic Z2l0bGFiOmdoeXQ5ZTRmdQ==
Content-Length: 0
Content-Type: application/json
```
#### Response
```
HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate
Content-Length: 37
Content-Type: application/json
{
"balance": "324.45",
"currency": "EUR"
}
```

View file

@ -23,36 +23,34 @@ Content-Type: application/json
``` ```
HTTP/1.1 200 HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate Cache-Control: max-age=0, private, must-revalidate
Content-Length: 562 Content-Length: 533
Content-Type: application/json Content-Type: application/json
{ {
"contacts": [ "contacts": [
{ {
"id": 1, "id": 1,
"code": "sh995165920", "code": "sh135909910",
"reg_no": null,
"phone": "+372.12345678", "phone": "+372.12345678",
"email": "ronaldo@sauer.biz", "email": "natasha.bechtelar@breitenberg.name",
"fax": null, "fax": null,
"created_at": "2015-04-01T13:59:45.332Z", "created_at": "2015-04-16T08:44:33.041Z",
"updated_at": "2015-04-01T13:59:45.332Z", "updated_at": "2015-04-16T08:44:33.041Z",
"ident": "37605030299", "ident": "37605030299",
"ident_type": "priv", "ident_type": "priv",
"created_by_id": null,
"updated_by_id": null,
"auth_info": "password", "auth_info": "password",
"name": "Meagan Roob Jr.0", "name": "Miss Sherwood Jacobi0",
"org_name": null, "org_name": null,
"registrar_id": 1, "registrar_id": 1,
"creator_str": "autotest", "creator_str": null,
"updator_str": "autotest", "updator_str": null,
"ident_country_code": "EE", "ident_country_code": "EE",
"city": "Tallinn", "city": "Tallinn",
"street": "Short street 11", "street": "Short street 11",
"zip": "11111", "zip": "11111",
"country_code": "EE", "country_code": "EE",
"state": null "state": null,
"legacy_id": null
} }
], ],
"total_number_of_records": 2 "total_number_of_records": 2
@ -81,7 +79,7 @@ Content-Type: application/json
{ {
"contacts": [ "contacts": [
"sh818918181" "sh056866451"
], ],
"total_number_of_records": 2 "total_number_of_records": 2
} }

View file

@ -23,7 +23,7 @@ Content-Type: application/json
``` ```
HTTP/1.1 200 HTTP/1.1 200
Cache-Control: max-age=0, private, must-revalidate Cache-Control: max-age=0, private, must-revalidate
Content-Length: 506 Content-Length: 578
Content-Type: application/json Content-Type: application/json
{ {
@ -32,21 +32,24 @@ Content-Type: application/json
"id": 1, "id": 1,
"name": "domain0.ee", "name": "domain0.ee",
"registrar_id": 1, "registrar_id": 1,
"registered_at": "2015-04-01T13:59:45.874Z", "registered_at": "2015-04-16T08:44:33.499Z",
"status": null, "status": null,
"valid_from": "2015-04-01T00:00:00.000Z", "valid_from": "2015-04-16T00:00:00.000Z",
"valid_to": "2016-04-01T00:00:00.000Z", "valid_to": "2016-04-16T00:00:00.000Z",
"owner_contact_id": 1, "owner_contact_id": 1,
"auth_info": "78d0edcd105c8e1936457c1eef659611", "auth_info": "d081ba64515bc8ae9a512a98e6b1baa1",
"created_at": "2015-04-01T13:59:45.871Z", "created_at": "2015-04-16T08:44:33.496Z",
"updated_at": "2015-04-01T13:59:45.871Z", "updated_at": "2015-04-16T08:44:33.496Z",
"name_dirty": "domain0.ee", "name_dirty": "domain0.ee",
"name_puny": "domain0.ee", "name_puny": "domain0.ee",
"period": 1, "period": 1,
"period_unit": "y", "period_unit": "y",
"creator_str": null, "creator_str": null,
"updator_str": null, "updator_str": null,
"whois_body": null "whois_body": null,
"legacy_id": null,
"legacy_registrar_id": null,
"legacy_registrant_id": null
} }
], ],
"total_number_of_records": 2 "total_number_of_records": 2

View file

@ -101,7 +101,7 @@ namespace :import do
Registrar.all.each do |x| Registrar.all.each do |x|
next if x.cash_account next if x.cash_account
x.accounts.create(account_type: Account::CASH) x.accounts.create(account_type: Account::CASH, currency: 'EUR')
x.save(validate: false) x.save(validate: false)
end end

View file

@ -1,4 +1,5 @@
Fabricator(:account) do Fabricator(:account) do
account_type { Account::CASH } account_type { Account::CASH }
balance 0.0 balance 0.0
currency 'EUR'
end end

View file

@ -89,7 +89,7 @@ RSpec.configure do |config|
c.syntax = [:should, :expect] c.syntax = [:should, :expect]
end end
Autodoc.configuration.path = 'doc/repp/v1' Autodoc.configuration.path = 'doc/repp'
Autodoc.configuration.suppressed_request_header = ['Host'] Autodoc.configuration.suppressed_request_header = ['Host']
Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime'] Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime']
Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb') Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb')

View file

@ -0,0 +1,30 @@
require 'rails_helper'
describe Repp::AccountV1 do
before :all do
@registrar1 = Fabricate(:registrar1, accounts:
[Fabricate(:account, { balance: '324.45' })]
)
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
end
describe 'GET /repp/v1/accounts/balance' do
it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
response.status.should == 200
body = JSON.parse(response.body)
body['balance'].should == '324.45'
body['currency'].should == 'EUR'
log = ApiLog::ReppLog.last
log[:request_path].should == '/repp/v1/accounts/balance'
log[:request_method].should == 'GET'
log[:request_params].should == '{}'
log[:response_code].should == '200'
log[:api_user_name].should == 'gitlab'
log[:api_user_registrar].should == 'registrar1'
log[:ip].should == '127.0.0.1'
end
end
end

View file

@ -37,6 +37,7 @@ module Autodoc
return unless example.metadata[:route_info_doc] return unless example.metadata[:route_info_doc]
route = request.env["rack.routing_args"][:route_info] route = request.env["rack.routing_args"][:route_info]
return unless route.route_params.is_a?(Hash) return unless route.route_params.is_a?(Hash)
return if route.route_params.empty?
rows = [ rows = [
"| Field name | Required | Type | Allowed values | Description |", "| Field name | Required | Type | Allowed values | Description |",