monopay-ruby 1.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f7b55974b07c60a80ba1251ae477f186566b9589342b8e941a8afaa3cfe41d
4
- data.tar.gz: 305d7898044358fc96ece83e506daba1f5282146218026352c5cbbda85140c66
3
+ metadata.gz: 855262b07f7c1bc58625497799d10574a7055ab75dddda4cb82da1b902b925be
4
+ data.tar.gz: 662f65553e5335d096ac041f5284236555fb4c6469b39a8f56535ea36ae4932a
5
5
  SHA512:
6
- metadata.gz: 3ffbc464d1238fee91fbe8dcfa9177b34536419092c7aa24cea40c583b3f729c9064ae3518c90e61cef6d15d033c45db5678830dcac9411d1644a002f6916ae5
7
- data.tar.gz: a636899d2837e6213d6014549dff9a62fddba0b4b6cc123ea1b20531a453f96f3729e898fa38a3934f8d0d1bb52c6e6dbad9d8b2094d8b200a399d449fd90cac
6
+ metadata.gz: ef8e096ed91863d2ce3969f4740d22da0a386975d489b4d9d8bddf47db5b38f58f890c444a6baac933521dd7fefdb864419b97e42d87c640dba6eb20f3eff46d
7
+ data.tar.gz: b73964a630ea445906ac8b4f2fed5a7dc37df411d1854a7dc1d5d6dcebcd806d0749deaf03d5b407be6b28b6f7aecf3208c8ac8b270736bd691067182e8ef3c3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  ## [1.0.0] - 2023-06-27
2
7
 
3
8
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monopay-ruby (1.0.0)
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.0.0)
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
- [![Actions Status](https://github.com/loqimean/monopay-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/loqimean/monopay-ruby/actions)
1
+ [![Actions Status](https://github.com/loqimean/monopay-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/loqimean/monopay-ruby/actions/workflows/ci.yml)
2
2
 
3
3
  # MonopayRuby
4
4
 
@@ -68,6 +68,29 @@ class PaymentsController < ApplicationController
68
68
  end
69
69
  ```
70
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(
78
+ redirect_url: "https://example.com",
79
+ webhook_url: "https://example.com/payments/webhook"
80
+ )
81
+
82
+ if payment.create(amount, additional_params: {})
83
+ # your success code processing
84
+ else
85
+ # your error code processing
86
+ # flash[:error] = payment.error_messages
87
+ end
88
+ end
89
+ end
90
+ ```
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
@@ -43,7 +43,7 @@ module MonopayRuby
43
43
  @invoice_id = JSON.parse(response.body)[INVOICE_ID_KEY]
44
44
 
45
45
  true
46
- rescue Exception => e
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
- private
56
+ protected
57
57
 
58
- # Request body required for Monobank API
58
+ # Default params required for request to Monobank
59
59
  #
60
- # @return [Hash] request body
61
- def request_body
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
- }.to_json
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MonopayRuby
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -2,7 +2,6 @@ require "rest-client"
2
2
  require "base64"
3
3
  require "json"
4
4
 
5
- require "pry"
6
5
  module MonopayRuby
7
6
  module Webhooks
8
7
  class PublicKey < MonopayRuby::Base
data/lib/monopay-ruby.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ begin
4
+ require "pry"
5
+ rescue LoadError
6
+ end
7
+
3
8
  module MonopayRuby
4
9
  class Base
5
10
  API_URL = "https://api.monobank.ua/api".freeze
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # to load all /lib files
4
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
5
+
6
+ require_relative "lib/monopay-ruby/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "monopay-ruby"
10
+ spec.version = MonopayRuby::VERSION
11
+ spec.authors = ["loqimean"]
12
+ spec.email = ["vanuha277@gmail.com"]
13
+
14
+ spec.summary = "The \"monopay-ruby\" gem is a powerful Ruby library designed for seamless integration with Monobank's payment system. It provides a convenient way to handle Monobank payments within Ruby and Rails applications, simplifying the process and saving you valuable development time."
15
+ spec.description = "The \"monopay-ruby\" gem simplifies Monobank payment integration in Ruby and Rails applications. It provides an intuitive interface and essential functionalities for generating payment requests, verifying transactions, handling callbacks, and ensuring data integrity. With this gem, you can quickly and securely implement Monobank payments, saving development time and delivering a seamless payment experience to your users."
16
+ spec.homepage = "https://github.com/loqimean/monopay-ruby"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = ">= 2.6.0"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/loqimean/monopay-ruby"
22
+ spec.metadata["changelog_uri"] = "https://github.com/loqimean/monopay-ruby/blob/master/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # TODO: Use metal versions of gems where possible to avoid unnecessary extra
37
+ spec.add_dependency "rest-client", "~> 2.1"
38
+ spec.add_dependency "base64", "~> 0.1.1"
39
+ spec.add_dependency "json", "~> 2.5"
40
+ # spec.add_dependency "openssl", "~> 2.1"
41
+ spec.add_dependency "money", "~> 6.13"
42
+ spec.add_dependency "bigdecimal", "~> 3.1.9"
43
+
44
+ spec.add_development_dependency "rspec", "~> 3.0"
45
+ spec.add_development_dependency "pry", "~> 0.14.2"
46
+ spec.add_development_dependency "simplecov", "~> 0.22.0"
47
+
48
+ # For more information and examples about making a new gem, check out our
49
+ # guide at: https://bundler.io/guides/creating_gem.html
50
+ end
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: 1.0.0
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: 2023-07-22 00:00:00.000000000 Z
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,10 +144,13 @@ 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
136
152
  - lib/monopay-ruby/webhooks/validator.rb
153
+ - monopay-ruby.gemspec
137
154
  - sig/monopay_ruby.rbs
138
155
  homepage: https://github.com/loqimean/monopay-ruby
139
156
  licenses:
@@ -157,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
174
  - !ruby/object:Gem::Version
158
175
  version: '0'
159
176
  requirements: []
160
- rubygems_version: 3.4.12
177
+ rubygems_version: 3.4.10
161
178
  signing_key:
162
179
  specification_version: 4
163
180
  summary: The "monopay-ruby" gem is a powerful Ruby library designed for seamless integration