monri 0.1.0 → 0.2.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/LICENCE +21 -0
  4. data/README.md +90 -1
  5. data/{bin → exe}/byebug +1 -1
  6. data/{bin → exe}/coderay +1 -1
  7. data/{bin → exe}/m +0 -0
  8. data/{bin → exe}/pry +0 -0
  9. data/{bin → exe}/rake +1 -1
  10. data/{bin → exe}/rubocop +0 -0
  11. data/{bin → exe}/ruby-parse +0 -0
  12. data/{bin → exe}/ruby-rewrite +0 -0
  13. data/extensions/x86_64-darwin-19/2.6.0/byebug-11.1.3/byebug/byebug.bundle +0 -0
  14. data/extensions/x86_64-darwin-19/2.6.0/byebug-11.1.3/gem_make.out +3 -2
  15. data/lib/monri/access_tokens/create_response.rb +37 -0
  16. data/lib/monri/access_tokens.rb +29 -12
  17. data/lib/monri/client.rb +49 -4
  18. data/lib/monri/customers/create_response.rb +97 -0
  19. data/lib/monri/customers.rb +11 -9
  20. data/lib/monri/errors.rb +7 -1
  21. data/lib/monri/http_client.rb +22 -11
  22. data/lib/monri/payment_methods.rb +2 -2
  23. data/lib/monri/payments/create_response.rb +36 -0
  24. data/lib/monri/payments/payment_result.rb +52 -0
  25. data/lib/monri/payments/status_response.rb +45 -0
  26. data/lib/monri/payments.rb +11 -8
  27. data/lib/monri/response.rb +13 -24
  28. data/lib/monri/tokens/ephemeral_card_token_response.rb +46 -0
  29. data/lib/monri/tokens.rb +68 -0
  30. data/lib/monri/transactions/secure_message.rb +30 -0
  31. data/lib/monri/transactions/transaction.rb +131 -0
  32. data/lib/monri/transactions/transaction_response.rb +59 -0
  33. data/lib/monri/transactions.rb +58 -0
  34. data/lib/monri/validate_callback.rb +47 -0
  35. data/lib/monri.rb +13 -1
  36. data/monri.gemspec +1 -2
  37. metadata +24 -47
  38. data/lib/monri/transaction.rb +0 -14
  39. data/specifications/addressable-2.8.1.gemspec +0 -40
  40. data/specifications/ast-2.4.2.gemspec +0 -50
  41. data/specifications/byebug-11.1.3.gemspec +0 -39
  42. data/specifications/coderay-1.1.3.gemspec +0 -25
  43. data/specifications/crack-0.4.5.gemspec +0 -32
  44. data/specifications/hashdiff-1.0.1.gemspec +0 -46
  45. data/specifications/jaro_winkler-1.5.4.gemspec +0 -44
  46. data/specifications/m-1.6.0.gemspec +0 -49
  47. data/specifications/metaclass-0.0.4.gemspec +0 -19
  48. data/specifications/method_source-1.0.0.gemspec +0 -35
  49. data/specifications/minitest-5.16.2.gemspec +0 -41
  50. data/specifications/mocha-0.13.3.gemspec +0 -43
  51. data/specifications/parallel-1.22.1.gemspec +0 -21
  52. data/specifications/parser-3.1.2.1.gemspec +0 -63
  53. data/specifications/power_assert-2.0.2.gemspec +0 -54
  54. data/specifications/pry-0.14.1.gemspec +0 -39
  55. data/specifications/pry-byebug-3.8.0.gemspec +0 -38
  56. data/specifications/public_suffix-5.0.0.gemspec +0 -24
  57. data/specifications/rack-3.0.0.gemspec +0 -45
  58. data/specifications/rainbow-3.1.1.gemspec +0 -33
  59. data/specifications/rake-13.0.6.gemspec +0 -26
  60. data/specifications/rexml-3.2.5.gemspec +0 -42
  61. data/specifications/rubocop-0.80.0.gemspec +0 -59
  62. data/specifications/ruby-progressbar-1.11.0.gemspec +0 -43
  63. data/specifications/test-unit-3.5.5.gemspec +0 -48
  64. data/specifications/unicode-display_width-1.6.1.gemspec +0 -39
  65. data/specifications/webmock-3.18.1.gemspec +0 -85
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a293840879ec1c2ca086127eab2b5dcd4b0ecae1e87d797ae164eb0f3f64bbe
4
- data.tar.gz: 9f08d57418affeee5e63778326921edbf50341dde0dc522679a0e54e5e7a6730
3
+ metadata.gz: 565bc669f0cfbbf63119c0784007bc598b2accd099b8e99fa47a483f65059a37
4
+ data.tar.gz: 970ef664eb0900f5c853bf860fdac430c2ac0abf14f72a1a8038b4dc2a0b94f9
5
5
  SHA512:
