besepa 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/besepa-ruby.gemspec +2 -4
- data/lib/besepa/api_calls/search.rb +1 -1
- data/lib/besepa/api_calls/update.rb +4 -8
- data/lib/besepa/bank_account.rb +17 -3
- data/lib/besepa/business_account.rb +10 -0
- data/lib/besepa/customer.rb +14 -2
- data/lib/besepa/debit.rb +1 -0
- data/lib/besepa/group.rb +10 -1
- data/lib/besepa/payment.rb +63 -0
- data/lib/besepa/product.rb +6 -5
- data/lib/besepa/remittance.rb +20 -10
- data/lib/besepa/subscription.rb +7 -1
- data/lib/besepa/user.rb +16 -0
- data/lib/besepa/utils/version.rb +1 -1
- data/spec/besepa/subscription_spec.rb +11 -0
- data/spec/fixtures/resource.json +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73ed9ea22a0fffcb79dd2d6ba7d1356b1273805
|
4
|
+
data.tar.gz: 226bd640c1a0a9ebc7ec3e27086a1c64e1f57ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3d220de2915a17686ffc5bb797f5415b1e5ebe220fedaaee3681f10e1ba6c6631ab360eb8ee7c852c865dcc60b4ead60dfd6d7f6c6b41c5f03e8b89dba7e272
|
7
|
+
data.tar.gz: 31c81e438ad72697b7bbcde1bb980905d72044d6eb065be4e887f96ed43860cf5c63efa27dec5c9f4b024f1abeb3fe14fac021ae85009b725bf3edcfd635e9e5
|
data/besepa-ruby.gemspec
CHANGED
@@ -4,7 +4,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'besepa/utils/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
|
8
7
|
spec.name = "besepa"
|
9
8
|
spec.version = Besepa::Utils::VERSION
|
10
9
|
spec.authors = ["besepa.com"]
|
@@ -21,11 +20,10 @@ Gem::Specification.new do |spec|
|
|
21
20
|
|
22
21
|
spec.add_dependency('faraday', '~> 0.9')
|
23
22
|
spec.add_dependency('faraday_middleware', '~> 0.9')
|
24
|
-
|
23
|
+
|
25
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
-
|
25
|
+
|
27
26
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
28
27
|
spec.add_development_dependency 'webmock', '~> 1.20'
|
29
28
|
spec.add_development_dependency "rake"
|
30
|
-
|
31
29
|
end
|
@@ -4,7 +4,7 @@ module Besepa
|
|
4
4
|
module ClassMethods
|
5
5
|
def search(filters = {})
|
6
6
|
path = "/#{api_path}/search"
|
7
|
-
params = filters.select{|x| [:page, :field, :value].include?(x)}
|
7
|
+
params = filters.select{|x| [:page, :query, :field, :value].include?(x)}
|
8
8
|
response = get(path, params)
|
9
9
|
Besepa::Collection.new(response, self)
|
10
10
|
end
|
@@ -1,15 +1,12 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
module ApiCalls
|
4
|
-
|
5
3
|
module Update
|
6
|
-
|
7
4
|
def save(filters={})
|
8
5
|
h = self.to_hash
|
9
|
-
#id and status should not be send back to the server
|
10
|
-
h.delete(:status)
|
6
|
+
# id and status should not be send back to the server
|
7
|
+
h.delete(:status)
|
11
8
|
h.delete(:id)
|
12
|
-
#remove all nil values. Not updated.
|
9
|
+
# remove all nil values. Not updated.
|
13
10
|
h.delete_if {|key, value| value.nil? unless allowed_nils.include?(key)}
|
14
11
|
payload = {}
|
15
12
|
payload[self.class.klass_name] = h
|
@@ -17,7 +14,6 @@ module Besepa
|
|
17
14
|
process_attributes(response['response'])
|
18
15
|
self
|
19
16
|
end
|
20
|
-
|
21
17
|
end
|
22
18
|
end
|
23
|
-
end
|
19
|
+
end
|
data/lib/besepa/bank_account.rb
CHANGED
@@ -2,17 +2,18 @@ module Besepa
|
|
2
2
|
class BankAccount < 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::Update
|
7
8
|
include Besepa::ApiCalls::Destroy
|
8
9
|
|
9
|
-
FIELDS = [:id, :iban, :bic, :bank_name, :status, :
|
10
|
+
FIELDS = [:id, :iban, :bic, :bank_name, :status, :created_at, :customer_id]
|
10
11
|
|
11
12
|
FIELDS.each do |f|
|
12
13
|
attr_accessor f
|
13
14
|
end
|
14
15
|
|
15
|
-
attr_accessor :mandate
|
16
|
+
attr_accessor :mandate, :customer
|
16
17
|
|
17
18
|
def self.klass_name
|
18
19
|
"bank_account"
|
@@ -55,9 +56,15 @@ module Besepa
|
|
55
56
|
values[key] = self.send("#{key.to_s}")
|
56
57
|
end
|
57
58
|
values[:mandate] = mandate.to_hash if mandate
|
59
|
+
values[:customer] = customer.to_hash if customer
|
58
60
|
values
|
59
61
|
end
|
60
62
|
|
63
|
+
def stats
|
64
|
+
response = get "#{api_path}/stats"
|
65
|
+
response['response']
|
66
|
+
end
|
67
|
+
|
61
68
|
protected
|
62
69
|
|
63
70
|
def self.query_params(filters = {})
|
@@ -67,11 +74,17 @@ module Besepa
|
|
67
74
|
end
|
68
75
|
|
69
76
|
def self.api_path(filters={})
|
77
|
+
customer_id = filters[:customer_id]
|
78
|
+
|
79
|
+
if customer_id
|
70
80
|
"#{Customer.api_path}/#{CGI.escape(filters[:customer_id])}/bank_accounts"
|
81
|
+
else
|
82
|
+
'/bank_accounts'
|
83
|
+
end
|
71
84
|
end
|
72
85
|
|
73
86
|
def api_path(filters={})
|
74
|
-
"#{
|
87
|
+
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
75
88
|
end
|
76
89
|
|
77
90
|
def process_attributes(attrs)
|
@@ -79,6 +92,7 @@ module Besepa
|
|
79
92
|
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
80
93
|
end
|
81
94
|
self.mandate = Besepa::Mandate.new(attrs['mandate']) if attrs['mandate']
|
95
|
+
self.customer = Besepa::Customer.new(attrs['customer']) if attrs['customer']
|
82
96
|
process_activities(attrs)
|
83
97
|
self
|
84
98
|
end
|
@@ -21,12 +21,22 @@ module Besepa
|
|
21
21
|
self
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.default
|
25
|
+
response = get "#{api_path}/default"
|
26
|
+
self.new(response['response'])
|
27
|
+
end
|
28
|
+
|
24
29
|
def activation_request
|
25
30
|
response = put "#{api_path}/activation_request"
|
26
31
|
process_attributes(response['response'])
|
27
32
|
self
|
28
33
|
end
|
29
34
|
|
35
|
+
def stats
|
36
|
+
response = get "#{api_path}/stats"
|
37
|
+
response['response']
|
38
|
+
end
|
39
|
+
|
30
40
|
protected
|
31
41
|
|
32
42
|
def self.api_path(filters={})
|
data/lib/besepa/customer.rb
CHANGED
@@ -10,7 +10,7 @@ module Besepa
|
|
10
10
|
FIELDS = [:id, :name, :taxid, :reference,
|
11
11
|
:contact_name, :contact_email, :contact_phone, :contact_language,
|
12
12
|
:address_street, :address_city, :address_postalcode, :address_state,
|
13
|
-
:address_country, :group_ids, :status, :created_at
|
13
|
+
:address_country, :group_ids, :status, :created_at]
|
14
14
|
|
15
15
|
FIELDS.each do |f|
|
16
16
|
attr_accessor f
|
@@ -107,7 +107,10 @@ module Besepa
|
|
107
107
|
|
108
108
|
params[:mandate] = { scheme: (mandate_options[:scheme] || "CORE"),
|
109
109
|
used: (mandate_options[:used] || false),
|
110
|
-
mandate_type: (mandate_options[:type] || "RECURRENT")
|
110
|
+
mandate_type: (mandate_options[:type] || "RECURRENT")
|
111
|
+
}
|
112
|
+
|
113
|
+
params[:mandate][:product_id] = mandate_options[:product_id] if mandate_options[:product_id]
|
111
114
|
|
112
115
|
if mandate_options[:signature_date]
|
113
116
|
params[:mandate][:signed_at] = mandate_options[:signature_date]
|
@@ -139,5 +142,14 @@ module Besepa
|
|
139
142
|
params[:metadata] = metadata if metadata
|
140
143
|
Debit.create( params, {:customer_id => id} )
|
141
144
|
end
|
145
|
+
|
146
|
+
def api_path(filters = {})
|
147
|
+
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def stats
|
151
|
+
response = get "#{api_path}/stats"
|
152
|
+
response['response']
|
153
|
+
end
|
142
154
|
end
|
143
155
|
end
|
data/lib/besepa/debit.rb
CHANGED
data/lib/besepa/group.rb
CHANGED
@@ -6,7 +6,7 @@ module Besepa
|
|
6
6
|
include Besepa::ApiCalls::Update
|
7
7
|
include Besepa::ApiCalls::Destroy
|
8
8
|
|
9
|
-
FIELDS = [:id, :name, :reference, :created_at, :
|
9
|
+
FIELDS = [:id, :name, :reference, :created_at, :memberships_count]
|
10
10
|
|
11
11
|
FIELDS.each do |f|
|
12
12
|
attr_accessor f
|
@@ -16,6 +16,15 @@ module Besepa
|
|
16
16
|
Customer.search({ field: :group_id, value: id})
|
17
17
|
end
|
18
18
|
|
19
|
+
def stats
|
20
|
+
response = get "#{api_path}/stats"
|
21
|
+
response['response']
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_path(filters = {})
|
25
|
+
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
26
|
+
end
|
27
|
+
|
19
28
|
protected
|
20
29
|
|
21
30
|
def self.query_params(filters = {})
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Besepa
|
2
|
+
class Payment < Besepa::Resource
|
3
|
+
|
4
|
+
include Besepa::ApiCalls::List
|
5
|
+
include Besepa::ApiCalls::Search
|
6
|
+
|
7
|
+
FIELDS = [:id, :reference, :amount, :currency, :status, :send_at, :sent_at, :description, :metadata, :created_at]
|
8
|
+
|
9
|
+
ALLOWED_NILS = [:collect_at]
|
10
|
+
|
11
|
+
FIELDS.each do |f|
|
12
|
+
attr_accessor f
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :customer, :debtor_bank_account, :creditor_bank_account
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
values = {}
|
19
|
+
self.class::FIELDS.each do |key|
|
20
|
+
values[key] = self.send("#{key.to_s}")
|
21
|
+
end
|
22
|
+
values[:debtor_bank_account] = debtor_bank_account.to_hash if debtor_bank_account
|
23
|
+
values[:creditor_bank_account] = creditor_bank_account.to_hash if creditor_bank_account
|
24
|
+
values[:customer] = customer.to_hash if customer
|
25
|
+
values
|
26
|
+
end
|
27
|
+
|
28
|
+
def allowed_nils
|
29
|
+
ALLOWED_NILS
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def self.query_params(filters = {})
|
35
|
+
filters = filters.dup
|
36
|
+
filters.delete(:customer_id)
|
37
|
+
filters
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.api_path(filters={})
|
41
|
+
customer_id = filters[:customer_id]
|
42
|
+
if customer_id
|
43
|
+
"#{Customer.api_path}/#{CGI.escape(customer_id)}/payments"
|
44
|
+
else
|
45
|
+
'/payments'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def api_path(filters={})
|
50
|
+
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_attributes(attrs)
|
54
|
+
self.class::FIELDS.each do |key|
|
55
|
+
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
56
|
+
end
|
57
|
+
self.debtor_bank_account = Besepa::BankAccount.new(attrs['debtor_bank_account']) if attrs['debtor_bank_account']
|
58
|
+
self.creditor_bank_account = Besepa::BusinessAccount.new(attrs['creditor_bank_account']) if attrs['creditor_bank_account']
|
59
|
+
self.customer = Besepa::Customer.new(attrs['customer']) if attrs['customer']
|
60
|
+
self
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/besepa/product.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
module Besepa
|
2
2
|
|
3
3
|
class Product < Besepa::Resource
|
4
|
-
|
4
|
+
|
5
5
|
include Besepa::ApiCalls::List
|
6
|
+
include Besepa::ApiCalls::Search
|
6
7
|
include Besepa::ApiCalls::Create
|
7
8
|
include Besepa::ApiCalls::Update
|
8
9
|
include Besepa::ApiCalls::Destroy
|
9
|
-
|
10
|
+
|
10
11
|
FIELDS = [:id, :name, :amount, :currency, :reference,
|
11
12
|
:recurrent, :max_charges, :periodicity, :period_count,
|
12
13
|
:status, :created_at]
|
13
|
-
|
14
|
+
|
14
15
|
FIELDS.each do |f|
|
15
16
|
attr_accessor f
|
16
|
-
end
|
17
|
+
end
|
17
18
|
|
18
19
|
end
|
19
|
-
end
|
20
|
+
end
|
data/lib/besepa/remittance.rb
CHANGED
@@ -1,23 +1,33 @@
|
|
1
1
|
module Besepa
|
2
2
|
|
3
3
|
class Remittance < Besepa::Resource
|
4
|
-
|
4
|
+
|
5
5
|
include Besepa::ApiCalls::List
|
6
|
-
|
7
|
-
FIELDS = [:id, :collect_at, :send_at, :sent_at, :status, :scheme, :created_at, :
|
8
|
-
|
6
|
+
|
7
|
+
FIELDS = [:id, :collect_at, :send_at, :sent_at, :status, :scheme, :created_at, :debits_count, :debits_amount]
|
8
|
+
|
9
9
|
attr_accessor :bank_account
|
10
|
-
|
10
|
+
|
11
11
|
FIELDS.each do |f|
|
12
12
|
attr_accessor f
|
13
|
-
end
|
14
|
-
|
13
|
+
end
|
14
|
+
|
15
15
|
def self.api_path(filters={})
|
16
16
|
"/remittances"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
|
+
def api_path(filters={})
|
20
|
+
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def stats
|
24
|
+
response = get "#{api_path}/stats"
|
25
|
+
response['response']
|
26
|
+
end
|
27
|
+
|
28
|
+
|
19
29
|
protected
|
20
|
-
|
30
|
+
|
21
31
|
def process_attributes(attrs)
|
22
32
|
self.class::FIELDS.each do |key|
|
23
33
|
self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym])
|
@@ -26,7 +36,7 @@ module Besepa
|
|
26
36
|
process_activities(attrs)
|
27
37
|
self
|
28
38
|
end
|
29
|
-
|
39
|
+
|
30
40
|
|
31
41
|
end
|
32
42
|
end
|
data/lib/besepa/subscription.rb
CHANGED
@@ -4,9 +4,10 @@ module Besepa
|
|
4
4
|
include Besepa::ApiCalls::List
|
5
5
|
include Besepa::ApiCalls::Search
|
6
6
|
include Besepa::ApiCalls::Create
|
7
|
+
include Besepa::ApiCalls::Update
|
7
8
|
include Besepa::ApiCalls::Destroy
|
8
9
|
|
9
|
-
FIELDS = [:id, :last_debit, :next_debit, :status, :metadata, :starts_at, :renew_at, :created_at, :setup_fee, :customer_code]
|
10
|
+
FIELDS = [:id, :last_debit, :next_debit, :status, :metadata, :starts_at, :renew_at, :created_at, :setup_fee, :customer_code, :debits_count]
|
10
11
|
|
11
12
|
FIELDS.each do |f|
|
12
13
|
attr_accessor f
|
@@ -40,6 +41,11 @@ module Besepa
|
|
40
41
|
filters
|
41
42
|
end
|
42
43
|
|
44
|
+
def stats
|
45
|
+
response = get "#{api_path}/stats"
|
46
|
+
response['response']
|
47
|
+
end
|
48
|
+
|
43
49
|
def api_path(filters={})
|
44
50
|
"#{self.class.api_path(filters)}/#{CGI.escape(id)}"
|
45
51
|
end
|
data/lib/besepa/user.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Besepa
|
2
|
+
class User < Besepa::Resource
|
3
|
+
|
4
|
+
include Besepa::ApiCalls::List
|
5
|
+
include Besepa::ApiCalls::Search
|
6
|
+
include Besepa::ApiCalls::Create
|
7
|
+
include Besepa::ApiCalls::Update
|
8
|
+
include Besepa::ApiCalls::Destroy
|
9
|
+
|
10
|
+
FIELDS = [:id, :name, :email, :account_id, :owner, :created_at, :updated_at, :last_sign_in_at, :time_zone, :notify_errors, :notify_mandate_signs]
|
11
|
+
|
12
|
+
FIELDS.each do |f|
|
13
|
+
attr_accessor f
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/besepa/utils/version.rb
CHANGED
@@ -63,5 +63,16 @@ describe Besepa::Subscription do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe '#update' do
|
67
|
+
it 'posts resource to API' do
|
68
|
+
stub_get('/subscriptions/res12345').to_return(body: fixture('resource.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
69
|
+
stub_put('/subscriptions/res12345').to_return(body: fixture('resource.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
66
70
|
|
71
|
+
subscription = Besepa::Subscription.find('res12345')
|
72
|
+
|
73
|
+
subscription.save
|
74
|
+
|
75
|
+
expect(subscription).to be_an Besepa::Subscription
|
76
|
+
end
|
77
|
+
end
|
67
78
|
end
|
data/spec/fixtures/resource.json
CHANGED
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.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- besepa.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -124,10 +124,12 @@ files:
|
|
124
124
|
- lib/besepa/errors/resource_not_found_error.rb
|
125
125
|
- lib/besepa/group.rb
|
126
126
|
- lib/besepa/mandate.rb
|
127
|
+
- lib/besepa/payment.rb
|
127
128
|
- lib/besepa/product.rb
|
128
129
|
- lib/besepa/remittance.rb
|
129
130
|
- lib/besepa/resource.rb
|
130
131
|
- lib/besepa/subscription.rb
|
132
|
+
- lib/besepa/user.rb
|
131
133
|
- lib/besepa/utils/config.rb
|
132
134
|
- lib/besepa/utils/connection.rb
|
133
135
|
- lib/besepa/utils/request.rb
|
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
167
|
version: '0'
|
166
168
|
requirements: []
|
167
169
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.5.
|
170
|
+
rubygems_version: 2.5.2
|
169
171
|
signing_key:
|
170
172
|
specification_version: 4
|
171
173
|
summary: Ruby client for besepa.com
|