mobilepay 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bab5344a65d680df787fc9f5b05c9d46b0e7a07
4
- data.tar.gz: d634adad086b8fec11b7ee7321fc3e237bca86b1
3
+ metadata.gz: ab2ecb74f00ea4ee578b918b4cf847729883292b
4
+ data.tar.gz: 78c3295ec71aa6a5e3d38eda4e6098e1e10cb173
5
5
  SHA512:
6
- metadata.gz: 336d31e06c454f751bb83b660f5d75dbaa9d2d7e1e742792606808888e9b186687a7e927f8c1374689060cafdf471856a7f1d51480de2ef3c3425b77f7645c66
7
- data.tar.gz: 5ac2ffd3fc2fcc26dabfc0df7a8892d0157a1b54c85951546e02285450c96b1515d821f0adc7ece59cccd54ed9fb2b7352d6f50d30e11e7579bbc5ca3e6ca5d3
6
+ metadata.gz: 2a1c19eb27c62f2d2eaa21a452d5da47686b417acbf33ed6d7302733d847934860fc6706216b7cfb2cf52ce9222391d63f6a729d844b9d0db4f823a37e437509
7
+ data.tar.gz: a6be43d4de495cb1397ed951353a4044ca6006e907edbe3a16ac8b86b8c6ee776b78d0da3937e042df2cf551e469a40d5c15b82d8c5863a7e0593a7fe4fc2793
data/README.md CHANGED
@@ -20,11 +20,203 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Create MobilePay object.
23
+ ### Create Security object
24
24
 