6
- metadata.gz: 2b1cade51de3cdf2694d5e4f7e98d8fbcd790087f411d1ff47fd31d10605a1aa4de675461a346c286d8aeb4318287a1d0c995546964b7b79f4b65bebcc04a4ae
7
- data.tar.gz: d763cb8b2c1e5a757d2866dd4c77bbbbe0f79c9ce53d08f65d39d2f48dd30edcfc175849907ea8b3d208e3d33f8e13cc64c35d922adb8092fe9d5db6bf13bcf7
6
+ metadata.gz: 9119aed8b6da8238051507afe712bcc74becda45041918030ead4f2d9ff79575d3ee180edd7c2191e808f63c17937d93563d2014ee710f107804bbf63bab6f86
7
+ data.tar.gz: 1f3c2dfe71df6ec9889798b787048ede14f541978d2ab915bc4c61c12373155d84bb6a2c9072024b2f286a90815d83e864b20df68b64b5a85819a944573d6c82
data/Gemfile CHANGED
@@ -9,16 +9,17 @@ group :development do
9
9
  gem 'mocha', '~> 0.13.2'
10
10
  gem 'rack', '>= 2.0.6'
11
11
  gem 'rake'
12
+ gem 'pry'
13
+ gem 'pry-byebug'
12
14
 
13
15
  gem 'test-unit'
14
16
 
15
17
  gem 'webmock', '>= 3.8.0'
16
18
 
17
19
  gem 'rubocop', '~> 1.43', require: false
20
+ gem 'simplecov', require: false, group: :test
18
21
 
19
22
  platforms :mri do
20
23
  gem 'byebug'
21
- gem 'pry'
22
- gem 'pry-byebug'
23
24
  end
