killbill-aviate 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +35 -0
- data/app/assets/config/aviate_manifest.js +3 -0
- data/app/assets/javascripts/application.js +14 -0
- data/app/assets/javascripts/aviate/aviate.js +7 -0
- data/app/assets/stylesheets/application.css +16 -0
- data/app/assets/stylesheets/aviate/aviate.css +16 -0
- data/app/controllers/aviate/configuration_controller.rb +19 -0
- data/app/controllers/aviate/engine_controller.rb +67 -0
- data/app/controllers/aviate/wallets_controller.rb +82 -0
- data/app/helpers/aviate/application_helper.rb +6 -0
- data/app/services/aviate/wallet.rb +57 -0
- data/app/services/aviate/wallet_api.rb +19 -0
- data/app/views/aviate/configuration/index.html.erb +30 -0
- data/app/views/aviate/layouts/aviate_application.html.erb +34 -0
- data/app/views/aviate/wallets/_form.html.erb +83 -0
- data/app/views/aviate/wallets/index.html.erb +45 -0
- data/app/views/aviate/wallets/new.html.erb +8 -0
- data/app/views/aviate/wallets/show.html.erb +8 -0
- data/config/locales/en.yml +8 -0
- data/config/routes.rb +20 -0
- data/lib/aviate/client.rb +104 -0
- data/lib/aviate/engine.rb +21 -0
- data/lib/aviate/version.rb +5 -0
- data/lib/aviate.rb +38 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1bca13b8981f496f2ed501a14dd981d240458cca6c6fb98d172b9a0599a442cc
|
4
|
+
data.tar.gz: 0d0735546412f82c502868d31b2c75760cbb66562e54ac7e9020d5fc75291b84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1cabf6b1f8998a4721bbf4e59a173a81a62c4c71dc2d8c50b90e904703ba441ecf8e47c94b2472da151a1a9e92df3b5f2b11fd7eccf84557e28e0747284dfe4c
|
7
|
+
data.tar.gz: 8c251920df3a0a0e94a03e4e5b0afcd3beaadef7432e7cc564ec8c306348d985d86ffa1f8f5b9ad0ca2d61fd19df718881ebbd31986f94da95a38ce76e30e328
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2021 Equinix, Inc
|
2
|
+
Copyright 2021 The Billing Project, LLC
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Overview
|
2
|
+
========
|
3
|
+
|
4
|
+
This Rails mountable engine allows you to manage your Aviate integration in Kill Bill.
|
5
|
+
|
6
|
+
* See [killbill-aviate-ui](https://github.com/killbill/killbill-aviate-ui) to get started with the Aviate plugin.
|
7
|
+
* See [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone) to get started with the Kill Bill Admin UI.
|
8
|
+
|
9
|
+
Kill Bill compatibility
|
10
|
+
-----------------------
|
11
|
+
|
12
|
+
| Aviate UI version | Kill Bill version |
|
13
|
+
|-------------------:|------------------:|
|
14
|
+
| 0.0.y | 0.24.z (Rails 7) |
|
15
|
+
|
16
|
+
Functionality
|
17
|
+
-------------
|
18
|
+
|
19
|
+
This app lets you:
|
20
|
+
|
21
|
+
* Record and categorize external payments as Cash, Check, Bank Transfer, etc.
|
22
|
+
* Apply payments to one or multiple invoices.
|
23
|
+
* Identify invoice line items that are unpaid (e.g. if the customer is disputing a subset of the invoice).
|
24
|
+
|
25
|
+
Getting Started
|
26
|
+
---------------
|
27
|
+
|
28
|
+
To run tests:
|
29
|
+
|
30
|
+
```
|
31
|
+
rails t
|
32
|
+
```
|
33
|
+
|
34
|
+
This plugin is using [killbill-assets-ui](https://github.com/killbill/killbill-assets-ui) to load the common assets.
|
35
|
+
If you want to override the assets you can add it to ```app/assets/stylesheet/aviate``` or ```app/assets/javascripts/aviate```
|
36
|
+
|
37
|
+
For integrate run with [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone), please update the Gemfile to use Aviate locally
|
38
|
+
|
39
|
+
```
|
40
|
+
# gem 'killbill-aviate'
|
41
|
+
gem 'killbill-aviate', :path => '../killbill-aviate-ui'
|
42
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Aviate'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.rdoc')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
20
|
+
load 'rails/tasks/engine.rake'
|
21
|
+
|
22
|
+
load 'rails/tasks/statistics.rake'
|
23
|
+
|
24
|
+
Bundler::GemHelper.install_tasks
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << 'lib'
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
task default: :test
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require aviate/aviate
|
14
|
+
//= require assets/common
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require_tree .
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_self
|
14
|
+
*= require aviate/aviate
|
15
|
+
*= require assets/common
|
16
|
+
*/
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_tree .
|
6
|
+
*/
|
7
|
+
|
8
|
+
.payment_amount_invoice {
|
9
|
+
width: 100%;
|
10
|
+
}
|
11
|
+
|
12
|
+
#deposit_amount_mismatch {
|
13
|
+
text-align: right;
|
14
|
+
padding-top: 15px;
|
15
|
+
visibility: hidden;
|
16
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aviate/client'
|
4
|
+
module Aviate
|
5
|
+
class ConfigurationController < Aviate::EngineController
|
6
|
+
def index
|
7
|
+
@available = Killbill::Aviate::AviateClient.aviate_plugin_available?(options_for_klient).first
|
8
|
+
end
|
9
|
+
|
10
|
+
def session_create
|
11
|
+
cached_options_for_klient = options_for_klient
|
12
|
+
email = params[:aviate_email]
|
13
|
+
password = params[:aviate_password]
|
14
|
+
response = Killbill::Aviate::AviateClient.authenticate(email, password, cached_options_for_klient)
|
15
|
+
session[:jwt_token] = response['token'] if response['token']
|
16
|
+
redirect_to aviate_root_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aviate
|
4
|
+
class EngineController < Kaui::EngineController
|
5
|
+
layout :layout
|
6
|
+
|
7
|
+
def as_string(error)
|
8
|
+
if error.is_a?(KillBillClient::API::ResponseError)
|
9
|
+
"Error #{error.response.code}: #{as_string_from_response(error.response.body)}"
|
10
|
+
else
|
11
|
+
log_rescue_error(error)
|
12
|
+
error.message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_rescue_error(error)
|
17
|
+
Rails.logger.warn "#{error.class} #{error.message}. #{error.backtrace.join("\n")}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def layout
|
21
|
+
Aviate.config[:layout]
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_tenant_user
|
25
|
+
user = current_user if respond_to?(:current_user)
|
26
|
+
Aviate.current_tenant_user.call(session, user)
|
27
|
+
end
|
28
|
+
|
29
|
+
def external_paginate(account_id, searcher, formatter)
|
30
|
+
search_key = (params[:search] || {})[:value].presence
|
31
|
+
data = []
|
32
|
+
begin
|
33
|
+
pages = searcher.call(search_key)
|
34
|
+
if pages.count.any?
|
35
|
+
pages.each do |page|
|
36
|
+
page['wallet_path'] = aviate_engine.account_wallet_path(account_id, page['walletId'])
|
37
|
+
data << formatter.call(page)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
rescue StandardError => e
|
41
|
+
error = e.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
json = {
|
45
|
+
draw: (params[:draw] || 0).to_i,
|
46
|
+
recordsTotal: pages.nil? ? 0 : SIMPLE_PAGINATION_THRESHOLD,
|
47
|
+
recordsFiltered: pages.nil? ? 0 : SIMPLE_PAGINATION_THRESHOLD,
|
48
|
+
data: data,
|
49
|
+
columns: []
|
50
|
+
}
|
51
|
+
|
52
|
+
json[:error] = error unless error.nil?
|
53
|
+
|
54
|
+
respond_to do |format|
|
55
|
+
format.json { render json: json }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def aviate_authentication
|
60
|
+
available = Killbill::Aviate::AviateClient.aviate_plugin_available?(options_for_klient)
|
61
|
+
return if available.first
|
62
|
+
|
63
|
+
flash[:error] = t('flashes.errors.wallet_authentication_failed')
|
64
|
+
redirect_to aviate_engine.aviate_root_path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aviate
|
4
|
+
class WalletsController < Aviate::EngineController
|
5
|
+
before_action :aviate_authentication
|
6
|
+
|
7
|
+
def index
|
8
|
+
@search_query = params[:account_id]
|
9
|
+
@account_id = params[:account_id]
|
10
|
+
@ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
|
11
|
+
@offset = params[:offset] || 0
|
12
|
+
@limit = params[:limit] || 5
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
@currency = @account.currency
|
17
|
+
end
|
18
|
+
|
19
|
+
def top_off_config
|
20
|
+
update_params = {
|
21
|
+
wallet_id: params.require(:wallet_id),
|
22
|
+
top_off_type: params.require(:top_off_type),
|
23
|
+
low_watermark: params.require(:low_watermark),
|
24
|
+
top_off_amount: params.require(:top_off_amount),
|
25
|
+
exp_duration_unit: params.require(:exp_duration_unit),
|
26
|
+
exp_duration_length: params.require(:exp_duration_length)
|
27
|
+
}
|
28
|
+
response_code = Aviate::WalletApi.modify_wallet(update_params, options_for_klient)
|
29
|
+
if response_code == '200'
|
30
|
+
flash[:notice] = t('flashes.notices.wallet_updated_successfully')
|
31
|
+
else
|
32
|
+
flash[:error] = t('flashes.errors.wallet_update_failed')
|
33
|
+
end
|
34
|
+
redirect_to kaui_engine.account_wallets_path(@account.account_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def show
|
38
|
+
wallets = Aviate::WalletApi.retrieve_wallets(params['account_id'], options_for_klient)
|
39
|
+
@wallet = wallets.find { |wallet| wallet['walletId'] == params['id'] }
|
40
|
+
@wallet = Aviate::Wallet.from_api_response(@wallet)
|
41
|
+
@wallet
|
42
|
+
end
|
43
|
+
|
44
|
+
def create
|
45
|
+
cached_options_for_klient = options_for_klient
|
46
|
+
wallet = {
|
47
|
+
currency: @account.currency,
|
48
|
+
credit_type: params.require(:credit_type),
|
49
|
+
amount: params.require(:amount),
|
50
|
+
exp_date: params.require(:exp_date).to_time.utc.iso8601,
|
51
|
+
top_off_type: params.require(:top_off_type),
|
52
|
+
low_watermark: params.require(:low_watermark),
|
53
|
+
top_off_amount: params.require(:top_off_amount),
|
54
|
+
exp_duration_unit: params.require(:exp_duration_unit),
|
55
|
+
exp_duration_length: params.require(:exp_duration_length)
|
56
|
+
}
|
57
|
+
response = Aviate::WalletApi.create_wallet(params[:account_id], wallet, cached_options_for_klient)
|
58
|
+
if response['status'] == 'WALLET_FAILED'
|
59
|
+
flash[:error] = response['errorMessage']
|
60
|
+
render :new
|
61
|
+
elsif response['wallet'].present?
|
62
|
+
flash[:error] = response['errorMessage'] if response['errorMessage'].present?
|
63
|
+
flash[:notice] = t('flashes.notices.wallet_created_successfully')
|
64
|
+
redirect_to account_wallets_path(@account.account_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def pagination
|
69
|
+
cached_options_for_klient = options_for_klient
|
70
|
+
account_id = params[:account_id]
|
71
|
+
searcher = lambda do |search_key|
|
72
|
+
WalletApi.retrieve_wallets(search_key, cached_options_for_klient)
|
73
|
+
end
|
74
|
+
|
75
|
+
formatter = lambda do |wallet|
|
76
|
+
Aviate.account_wallets_columns.call(wallet, account_id, view_context)[1]
|
77
|
+
end
|
78
|
+
|
79
|
+
external_paginate account_id, searcher, formatter
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aviate
|
4
|
+
class Wallet
|
5
|
+
attr_accessor :wallet_id, :kb_account_id, :currency, :balance, :live_balance,
|
6
|
+
:credit_type, :amount, :exp_date, :top_off_type, :low_watermark,
|
7
|
+
:top_off_amount, :exp_duration_unit, :exp_duration_length
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@wallet_id = attributes[:wallet_id]
|
11
|
+
@kb_account_id = attributes[:kb_account_id]
|
12
|
+
@currency = attributes[:currency]
|
13
|
+
@balance = attributes[:balance]
|
14
|
+
@live_balance = attributes[:live_balance]
|
15
|
+
@credit_type = attributes[:credit_type]
|
16
|
+
@amount = attributes[:amount]
|
17
|
+
@exp_date = attributes[:exp_date]
|
18
|
+
@top_off_type = attributes[:top_off_type]
|
19
|
+
@low_watermark = attributes[:low_watermark]
|
20
|
+
@top_off_amount = attributes[:top_off_amount]
|
21
|
+
@exp_duration_unit = attributes[:exp_duration_unit]
|
22
|
+
@exp_duration_length = attributes[:exp_duration_length]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.from_api_response(response)
|
26
|
+
{
|
27
|
+
wallet_id: response['walletId'],
|
28
|
+
kb_account_id: response['kbAccountId'],
|
29
|
+
currency: response['currency'],
|
30
|
+
balance: response['balance'],
|
31
|
+
live_balance: response['liveBalance'],
|
32
|
+
credit_type: response['creditType'],
|
33
|
+
amount: response['amount'],
|
34
|
+
exp_date: response['expDate'],
|
35
|
+
top_off_type: response['topOff']['topOffType'],
|
36
|
+
low_watermark: response['topOff']['lowWatermark'],
|
37
|
+
top_off_amount: response['topOff']['amount'],
|
38
|
+
exp_duration_unit: response['topOff']['expDurationUnit'],
|
39
|
+
exp_duration_length: response['topOff']['expDurationLength']
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_api_params
|
44
|
+
{
|
45
|
+
currency: @currency,
|
46
|
+
credit_type: @credit_type,
|
47
|
+
amount: @amount,
|
48
|
+
exp_date: @exp_date,
|
49
|
+
top_off_type: @top_off_type,
|
50
|
+
low_watermark: @low_watermark,
|
51
|
+
top_off_amount: @top_off_amount,
|
52
|
+
exp_duration_unit: @exp_duration_unit,
|
53
|
+
exp_duration_length: @exp_duration_length
|
54
|
+
}.compact
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aviate
|
4
|
+
module WalletApi
|
5
|
+
class << self
|
6
|
+
def retrieve_wallets(account_id, options_for_klient)
|
7
|
+
Killbill::Aviate::AviateClient.retrieve_wallets(account_id, options_for_klient)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_wallet(account_id, wallet, options_for_klient)
|
11
|
+
Killbill::Aviate::AviateClient.create_wallet(account_id, wallet, options_for_klient)
|
12
|
+
end
|
13
|
+
|
14
|
+
def modify_wallet(wallet_params, options_for_klient)
|
15
|
+
Killbill::Aviate::AviateClient.modify_wallet(wallet_params, options_for_klient)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<div class="search">
|
2
|
+
<div class="column-block">
|
3
|
+
<h1>Aviate</h1>
|
4
|
+
<% if @available %>
|
5
|
+
<div class="alert alert-success" role="alert">
|
6
|
+
Successfully authenticated. Welcome to Aviate!
|
7
|
+
</div>
|
8
|
+
<% else %>
|
9
|
+
<div class="column-block d-flex justify-content-center" style="width: 50%;margin-left: 30%;">
|
10
|
+
<div class="configuration-form-container">
|
11
|
+
<%= form_tag aviate_session_create_path, method: :post, class: 'configuration-form' do %>
|
12
|
+
<div class="form-group mb-3">
|
13
|
+
<%= label_tag :aviate_email, 'Email', class: 'form-label' %>
|
14
|
+
<%= email_field_tag :aviate_email, nil, class: 'form-control', required: true %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="form-group mb-3">
|
18
|
+
<%= label_tag :aviate_password, 'Password', class: 'form-label' %>
|
19
|
+
<%= password_field_tag :aviate_password, nil, class: 'form-control', required: true %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="text-center">
|
23
|
+
<%= submit_tag 'Submit', class: 'btn btn-primary' %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
</div>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Aviate</title>
|
5
|
+
<%= yield :scripts %>
|
6
|
+
<%= stylesheet_link_tag 'application', :media => 'all' %>
|
7
|
+
<%= javascript_include_tag 'application' %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div class="container">
|
12
|
+
<div class="container-fluid">
|
13
|
+
<%- # :alert used by devise -%>
|
14
|
+
<% [:error, :alert].each do |key| %>
|
15
|
+
<% if flash[key] %>
|
16
|
+
<div class="row">
|
17
|
+
<div class="col-md-10 col-md-offset-2">
|
18
|
+
<div class="alert alert-error"><%= flash[key] %></div>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<% if flash[:notice] %>
|
24
|
+
<div class="row">
|
25
|
+
<div class="col-md-10 col-md-offset-2">
|
26
|
+
<div class="alert alert-info"><%= flash[:notice] %></div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
30
|
+
<%= yield %>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</body>
|
34
|
+
</html>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
<%= form_tag @wallet ? aviate_engine.top_off_config_account_wallet_path(@account.account_id, @wallet[:wallet_id]) : aviate_engine.account_wallets_path(@account.account_id), :class => 'form-horizontal', :method => :post, :multipart => true do %>
|
2
|
+
<%= hidden_field_tag :account_id, @account.account_id %>
|
3
|
+
<%= hidden_field_tag :wallet_id, @wallet[:wallet_id] if @wallet %>
|
4
|
+
<div class="form-group">
|
5
|
+
<%= label_tag :currency, 'Currency', :class => 'col-sm-2 control-label' %>
|
6
|
+
<div class="col-sm-10">
|
7
|
+
<%= hidden_field_tag :currency, @wallet ? @wallet[:currency] : @currency, required: true %>
|
8
|
+
<p class="form-control-static"><%= @wallet ? @wallet[:currency] : @currency %></p>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<% unless @wallet %>
|
13
|
+
<h3>Initial Credit</h3>
|
14
|
+
<div class="form-group">
|
15
|
+
<%= label_tag :credit_type, 'Credit Type', :class => 'col-sm-2 control-label' %>
|
16
|
+
<div class="col-sm-10">
|
17
|
+
<%= select_tag :credit_type,
|
18
|
+
options_for_select(['CREDIT_PAID', 'CREDIT_FREE'], @wallet.try(:[], :credit_type)),
|
19
|
+
:class => 'form-control',
|
20
|
+
:disabled => local_assigns[:readonly],
|
21
|
+
required: true %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<div class="form-group">
|
25
|
+
<%= label_tag :amount, 'Amount', :class => 'col-sm-2 control-label' %>
|
26
|
+
<div class="col-sm-10">
|
27
|
+
<%= number_field_tag :amount, @wallet.try(:[], :amount), :class => 'form-control', :step => '0.01', :min => '0', required: true %>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
<div class="form-group">
|
31
|
+
<%= label_tag :exp_date, 'Expiration Date', :class => 'col-sm-2 control-label' %>
|
32
|
+
<div class="col-sm-10">
|
33
|
+
<%= date_field_tag :exp_date, @wallet.try(:[], :exp_date), :class => 'form-control', required: true %>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
<% end %>
|
37
|
+
|
38
|
+
<h3>Top Off</h3>
|
39
|
+
<div class="form-group">
|
40
|
+
<%= label_tag :top_off_type, 'Top Off Type', :class => 'col-sm-2 control-label' %>
|
41
|
+
<div class="col-sm-10">
|
42
|
+
<%= select_tag :top_off_type,
|
43
|
+
options_for_select(['TOP_OFF_FIXED', 'TOP_OFF_TARGET'], @wallet.try(:[], :top_off_type)),
|
44
|
+
:class => 'form-control',
|
45
|
+
:disabled => local_assigns[:readonly],
|
46
|
+
required: true %>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
<div class="form-group">
|
50
|
+
<%= label_tag :low_watermark, 'Low Water Mark', :class => 'col-sm-2 control-label' %>
|
51
|
+
<div class="col-sm-10">
|
52
|
+
<%= text_field_tag :low_watermark, @wallet.try(:[], :low_watermark), :class => 'form-control', required: true %>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
<div class="form-group">
|
56
|
+
<%= label_tag :top_off_amount, 'Amount', :class => 'col-sm-2 control-label' %>
|
57
|
+
<div class="col-sm-10">
|
58
|
+
<%= number_field_tag :top_off_amount, @wallet.try(:[], :top_off_amount), :class => 'form-control', :step => '0.01', :min => '0', required: true %>
|
59
|
+
</div>
|
60
|
+
</div>
|
61
|
+
<div class="form-group">
|
62
|
+
<%= label_tag :exp_duration_unit, 'Expiration Duration Unit', :class => 'col-sm-2 control-label' %>
|
63
|
+
<div class="col-sm-10">
|
64
|
+
<%= select_tag :exp_duration_unit,
|
65
|
+
options_for_select(['DAYS', 'WEEKS', 'MONTHS', 'YEARS'], @wallet.try(:[], :exp_duration_unit)),
|
66
|
+
:class => 'form-control',
|
67
|
+
:disabled => local_assigns[:readonly],
|
68
|
+
required: true %>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
<div class="form-group">
|
72
|
+
<%= label_tag :exp_duration_length, 'Expiration Duration Length', :class => 'col-sm-2 control-label' %>
|
73
|
+
<div class="col-sm-10">
|
74
|
+
<%= number_field_tag :exp_duration_length, @wallet.try(:[], :exp_duration_length), :class => 'form-control', required: true %>
|
75
|
+
</div>
|
76
|
+
</div>
|
77
|
+
|
78
|
+
<div class="form-group">
|
79
|
+
<div class="col-sm-offset-2 col-sm-10">
|
80
|
+
<%= submit_tag 'Save', :class => 'btn btn-default' %>
|
81
|
+
</div>
|
82
|
+
</div>
|
83
|
+
<% end %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<div class="search">
|
2
|
+
|
3
|
+
<div class="column-block">
|
4
|
+
|
5
|
+
<h1>
|
6
|
+
Wallets
|
7
|
+
<%= link_to '<i class="fa fa-plus-square"></i>'.html_safe,
|
8
|
+
aviate_engine.new_account_wallet_path(@account_id),
|
9
|
+
:class => 'btn btn-xs' %>
|
10
|
+
</h1>
|
11
|
+
|
12
|
+
|
13
|
+
<table id="wallets-table" class="table table-condensed mobile-data">
|
14
|
+
<thead>
|
15
|
+
<tr>
|
16
|
+
<th>Wallet ID</th>
|
17
|
+
<th>Account ID</th>
|
18
|
+
<th>Wallet Currency</th>
|
19
|
+
<th>Wallet Balance</th>
|
20
|
+
<th>Live Balance</th>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
<tbody>
|
24
|
+
<tr>
|
25
|
+
<td colspan="1" class="dataTables_empty">Loading data from server</td>
|
26
|
+
</tr>
|
27
|
+
</tbody>
|
28
|
+
</table>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<%= javascript_tag do %>
|
33
|
+
|
34
|
+
$(document).ready(function() {
|
35
|
+
var table = $('#wallets-table').DataTable({
|
36
|
+
"processing": true,
|
37
|
+
"serverSide": true,
|
38
|
+
"info": false,
|
39
|
+
"paging": false,
|
40
|
+
"searching": false,
|
41
|
+
"search": {"search": "<%= @search_query %>"},
|
42
|
+
"ajax": "<%= aviate_engine.pagination_account_wallets_path(:account_id => @account_id, :ordering => @ordering, :format => :json) %>"
|
43
|
+
});
|
44
|
+
});
|
45
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
en:
|
2
|
+
flashes:
|
3
|
+
notices:
|
4
|
+
wallet_created_successfully: "Wallet created successfully"
|
5
|
+
wallet_updated_successfully: "Wallet updated successfully"
|
6
|
+
errors:
|
7
|
+
wallet_update_failed: "Wallet update failed"
|
8
|
+
wallet_authentication_failed: "Authentication required to access wallet features"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Aviate::Engine.routes.draw do
|
4
|
+
root to: 'configuration#index', as: 'aviate_root'
|
5
|
+
|
6
|
+
scope '/configuration' do
|
7
|
+
match '/session_create' => 'configuration#session_create', :via => :post, :as => 'aviate_session_create'
|
8
|
+
end
|
9
|
+
|
10
|
+
resources :accounts, param: :account_id do
|
11
|
+
resources :wallets, only: %i[index new create show update] do
|
12
|
+
collection do
|
13
|
+
get :pagination
|
14
|
+
end
|
15
|
+
member do
|
16
|
+
post :top_off_config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Killbill
|
4
|
+
module Aviate
|
5
|
+
class AviateClient < KillBillClient::Model::Resource
|
6
|
+
KILLBILL_AVIATE_PREFIX = '/plugins/aviate-plugin/v1'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def aviate_plugin_available?(options = nil)
|
10
|
+
path = "#{KILLBILL_AVIATE_PREFIX}/health/data"
|
11
|
+
KillBillClient::API.get path, {}, get_token(options)
|
12
|
+
|
13
|
+
[true, nil]
|
14
|
+
rescue KillBillClient::API::ResponseError => e
|
15
|
+
[false, e.message.to_s]
|
16
|
+
end
|
17
|
+
|
18
|
+
def aviate_plugin_installed(options = nil)
|
19
|
+
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(options) || []
|
20
|
+
plugins_info = nodes_info.empty? ? [] : (nodes_info.first.plugins_info || [])
|
21
|
+
|
22
|
+
return [true, nil] if plugins_info.any? { |plugin| plugin.plugin_name == 'aviate-plugin' }
|
23
|
+
|
24
|
+
[false, nil]
|
25
|
+
rescue KillBillClient::API::ResponseError => e
|
26
|
+
[false, e.message.to_s]
|
27
|
+
end
|
28
|
+
|
29
|
+
def retrieve_wallets(account_id, options = nil)
|
30
|
+
path = "#{KILLBILL_AVIATE_PREFIX}/wallet/#{account_id}"
|
31
|
+
response = KillBillClient::API.get path, {}, get_token(options)
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def modify_wallet(wallet_params, options = nil)
|
36
|
+
path = "#{KILLBILL_AVIATE_PREFIX}/wallet/#{wallet_params[:wallet_id]}/topOffConfig"
|
37
|
+
body = {
|
38
|
+
topOffType: wallet_params[:top_off_type],
|
39
|
+
lowWatermark: wallet_params[:low_watermark],
|
40
|
+
amount: wallet_params[:top_off_amount],
|
41
|
+
expDurationUnit: wallet_params[:exp_duration_unit],
|
42
|
+
expDurationLength: wallet_params[:exp_duration_length]
|
43
|
+
}
|
44
|
+
response = KillBillClient::API.put path, body.to_json, {}, get_token(options)
|
45
|
+
response.code
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_wallet(account_id, wallet, options = nil)
|
49
|
+
path = "#{KILLBILL_AVIATE_PREFIX}/wallet"
|
50
|
+
body = {
|
51
|
+
kbAccountId: account_id,
|
52
|
+
currency: wallet[:currency],
|
53
|
+
initCredit: {
|
54
|
+
creditType: wallet[:credit_type],
|
55
|
+
amount: wallet[:amount],
|
56
|
+
expDate: wallet[:exp_date]
|
57
|
+
},
|
58
|
+
topOff: {
|
59
|
+
topOffType: wallet[:top_off_type],
|
60
|
+
lowWatermark: wallet[:low_watermark],
|
61
|
+
amount: wallet[:top_off_amount],
|
62
|
+
expDurationUnit: wallet[:exp_duration_unit],
|
63
|
+
expDurationLength: wallet[:exp_duration_length]
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
response = KillBillClient::API.post path, body.to_json, {}, get_token(options)
|
68
|
+
JSON.parse(response.body)
|
69
|
+
rescue StandardError => e
|
70
|
+
JSON.parse(e.message)
|
71
|
+
end
|
72
|
+
|
73
|
+
def authenticate(email, password, options = nil)
|
74
|
+
path = "#{KILLBILL_AVIATE_PREFIX}/auth"
|
75
|
+
auth = Base64.strict_encode64("#{email}:#{password}")
|
76
|
+
|
77
|
+
base_url = KillBillClient::API.base_uri
|
78
|
+
uri = URI("#{base_url}#{path}")
|
79
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
80
|
+
|
81
|
+
request = Net::HTTP::Post.new(uri.path)
|
82
|
+
request['Content-Type'] = 'application/json'
|
83
|
+
request['X-killbill-apiKey'] = options[:api_key]
|
84
|
+
request['X-killbill-apisecret'] = options[:api_secret]
|
85
|
+
request['Authorization'] = "Basic #{auth}"
|
86
|
+
request.body = {}.to_json
|
87
|
+
response = http.request(request)
|
88
|
+
JSON.parse(response.body)
|
89
|
+
rescue StandardError => e
|
90
|
+
e.message.to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def get_token(options = nil)
|
96
|
+
{
|
97
|
+
api_key: options[:api_key],
|
98
|
+
api_secret: options[:api_secret]
|
99
|
+
}.merge({ bearer: options[:jwt_token].to_s })
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Dependencies
|
4
|
+
#
|
5
|
+
# Sigh. Rails autoloads the gems specified in the Gemfile and nothing else.
|
6
|
+
# We need to explicitly require all of our dependencies listed in aviate.gemspec
|
7
|
+
#
|
8
|
+
# See also https://github.com/carlhuda/bundler/issues/49
|
9
|
+
|
10
|
+
require 'money-rails'
|
11
|
+
require 'killbill_client'
|
12
|
+
require 'killbill_assets_ui'
|
13
|
+
|
14
|
+
module Aviate
|
15
|
+
class Engine < ::Rails::Engine
|
16
|
+
isolate_namespace Aviate
|
17
|
+
|
18
|
+
# Configure i18n
|
19
|
+
config.i18n.load_path += Dir[Engine.root.join('config', 'locales', '**', '*.{rb,yml}')]
|
20
|
+
end
|
21
|
+
end
|
data/lib/aviate.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aviate/engine'
|
4
|
+
require 'aviate/client'
|
5
|
+
|
6
|
+
module Aviate
|
7
|
+
mattr_accessor :current_tenant_user
|
8
|
+
mattr_accessor :layout
|
9
|
+
mattr_accessor :account_wallets_columns
|
10
|
+
|
11
|
+
self.current_tenant_user = lambda { |_session, _user|
|
12
|
+
{ username: KillBillClient.username || 'admin',
|
13
|
+
password: KillBillClient.password || 'password',
|
14
|
+
session_id: nil,
|
15
|
+
api_key: KillBillClient.api_key,
|
16
|
+
api_secret: KillBillClient.api_secret }
|
17
|
+
}
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
{
|
21
|
+
layout: layout || 'aviate/layouts/aviate_application'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
self.account_wallets_columns = lambda do |wallet = nil, _account_id = nil, view_context = nil|
|
26
|
+
headers = %w[walletId kbAccountId currency balance liveBalance]
|
27
|
+
values = []
|
28
|
+
headers.each do |header|
|
29
|
+
if header == 'walletId'
|
30
|
+
values.push view_context.link_to(wallet[header], wallet['wallet_path'])
|
31
|
+
else
|
32
|
+
values.push wallet[header]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
[headers, values]
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: killbill-aviate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kill Bill core team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: killbill-assets-ui
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: killbill-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: money-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '7.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '7.0'
|
69
|
+
description: Rails UI plugin for the Aviate plugin.
|
70
|
+
email: killbilling-users@googlegroups.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- MIT-LICENSE
|
76
|
+
- README.md
|
77
|
+
- Rakefile
|
78
|
+
- app/assets/config/aviate_manifest.js
|
79
|
+
- app/assets/javascripts/application.js
|
80
|
+
- app/assets/javascripts/aviate/aviate.js
|
81
|
+
- app/assets/stylesheets/application.css
|
82
|
+
- app/assets/stylesheets/aviate/aviate.css
|
83
|
+
- app/controllers/aviate/configuration_controller.rb
|
84
|
+
- app/controllers/aviate/engine_controller.rb
|
85
|
+
- app/controllers/aviate/wallets_controller.rb
|
86
|
+
- app/helpers/aviate/application_helper.rb
|
87
|
+
- app/services/aviate/wallet.rb
|
88
|
+
- app/services/aviate/wallet_api.rb
|
89
|
+
- app/views/aviate/configuration/index.html.erb
|
90
|
+
- app/views/aviate/layouts/aviate_application.html.erb
|
91
|
+
- app/views/aviate/wallets/_form.html.erb
|
92
|
+
- app/views/aviate/wallets/index.html.erb
|
93
|
+
- app/views/aviate/wallets/new.html.erb
|
94
|
+
- app/views/aviate/wallets/show.html.erb
|
95
|
+
- config/locales/en.yml
|
96
|
+
- config/routes.rb
|
97
|
+
- lib/aviate.rb
|
98
|
+
- lib/aviate/client.rb
|
99
|
+
- lib/aviate/engine.rb
|
100
|
+
- lib/aviate/version.rb
|
101
|
+
homepage: https://killbill.io
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata:
|
105
|
+
rubygems_mfa_required: 'true'
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.4.10
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Kill Bill Aviate UI mountable engine
|
125
|
+
test_files: []
|