25
25
  ```ruby
26
26
  require 'mobilepay'
27
- translator = MobilePay::Client.new('merchant_id', 'subscription_key')
27
+ security = Mobilepay::Security.new subscription_key: 'subscription_key'
28
+ ```
29
+ merchant_id - Merchant ID, required
30
+
31
+ ### Create MobilePay object
32
+
33
+ ```ruby
34
+ require 'mobilepay'
35
+ client = Mobilepay::Client.new merchant_id: 'merchant_id', subscription_key: 'subscription_key'
36
+ ```
37
+ subscription_key - Subscription Key for MobilePay, required
38
+ merchant_id - Merchant ID, required
39
+
40
+ ### Public Key
41
+
42
+ Request for getting MobilePay's public key to use when signing up new merchants.
43
+
44
+ ```ruby
45
+ security.public_key
46
+ ```
47
+
48
+ #### Responces
49
+
50
+ ```ruby
51
+ {
52
+ "PublicKey": "-----BEGIN CERTIFICATE-----certificate body-----END CERTIFICATE-----"
53
+ }
54
+ ```
55
+
56
+ ### Payment Status
57
+
58
+ Request for getting the status of a given order is #payment_status.
59
+
60
+ ```ruby
61
+ client.payment_status order_id: '111'
62
+ ```
63
+ order_id - Order ID, required
64
+
65
+ #### Responces
66
+
67
+ ```ruby
68
+ {
69
+ "LatestPaymentStatus": "Captured",
70
+ "TransactionId": "61872634691623746",
71
+ "OriginalAmount": 123.45
72
+ }
73
+ ```
74
+
75
+ ### Payment Transactions
76
+
77
+ Request for getting the transactions for a given order is #payment_transactions.
78
+
79
+ ```ruby
80
+ client.payment_transactions order_id: '111'
81
+ ```
82
+ order_id - Order ID, required
83
+
84
+ #### Responces
85
+
86
+ ```ruby
87
+ [
88
+ {
89
+ "TimeStamp": "2016-04-08T07:45:36.533Z",
90
+ "PaymentStatus": "Captured",
91
+ "TransactionId": "61872634691623746",
92
+ "Amount": 11.5
93
+ },
94
+ {
95
+ "TimeStamp": "2016-04-09T07:45:36.672Z",
96
+ "PaymentStatus": "Cancelled",
97
+ "TransactionId": "61872634691623799",
98
+ "Amount": 18.9
99
+ }
100
+ ]
101
+ ```
102
+
103
+ ### Reservations
104
+
105
+ Request for getting the reservations for a particular date/time interval, and alternatively also for a specific customer is #reservations.
106
+
107
+ ```ruby
108
+ client.reservations datetime_from: 'YYYY-MM-DDTHH_MM', datetime_to: 'YYYY-MM-DDTHH_MM', customer_id: '111'
109
+ ```
110
+ datetime_from - Date from, required
111
+ datetime_to - Date to, required
112
+ customer_id - Customer ID, optional
113
+
114
+ #### Responces
115
+
116
+ ```ruby
117
+ [
118
+ {
119
+ "TimeStamp": "2016-04-08T07_45_36Z",
120
+ "OrderId": "DB TESTING 2015060908",
121
+ "TransactionId": "61872634691623746",
122
+ "Amount": 100.25,
123
+ "CaptureType": "Full"
124
+ },
125
+ {
126
+ "TimeStamp": "2016-04-09T07_45_36Z",
127
+ "OrderId": "DB TESTING 2015060908",
128
+ "TransactionId": "61872634691623799"
129
+ "Amount": 100.25,
130
+ "CaptureType": "Partial"
131
+ }
132
+ ]
133
+ ```
134
+
135
+ ### Refund Amount
136
+
137
+ Request for refunding the transaction amount, either the entire amount or just a part of the amount is #refund_amount.
138
+
139
+ ```ruby
140
+ client.refund_amount order_id: '111', body: '{}'
141
+ ```
142
+ order_id - Order ID, required
143
+ body - text body for request, optional
144
+
145
+ #### Request body examples
146
+
147
+ ```ruby
148
+ {
149
+ "Amount" : 100.00,
150
+ "BulkRef" : "123456789"
151
+ }
152
+
153
+ {
154
+ "Amount" : 100.00
155
+ }
156
+
157
+ {
158
+ }
159
+ ```
160
+
161
+ #### Responces
162
+
163
+ ```ruby
164
+ {
165
+ "TransactionId" : "61872634691623757",
166
+ "OriginalTransactionId" : "61872634691623746",
167
+ "Remainder" : 20.00
168
+ }
169
+ ```
170
+
171
+ ### Capture Amount
172
+
173
+ Request for capturing the transaction, i.e. carries out the actual payment is #capture_amount.
174
+
175
+ ```ruby
176
+ client.capture_amount order_id: '111', body: '{}'
177
+ ```
178
+ order_id - Order ID, required
179
+ body - text body for request, optional
180
+
181
+ #### Request body examples
182
+
183
+ ```ruby
184
+ {
185
+ "Amount" : 100.00,
186
+ "BulkRef" : "123456789"
187
+ }
188
+
189
+ {
190
+ "Amount" : 100.00
191
+ }
192
+
193
+ {
194
+ }
195
+ ```
196
+
197
+ #### Responces
198
+
199
+ ```ruby
200
+ {
201
+ "TransactionId" : "61872634691623746"
202
+ }
203
+ ```
204
+
205
+ ### Cancel Reservation
206
+
207
+ Request for canceling previously made reservations is #cancel_reservation.
208
+
209
+ ```ruby
210
+ client.cancel_reservation order_id: '111'
211
+ ```
212
+ order_id - Order ID, required
213
+
214
+ #### Responces
215
+
216
+ ```ruby
217
+ {
218
+ "TransactionId" : "61872634691623746"
219
+ }
28
220
  ```
29
221
 
30
222
  ## Contributing
data/lib/mobilepay.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'mobilepay/version'
1
+ require_relative 'mobilepay/version'
2
+ require_relative 'mobilepay/client'
3
+ require_relative 'mobilepay/security'
2
4
 
3
5
  module Mobilepay
4
6
  end
