monobank-lotarc 1.1.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 +7 -0
- data/Rakefile +6 -0
- data/lib/monobank/auth/corporate.rb +35 -0
- data/lib/monobank/auth/private.rb +17 -0
- data/lib/monobank/bank/currency.rb +22 -0
- data/lib/monobank/client.rb +44 -0
- data/lib/monobank/configuration.rb +9 -0
- data/lib/monobank/connection.rb +16 -0
- data/lib/monobank/corporate/client.rb +60 -0
- data/lib/monobank/corporate.rb +21 -0
- data/lib/monobank/error.rb +3 -0
- data/lib/monobank/methods/base.rb +48 -0
- data/lib/monobank/methods/get.rb +15 -0
- data/lib/monobank/methods/post.rb +15 -0
- data/lib/monobank/personal/auth_check.rb +22 -0
- data/lib/monobank/personal/auth_request.rb +31 -0
- data/lib/monobank/personal/client_info.rb +20 -0
- data/lib/monobank/personal/corporate_webhook.rb +15 -0
- data/lib/monobank/personal/registration.rb +46 -0
- data/lib/monobank/personal/registration_status.rb +32 -0
- data/lib/monobank/personal/settings.rb +20 -0
- data/lib/monobank/personal/statement.rb +34 -0
- data/lib/monobank/personal/webhook.rb +32 -0
- data/lib/monobank/resources/bank/currency.rb +11 -0
- data/lib/monobank/resources/base.rb +35 -0
- data/lib/monobank/resources/error.rb +9 -0
- data/lib/monobank/resources/personal/accounts.rb +11 -0
- data/lib/monobank/resources/personal/auth_check.rb +11 -0
- data/lib/monobank/resources/personal/auth_request.rb +15 -0
- data/lib/monobank/resources/personal/client_info.rb +18 -0
- data/lib/monobank/resources/personal/registration.rb +11 -0
- data/lib/monobank/resources/personal/registration_status.rb +11 -0
- data/lib/monobank/resources/personal/settings.rb +11 -0
- data/lib/monobank/resources/personal/statement.rb +11 -0
- data/lib/monobank/resources/personal/webhook.rb +12 -0
- data/lib/monobank/version.rb +3 -0
- data/lib/monobank.rb +32 -0
- data/spec/monobank_corporate_spec.rb +290 -0
- data/spec/monobank_spec.rb +147 -0
- data/spec/spec_helper.rb +21 -0
- metadata +162 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'monobank/resources/base'
|
2
|
+
require 'monobank/resources/personal/accounts'
|
3
|
+
|
4
|
+
module Monobank
|
5
|
+
module Resources
|
6
|
+
module Personal
|
7
|
+
class ClientInfo < Base
|
8
|
+
define_fields %w[name web_hook_url accounts]
|
9
|
+
|
10
|
+
def accounts
|
11
|
+
@attributes['accounts'].map do |account|
|
12
|
+
Monobank::Resources::Personal::Accounts.new(account)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'monobank/resources/base'
|
2
|
+
|
3
|
+
module Monobank
|
4
|
+
module Resources
|
5
|
+
module Personal
|
6
|
+
class Statement < Base
|
7
|
+
define_fields %w[id time description mcc hold amount operation_amount currency_code commission_rate cashback_amount balance]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/monobank.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'monobank/version'
|
2
|
+
require 'monobank/client'
|
3
|
+
require 'monobank/corporate'
|
4
|
+
require 'monobank/configuration'
|
5
|
+
require 'forwardable'
|
6
|
+
|
7
|
+
module Monobank
|
8
|
+
extend SingleForwardable
|
9
|
+
def_delegators :client, :bank_currency, :client_info, :statement, :set_webhook
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :configuration
|
13
|
+
|
14
|
+
def configure
|
15
|
+
self.configuration ||= Configuration.new
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= Client.new(token: configuration.token)
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset
|
28
|
+
@configuration = nil
|
29
|
+
@client = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,290 @@
|
|
1
|
+
describe Monobank::Corporate do
|
2
|
+
let(:key_id) { nil }
|
3
|
+
|
4
|
+
before do
|
5
|
+
allow(Time).to receive(:now).and_return(Time.parse('2024-01-31'))
|
6
|
+
|
7
|
+
fake_private_key = OpenSSL::PKey::EC.new
|
8
|
+
allow(fake_private_key).to(receive(:sign)) { |_, args| "__SIGNED__#{args}" }
|
9
|
+
allow_any_instance_of(Monobank::Auth::Corporate).to receive(:init_key).and_return(fake_private_key)
|
10
|
+
|
11
|
+
allow(Base64).to(receive(:strict_encode64)) { |arg| "__BASE64__#{arg}" }
|
12
|
+
|
13
|
+
Monobank::Corporate.configure(private_key: 'FAKE PRIVATE KEY', key_id:)
|
14
|
+
end
|
15
|
+
|
16
|
+
context '.registration' do
|
17
|
+
before do
|
18
|
+
stub_request(:post, 'https://api.monobank.ua/personal/auth/registration').
|
19
|
+
with(
|
20
|
+
body: {
|
21
|
+
"pubkey": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZZd0VBWUhLb1pJemow...",
|
22
|
+
"name": "ТОВ \"Ворона\"",
|
23
|
+
"description": "Ми робимо найрозумніший PFM з усіх можливих і нам потрібен доступ до виписка користувача, щоб створювати красиву статистику",
|
24
|
+
"contactPerson": "Роман Шевченко",
|
25
|
+
"phone": "380671234567",
|
26
|
+
"email": "etс@example.com",
|
27
|
+
"logo": "iVBORw0KGgoAAAANSUhEUgAAAUAAAACECAYAAADhnvK8AAAapElEQVR42..."
|
28
|
+
}.to_json,
|
29
|
+
headers: {
|
30
|
+
'X-Sign'=>'__BASE64____SIGNED__1706652000/personal/auth/registration',
|
31
|
+
'X-Time'=>'1706652000'
|
32
|
+
}).
|
33
|
+
to_return(status: 200, body: { status: 'New' }.to_json, headers: {'Content-Type' => 'application/json'})
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns correct data' do
|
37
|
+
result = Monobank::Corporate.registration(
|
38
|
+
public_key: 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZZd0VBWUhLb1pJemow...',
|
39
|
+
name: 'ТОВ "Ворона"',
|
40
|
+
description: 'Ми робимо найрозумніший PFM з усіх можливих і нам потрібен доступ до виписка користувача, щоб створювати красиву статистику',
|
41
|
+
contact_person: 'Роман Шевченко',
|
42
|
+
phone: '380671234567',
|
43
|
+
email: 'etс@example.com',
|
44
|
+
logo: 'iVBORw0KGgoAAAANSUhEUgAAAUAAAACECAYAAADhnvK8AAAapElEQVR42...'
|
45
|
+
)
|
46
|
+
|
47
|
+
expect(result.status).to eq 'New'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context '.registration_status' do
|
52
|
+
before do
|
53
|
+
stub_request(:post, 'https://api.monobank.ua/personal/auth/registration/status').
|
54
|
+
with(
|
55
|
+
body: {
|
56
|
+
"pubkey": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZZd0VBWUhLb1pJemow..."
|
57
|
+
}.to_json,
|
58
|
+
headers: {
|
59
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000/personal/auth/registration/status',
|
60
|
+
'X-Time' => '1706652000'
|
61
|
+
}).
|
62
|
+
to_return(
|
63
|
+
status: 200,
|
64
|
+
body: { status: 'Approved', keyId: '28a75537175a018645e6f8b14be7681791e701e0' }.to_json,
|
65
|
+
headers: {'Content-Type' => 'application/json'}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns correct data' do
|
70
|
+
result = Monobank::Corporate.registration_status(public_key: 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZZd0VBWUhLb1pJemow...')
|
71
|
+
|
72
|
+
expect(result.status).to eq 'Approved'
|
73
|
+
expect(result.key_id).to eq '28a75537175a018645e6f8b14be7681791e701e0'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with key_id' do
|
78
|
+
let(:key_id) { '28a75537175a018645e6f8b14be7681791e701e0' }
|
79
|
+
|
80
|
+
context '.set_webhook' do
|
81
|
+
before do
|
82
|
+
stub_request(:post, 'https://api.monobank.ua/personal/corp/webhook').
|
83
|
+
with(
|
84
|
+
body: {'webHookUrl': 'https://example.com/some_random_data_for_security'}.to_json,
|
85
|
+
headers: {
|
86
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
87
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000/personal/corp/webhook',
|
88
|
+
'X-Time' => '1706652000'
|
89
|
+
}).
|
90
|
+
to_return(status: 200, body: {'status' => 'ok'}.to_json, headers: {'Content-Type' => 'application/json'})
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns correct data' do
|
94
|
+
result = Monobank::Corporate.set_webhook(url: 'https://example.com/some_random_data_for_security')
|
95
|
+
|
96
|
+
expect(result.status).to eq 'ok'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context '.settings' do
|
101
|
+
before do
|
102
|
+
stub_request(:post, 'https://api.monobank.ua/personal/corp/settings').
|
103
|
+
with(
|
104
|
+
headers: {
|
105
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
106
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000/personal/corp/settings',
|
107
|
+
'X-Time' => '1706652000'
|
108
|
+
}).
|
109
|
+
to_return(
|
110
|
+
status: 200,
|
111
|
+
body: {
|
112
|
+
"pubkey": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZZd0VBWUhLb1pJemow...",
|
113
|
+
"name": "Компанія",
|
114
|
+
"permission": "psf",
|
115
|
+
"logo": "iVBORw0KGgoAAAANSUhEUgAAAUAAAACECAYAAADhnvK8AAAapElEQVR42...",
|
116
|
+
"webhook": "https://example.com/mono/corp/webhook/maybesomegibberishuniquestringbutnotnecessarily"
|
117
|
+
}.to_json,
|
118
|
+
headers: {'Content-Type' => 'application/json'}
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns correct data' do
|
123
|
+
result = Monobank::Corporate.settings
|
124
|
+
|
125
|
+
expect(result.name).to eq 'Компанія'
|
126
|
+
expect(result.webhook).to eq 'https://example.com/mono/corp/webhook/maybesomegibberishuniquestringbutnotnecessarily'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context '.auth_request' do
|
131
|
+
let(:headers) { {} }
|
132
|
+
|
133
|
+
before do
|
134
|
+
stub_request(:post, 'https://api.monobank.ua/personal/auth/request').
|
135
|
+
with(
|
136
|
+
headers: {
|
137
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
138
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000/personal/auth/request',
|
139
|
+
'X-Time' => '1706652000',
|
140
|
+
**headers
|
141
|
+
}).
|
142
|
+
to_return(
|
143
|
+
status: 200,
|
144
|
+
body: {
|
145
|
+
"tokenRequestId": "uLkwh3NzFAfEkj7urj5C7AU_",
|
146
|
+
"acceptUrl": "https://mbnk.app/auth/uLkwh3NzFAfEkj7urj5C7AU_"
|
147
|
+
}.to_json,
|
148
|
+
headers: {'Content-Type' => 'application/json'}
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'returns correct data' do
|
153
|
+
result = Monobank::Corporate.auth_request
|
154
|
+
|
155
|
+
expect(result.request_id).to eq 'uLkwh3NzFAfEkj7urj5C7AU_'
|
156
|
+
expect(result.accept_url).to eq 'https://mbnk.app/auth/uLkwh3NzFAfEkj7urj5C7AU_'
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when a callback is passed' do
|
160
|
+
let(:headers) { {'X-Callback' => 'https://example.com' }}
|
161
|
+
|
162
|
+
it 'returns passes it as headers' do
|
163
|
+
result = Monobank::Corporate.auth_request(callback: 'https://example.com')
|
164
|
+
|
165
|
+
expect(result.request_id).to eq 'uLkwh3NzFAfEkj7urj5C7AU_'
|
166
|
+
expect(result.accept_url).to eq 'https://mbnk.app/auth/uLkwh3NzFAfEkj7urj5C7AU_'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'with request_id' do
|
172
|
+
let(:request_id) { 'uLkwh3NzFAfEkj7urj5C7AU_' }
|
173
|
+
|
174
|
+
context '.auth_check' do
|
175
|
+
before do
|
176
|
+
stub_request(:get, 'https://api.monobank.ua/personal/auth/request').
|
177
|
+
with(
|
178
|
+
headers: {
|
179
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
180
|
+
'X-Request-Id' => 'uLkwh3NzFAfEkj7urj5C7AU_',
|
181
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000uLkwh3NzFAfEkj7urj5C7AU_/personal/auth/request',
|
182
|
+
'X-Time' => '1706652000'
|
183
|
+
}).
|
184
|
+
to_return(
|
185
|
+
status: 200,
|
186
|
+
body: { status: 'ok' }.to_json,
|
187
|
+
headers: {'Content-Type' => 'application/json'}
|
188
|
+
)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'returns correct data' do
|
192
|
+
result = Monobank::Corporate.auth_check(request_id:)
|
193
|
+
|
194
|
+
expect(result.status).to eq 'ok'
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context '.client_info' do
|
199
|
+
before do
|
200
|
+
stub_request(:get, 'https://api.monobank.ua/personal/client-info').
|
201
|
+
with(
|
202
|
+
headers: {
|
203
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
204
|
+
'X-Request-Id' => 'uLkwh3NzFAfEkj7urj5C7AU_',
|
205
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000uLkwh3NzFAfEkj7urj5C7AU_/personal/client-info',
|
206
|
+
'X-Time' => '1706652000'
|
207
|
+
}).
|
208
|
+
to_return(
|
209
|
+
status: 200,
|
210
|
+
body: {
|
211
|
+
"clientId": "3MSaMMtczs",
|
212
|
+
"name": "Мазепа Іван",
|
213
|
+
"webHookUrl": "https://mysomesite.copm/some_random_data_for_security",
|
214
|
+
"permissions": "psf",
|
215
|
+
"accounts": [
|
216
|
+
{
|
217
|
+
"id": "kKGVoZuHWzqVoZuH",
|
218
|
+
"sendId": "uHWzqVoZuH",
|
219
|
+
"balance": 10000000,
|
220
|
+
"creditLimit": 10000000,
|
221
|
+
"type": "black",
|
222
|
+
"currencyCode": 980,
|
223
|
+
"cashbackType": "UAH",
|
224
|
+
"maskedPan": [
|
225
|
+
"537541******1234"
|
226
|
+
],
|
227
|
+
"iban": "UA733220010000026201234567890"
|
228
|
+
}
|
229
|
+
]
|
230
|
+
}.to_json,
|
231
|
+
headers: {'Content-Type' => 'application/json'}
|
232
|
+
)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'returns correct data' do
|
236
|
+
result = Monobank::Corporate.client_info(request_id:)
|
237
|
+
|
238
|
+
expect(result.name).to eq 'Мазепа Іван'
|
239
|
+
expect(result.accounts.length).to eq 1
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context '.statement' do
|
244
|
+
before do
|
245
|
+
stub_request(:get, 'https://api.monobank.ua/personal/statement/0/1546304461').
|
246
|
+
with(
|
247
|
+
headers: {
|
248
|
+
'X-Key-Id' => '28a75537175a018645e6f8b14be7681791e701e0',
|
249
|
+
'X-Request-Id' => 'uLkwh3NzFAfEkj7urj5C7AU_',
|
250
|
+
'X-Sign' => '__BASE64____SIGNED__1706652000uLkwh3NzFAfEkj7urj5C7AU_/personal/statement/0/1546304461',
|
251
|
+
'X-Time' => '1706652000'
|
252
|
+
}).
|
253
|
+
to_return(
|
254
|
+
status: 200,
|
255
|
+
body: [
|
256
|
+
{
|
257
|
+
"id": "ZuHWzqkKGVo=",
|
258
|
+
"time": 1554466347,
|
259
|
+
"description": "Покупка щастя",
|
260
|
+
"mcc": 7997,
|
261
|
+
"originalMcc": 7997,
|
262
|
+
"hold": false,
|
263
|
+
"amount": -95000,
|
264
|
+
"operationAmount": -95000,
|
265
|
+
"currencyCode": 980,
|
266
|
+
"commissionRate": 0,
|
267
|
+
"cashbackAmount": 19000,
|
268
|
+
"balance": 10050000,
|
269
|
+
"comment": "За каву",
|
270
|
+
"receiptId": "XXXX-XXXX-XXXX-XXXX",
|
271
|
+
"counterEdrpou": "3096889974",
|
272
|
+
"counterIban": "UA898999980000355639201001404",
|
273
|
+
"counterName": "ТОВАРИСТВО З ОБМЕЖЕНОЮ ВІДПОВІДАЛЬНІСТЮ «ВОРОНА»"
|
274
|
+
}
|
275
|
+
].to_json,
|
276
|
+
headers: {'Content-Type' => 'application/json'}
|
277
|
+
)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'returns correct data' do
|
281
|
+
result = Monobank::Corporate.statement(request_id:, account_id: 0, from: 1546304461)
|
282
|
+
|
283
|
+
expect(result.first.id).to eq 'ZuHWzqkKGVo='
|
284
|
+
expect(result.first.amount).to eq -95000
|
285
|
+
expect(result.first.currency_code).to eq 980
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
describe Monobank do
|
2
|
+
let(:token) { 'FAKE_TOKEN' }
|
3
|
+
|
4
|
+
context '.bank_currency' do
|
5
|
+
before do
|
6
|
+
stub_request(:get, "https://api.monobank.ua/bank/currency").
|
7
|
+
to_return(
|
8
|
+
status: 200,
|
9
|
+
body: [
|
10
|
+
{
|
11
|
+
'currencyCodeA' => 840,
|
12
|
+
'currencyCodeB' => 980,
|
13
|
+
'date' => 1552392228,
|
14
|
+
'rateSell' => 27,
|
15
|
+
'rateBuy' => 27.2,
|
16
|
+
'rateCross' => 27.1
|
17
|
+
}
|
18
|
+
].to_json,
|
19
|
+
headers: {'Content-Type' => 'application/json'}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns correct data' do
|
24
|
+
result = Monobank.bank_currency
|
25
|
+
expect(result.first.currency_code_a).to eq 840
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '.client_info' do
|
30
|
+
before do
|
31
|
+
stub_request(:get, "https://api.monobank.ua/personal/client-info").
|
32
|
+
with(headers: {'X-Token' => 'FAKE_TOKEN'}).
|
33
|
+
to_return(
|
34
|
+
status: 200,
|
35
|
+
body: {
|
36
|
+
"clientId": "3MSaMMtczs",
|
37
|
+
"name": "Мазепа Іван",
|
38
|
+
"webHookUrl": "https://example.com/some_random_data_for_security",
|
39
|
+
"permissions": "psfj",
|
40
|
+
"accounts": [
|
41
|
+
{
|
42
|
+
"id": "kKGVoZuHWzqVoZuH",
|
43
|
+
"sendId": "uHWzqVoZuH",
|
44
|
+
"balance": 10000000,
|
45
|
+
"creditLimit": 10000000,
|
46
|
+
"type": "black",
|
47
|
+
"currencyCode": 980,
|
48
|
+
"cashbackType": "UAH",
|
49
|
+
"maskedPan": [
|
50
|
+
"537541******1234"
|
51
|
+
],
|
52
|
+
"iban": "UA733220010000026201234567890"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"jars": [
|
56
|
+
{
|
57
|
+
"id": "kKGVoZuHWzqVoZuH",
|
58
|
+
"sendId": "uHWzqVoZuH",
|
59
|
+
"title": "На тепловізор",
|
60
|
+
"description": "На тепловізор",
|
61
|
+
"currencyCode": 980,
|
62
|
+
"balance": 1000000,
|
63
|
+
"goal": 10000000
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}.to_json,
|
67
|
+
headers: {'Content-Type' => 'application/json'}
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns correct data' do
|
72
|
+
result = Monobank.client_info(token:)
|
73
|
+
expect(result.name).to eq 'Мазепа Іван'
|
74
|
+
expect(result.accounts.length).to eq 1
|
75
|
+
expect(result.accounts.first.type).to eq 'black'
|
76
|
+
expect(result.accounts.first.currency_code).to eq 980
|
77
|
+
expect(result.attributes).to match hash_including(
|
78
|
+
'accounts' => array_including([
|
79
|
+
hash_including(
|
80
|
+
"currency_code" => 980
|
81
|
+
)
|
82
|
+
])
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context '.statement' do
|
88
|
+
before do
|
89
|
+
stub_request(:get, "https://api.monobank.ua/personal/statement/0/1546304461").
|
90
|
+
with(headers: {'X-Token' => 'FAKE_TOKEN'}).
|
91
|
+
to_return(
|
92
|
+
status: 200,
|
93
|
+
body: [
|
94
|
+
{
|
95
|
+
"id": "ZuHWzqkKGVo=",
|
96
|
+
"time": 1554466347,
|
97
|
+
"description": "Покупка щастя",
|
98
|
+
"mcc": 7997,
|
99
|
+
"originalMcc": 7997,
|
100
|
+
"hold": false,
|
101
|
+
"amount": -95000,
|
102
|
+
"operationAmount": -95000,
|
103
|
+
"currencyCode": 980,
|
104
|
+
"commissionRate": 0,
|
105
|
+
"cashbackAmount": 19000,
|
106
|
+
"balance": 10050000,
|
107
|
+
"comment": "За каву",
|
108
|
+
"receiptId": "XXXX-XXXX-XXXX-XXXX",
|
109
|
+
"invoiceId": "2103.в.27",
|
110
|
+
"counterEdrpou": "3096889974",
|
111
|
+
"counterIban": "UA898999980000355639201001404",
|
112
|
+
"counterName": "ТОВАРИСТВО З ОБМЕЖЕНОЮ ВІДПОВІДАЛЬНІСТЮ «ВОРОНА»"
|
113
|
+
}
|
114
|
+
].to_json,
|
115
|
+
headers: {'Content-Type' => 'application/json'}
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns correct data' do
|
120
|
+
result = Monobank.statement(token:, account_id: 0, from: 1546304461)
|
121
|
+
expect(result.first.id).to eq 'ZuHWzqkKGVo='
|
122
|
+
expect(result.first.amount).to eq -95000
|
123
|
+
expect(result.first.currency_code).to eq 980
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context '.set_webhook' do
|
128
|
+
before do
|
129
|
+
stub_request(:post, "https://api.monobank.ua/personal/webhook").
|
130
|
+
with(
|
131
|
+
body: {'webHookUrl': 'https://example.com/some_random_data_for_security'}.to_json,
|
132
|
+
headers: {
|
133
|
+
'Accept'=>'*/*',
|
134
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
135
|
+
'User-Agent'=>'Ruby',
|
136
|
+
'X-Token'=>'FAKE_TOKEN'
|
137
|
+
}).
|
138
|
+
to_return(status: 200, body: {'status' => 'ok'}.to_json, headers: {'Content-Type' => 'application/json'})
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns correct data' do
|
142
|
+
result = Monobank.set_webhook(token:, url: 'https://example.com/some_random_data_for_security')
|
143
|
+
|
144
|
+
expect(result.status).to eq 'ok'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
require 'monobank'
|
6
|
+
|
7
|
+
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
|
8
|
+
|
9
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
10
|
+
# in spec/support/ and its subdirectories.
|
11
|
+
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.expect_with :rspec do |expectations|
|
15
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
16
|
+
end
|
17
|
+
|
18
|
+
config.mock_with :rspec do |mocks|
|
19
|
+
mocks.verify_partial_doubles = true
|
20
|
+
end
|
21
|
+
end
|