mono-merchant 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -3
- data/lib/mono-merchant/details.rb +15 -0
- data/lib/mono-merchant/invoice/cancel.rb +1 -0
- data/lib/mono-merchant/invoice/create.rb +4 -4
- data/lib/mono-merchant/invoice/fiscal_checks.rb +17 -0
- data/lib/mono-merchant/invoice/remove.rb +1 -0
- data/lib/mono-merchant/qr/details.rb +24 -0
- data/lib/mono-merchant/qr/list.rb +17 -0
- data/lib/mono-merchant/qr/reset_amount.rb +21 -0
- data/lib/mono-merchant/statement.rb +26 -0
- data/lib/mono-merchant/submerchant/list.rb +17 -0
- data/lib/mono-merchant/version.rb +1 -1
- data/lib/mono-merchant/wallet/card.rb +23 -0
- data/lib/mono-merchant/wallet/list.rb +31 -0
- data/lib/mono-merchant/wallet/payment.rb +55 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f97902ac1184bdce16efdf5357e28a06d3435b6559f6f11dce3c09fe25c73c0
|
4
|
+
data.tar.gz: 1b4ba516a202e3f9f73b422cc077926ea266d22e1c70ce381512526cf38d9a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3d4f24ee3c038a32c9b5e24dcbaa084d084c8d7cf14d6f7b7a4111b1cc0e8edf4eec647f6c7f30d9855aa3afb105458938bc26221e1c646ca3bc3ee16a04d78
|
7
|
+
data.tar.gz: b0971afe5cc811e3f816fecebb183c19da73e65f5038f6757c8cca621d83c4d64a59b6becf19845dc5fcdeb75eb66f350d07eb5c54ce57c1794aaa8c2ff9e5af
|
data/README.md
CHANGED
@@ -31,6 +31,15 @@ Development: [https://api.monobank.ua/](https://api.monobank.ua/)
|
|
31
31
|
|
32
32
|
Production: [https://fop.monobank.ua/](https://fop.monobank.ua/)
|
33
33
|
|
34
|
+
### Verify webhook transaction
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
|
38
|
+
request_to_validate = MonoMerchant::WebhookValidator.new(request)
|
39
|
+
request_to_validate.valid?
|
40
|
+
|
41
|
+
```
|
42
|
+
|
34
43
|
### Create invoice request
|
35
44
|
|
36
45
|
```ruby
|
@@ -40,15 +49,42 @@ MonoMerchant::Invoice::Create.new(amount) # see other params in code comments
|
|
40
49
|
|
41
50
|
```
|
42
51
|
|
43
|
-
###
|
52
|
+
### Other methods
|
44
53
|
|
45
54
|
```ruby
|
46
55
|
|
47
|
-
|
48
|
-
|
56
|
+
# Invoice
|
57
|
+
MonoMerchant::Invoice::Status.new(invoice_id) # check status
|
58
|
+
MonoMerchant::Invoice::Cancel.new(invoice_id) # cancel successful payment
|
59
|
+
MonoMerchant::Invoice::Remove.new(invoice_id) # invalidate created invoice
|
60
|
+
MonoMerchant::Invoice::Finalize.new(invoice_id, amount, items: []) # finalize holding amount with possibility to modify it
|
61
|
+
MonoMerchant::Invoice::FiscalChecks.new(invoice_id) # get fiscal check(s)
|
62
|
+
|
63
|
+
# QR
|
64
|
+
MonoMerchant::Qr::List.new # list QR cash-boxes
|
65
|
+
MonoMerchant::Qr::Details.new(qr_id) # get QR details
|
66
|
+
MonoMerchant::Qr::ResetAmount.new(qr_id) # reset/remove payment
|
67
|
+
|
68
|
+
# Submerchant
|
69
|
+
MonoMerchant::Submerchant::List.new # get list of submerchants
|
70
|
+
|
71
|
+
# Wallet
|
72
|
+
MonoMerchant::Wallet::List.new(wallet_id)
|
73
|
+
MonoMerchant::Wallet::Card.new(card_token) # delete card token
|
74
|
+
MonoMerchant::Wallet::Payment.new(card_token, amount) # see other attributes directly in code
|
75
|
+
|
76
|
+
# Merchant
|
77
|
+
MonoMerchant::Details.new # basic info about merchant: Id, Name, edrpou
|
78
|
+
MonoMerchant::Statement.new(from: 1649329978, to: 1649329978) # get bank account statement for defined period. from & to are utc unix timestamps
|
49
79
|
|
50
80
|
```
|
51
81
|
|
82
|
+
## TODO
|
83
|
+
|
84
|
+
- [credentials payment](https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1payment-direct/post)
|
85
|
+
- better Readme
|
86
|
+
- minor todos (noticed directly in code)
|
87
|
+
|
52
88
|
## Development
|
53
89
|
|
54
90
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -16,17 +16,17 @@ module MonoMerchant
|
|
16
16
|
# @param [Array] items - cart content
|
17
17
|
# @param [String] redirect_url - url where user will be redirected after payment
|
18
18
|
# @param [String] webhook_url - url where Monobank will send webhook after payment
|
19
|
-
def initialize(amount,
|
19
|
+
def initialize(amount, currency: DEFAULT_CURRENCY, items: [], hold: false, reference: nil, redirect_url: nil, webhook_url: nil, email: nil, destination: nil, comment: nil)
|
20
20
|
@amount = convert_to_cents(amount)
|
21
21
|
@destination = destination
|
22
22
|
@reference = reference
|
23
23
|
@comment = comment
|
24
|
-
@currency = Money::Currency.new(currency)
|
25
|
-
@payment_type = hold ? 'hold' : 'debit'
|
26
24
|
@customer_emails = [email] if email
|
27
|
-
@items = items.map { |i| Item.new(i).to_hash.presence }
|
28
25
|
@redirect_url = redirect_url
|
29
26
|
@webhook_url = webhook_url
|
27
|
+
@currency = Money::Currency.new(currency)
|
28
|
+
@items = items.map { |i| Item.new(i).to_hash.presence }
|
29
|
+
@payment_type = hold ? 'hold' : 'debit'
|
30
30
|
super()
|
31
31
|
end
|
32
32
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonoMerchant
|
4
|
+
module Invoice
|
5
|
+
|
6
|
+
class FiscalChecks < PaymentInfo
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
# todo: objectify array of checks?
|
11
|
+
# https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1fiscal-checks?invoiceId={invoiceId}/get
|
12
|
+
def data
|
13
|
+
%w[checks]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Qr
|
3
|
+
|
4
|
+
# Get info about QR paydesk
|
5
|
+
class Details < ApiRequest
|
6
|
+
|
7
|
+
attr_reader :qr_id
|
8
|
+
|
9
|
+
def initialize(qr_id)
|
10
|
+
@qr_id = qr_id
|
11
|
+
super(type: :get)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def params
|
16
|
+
{ qrId: qr_id }
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
%w[shortQrId invoiceId amount ccy]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Qr
|
3
|
+
|
4
|
+
# Get list of QR paydesks
|
5
|
+
class List < ApiRequest
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super(type: :get)
|
9
|
+
end
|
10
|
+
|
11
|
+
# todo: make array of objects from response list (shortQrId, qrId, amountType, pageUrl)?
|
12
|
+
def data
|
13
|
+
%w[list]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Qr
|
3
|
+
|
4
|
+
# Reset/remove payment
|
5
|
+
class ResetAmount < ApiRequest
|
6
|
+
|
7
|
+
attr_reader :qr_id
|
8
|
+
|
9
|
+
def initialize(qr_id)
|
10
|
+
@qr_id = qr_id
|
11
|
+
super()
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def body
|
17
|
+
{ qrId: qr_id }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
class Statement < ApiRequest
|
3
|
+
|
4
|
+
attr_reader :from, :to
|
5
|
+
|
6
|
+
# @param [Integer] from - utc unix timestamp
|
7
|
+
# @param [Integer] to - utc unix timestamp
|
8
|
+
def initialize(from: nil, to: nil)
|
9
|
+
@from, @to = from, to
|
10
|
+
super(type: :get)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def params
|
16
|
+
{ from: from, to: to }.compact
|
17
|
+
end
|
18
|
+
|
19
|
+
# todo: objectify data?
|
20
|
+
# https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1statement/get
|
21
|
+
def data
|
22
|
+
%w[list]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Submerchant
|
3
|
+
|
4
|
+
# Get list of sub-merchants
|
5
|
+
class List < ApiRequest
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super(type: :get)
|
9
|
+
end
|
10
|
+
|
11
|
+
# todo: make array of objects from response list (code, edrpou, iban)?
|
12
|
+
def data
|
13
|
+
%w[list]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Wallet
|
3
|
+
|
4
|
+
# Remove card token
|
5
|
+
class Card < ApiRequest
|
6
|
+
|
7
|
+
attr_reader :card_token
|
8
|
+
|
9
|
+
def initialize(card_token)
|
10
|
+
@card_token = card_token
|
11
|
+
super(type: :delete)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def body
|
17
|
+
{ cardToken: card_token }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Wallet
|
3
|
+
class List < ApiRequest
|
4
|
+
|
5
|
+
attr_reader :wallet_id
|
6
|
+
|
7
|
+
# @param [String] wallet_id - wallet id
|
8
|
+
def initialize(wallet_id = nil)
|
9
|
+
@wallet_id = wallet_id
|
10
|
+
super(type: :get)
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
"#{API_URL}/merchant/wallet/#{url_query}"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def params
|
20
|
+
{ walletId: wallet_id }.compact
|
21
|
+
end
|
22
|
+
|
23
|
+
# todo: objectify wallets?
|
24
|
+
# https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1wallet/get
|
25
|
+
def data
|
26
|
+
%w[wallet]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module MonoMerchant
|
2
|
+
module Wallet
|
3
|
+
|
4
|
+
# Create payment for card token
|
5
|
+
# todo DRY it with Invoice::Create
|
6
|
+
class Payment < ApiRequest
|
7
|
+
|
8
|
+
attr_reader :card_token, :amount, :currency, :initiation_kind, :customer_emails, :items, :destination, :comment, :reference, :redirect_url, :webhook_url
|
9
|
+
|
10
|
+
def initialize(card_token, amount, currency = DEFAULT_CURRENCY, by_client: false, items: [], reference: nil, redirect_url: nil, webhook_url: nil, email: nil, destination: nil, comment: nil)
|
11
|
+
@card_token = card_token
|
12
|
+
@amount = convert_to_cents(amount)
|
13
|
+
@destination = destination
|
14
|
+
@reference = reference
|
15
|
+
@comment = comment
|
16
|
+
@customer_emails = [email] if email
|
17
|
+
@redirect_url = redirect_url
|
18
|
+
@webhook_url = webhook_url
|
19
|
+
@currency = Money::Currency.new(currency)
|
20
|
+
# todo: append barcode, uktzed, tax, discounts etc.
|
21
|
+
@items = items.map { |i| Invoice::Item.new(i).to_hash.presence }
|
22
|
+
@initiation_kind = by_client ? 'client' : 'merchant'
|
23
|
+
super()
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
delegate :iso_numeric, to: :currency, prefix: true
|
29
|
+
alias_method :ccy, :currency_iso_numeric
|
30
|
+
|
31
|
+
def body
|
32
|
+
{
|
33
|
+
ccy: ccy.to_i,
|
34
|
+
amount: amount,
|
35
|
+
initiationKind: initiation_kind,
|
36
|
+
redirectUrl: redirect_url,
|
37
|
+
webHookUrl: webhook_url,
|
38
|
+
merchantPaymInfo: {
|
39
|
+
basketOrder: items.presence,
|
40
|
+
reference: reference,
|
41
|
+
comment: comment,
|
42
|
+
destination: destination,
|
43
|
+
customerEmails: customer_emails
|
44
|
+
}.compact
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def data
|
49
|
+
%w[invoiceId tdsUrl status failureReason amount ccy createdDate modifiedDate]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mono-merchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okliv
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -99,15 +99,25 @@ files:
|
|
99
99
|
- Rakefile
|
100
100
|
- lib/mono-merchant.rb
|
101
101
|
- lib/mono-merchant/api_request.rb
|
102
|
+
- lib/mono-merchant/details.rb
|
102
103
|
- lib/mono-merchant/invoice/cancel.rb
|
103
104
|
- lib/mono-merchant/invoice/create.rb
|
104
105
|
- lib/mono-merchant/invoice/finalize.rb
|
106
|
+
- lib/mono-merchant/invoice/fiscal_checks.rb
|
105
107
|
- lib/mono-merchant/invoice/item.rb
|
106
108
|
- lib/mono-merchant/invoice/payment_info.rb
|
107
109
|
- lib/mono-merchant/invoice/remove.rb
|
108
110
|
- lib/mono-merchant/invoice/status.rb
|
109
111
|
- lib/mono-merchant/pubkey.rb
|
112
|
+
- lib/mono-merchant/qr/details.rb
|
113
|
+
- lib/mono-merchant/qr/list.rb
|
114
|
+
- lib/mono-merchant/qr/reset_amount.rb
|
115
|
+
- lib/mono-merchant/statement.rb
|
116
|
+
- lib/mono-merchant/submerchant/list.rb
|
110
117
|
- lib/mono-merchant/version.rb
|
118
|
+
- lib/mono-merchant/wallet/card.rb
|
119
|
+
- lib/mono-merchant/wallet/list.rb
|
120
|
+
- lib/mono-merchant/wallet/payment.rb
|
111
121
|
- lib/mono-merchant/webhook_validator.rb
|
112
122
|
- mono-merchant.gemspec
|
113
123
|
homepage: https://github.com/okliv/mono-merchant
|