monopay-ruby 0.1.1 → 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 +4 -4
- data/CHANGELOG.md +21 -2
- data/Gemfile.lock +5 -2
- data/README.md +31 -2
- data/lib/monopay-ruby/extensions/blank_method_extension.rb +23 -0
- data/lib/monopay-ruby/invoices/advanced_invoice.rb +78 -0
- data/lib/monopay-ruby/invoices/simple_invoice.rb +14 -7
- data/lib/monopay-ruby/version.rb +1 -1
- data/lib/monopay-ruby/webhooks/public_key.rb +0 -1
- data/lib/monopay-ruby.rb +5 -0
- data/monopay-ruby.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 855262b07f7c1bc58625497799d10574a7055ab75dddda4cb82da1b902b925be
|
4
|
+
data.tar.gz: 662f65553e5335d096ac041f5284236555fb4c6469b39a8f56535ea36ae4932a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef8e096ed91863d2ce3969f4740d22da0a386975d489b4d9d8bddf47db5b38f58f890c444a6baac933521dd7fefdb864419b97e42d87c640dba6eb20f3eff46d
|
7
|
+
data.tar.gz: b73964a630ea445906ac8b4f2fed5a7dc37df411d1854a7dc1d5d6dcebcd806d0749deaf03d5b407be6b28b6f7aecf3208c8ac8b270736bd691067182e8ef3c3
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,27 @@
|
|
1
|
+
## [1.1.0] - 2024-08-12
|
2
|
+
- add ability make payments' requests more advanced by adding more params into `MonopayRuby::Invoices::AdvancedInvoice::create` method
|
3
|
+
- change private methods to protected
|
4
|
+
- modify `request_body` for additional params
|
5
|
+
|
6
|
+
## [1.0.0] - 2023-06-27
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
|
10
|
+
### Breaking Change
|
11
|
+
Updated method signatures in the gem to use keyword arguments instead of named arguments.
|
12
|
+
|
13
|
+
###### Specifically
|
14
|
+
`MonopayRuby::Invoices::SimpleInvoice::new` method was affected by this change.
|
15
|
+
###### Previously
|
16
|
+
the method was called like `new("redirect/url", "webhook/url")`. Now, it should be called like `new(redirect_url: "redirect/url", webhook_url: "webhook/url")`.
|
17
|
+
#### Note
|
18
|
+
This is a breaking change and will require updating your code if you are updating to this version of the gem from an earlier version.
|
19
|
+
|
1
20
|
## [0.1.1] - 2023-06-19
|
2
21
|
|
3
22
|
- Fix typo in a `README.md` file
|
4
|
-
-
|
5
|
-
- Use
|
23
|
+
- Add ability to pass reference to an invoice by `reference` parameter in a `MonopayRuby::Invoices::SimpleInvoice::create` method
|
24
|
+
- Use keyword parameter of `destination` for "MonopayRuby::Invoices::SimpleInvoice::create" method
|
6
25
|
|
7
26
|
## [0.1.0] - 2023-06-18
|
8
27
|
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
monopay-ruby (
|
4
|
+
monopay-ruby (1.1.0)
|
5
5
|
base64 (~> 0.1.1)
|
6
|
+
bigdecimal (~> 3.1.9)
|
6
7
|
json (~> 2.5)
|
7
8
|
money (~> 6.13)
|
8
9
|
rest-client (~> 2.1)
|
@@ -11,6 +12,7 @@ GEM
|
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
14
|
base64 (0.1.1)
|
15
|
+
bigdecimal (3.1.9)
|
14
16
|
coderay (1.1.3)
|
15
17
|
concurrent-ruby (1.2.2)
|
16
18
|
diff-lcs (1.5.0)
|
@@ -23,7 +25,7 @@ GEM
|
|
23
25
|
i18n (1.14.1)
|
24
26
|
concurrent-ruby (~> 1.0)
|
25
27
|
json (2.6.3)
|
26
|
-
method_source (1.
|
28
|
+
method_source (1.1.0)
|
27
29
|
mime-types (3.4.1)
|
28
30
|
mime-types-data (~> 3.2015)
|
29
31
|
mime-types-data (3.2023.0218.1)
|
@@ -64,6 +66,7 @@ GEM
|
|
64
66
|
|
65
67
|
PLATFORMS
|
66
68
|
arm64-darwin-21
|
69
|
+
arm64-darwin-23
|
67
70
|
x86_64-linux
|
68
71
|
|
69
72
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](https://github.com/loqimean/monopay-ruby/actions)
|
1
|
+
[](https://github.com/loqimean/monopay-ruby/actions/workflows/ci.yml)
|
2
2
|
|
3
3
|
# MonopayRuby
|
4
4
|
|
@@ -54,11 +54,32 @@ Just get the token and go to earn moneys! 🚀
|
|
54
54
|
class PaymentsController < ApplicationController
|
55
55
|
def create
|
56
56
|
payment = MonopayRuby::Invoices::SimpleInvoice.new(
|
57
|
+
"https://example.com",
|
58
|
+
"https://example.com/payments/webhook"
|
59
|
+
)
|
60
|
+
|
61
|
+
if payment.create(amount: 100, destination: "Payment description",)
|
62
|
+
# your success code processing
|
63
|
+
else
|
64
|
+
# your error code processing
|
65
|
+
# flash[:error] = payment.error_messages
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Generate advanced payment request:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# app/controllers/payments_controller.rb
|
75
|
+
class PaymentsController < ApplicationController
|
76
|
+
def create
|
77
|
+
payment = MonopayRuby::Invoices::AdvancedInvoice.new(
|
57
78
|
redirect_url: "https://example.com",
|
58
79
|
webhook_url: "https://example.com/payments/webhook"
|
59
80
|
)
|
60
81
|
|
61
|
-
if payment.create(amount
|
82
|
+
if payment.create(amount, additional_params: {})
|
62
83
|
# your success code processing
|
63
84
|
else
|
64
85
|
# your error code processing
|
@@ -68,6 +89,8 @@ class PaymentsController < ApplicationController
|
|
68
89
|
end
|
69
90
|
```
|
70
91
|
|
92
|
+
`additional_params` - [Read more about params](https://api.monobank.ua/docs/acquiring.html)
|
93
|
+
|
71
94
|
### Verify transaction
|
72
95
|
|
73
96
|
```ruby
|
@@ -88,6 +111,9 @@ class PaymentsController < ApplicationController
|
|
88
111
|
end
|
89
112
|
```
|
90
113
|
|
114
|
+
## Useful
|
115
|
+
[Test cards](https://na-gateway.mastercard.com/api/documentation/integrationGuidelines/supportedFeatures/testAndGoLive.html?locale=en_US)
|
116
|
+
|
91
117
|
## Development
|
92
118
|
|
93
119
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -101,3 +127,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/loqime
|
|
101
127
|
## License
|
102
128
|
|
103
129
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
130
|
+
|
131
|
+
## Thanks for your support!
|
132
|
+
[<img width="100" alt="RailsJazz" src="https://avatars.githubusercontent.com/u/104008706?s=200">](https://github.com/railsjazz)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MonopayRuby
|
2
|
+
module Extensions
|
3
|
+
module BlankMethodExtension
|
4
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
5
|
+
|
6
|
+
refine Object do
|
7
|
+
# Check if the object is blank
|
8
|
+
#
|
9
|
+
# @return [Boolean] true if the object is blank, false otherwise
|
10
|
+
def blank?
|
11
|
+
nil? || respond_to?(:empty?) && empty? || (self.is_a?(String) && BLANK_RE.match?(self))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Check if the object is present
|
15
|
+
#
|
16
|
+
# @return [Boolean] true if the object is present, false otherwise
|
17
|
+
def present?
|
18
|
+
!blank?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative "simple_invoice"
|
2
|
+
|
3
|
+
module MonopayRuby
|
4
|
+
module Invoices
|
5
|
+
class AdvancedInvoice < MonopayRuby::Invoices::SimpleInvoice
|
6
|
+
using MonopayRuby::Extensions::BlankMethodExtension
|
7
|
+
|
8
|
+
attr_reader :additional_params, :amount
|
9
|
+
|
10
|
+
# Create invoice for Monobank API
|
11
|
+
#
|
12
|
+
# This method sets up the required instance variables and then calls the `create`
|
13
|
+
# method from the parent class with the relevant parameters.
|
14
|
+
#
|
15
|
+
# @param amount [Numeric] The amount of the payment.
|
16
|
+
# @param additional_params [Hash] (optional) Additional parameters for the payment.
|
17
|
+
# - :merchantPaymInfo [Hash] Information about the merchant payment.
|
18
|
+
# - :destination [String] The destination of the payment.
|
19
|
+
# - :reference [String] A reference for the payment.
|
20
|
+
#
|
21
|
+
# @return [Boolean] The result of the `create` method in the parent class,
|
22
|
+
# which returns true if invoice was created successfully, false otherwise
|
23
|
+
#
|
24
|
+
# @example Create a payment with amount and additional parameters
|
25
|
+
# create(100, additional_params: { merchantPaymInfo: { destination: "Happy payment", reference: "ref123" } })
|
26
|
+
def create(amount, additional_params: {})
|
27
|
+
@amount = amount
|
28
|
+
@additional_params = additional_params
|
29
|
+
@destination = @additional_params.dig(:merchantPaymInfo, :destination)
|
30
|
+
@reference = @additional_params.dig(:merchantPaymInfo, :reference)
|
31
|
+
|
32
|
+
super(amount, destination: @destination, reference: @reference)
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def request_body
|
38
|
+
current_params = default_params
|
39
|
+
|
40
|
+
return current_params.to_json if additional_params.blank?
|
41
|
+
|
42
|
+
merge_merchant_payment_info!(current_params)
|
43
|
+
current_params.merge!(additional_params.except(:merchantPaymInfo))
|
44
|
+
|
45
|
+
update_sum_and_qty_params(current_params.dig(:merchantPaymInfo, :basketOrder))
|
46
|
+
update_sum_and_qty_params(current_params[:items])
|
47
|
+
|
48
|
+
current_params.to_json
|
49
|
+
end
|
50
|
+
|
51
|
+
# Merges merchant payment information into the current parameters.
|
52
|
+
#
|
53
|
+
# @param current_params [Hash] The current parameters to update.
|
54
|
+
def merge_merchant_payment_info!(current_params)
|
55
|
+
return if additional_params[:merchantPaymInfo].blank?
|
56
|
+
|
57
|
+
current_params[:merchantPaymInfo] = {
|
58
|
+
reference: @reference,
|
59
|
+
destination: @destination
|
60
|
+
}.merge!(additional_params[:merchantPaymInfo].except(:reference, :destination))
|
61
|
+
end
|
62
|
+
|
63
|
+
# Updates sum and quantity parameters for the given items.
|
64
|
+
#
|
65
|
+
# @param items [Array<Hash>] The items to update.
|
66
|
+
def update_sum_and_qty_params(items)
|
67
|
+
return if items.blank?
|
68
|
+
|
69
|
+
items.each do |item|
|
70
|
+
next if item.blank?
|
71
|
+
|
72
|
+
item[:sum] = convert_to_cents(item[:sum] || amount)
|
73
|
+
item[:qty] ||= 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -17,7 +17,7 @@ module MonopayRuby
|
|
17
17
|
#
|
18
18
|
# @param [String] redirect_url - url where user will be redirected after payment
|
19
19
|
# @param [String] webhook_url - url where Monobank will send webhook after payment
|
20
|
-
def initialize(redirect_url
|
20
|
+
def initialize(redirect_url: nil, webhook_url: nil)
|
21
21
|
@redirect_url = redirect_url
|
22
22
|
@webhook_url = webhook_url
|
23
23
|
|
@@ -43,7 +43,7 @@ module MonopayRuby
|
|
43
43
|
@invoice_id = JSON.parse(response.body)[INVOICE_ID_KEY]
|
44
44
|
|
45
45
|
true
|
46
|
-
rescue
|
46
|
+
rescue RestClient::ExceptionWithResponse => e
|
47
47
|
response_body = JSON.parse(e.response.body)
|
48
48
|
@error_messages << [e.message, response_body].join(", ")
|
49
49
|
# TODO: use errors and full_messages like rails
|
@@ -53,12 +53,12 @@ module MonopayRuby
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
protected
|
57
57
|
|
58
|
-
#
|
58
|
+
# Default params required for request to Monobank
|
59
59
|
#
|
60
|
-
# @return [Hash]
|
61
|
-
def
|
60
|
+
# @return [Hash] default params
|
61
|
+
def default_params
|
62
62
|
# TODO: add "ccy" and another missing params
|
63
63
|
# TODO: remove nil valued params
|
64
64
|
{
|
@@ -69,7 +69,14 @@ module MonopayRuby
|
|
69
69
|
reference: reference,
|
70
70
|
destination: destination
|
71
71
|
}
|
72
|
-
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# Request body required for Monobank API
|
76
|
+
#
|
77
|
+
# @return [Hash] request body
|
78
|
+
def request_body
|
79
|
+
default_params.to_json
|
73
80
|
end
|
74
81
|
|
75
82
|
def convert_to_cents(amount)
|
data/lib/monopay-ruby/version.rb
CHANGED
data/lib/monopay-ruby.rb
CHANGED
data/monopay-ruby.gemspec
CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_dependency "json", "~> 2.5"
|
40
40
|
# spec.add_dependency "openssl", "~> 2.1"
|
41
41
|
spec.add_dependency "money", "~> 6.13"
|
42
|
+
spec.add_dependency "bigdecimal", "~> 3.1.9"
|
42
43
|
|
43
44
|
spec.add_development_dependency "rspec", "~> 3.0"
|
44
45
|
spec.add_development_dependency "pry", "~> 0.14.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monopay-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- loqimean
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '6.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bigdecimal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.9
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.9
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,8 @@ files:
|
|
130
144
|
- Rakefile
|
131
145
|
- lib/monopay-ruby.rb
|
132
146
|
- lib/monopay-ruby/configuration.rb
|
147
|
+
- lib/monopay-ruby/extensions/blank_method_extension.rb
|
148
|
+
- lib/monopay-ruby/invoices/advanced_invoice.rb
|
133
149
|
- lib/monopay-ruby/invoices/simple_invoice.rb
|
134
150
|
- lib/monopay-ruby/version.rb
|
135
151
|
- lib/monopay-ruby/webhooks/public_key.rb
|
@@ -158,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
174
|
- !ruby/object:Gem::Version
|
159
175
|
version: '0'
|
160
176
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
177
|
+
rubygems_version: 3.4.10
|
162
178
|
signing_key:
|
163
179
|
specification_version: 4
|
164
180
|
summary: The "monopay-ruby" gem is a powerful Ruby library designed for seamless integration
|