monri 0.2.0 → 0.3.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/README.md +0 -87
- data/lib/monri/transactions.rb +60 -1
- data/monri.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e15c7a6d551450e21cfb4d08eab441e091a8cf217e89e7cc033d864a0daf7a6e
|
4
|
+
data.tar.gz: b08f957de769d5a921e0e47c17b79f24409db978e36c8a91bdb264aaaf0b7d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c820b695a2f03781c96bf20d07966f6007bba5e7e6a40d9ffe6fc20d9d2799ac7734fc9948fe6dc43054cbab099aec7418d36c1877f608d727372759b935b15f
|
7
|
+
data.tar.gz: f134006d1737b1f4b03996155cd97ef2a693eeafa82906113084f48ce59bb7abaeb8eaed1b2e64ab34573c56ceb42b9c5e384d65de1bab36c84fca170ab58ad3
|
data/README.md
CHANGED
@@ -1,90 +1,3 @@
|
|
1
1
|
# Monri API Library for Ruby
|
2
2
|
|
3
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/lib/monri/transactions.rb
CHANGED
@@ -24,6 +24,12 @@ module Monri
|
|
24
24
|
:language
|
25
25
|
].freeze
|
26
26
|
|
27
|
+
REQUIRED_TRX_MANAGEMENT_FIELDS = [
|
28
|
+
:amount,
|
29
|
+
:currency,
|
30
|
+
:order_number
|
31
|
+
].freeze
|
32
|
+
|
27
33
|
# @param [Hash] params
|
28
34
|
# @return [Monri::Transactions::TransactionResponse]
|
29
35
|
def transaction(params)
|
@@ -49,10 +55,63 @@ module Monri
|
|
49
55
|
elsif rv.success?
|
50
56
|
rv.body
|
51
57
|
else
|
52
|
-
|
58
|
+
raise "Unhandled state, exception=#{rv.exception}, failed=#{rv.failed?}, success=#{rv.success?}"
|
53
59
|
end
|
54
60
|
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def void(params)
|
64
|
+
unless params.is_a?(Hash)
|
65
|
+
raise Monri::Errors::InvalidArgumentsError.new('First parameter - params, should be a Hash')
|
66
|
+
end
|
67
|
+
trx_management(params.merge(transaction_type: 'void'))
|
68
|
+
end
|
69
|
+
|
70
|
+
def refund(params)
|
71
|
+
unless params.is_a?(Hash)
|
72
|
+
raise Monri::Errors::InvalidArgumentsError.new('First parameter - params, should be a Hash')
|
73
|
+
end
|
74
|
+
trx_management(params.merge(transaction_type: 'refund'))
|
75
|
+
end
|
76
|
+
|
77
|
+
def capture(params)
|
78
|
+
unless params.is_a?(Hash)
|
79
|
+
raise Monri::Errors::InvalidArgumentsError.new('First parameter - params, should be a Hash')
|
80
|
+
end
|
81
|
+
trx_management(params.merge(transaction_type: 'capture'))
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# @param [Hash] params
|
87
|
+
# @return [Monri::Transactions::TransactionResponse]
|
88
|
+
def trx_management(params)
|
89
|
+
TransactionResponse.create do
|
90
|
+
unless params.is_a?(Hash)
|
91
|
+
raise Monri::Errors::InvalidArgumentsError.new('First parameter - params, should be a Hash')
|
92
|
+
end
|
93
|
+
|
94
|
+
missing_keys = REQUIRED_TRX_MANAGEMENT_FIELDS.reject { |k| params.has_key?(k) }
|
95
|
+
if missing_keys.length > 0
|
96
|
+
raise Monri::Errors::InvalidArgumentsError.new("Missing required keys=#{missing_keys.join(', ')}")
|
97
|
+
end
|
98
|
+
|
99
|
+
params[:authenticity_token] = @config.authenticity_token
|
100
|
+
digest_parts = [@config.merchant_key, params[:order_number], params[:amount], params[:currency]]
|
101
|
+
params[:digest] = Digest::SHA512.hexdigest(digest_parts.join)
|
55
102
|
|
103
|
+
req = { transaction: params }
|
104
|
+
|
105
|
+
rv = @http_client.post('/v2/trx-management', req)
|
106
|
+
if rv.failed?
|
107
|
+
raise rv.exception
|
108
|
+
elsif rv.success?
|
109
|
+
rv.body
|
110
|
+
else
|
111
|
+
raise "Unhandled state, exception=#{rv.exception}, failed=#{rv.failed?}, success=#{rv.success?}"
|
112
|
+
end
|
113
|
+
end
|
56
114
|
end
|
115
|
+
|
57
116
|
end
|
58
117
|
end
|
data/monri.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'monri'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.3.0'
|
6
6
|
s.required_ruby_version = '>= 2.3.0'
|
7
7
|
s.summary = 'Ruby bindings for the Monri API'
|
8
8
|
s.description = 'Your voyage through payment experience starts here. Learn more about how Monri helps to power your business.' \
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Monri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Your voyage through payment experience starts here. Learn more about
|
14
14
|
how Monri helps to power your business.See https://monri.com for details.
|