@@ -0,0 +1,55 @@
1
+ require 'json'
2
+ require_relative 'client/payment_status'
3
+ require_relative 'client/payment_transactions'
4
+ require_relative 'client/reservations'
5
+ require_relative 'client/refund_amount'
6
+ require_relative 'client/capture_amount'
7
+ require_relative 'client/cancel_reservation'
8
+ require_relative 'requests'
9
+
10
+ module Mobilepay
11
+ class Client
12
+ include Mobilepay::Client::PaymentStatus
13
+ include Mobilepay::Client::PaymentTransactions
14
+ include Mobilepay::Client::Reservations
15
+ include Mobilepay::Client::RefundAmount
16
+ include Mobilepay::Client::CaptureAmount
17
+ include Mobilepay::Client::CancelReservation
18
+ include Mobilepay::Requests
19
+
20
+ class MobilePayFailure < StandardError; end
21
+
22
+ attr_reader :merchant_id, :subscription_key, :base_uri
23
+
24
+ def initialize(args = {})
25
+ @merchant_id = args[:merchant_id] || ''
26
+ @subscription_key = args[:subscription_key] || ''
27
+ @base_uri = 'https://api.mobeco.dk/appswitch/api/v1'
28
+ end
29
+
30
+ private
31
+
32
+ def call(req, address, args = {})
33
+ response = case req
34
+ when :get, :put, :delete then http_request(req, address, args)
35
+ else raise MobilePayFailure, 'Undefined type for call'
36
+ end
37
+ check_response(response)
38
+ response
39
+ end
40
+
41
+ def check_response(response)
42
+ if response.code != '200'
43
+ raise MobilePayFailure, JSON.parse(response.body)['message']
44
+ end
45
+ end
46
+
47
+ def check_args(args)
48
+ args.each do |arg_name, value|
49
+ if value.nil? || !value.is_a?(String)
50
+ raise MobilePayFailure, "Invalid argument '#{arg_name}', must be string"
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ module Mobilepay
2
+ class Client
3
+ module CancelReservation
4
+
5
+ # Reservations_CancelReservation
6
+ # Cancels a specific reservation
7
+ def cancel_reservation(args = {})
8
+ check_args(order_id: args[:order_id])
9
+ response = call(:delete, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: '{}' })
10
+ JSON.parse(response.body)
11
+ rescue MobilePayFailure => ex
12
+ return { error: ex.message }
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Mobilepay
2
+ class Client
3
+ module CaptureAmount
4
+
5
+ # Reservations_CaptureAmount
6
+ # Captures a previously reserved amount, either in full or partially
7
+ def capture_amount(args = {})
8
+ check_args(order_id: args[:order_id])
9
+ response = call(:put, "/reservations/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: args[:body] || '{}' })
10
+ JSON.parse(response.body)
11
+ rescue MobilePayFailure => ex
12
+ return { error: ex.message }
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Mobilepay
2
+ class Client
3
+ module PaymentStatus
4
+
5
+ # Merchants_GetPaymentStatus
6
+ # Gets the status of a given order
7
+ def payment_status(args = {})
8
+ check_args(order_id: args[:order_id])
9
+ response = call(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: '{}' })
10
+ JSON.parse(response.body)
11
+ rescue MobilePayFailure => ex
12
+ return { error: ex.message }
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Mobilepay
2
+ class Client
3
+ module PaymentTransactions
4
+
5
+ # Merchants_GetPaymentTransactions
6
+ # Gets the transactions for a given order
7
+ def payment_transactions(args = {})
8
+ check_args(order_id: args[:order_id])
9
+ response = call(:get, "/merchants/#{merchant_id}/orders/#{args[:order_id]}/transactions", { body: '{}' })
10
+ JSON.parse(response.body)
11
+ rescue MobilePayFailure => ex
12
+ return { error: ex.message }
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Mobilepay
2
+ class Client
3
+ module RefundAmount
4
+
5
+ # Merchants_RefundAmount
6
+ # Refunds an amount to the customer based on an order id
7
+ def refund_amount(args = {})
8
+ check_args(order_id: args[:order_id])
9
+ response = call(:put, "/merchants/#{merchant_id}/orders/#{args[:order_id]}", { body: args[:body] || '{}' })
10
+ JSON.parse(response.body)
11
+ rescue MobilePayFailure => ex
12
+ return { error: ex.message }
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Mobilepay
2
+ class Client
3
+ module Reservations
4
+
5
+ # Reservations_GetReservations
6
+ # Get the reservations for a particular date/time interval, and alternatively also for a specific customer
7
+ def reservations(args = {})
8
+ check_args(datetime_from: args[:datetime_from], datetime_to: args[:datetime_to])
9
+ address = "/reservations/merchants/#{merchant_id}/#{args[:datetime_from]}/#{args[:datetime_to]}"
10
+ address += "?customerId=#{args[:customer_id]}" if args[:customer_id]
11
+ response = call(:get, address, { body: '{}' })
12
+ JSON.parse(response.body)
13
+ rescue MobilePayFailure => ex
14
+ return { error: ex.message }
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+
3
+ module Mobilepay
4
+ module Requests
5
+
6
+ private
7
+
8
+ def http_request(req, address, args = {})
9
+ uri = generate_uri(address)
10
+ req = generate_request(req, uri)
11
+ req = generate_headers(req, args[:body])
12
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
13
+ end
14
+
15
+ def generate_uri(address = '')
16
+ URI("#{base_uri}#{address}")
17
+ end
18
+
19
+ def generate_request(req, uri)
20
+ case req
21
+ when :get then Net::HTTP::Get.new(uri)
22
+ when :put then Net::HTTP::Put.new(uri)
23
+ when :delete then Net::HTTP::Delete.new(uri)
24
+ end
25
+ end
26
+
27
+ def generate_headers(req, body)
28
+ req['Content-Type'] = 'application/json'
29
+ req['Ocp-Apim-Subscription-Key'] = subscription_key
30
+ req.body = body
31
+ req
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ require_relative 'security/public_key'
3
+ require_relative 'requests'
4
+
5
+ module Mobilepay
6
+ class Security
7
+ include Mobilepay::Security::PublicKey
8
+ include Mobilepay::Requests
9
+
10
+ class SecurityFailure < StandardError; end
11
+
12
+ attr_reader :subscription_key, :base_uri
13
+
14
+ def initialize(args = {})
15
+ @subscription_key = args[:subscription_key] || ''
16
+ @base_uri = 'https://api.mobeco.dk/merchantsecurity/api'
17
+ end
18
+
19
+ private
20
+
21
+ def call
22
+ response = http_request(:get, '/publickey')
23
+ check_response(response)
24
+ response
25
+ end
26
+
27
+ def check_response(response)
28
+ if response.code != '200'
29
+ raise SecurityFailure, JSON.parse(response.body)['message']
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module Mobilepay
2
+ class Security
3
+ module PublicKey
4
+
5
+ # Secutiry_PublicKey
6
+ # Get MobilePay's public key to use when signing up new merchants
7
+ def public_key
8
+ response = call
9
+ JSON.parse(response.body)
10
+ rescue SecurityFailure => ex
11
+ return { error: ex.message }
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Mobilepay
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilepay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Bogdanov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-20 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,16 @@ files:
69
69
  - bin/console
70
70
  - bin/setup
71
71
  - lib/mobilepay.rb
72
+ - lib/mobilepay/client.rb
73
+ - lib/mobilepay/client/cancel_reservation.rb
74
+ - lib/mobilepay/client/capture_amount.rb
75
+ - lib/mobilepay/client/payment_status.rb
76
+ - lib/mobilepay/client/payment_transactions.rb
77
+ - lib/mobilepay/client/refund_amount.rb
78
+ - lib/mobilepay/client/reservations.rb
79
+ - lib/mobilepay/requests.rb
80
+ - lib/mobilepay/security.rb
81
+ - lib/mobilepay/security/public_key.rb
72
82
  - lib/mobilepay/version.rb
73
83
  - mobilepay.gemspec
74
84
  homepage: https://github.com/kortirso/mobilepay