besepa 0.7.0 → 0.8.0
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 +73 -11
- data/lib/besepa.rb +1 -1
- data/lib/besepa/api_calls/list.rb +3 -6
- data/lib/besepa/bank_account.rb +32 -28
- data/lib/besepa/business_account.rb +18 -21
- data/lib/besepa/customer.rb +26 -28
- data/lib/besepa/debit.rb +8 -1
- data/lib/besepa/group.rb +17 -13
- data/lib/besepa/mandate.rb +7 -10
- data/lib/besepa/resource.rb +36 -37
- data/lib/besepa/subscription.rb +7 -0
- data/lib/besepa/utils/version.rb +1 -1
- data/spec/besepa/subscription_spec.rb +22 -3
- 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: 3647a0a8bc901a587aec5c143a5b0d0da848c9ac
|
4
|
+
data.tar.gz: 4ea5a9c0b577a53899c394111e1f698c14ec7fea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3251bf4dd2eb6a7beb7bef020827c1b0988d6da149adb16a25b5e98c56fbe0da7d2f641462bfcd6984aa3c20c88e8bde20ad441294d284212d569f1d4239a039
|
7
|
+
data.tar.gz: 3814f1e3e65b9710d60435d50d45e5551b82432dd56f067ac0080d755e433216a1b0af1e3512a7bde7c970563047be0fc86ddf91755a3f551812a200de67dd4c
|
data/README.md
CHANGED
@@ -22,7 +22,6 @@ http://apidocs.besepa.com
|
|
22
22
|
|
23
23
|
|
24
24
|
## Configuration
|
25
|
-
|
26
25
|
```ruby
|
27
26
|
Besepa.configure do |config|
|
28
27
|
config.api_key = API_KEY
|
@@ -36,31 +35,52 @@ Remeber that API_KEY changes from one environment to the other.
|
|
36
35
|
|
37
36
|
## Usage
|
38
37
|
|
38
|
+
**Add new customer**
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Besepa::Customer.new(id: customer_id)
|
42
|
+
#=> <Besepa::Customer:0x0000 @id=nil, @name=nil, @taxid=nil, @reference=nil, @contact_name=nil, @contact_email=nil, @contact_phone=nil, @contact_language=nil, @address_street=nil, @address_city=nil, @address_postalcode=nil, @address_state=nil, @address_country=nil, @status=nil, @created_at=nil>
|
43
|
+
```
|
44
|
+
Create empty object but do not save it.
|
45
|
+
|
46
|
+
or
|
47
|
+
```ruby
|
48
|
+
Besepa::Customer.create(name: 'name')
|
49
|
+
#=> <Besepa::Customer:...,@name="name",...>
|
50
|
+
```
|
51
|
+
|
39
52
|
**Get all customers**
|
40
53
|
|
41
54
|
```ruby
|
42
55
|
Besepa::Customer.all
|
56
|
+
#=>=> [#<Besepa::Customer:...>, #<Besepa::Customer:...>]
|
43
57
|
```
|
44
58
|
|
45
59
|
**Get one customer's information**
|
46
60
|
|
47
61
|
```ruby
|
48
62
|
Besepa::Customer.find( customer_id )
|
63
|
+
#=> #<Besepa::Customer:...,@id= customer_id>
|
49
64
|
```
|
50
65
|
|
51
66
|
**Update customer**
|
52
67
|
|
53
68
|
```ruby
|
54
69
|
c = Besepa::Customer.find( customer_id )
|
70
|
+
#=>#<Besepa::Customer:...>
|
55
71
|
c.name = 'New name'
|
72
|
+
#=> "New name"
|
56
73
|
c.save
|
74
|
+
#=>=> #<Besepa::Customer:..., @name= "New name",...>
|
57
75
|
```
|
58
76
|
|
59
77
|
**Remove customer**
|
60
78
|
|
61
79
|
```ruby
|
62
80
|
c = Besepa::Customer.find( customer_id )
|
81
|
+
#=>#<Besepa::Customer:...>
|
63
82
|
c.destroy #customer's state is change to 'REMOVED'
|
83
|
+
#=> #<Besepa::Customer:..., @status="REMOVED",...>
|
64
84
|
```
|
65
85
|
|
66
86
|
Note all subscriptions, upcoming debits and mandates for this customer will be cancelled
|
@@ -70,46 +90,88 @@ Note all subscriptions, upcoming debits and mandates for this customer will be c
|
|
70
90
|
|
71
91
|
```ruby
|
72
92
|
Besepa::Customer.find( customer_id ).bank_accounts
|
93
|
+
# => [#<Besepa::BankAccount:..., #<Besepa::BankAccount:...>]
|
73
94
|
```
|
95
|
+
The result is a array of Besepa::BankAccount
|
74
96
|
|
75
97
|
In case you don't have a Customer yet, just create one Customer object with it's id.
|
76
98
|
```ruby
|
77
99
|
Besepa::Customer.new( id: customer_id ).bank_accounts
|
78
100
|
```
|
79
101
|
|
80
|
-
**
|
102
|
+
**Add a bank account to a customer**
|
81
103
|
|
82
104
|
```ruby
|
83
|
-
Besepa::Customer.new( id: customer_id ).
|
105
|
+
Besepa::Customer.new( id: customer_id ).add_bank_account(iban, bic, bank_name)
|
106
|
+
# => #<Besepa::BankAccount:...>
|
107
|
+
|
84
108
|
```
|
109
|
+
bank_name is optional.
|
85
110
|
|
86
|
-
**
|
111
|
+
**Update bank account**
|
87
112
|
|
88
113
|
```ruby
|
89
|
-
Besepa::Customer.
|
114
|
+
b = Besepa::Customer.find(customer_id).bank_accounts.detect{|b| b.id == bank_account_id }
|
115
|
+
# => #<Besepa::BankAccount:...>
|
116
|
+
b.replace(iban, bic, bank_name)
|
117
|
+
#=> #<Besepa::BankAccount:... >
|
90
118
|
```
|
119
|
+
bank_name is optional.
|
120
|
+
Other possible arguments are signature_type, phone_number and redirect_after_signature
|
91
121
|
|
92
|
-
**Add a bank account to a customer**
|
93
122
|
|
94
|
-
|
95
|
-
Besepa::Customer.new( id: customer_id ).add_bank_account(iban, bic, bank_name)
|
123
|
+
**Get customer's debits**
|
96
124
|
|
125
|
+
```ruby
|
126
|
+
Besepa::Customer.new( id: customer_id ).debits
|
127
|
+
#=>=> [#<Besepa::Debit:...>, #<Besepa::Debit:...>]
|
97
128
|
```
|
98
|
-
bank_name is optional.
|
99
129
|
|
100
130
|
**Create a debit for a customer**
|
101
131
|
|
102
132
|
```ruby
|
103
|
-
Besepa::Customer.new(
|
133
|
+
Besepa::Customer.new(id: customer_id ).add_debit(bank_account_id, reference, description, amount, collect_at, creditor_account_id, metadata)
|
134
|
+
#=> #<Besepa::Debit:...>
|
104
135
|
```
|
105
|
-
|
106
136
|
Amount is with two decimals, without separation character (1000 == 10.00)
|
107
137
|
Metadata can be a hash that we will store associated to this debit. creditor_account_id is optional, if none passed, we will use account's default one.
|
138
|
+
The bank_account status should be 'ACTIVE'
|
139
|
+
|
140
|
+
**Get customer's subscriptions**
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
Besepa::Customer.new( id: customer_id ).subscriptions
|
144
|
+
#=> [#<Besepa::Subscription:...>, #<Besepa::Subscription:...>]>
|
145
|
+
```
|
108
146
|
|
147
|
+
**Add customer'subscription**
|
109
148
|
|
149
|
+
```ruby
|
150
|
+
Besepa::Customer.find(customer_id).add_subscription(starts_at, product_code, bank_account_id)
|
151
|
+
#=> #<Besepa::Subscription:...>
|
152
|
+
```
|
153
|
+
Remmember that the bank account status should be 'ACTIVE'
|
154
|
+
|
155
|
+
**Get customer's groups**
|
156
|
+
List of groups this customer belongs to
|
157
|
+
```ruby
|
158
|
+
Besepa::Customer.find(customer_id).groups
|
159
|
+
#=>[#<Besepa::Group:...>, #<Besepa::Group:...>]
|
160
|
+
```
|
110
161
|
|
162
|
+
**Add customer to group**
|
111
163
|
|
164
|
+
```ruby
|
165
|
+
Besepa::Customer.find(customer_id).add_to_group(group_id)
|
166
|
+
# => true
|
167
|
+
```
|
168
|
+
|
169
|
+
**Remove customer from the group**
|
112
170
|
|
171
|
+
```ruby
|
172
|
+
Besepa::Customer.find(customer_id).remove_from_group(group_id)
|
173
|
+
# => true
|
174
|
+
```
|
113
175
|
|
114
176
|
|
115
177
|
|
data/lib/besepa.rb
CHANGED
@@ -3,15 +3,13 @@ module Besepa
|
|
3
3
|
module List
|
4
4
|
module ClassMethods
|
5
5
|
def all(filters={})
|
6
|
-
path =
|
7
|
-
|
8
|
-
response = get(path, params)
|
9
|
-
|
6
|
+
path = api_path(filters)
|
7
|
+
response = get(path, query_params(filters))
|
10
8
|
Besepa::Collection.new(response, self)
|
11
9
|
end
|
12
10
|
|
13
11
|
def find(id, filters={})
|
14
|
-
response = get "
|
12
|
+
response = get "#{api_path(filters)}/#{id}"
|
15
13
|
c = self.new(response['response'])
|
16
14
|
c
|
17
15
|
end
|
@@ -20,7 +18,6 @@ module Besepa
|
|
20
18
|
def self.included(base)
|
21
19
|
base.extend(ClassMethods)
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
22
|
end
|
26
23
|
end
|
data/lib/besepa/bank_account.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
class BankAccount < Besepa::Resource
|
4
|
-
|
3
|
+
|
5
4
|
include Besepa::ApiCalls::List
|
6
5
|
include Besepa::ApiCalls::Create
|
7
6
|
include Besepa::ApiCalls::Update
|
8
7
|
include Besepa::ApiCalls::Destroy
|
9
|
-
|
10
|
-
FIELDS = [:id, :iban, :bic, :bank_name, :status, :customer_id, :created_at]
|
11
|
-
|
8
|
+
|
9
|
+
FIELDS = [:id, :iban, :bic, :bank_name, :status, :customer_id, :created_at]
|
10
|
+
|
12
11
|
FIELDS.each do |f|
|
13
12
|
attr_accessor f
|
14
|
-
end
|
13
|
+
end
|
15
14
|
|
16
15
|
attr_accessor :mandate
|
17
|
-
|
16
|
+
|
18
17
|
def self.klass_name
|
19
18
|
"bank_account"
|
20
19
|
end
|
@@ -24,7 +23,7 @@ module Besepa
|
|
24
23
|
process_attributes(response['response'])
|
25
24
|
self
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def replace(iban, bic, bank_name=nil, signature_type=nil, phone_number=nil, redirect_after_signature=nil)
|
29
28
|
payload = {}
|
30
29
|
payload[self.class.klass_name] = {
|
@@ -43,13 +42,13 @@ module Besepa
|
|
43
42
|
process_attributes(response['response'])
|
44
43
|
self
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
def generate_signature_request
|
48
47
|
response = put "/#{api_path({customer_id: customer_id})}/generate_signature_request"
|
49
48
|
process_attributes(response['response'])
|
50
49
|
self
|
51
50
|
end
|
52
|
-
|
51
|
+
|
53
52
|
def to_hash
|
54
53
|
values = {}
|
55
54
|
self.class::FIELDS.each do |key|
|
@@ -58,25 +57,30 @@ module Besepa
|
|
58
57
|
values[:mandate] = mandate.to_hash if mandate
|
59
58
|
values
|
60
59
|
end
|
61
|
-
|
60
|
+
|
62
61
|
protected
|
63
|
-
|
64
|
-
def self.api_path(filters={})
|
65
|
-
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id])}/bank_accounts"
|
66
|
-
end
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.class::FIELDS.each do |key|
|
74
|
-
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
75
|
-
end
|
76
|
-
self.mandate = Besepa::Mandate.new(attrs['mandate']) if attrs['mandate']
|
77
|
-
process_activities(attrs)
|
78
|
-
self
|
79
|
-
end
|
63
|
+
def self.query_params(filters = {})
|
64
|
+
filters = filters.dup
|
65
|
+
filters.delete(:customer_id)
|
66
|
+
filters
|
67
|
+
end
|
80
68
|
|
69
|
+
def self.api_path(filters={})
|
70
|
+
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id])}/bank_accounts"
|
71
|
+
end
|
72
|
+
|
73
|
+
def api_path(filters={})
|
74
|
+
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id]||customer_id)}/bank_accounts/#{CGI.escape(id)}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_attributes(attrs)
|
78
|
+
self.class::FIELDS.each do |key|
|
79
|
+
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
80
|
+
end
|
81
|
+
self.mandate = Besepa::Mandate.new(attrs['mandate']) if attrs['mandate']
|
82
|
+
process_activities(attrs)
|
83
|
+
self
|
84
|
+
end
|
81
85
|
end
|
82
|
-
end
|
86
|
+
end
|
@@ -1,43 +1,40 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
class BusinessAccount < Besepa::Resource
|
4
|
-
|
3
|
+
|
5
4
|
include Besepa::ApiCalls::List
|
6
5
|
include Besepa::ApiCalls::Create
|
7
6
|
include Besepa::ApiCalls::Update
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
|
8
|
+
FIELDS = [:id, :iban, :bic, :bank_name, :status, :default, :core_enabled, :core_suffix, :b2b_enabled, :b2b_suffix, :created_at, :authorization]
|
9
|
+
|
12
10
|
FIELDS.each do |f|
|
13
11
|
attr_accessor f
|
14
|
-
end
|
15
|
-
|
12
|
+
end
|
13
|
+
|
16
14
|
def self.klass_name
|
17
15
|
"bank_account"
|
18
16
|
end
|
19
17
|
|
20
18
|
def set_as_default
|
21
|
-
response = put "
|
19
|
+
response = put "#{api_path}/set_as_default"
|
22
20
|
process_attributes(response['response'])
|
23
21
|
self
|
24
22
|
end
|
25
|
-
|
23
|
+
|
26
24
|
def activation_request
|
27
|
-
response = put "
|
25
|
+
response = put "#{api_path}/activation_request"
|
28
26
|
process_attributes(response['response'])
|
29
27
|
self
|
30
28
|
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
|
34
|
-
def self.api_path(filters={})
|
35
|
-
"/account/bank_accounts"
|
36
|
-
end
|
37
29
|
|
38
|
-
|
39
|
-
"/account/bank_accounts/#{CGI.escape(id)}"
|
40
|
-
end
|
30
|
+
protected
|
41
31
|
|
32
|
+
def self.api_path(filters={})
|
33
|
+
"/account/bank_accounts"
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_path(filters={})
|
37
|
+
"/account/bank_accounts/#{CGI.escape(id)}"
|
38
|
+
end
|
42
39
|
end
|
43
|
-
end
|
40
|
+
end
|
data/lib/besepa/customer.rb
CHANGED
@@ -1,77 +1,76 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
class Customer < Besepa::Resource
|
4
|
-
|
3
|
+
|
5
4
|
include Besepa::ApiCalls::List
|
6
5
|
include Besepa::ApiCalls::Search
|
7
6
|
include Besepa::ApiCalls::Create
|
8
7
|
include Besepa::ApiCalls::Update
|
9
8
|
include Besepa::ApiCalls::Destroy
|
10
|
-
|
9
|
+
|
11
10
|
FIELDS = [:id, :name, :taxid, :reference,
|
12
11
|
:contact_name, :contact_email, :contact_phone, :contact_language,
|
13
|
-
:address_street, :address_city, :address_postalcode, :address_state,
|
14
|
-
:status, :created_at]
|
15
|
-
|
12
|
+
:address_street, :address_city, :address_postalcode, :address_state,
|
13
|
+
:address_country, :group_ids, :status, :created_at]
|
14
|
+
|
16
15
|
FIELDS.each do |f|
|
17
16
|
attr_accessor f
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
# Customer's bank accounts
|
21
20
|
#
|
22
21
|
# @return collection of Besepa::BankAccount
|
23
22
|
def bank_accounts
|
24
23
|
BankAccount.all( {:customer_id => id} )
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
# Debits sent to this customer
|
28
27
|
#
|
29
28
|
# @return collection of Besepa::Debits
|
30
29
|
def debits
|
31
30
|
Debit.all( {:customer_id => id} )
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
# Subscriptions from this customer
|
35
34
|
#
|
36
35
|
# @return collection of Besepa::Subscription
|
37
36
|
def subscriptions
|
38
37
|
Subscription.all( {:customer_id => id} )
|
39
38
|
end
|
40
|
-
|
39
|
+
|
41
40
|
# List of groups this customers blongs to
|
42
41
|
#
|
43
42
|
# @return collection of Besepa::Group
|
44
43
|
def groups
|
45
44
|
Group.all( {:customer_id => id} )
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
# Adds this customer to the given group
|
49
48
|
#
|
50
49
|
# @param group_id The ID of the group to which this user should be added
|
51
50
|
#
|
52
51
|
# @return true if user is now a member of the group
|
53
52
|
def add_to_group(group_id)
|
54
|
-
response = post "
|
53
|
+
response = post "#{self.class.api_path}/#{id}/memberships/#{group_id}"
|
55
54
|
response['response'].select{|c| c['id'] == group_id}.any?
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
# Removed this customer from the given group
|
59
58
|
#
|
60
59
|
# @param group_id The ID of the group from which this user should be removed
|
61
60
|
#
|
62
61
|
# @return true if user is no longer a member of the group
|
63
62
|
def remove_from_group(group_id)
|
64
|
-
response = delete "
|
63
|
+
response = delete "#{self.class.api_path}/#{id}/memberships/#{group_id}"
|
65
64
|
response['response'].select{|c| c['id'] == group_id}.empty?
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
# Creates a new subscription for this customer
|
69
68
|
#
|
70
69
|
# @param starts_at The date this subscription should start (Format: YYYY-MM-DD)
|
71
70
|
# @param product_code The ID of the product the customer is subscribing to
|
72
71
|
# @param bank_account_code The ID of the bank account where debits should be sent to
|
73
72
|
# @param setup_fee Initial set-up fee. Optional, default: 0
|
74
|
-
# @param metadata Optional Hash with metadata related to this subscription, if any.
|
73
|
+
# @param metadata Optional Hash with metadata related to this subscription, if any.
|
75
74
|
#
|
76
75
|
# @return new created Besepa::Subscription
|
77
76
|
def add_subscription(starts_at, product_code, bank_account_code, setup_fee=0, metadata=nil)
|
@@ -82,8 +81,8 @@ module Besepa
|
|
82
81
|
end
|
83
82
|
|
84
83
|
# Adds a bank account to this customer.
|
85
|
-
# IBAN and BIC are the only mandatory fields. If you already have the mandate signed, you can pass mandate
|
86
|
-
# detail's and account will be activated by default. Otherwise BankAccount will be marked as inactive (not usable
|
84
|
+
# IBAN and BIC are the only mandatory fields. If you already have the mandate signed, you can pass mandate
|
85
|
+
# detail's and account will be activated by default. Otherwise BankAccount will be marked as inactive (not usable
|
87
86
|
# for creating debits or subscriptions) until mandate is signed. BankAccount includes mandate's info, including
|
88
87
|
# signature URL.
|
89
88
|
#
|
@@ -92,7 +91,7 @@ module Besepa
|
|
92
91
|
# @param bank_name
|
93
92
|
# @param mandate_options options to configure mandate
|
94
93
|
# - scheme: CORE|COR1|B2B. Default: CORE
|
95
|
-
# - signature_date: Date in which this mandate was signed if already signed (Format: YYYY-MM-DD)
|
94
|
+
# - signature_date: Date in which this mandate was signed if already signed (Format: YYYY-MM-DD)
|
96
95
|
# - reference: Mandate's reference. If none, Besepa will create one.
|
97
96
|
# - used: Says if this mandate has already been used or not.
|
98
97
|
# - signature_type: Signature to be used: checkbox|sms|biometric
|
@@ -105,32 +104,32 @@ module Besepa
|
|
105
104
|
params = {:iban => iban }
|
106
105
|
params[:bank_name] = bank_name if bank_name
|
107
106
|
params[:bic] = bic if bic
|
108
|
-
|
109
|
-
params[:mandate] = { scheme: (mandate_options[:scheme] || "CORE"),
|
107
|
+
|
108
|
+
params[:mandate] = { scheme: (mandate_options[:scheme] || "CORE"),
|
110
109
|
used: (mandate_options[:used] || false),
|
111
110
|
mandate_type: (mandate_options[:type] || "RECURRENT") }
|
112
|
-
|
111
|
+
|
113
112
|
if mandate_options[:signature_date]
|
114
113
|
params[:mandate][:signed_at] = mandate_options[:signature_date]
|
115
114
|
params[:mandate][:reference] = mandate_options[:reference] if mandate_options[:reference]
|
116
115
|
else
|
117
116
|
params[:mandate][:signature_type] = mandate_options[:signature_type] || 'checkbox'
|
118
|
-
params[:mandate][:phone_number] = mandate_options[:phone_number] if mandate_options[:phone_number]
|
117
|
+
params[:mandate][:phone_number] = mandate_options[:phone_number] if mandate_options[:phone_number]
|
119
118
|
end
|
120
119
|
params[:mandate][:redirect_after_signature] = mandate_options[:redirect_after_signature] if mandate_options[:redirect_after_signature]
|
121
|
-
|
120
|
+
|
122
121
|
BankAccount.create( params, {:customer_id => id} )
|
123
122
|
end
|
124
|
-
|
123
|
+
|
125
124
|
# Generates a direct debit that will be charged to this customer.
|
126
|
-
#
|
125
|
+
#
|
127
126
|
# @param debtor_bank_account_id Customer's BankAccount code this Debit shouyd be charged to.
|
128
127
|
# @param reference Debit's unique reference
|
129
128
|
# @param description Debit's description. Customer will see this in his Bank's statements
|
130
129
|
# @param amount Amount to be charged. Integer, last two digits represent decimals: 10.25 should be 1025
|
131
130
|
# @param collect_at Date in which the charge should be made (Format: YYYY-MM-DD).
|
132
131
|
# @param creditor_account_id Business' BankAccount that should receive the money. If none passed, account marked as default in Besepa's dashboard will be used.
|
133
|
-
# @param metadata Optional Hash with metadata related to this debit, if any.
|
132
|
+
# @param metadata Optional Hash with metadata related to this debit, if any.
|
134
133
|
#
|
135
134
|
# @return new created Besepa::Debit
|
136
135
|
def add_debit(debtor_bank_account_id, reference, description, amount, collect_at, creditor_account_id=nil, metadata=nil)
|
@@ -140,6 +139,5 @@ module Besepa
|
|
140
139
|
params[:metadata] = metadata if metadata
|
141
140
|
Debit.create( params, {:customer_id => id} )
|
142
141
|
end
|
143
|
-
|
144
142
|
end
|
145
143
|
end
|
data/lib/besepa/debit.rb
CHANGED
@@ -47,6 +47,13 @@ module Besepa
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.query_params(filters = {})
|
51
|
+
filters = filters.dup
|
52
|
+
filters.delete(:group_id) if filters[:customer_id]
|
53
|
+
filters.delete(:customer_id)
|
54
|
+
filters
|
55
|
+
end
|
56
|
+
|
50
57
|
def api_path(filters={})
|
51
58
|
if filters[:customer_id]
|
52
59
|
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id])}/debits/#{CGI.escape(id)}"
|
@@ -68,4 +75,4 @@ module Besepa
|
|
68
75
|
self
|
69
76
|
end
|
70
77
|
end
|
71
|
-
end
|
78
|
+
end
|
data/lib/besepa/group.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
class Group < Besepa::Resource
|
4
|
-
|
3
|
+
|
5
4
|
include Besepa::ApiCalls::List
|
6
5
|
include Besepa::ApiCalls::Create
|
7
6
|
include Besepa::ApiCalls::Update
|
8
7
|
include Besepa::ApiCalls::Destroy
|
9
|
-
|
8
|
+
|
10
9
|
FIELDS = [:id, :name, :reference, :created_at]
|
11
|
-
|
10
|
+
|
12
11
|
FIELDS.each do |f|
|
13
12
|
attr_accessor f
|
14
|
-
end
|
13
|
+
end
|
15
14
|
|
16
15
|
def customers
|
17
16
|
Customer.search({ field: :group_id, value: id})
|
18
17
|
end
|
19
18
|
|
20
19
|
protected
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
|
21
|
+
def self.query_params(filters = {})
|
22
|
+
filters = filters.dup
|
23
|
+
filters.delete(:customer_id)
|
24
|
+
filters
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.api_path(filters={})
|
28
|
+
if filters[:customer_id]
|
29
|
+
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id])}/groups"
|
30
|
+
else
|
31
|
+
"/groups"
|
28
32
|
end
|
29
|
-
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
data/lib/besepa/mandate.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
class Mandate < Besepa::Resource
|
4
|
-
|
5
3
|
include Besepa::ApiCalls::List
|
6
|
-
|
7
|
-
FIELDS = [:id, :signed_at, :status, :description, :signature_type,
|
4
|
+
|
5
|
+
FIELDS = [:id, :signed_at, :status, :description, :signature_type,
|
8
6
|
:mandate_type, :reference, :url, :used, :phone_number, :scheme,
|
9
7
|
:signature_url, :download_url, :created_at, :redirect_after_signature]
|
10
|
-
|
8
|
+
|
11
9
|
FIELDS.each do |f|
|
12
10
|
attr_accessor f
|
13
|
-
end
|
14
|
-
|
15
|
-
def api_path
|
16
|
-
"/customers/#{self.customer_id}/#{self.class.api_path}"
|
17
11
|
end
|
18
12
|
|
13
|
+
def api_path
|
14
|
+
"/customers/#{self.customer_id}#{self.class.api_path}"
|
15
|
+
end
|
19
16
|
end
|
20
|
-
end
|
17
|
+
end
|
data/lib/besepa/resource.rb
CHANGED
@@ -3,20 +3,22 @@ require 'besepa/utils/connection'
|
|
3
3
|
require 'besepa/utils/config'
|
4
4
|
|
5
5
|
module Besepa
|
6
|
-
|
7
6
|
class Resource
|
8
|
-
|
9
7
|
class <<self
|
10
|
-
|
8
|
+
|
11
9
|
include Besepa::Utils::Connection
|
12
10
|
include Besepa::Utils::Request
|
13
|
-
|
11
|
+
|
14
12
|
ALLOWED_NILS = []
|
15
|
-
|
13
|
+
|
14
|
+
def query_params(filters = {})
|
15
|
+
filters
|
16
|
+
end
|
17
|
+
|
16
18
|
def api_path(filters={})
|
17
|
-
"
|
19
|
+
"/#{klass_name}s"
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
def klass_name
|
21
23
|
name.split('::')[-1].downcase
|
22
24
|
end
|
@@ -24,7 +26,7 @@ module Besepa
|
|
24
26
|
def handle_errors(http_status, response)
|
25
27
|
error = response['error']
|
26
28
|
desc = response['error_description']
|
27
|
-
msgs = response['messages']
|
29
|
+
msgs = response['messages']
|
28
30
|
if error == 'invalid_resource'
|
29
31
|
raise Besepa::Errors::InvalidResourceError.new(error, desc, http_status, msgs)
|
30
32
|
elsif error == 'not_found'
|
@@ -33,18 +35,18 @@ module Besepa
|
|
33
35
|
raise Besepa::Errors::BesepaError.new(error, desc, http_status, msgs)
|
34
36
|
end
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
end
|
38
40
|
|
39
41
|
include Besepa::Utils::Connection
|
40
42
|
include Besepa::Utils::Request
|
41
43
|
|
42
44
|
attr_accessor :activities
|
43
|
-
|
45
|
+
|
44
46
|
def initialize(attrs={})
|
45
47
|
process_attributes(attrs)
|
46
48
|
end
|
47
|
-
|
49
|
+
|
48
50
|
def to_hash
|
49
51
|
values = {}
|
50
52
|
self.class::FIELDS.each do |key|
|
@@ -52,46 +54,43 @@ module Besepa
|
|
52
54
|
end
|
53
55
|
values
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def serializable_hash
|
57
59
|
to_hash
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
def as_json
|
61
63
|
to_hash.as_json
|
62
64
|
end
|
63
|
-
|
65
|
+
|
64
66
|
def klass_name
|
65
67
|
self.class.name.split('::')[-1].downcase
|
66
68
|
end
|
67
|
-
|
69
|
+
|
68
70
|
def allowed_nils
|
69
71
|
[]
|
70
72
|
end
|
71
|
-
|
72
|
-
protected
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
process_activities(attrs)
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def handle_errors(http_status, response)
|
77
|
+
Module.const_get(self.class.name).handle_errors(http_status, response)
|
78
|
+
end
|
79
|
+
|
80
|
+
def process_attributes(attrs)
|
81
|
+
self.class::FIELDS.each do |key|
|
82
|
+
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
83
83
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
process_activities(attrs)
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_activities(attrs)
|
88
|
+
if attrs['activities']
|
89
|
+
self.activities = Array.new
|
90
|
+
attrs['activities'].each do |a|
|
91
|
+
self.activities << Besepa::Activity.new(a)
|
91
92
|
end
|
92
93
|
end
|
93
|
-
|
94
|
+
end
|
94
95
|
end
|
95
|
-
|
96
|
-
|
97
96
|
end
|
data/lib/besepa/subscription.rb
CHANGED
@@ -2,6 +2,7 @@ module Besepa
|
|
2
2
|
class Subscription < Besepa::Resource
|
3
3
|
|
4
4
|
include Besepa::ApiCalls::List
|
5
|
+
include Besepa::ApiCalls::Search
|
5
6
|
include Besepa::ApiCalls::Create
|
6
7
|
include Besepa::ApiCalls::Destroy
|
7
8
|
|
@@ -33,6 +34,12 @@ module Besepa
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def self.query_params(filters = {})
|
38
|
+
filters = filters.dup
|
39
|
+
filters.delete(:customer_id)
|
40
|
+
filters
|
41
|
+
end
|
42
|
+
|
36
43
|
def api_path(filters={})
|
37
44
|
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
38
45
|
end
|
data/lib/besepa/utils/version.rb
CHANGED
@@ -32,17 +32,36 @@ describe Besepa::Subscription do
|
|
32
32
|
|
33
33
|
describe '#find' do
|
34
34
|
it 'without customer' do
|
35
|
-
stub_get('/
|
35
|
+
stub_get('/subscriptions/1').to_return(body: fixture('resource.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
36
36
|
|
37
37
|
subscription = Besepa::Subscription.find('1')
|
38
38
|
expect(subscription).to be_an Besepa::Subscription
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'with customer' do
|
42
|
-
stub_get('/customers/bar/
|
42
|
+
stub_get('/customers/bar/subscriptions/1').to_return(body: fixture('resource.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
43
43
|
|
44
|
-
subscription = Besepa::Subscription.find('1')
|
44
|
+
subscription = Besepa::Subscription.find('1', customer_id: 'bar')
|
45
45
|
expect(subscription).to be_an Besepa::Subscription
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe '#search' do
|
50
|
+
before do
|
51
|
+
stub_get('/subscriptions/search?field=product_id&value=foo&page=1').to_return(body: fixture('collection.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returs a list of customers' do
|
55
|
+
customers = Besepa::Subscription.search(field: 'product_id', value: 'foo', page: 1)
|
56
|
+
expect(customers).to respond_to(:each)
|
57
|
+
expect(customers.first).to be_an Besepa::Subscription
|
58
|
+
expect(customers.size).to eq(1)
|
59
|
+
expect(customers.per_page).to eq(50)
|
60
|
+
expect(customers.current_page).to eq(1)
|
61
|
+
expect(customers.total).to eq(1)
|
62
|
+
expect(customers.pages).to eq(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
48
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: besepa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- besepa.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|