openbill-ruby 0.1.5 → 0.1.6
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 +4 -4
- data/README.md +90 -10
- data/lib/openbill/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e8d41cf49c4b4c79c67648a13bb8d620021fdff
|
4
|
+
data.tar.gz: cefc16e4aa3aaa1a0f64c1da0048e9ea30a7ff8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b78ea598a78806137e6844fb7fcd35526dcaac3791ac53c2cadc34dc06972a580c0908a2421a5466a79887d94c6e9e01f93e687a56c29f1c1d912e02caaa86
|
7
|
+
data.tar.gz: 6053481084ad0b63af80a33c881e380281b054f1616f00a2c26e0bc2105b27b8a4fc813234378d3be5347a0d78c066ef0c9e8511ba9b40279d85149c018388fd
|
data/README.md
CHANGED
@@ -1,34 +1,114 @@
|
|
1
1
|
# Openbill
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Это модуль для биллиноговой системы [openbill-core](https://github.com/dapi/openbill-core).
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem 'openbill'
|
10
|
+
gem 'openbill-ruby'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
15
|
$ bundle
|
18
16
|
|
19
|
-
|
17
|
+
Migrate database:
|
18
|
+
|
19
|
+
$ rake db:migrate
|
20
|
+
|
21
|
+
Add database configurartion to `./config/initializers/openbill.rb`
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Openbill.config.database = ActiveRecord::Base.connection.instance_variable_get('@config');
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Создание системных счетов
|
20
30
|
|
21
|
-
$ gem install openbill
|
22
31
|
|
32
|
+
Рекомендую создать такой сервис для работы с системными счетами:
|
23
33
|
|
34
|
+
```ruby
|
35
|
+
module Billing
|
36
|
+
NS = :system
|
24
37
|
|
25
|
-
|
26
|
-
|
38
|
+
class << self
|
39
|
+
def payments
|
40
|
+
account :payments, 'Счет с которого поступает оплата'
|
27
41
|
end
|
28
42
|
|
29
|
-
|
43
|
+
def subscriptions
|
44
|
+
account :subscriptions, 'Абонентская плата'
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Находит, или создает аккаунт с указанным именем
|
50
|
+
#
|
51
|
+
def account(path, details)
|
52
|
+
# Создаем uri аккаунта из его названия
|
53
|
+
uri = Openbill.generate_uri NS, path
|
54
|
+
|
55
|
+
Openbill.get_account_by_uri(uri) ||
|
56
|
+
Openbill.create_account(uri, details: details)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
Таким образом в системе появляется два счета `Billing.payments` и `Billing.subscriptions`
|
30
63
|
|
31
|
-
|
64
|
+
### Поддержка биллинга со стороны клиента (автоматическое создание клиентского счета):
|
65
|
+
|
66
|
+
```
|
67
|
+
module AccountBilling
|
68
|
+
extend ActiveSupport::Concern
|
69
|
+
|
70
|
+
included do
|
71
|
+
after_commit :attach_billing, on: :create
|
72
|
+
end
|
73
|
+
|
74
|
+
delegate :amount, to: :billing_account
|
75
|
+
|
76
|
+
def billing_account
|
77
|
+
find_billing || attach_billing
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def account_uri
|
83
|
+
Openbill.generate_uri :accounts, id
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_billing
|
87
|
+
Openbill.current.get_account_by_uri account_uri
|
88
|
+
end
|
89
|
+
|
90
|
+
def attach_billing
|
91
|
+
Openbill.current.create_account account_uri
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
Добавляем concern в модель ответсвенную за счет (например в User)
|
97
|
+
|
98
|
+
|
99
|
+
### Прием оплаты.
|
100
|
+
|
101
|
+
Оплата проводится транзакцией между системным счетом `payments` и счетом клиента.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Openbill.current.make_transaction(
|
105
|
+
from_account_id: Billing.payment.id,
|
106
|
+
to_account_id: user.billing_account.id,
|
107
|
+
amount: Money(123),
|
108
|
+
details: 'Оплата такая-то',
|
109
|
+
meta: { key: 'value' } // не обязательно
|
110
|
+
)
|
111
|
+
```
|
32
112
|
|
33
113
|
## Development
|
34
114
|
|
data/lib/openbill/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openbill-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danil Pismenny
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|