24
25
  end
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2023] [Monri Payments]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1 +1,90 @@
1
- # monri-ruby
1
+ # Monri API Library for Ruby
2
+
3
+ This is the officially supported Ruby library for using Monri's APIs.
4
+
5
+ ## Integration
6
+ The library supports all APIs under the following services:
7
+
8
+ * [Payments API](https://docs.monri.com/documentation/api-documentation/api-v2/payment-api): Payments integration
9
+ * [Customers API](https://docs.monri.com/documentation/api-documentation/api-v2/customers-api): Customers integration
10
+ * [Payment Methods API](https://docs.monri.com/documentation/api-documentation/api-v2/payment-method-api): Payment methods integration
11
+
12
+ For more information, refer to our [documentation](https://docs.monri.com/)
13
+
14
+ ## Prerequisites
15
+ - Monri test account
16
+ - Merchant key + authenticity token
17
+ - Ruby >= 2.2
18
+
19
+ ## Installation
20
+
21
+ The sole dependency is faraday for HTTP communication. Run the following command to install faraday if you don't already have it:
22
+
23
+ ````bash
24
+ bundle install
25
+ ````
26
+
27
+ To validate functionality of client and run mock API tests use
28
+
29
+ ````bash
30
+ bundle install --with development
31
+ ````
32
+ and
33
+ ````bash
34
+ rspec
35
+ ````
36
+ ## Documentation
37
+
38
+ Follow the rest of our guides from the [documentation](https://docs.monri.com/) on how to use this library.
39
+
40
+ ## Using the library
41
+
42
+ ### General use with API key
43
+
44
+ ````bash
45
+ require 'monri-ruby-api-library'
46
+ ````
47
+ ````ruby
48
+ monri = Monri::Client.new
49
+
50
+ monri.api_key = 'AF5XXXXXXXXXXXXXXXXXXXX'
51
+
52
+ ````
53
+
54
+ - Create a Payment
55
+ ````ruby
56
+ response = monri.payments.create(
57
+ order_number: SecureRandom.hex,
58
+ amount: 10_00,
59
+ currency: 'EUR',
60
+ transaction_type: 'purchase'
61
+ )
62
+ # check if request failed
63
+ assert !response.failed?
64
+ # Get payment id
65
+ puts response.id
66
+ ````
67
+
68
+ ### Example integration
69
+
70
+ For a closer look at how our Ruby library works, clone our [example integration](https://github.com/MonriPayments/monri-ruby-example)
71
+
72
+ ### Running the tests
73
+ To run the tests use :
74
+ ````bash
75
+ bundle install --with development
76
+ ````
77
+
78
+
79
+
80
+ ## Support
81
+ If you have a feature request, or spotted a bug or a technical problem, [create an issue here](https://github.com/MonriPayments/monri-ruby/issues/new/choose).
82
+
83
+ For other questions, [contact our Support Team](https://www.monri.com).
84
+
85
+ ## Licence
86
+ This repository is available under the [MIT license](https://github.com/MonriPayments/monri-ruby/blob/master/LICENSE).
87
+
88
+ ## See also
89
+ * [Example integration](https://github.com/MonriPayments/monri-ruby-example)
90
+ * [Monri docs](https://docs.monri.com/)
data/{bin → exe}/byebug RENAMED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/jasminsuljic/.rbenv/versions/2.6.3/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/jasminsuljic/.rbenv/versions/2.6.3/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
data/{bin → exe}/m RENAMED
File without changes
data/{bin → exe}/pry RENAMED
File without changes
data/{bin → exe}/rake RENAMED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/jasminsuljic/.rbenv/versions/2.6.3/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  current directory: /Users/jasminsuljic/developing/monri/ruby-sdk-monri/gems/byebug-11.1.3/ext/byebug
2
- /Users/jasminsuljic/.rbenv/versions/2.6.3/bin/ruby -I /Users/jasminsuljic/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20221114-79509-1h8arsl.rb extconf.rb
2
+ /Users/jasminsuljic/.rbenv/versions/2.6.3/bin/ruby -I /Users/jasminsuljic/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20230111-7399-1izsgck.rb extconf.rb
3
3
  creating Makefile
4
4
 
5
5
  current directory: /Users/jasminsuljic/developing/monri/ruby-sdk-monri/gems/byebug-11.1.3/ext/byebug
@@ -1037,7 +1037,8 @@ threads.c:85:37: note: ')' token is here
1037
1037
  ^~~
1038
1038
  2 warnings generated.
1039
1039
  linking shared-object byebug/byebug.bundle
1040
+ ld: warning: -undefined dynamic_lookup may not work with chained fixups
1040
1041
 
1041
1042
  current directory: /Users/jasminsuljic/developing/monri/ruby-sdk-monri/gems/byebug-11.1.3/ext/byebug
1042
1043
  make "DESTDIR=" install
1043
- /usr/bin/install -c -m 0755 byebug.bundle ./.gem.20221114-79509-5pxjsw/byebug
1044
+ /usr/bin/install -c -m 0755 byebug.bundle ./.gem.20230111-7399-p10xqg/byebug
@@ -0,0 +1,37 @@
1
+ module Monri
2
+ class AccessTokens
3
+ class CreateResponse < Response
4
+
5
+ # @return [String]
6
+ def access_token
7
+ self[:access_token]
8
+ end
9
+
10
+ # @return [String]
11
+ def status
12
+ self[:status]
13
+ end
14
+
15
+ # @return [String]
16
+ def token_type
17
+ self[:token_type]
18
+ end
19
+
20
+ # @return [String]
21
+ def expires_in
22
+ self[:expires_in]
23
+ end
24
+
25
+ # @return [CreateResponse]
26
+ def self.create
27
+ raise ArgumentError, 'Provide a block' unless block_given?
28
+
29
+ begin
30
+ CreateResponse.new(yield)
31
+ rescue StandardError => e
32
+ CreateResponse.new(exception: e)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -7,20 +7,37 @@ module Monri
7
7
  # @return [Monri::HttpClient]
8
8
  attr_writer :http_client
9
9
 
10
+ # @param [Hash] options
11
+ # @return [Monri::AccessTokens::CreateResponse]
12
+ def create!(options)
13
+ rv = create(options)
14
+ if rv.failed?
15
+ #noinspection RubyMismatchedArgumentType
16
+ raise rv.exception
17
+ end
18
+ rv
19
+ end
20
+
21
+ # @param [Hash] options
22
+ # @return [Monri::AccessTokens::CreateResponse]
10
23
  def create(options)
11
- body = {
12
- client_id: config.authenticity_token,
13
- client_secret: config.merchant_key,
14
- grant_type: 'client_credentials',
15
- scopes: options.delete(:scopes) || []
16
- }
17
- response = @http_client.post('/v2/oauth', body)
18
- # TODO: do we set exception?
19
- if response.success?
20
- response.body
21
- else
22
- # TODO: handle this case
24
+ Monri::AccessTokens::CreateResponse.create do
25
+ body = {
26
+ client_id: config.authenticity_token,
27
+ client_secret: config.merchant_key,
28
+ grant_type: 'client_credentials',
29
+ scopes: options.delete(:scopes) || []
30
+ }
31
+ response = @http_client.post('/v2/oauth', body)
32
+ if response.failed?
33
+ raise response.exception
34
+ elsif response.success?
35
+ response.body
36
+ else
37
+ # TODO: handle this case
38
+ end
23
39
  end
40
+
24
41
  end
25
42
  end
26
43
  end
data/lib/monri/client.rb CHANGED
@@ -32,6 +32,24 @@ module Monri
32
32
  @payment_methods ||= create_payment_methods_api
33
33
  end
34
34
 
35
+ # @return [Monri::Tokens]
36
+ def tokens
37
+ @tokens ||= create_tokens_api
38
+ end
39
+
40
+ # @return [Monri::Transactions]
41
+ def transactions
42
+ @transactions ||= create_transactions_api
43
+ end
44
+
45
+ # @param [String] header
46
+ # @param [String] body
47
+ # @param [Hash] options
48
+ # @return [Hash{Symbol->String | TrueClass | FalseClass}]
49
+ def validate_callback(header, body, options = {})
50
+ create_validate_callback.validate(header, body, options)
51
+ end
52
+
35
53
  private
36
54
 
37
55
  def ensure_config_set!
@@ -41,14 +59,41 @@ module Monri
41
59
  end
42
60
 
43
61
  def http_client
44
- if @http_client == nil
45
- @http_client = Monri::HttpClient.new
46
- @http_client.config = @config
62
+ if defined?(@http_client) && @http_client != nil
63
+ return @http_client
47
64
  end
48
-
65
+ @http_client = Monri::HttpClient.new
66
+ @http_client.config = @config
49
67
  @http_client
50
68
  end
51
69
 
70
+ # @return [Monri::ValidateCallback]
71
+ def create_validate_callback
72
+ if @validate_callback_action != nil
73
+ return @validate_callback_action
74
+ end
75
+ ensure_config_set!
76
+ @validate_callback_action = Monri::ValidateCallback.new
77
+ @validate_callback_action.config = @config
78
+ @validate_callback_action
79
+ end
80
+
81
+ def create_tokens_api
82
+ ensure_config_set!
83
+ rv = Monri::Tokens.new
84
+ rv.config = @config
85
+ rv.http_client = http_client
86
+ rv
87
+ end
88
+
89
+ def create_transactions_api
90
+ ensure_config_set!
91
+ rv = Monri::Transactions.new
92
+ rv.config = @config
93
+ rv.http_client = http_client
94
+ rv
95
+ end
96
+
52
97
  def create_customers_api
53
98
  ensure_config_set!
54
99
  rv = Monri::Customers.new
@@ -0,0 +1,97 @@
1
+ module Monri
2
+ class Customers
3
+ class CreateResponse < Response
4
+
5
+ # @return [String]
6
+ def uuid
7
+ self[:uuid]
8
+ end
9
+
10
+ # @return [String]
11
+ def merchant_customer_id
12
+ self[:merchant_customer_id]
13
+ end
14
+
15
+ # @return [String]
16
+ def description
17
+ self[:description]
18
+ end
19
+
20
+ # @return [String]
21
+ def email
22
+ self[:email]
23
+ end
24
+
25
+ # @return [String]
26
+ def name
27
+ self[:name]
28
+ end
29
+
30
+ # @return [String]
31
+ def phone
32
+ self[:phone]
33
+ end
34
+
35
+ # @return [String]
36
+ def status
37
+ self[:status]
38
+ end
39
+
40
+ # @return [String]
41
+ def deleted
42
+ self[:deleted]
43
+ end
44
+
45
+ # @return [String]
46
+ def city
47
+ self[:city]
48
+ end
49
+
50
+ # @return [String]
51
+ def country
52
+ self[:country]
53
+ end
54
+
55
+ # @return [String]
56
+ def zip_code
57
+ self[:zip_code]
58
+ end
59
+
60
+ # @return [String]
61
+ def address
62
+ self[:address]
63
+ end
64
+
65
+ # @return [String]
66
+ def metadata
67
+ self[:metadata]
68
+ end
69
+
70
+ # @return [String]
71
+ def created_at
72
+ self[:created_at]
73
+ end
74
+
75
+ # @return [String]
76
+ def updated_at
77
+ self[:updated_at]
78
+ end
79
+
80
+ # @return [String]
81
+ def deleted_at
82
+ self[:deleted_at]
83
+ end
84
+
85
+ # @return [CreateResponse]
86
+ def self.create
87
+ raise ArgumentError, 'Provide a block' unless block_given?
88
+
89
+ begin
90
+ CreateResponse.new(yield)
91
+ rescue StandardError => e
92
+ CreateResponse.new(exception: e)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -9,16 +9,18 @@ module Monri
9
9
 
10
10
  # @param [Hash] options
11
11
  def create(options)
12
- access_token = @access_tokens.create(scopes: ['customers'])[:access_token]
13
- response = @http_client.post('/v2/customers', options, headers: { 'Authorization' => "Bearer #{access_token}" })
14
- if response.success?
15
- response.body
16
- else
17
- # TODO: handle this case
12
+ CreateResponse.create do
13
+ token_rv = @access_tokens.create!(scopes: ['customers'])
14
+ response = @http_client.post('/v2/customers', options, oauth: token_rv.access_token)
15
+
16
+ if response.failed?
17
+ raise response.exception
18
+ elsif response.success?
19
+ response.body
20
+ else
21
+ # TODO: handle this case
22
+ end
18
23
  end
19
- rescue StandardError => e
20
- # TODO: handle this case
21
- nil
22
24
  end
23
25
  end
24
26
  end
data/lib/monri/errors.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  module Monri
2
2
  module Errors
3
+
4
+ class InvalidArgumentsError < StandardError
5
+
6
+ end
7
+
3
8
  class HttpRequestError < StandardError
4
9
 
5
10
  # @return [Integer]
6
11
  attr_reader :code
12
+
7
13
  # @return [String, NilClass]
8
14
  attr_reader :body
9
15
 
@@ -16,7 +22,7 @@ module Monri
16
22
  super(message)
17
23
  @code = options.delete(:code) || 500
18
24
  @body = options.delete(:body)
19
- @headers = options.delete(:headers)
25
+ @headers = options.delete(:headers) || {}
20
26
  end
21
27
  end
22
28
  end
@@ -10,11 +10,7 @@ module Monri
10
10
  def get(url, options = {})
11
11
  # TODO: validate
12
12
  uri = build_url(url)
13
- req_headers = options.delete(:headers) || {}
14
- headers = {
15
- 'Accept': 'application/json',
16
- 'x-request-id': SecureRandom.hex
17
- }.merge(req_headers)
13
+ headers = prepare_headers(options)
18
14
  # Create the HTTP objects
19
15
  http = Net::HTTP.new(uri.host, uri.port)
20
16
  http.use_ssl = true
@@ -31,12 +27,7 @@ module Monri
31
27
  def post(url, body, options = {})
32
28
  # TODO: validate
33
29
  uri = build_url(url)
34
- req_headers = options.delete(:headers) || {}
35
- headers = {
36
- 'Content-Type': 'application/json',
37
- 'Accept': 'application/json',
38
- 'x-request-id': SecureRandom.hex
39
- }.merge(req_headers)
30
+ headers = prepare_headers(options)
40
31
  # Create the HTTP objects
41
32
  http = Net::HTTP.new(uri.host, uri.port)
42
33
  http.use_ssl = true
@@ -53,5 +44,25 @@ module Monri
53
44
  URI.parse("#{config.base_api_url}#{url}")
54
45
  end
55
46
 
47
+ private
48
+
49
+ # @param [Hash] options
50
+ # @return [Hash{Symbol->String}]
51
+ def prepare_headers(options)
52
+ req_headers = options.delete(:headers) || {}
53
+ headers = {
54
+ 'Content-Type': 'application/json',
55
+ 'Accept': 'application/json',
56
+ 'x-request-id': SecureRandom.hex
57
+ }
58
+
59
+ if options.has_key?(:oauth)
60
+ headers['Authorization'] = "Bearer #{options.delete(:oauth)}"
61
+ end
62
+
63
+ headers.merge!(req_headers)
64
+ headers
65
+ end
66
+
56
67
  end
57
68
  end
@@ -10,8 +10,8 @@ module Monri
10
10
 
11
11
  # @param [Hash] options
12
12
  def list(options = {})
13
- access_token = @access_tokens.create(scopes: ['payment-methods'])[:access_token]
14
- response = @http_client.get('/v2/payment-methods', headers: { 'Authorization' => "Bearer #{access_token}" })
13
+ access_token = @access_tokens.create!(scopes: ['payment-methods']).access_token
14
+ response = @http_client.get('/v2/payment-methods', oauth: access_token)
15
15
  if response.success?
16
16
  response.body
17
17
  else
@@ -0,0 +1,36 @@
1
+ module Monri
2
+ class Payments
3
+ class CreateResponse < Response
4
+
5
+ def approved?
6
+ status == 'approved'
7
+ end
8
+
9
+ # @return [String]
10
+ def status
11
+ self[:status]
12
+ end
13
+
14
+ # @return [String]
15
+ def id
16
+ self[:id]
17
+ end
18
+
19
+ # @return [String]
20
+ def client_secret
21
+ self[:client_secret]
22
+ end
23
+
24
+ # @return [CreateResponse]
25
+ def self.create
26
+ raise ArgumentError, 'Provide a block' unless block_given?
27
+
28
+ begin
29
+ CreateResponse.new(yield)
30
+ rescue StandardError => e
31
+ CreateResponse.new(exception: e)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module Monri
2
+ class Payments
3
+ class PaymentResult < Hash
4
+
5
+ # @param [Hash] params
6
+ def initialize(params)
7
+ merge!(params)
8
+ end
9
+
10
+ # @return [String]
11
+ def currency
12
+ self[:currency]
13
+ end
14
+
15
+ # @return [String]
16
+ def amount
17
+ self[:amount]
18
+ end
19
+
20
+ # @return [String]
21
+ def order_number
22
+ self[:order_number]
23
+ end
24
+
25
+ # @return [String]
26
+ def created_at
27
+ self[:created_at]
28
+ end
29
+
30
+ # @return [String]
31
+ def status
32
+ self[:status]
33
+ end
34
+
35
+ # @return [String]
36
+ def transaction_type
37
+ self[:transaction_type]
38
+ end
39
+
40
+ # @return [String]
41
+ def payment_method
42
+ self[:payment_method]
43
+ end
44
+
45
+ # @return [String]
46
+ def response_message
47
+ self[:response_message]
48
+ end
49
+
50
+ end
51
+ end
52
+ end