portmone 0.0.8 → 0.0.9

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
- SHA1:
3
- metadata.gz: 23038c64f8880639aca64c4e752025cad7ad925a
4
- data.tar.gz: 247215a59bac78eaa85e662ecf5736c6e1bddcf6
2
+ SHA256:
3
+ metadata.gz: 9a1600b423ce55672d03a7906e474823f73eeb0232e8fe08d9bec074c989e585
4
+ data.tar.gz: 3648a02b61846f275ae160acd9767017bed22cca5bf243915285a1a433d6b3c0
5
5
  SHA512:
6
- metadata.gz: 94c9f01dffce261d68d1f44888c576ed2d3022386575000209dcc1250edd07bd3865716dd2d0864dd8705916f1c0d3269e4e32ffe2f682344c590498e8e8b045
7
- data.tar.gz: c8d8f71f58f9e39cfdc764c03e005b526d6f2ca3c18d08bb26311eaa062345e66d7042d1a3ee0df40152fbac7540e6c35ed969d393b5db78efe2f25207049bdb
6
+ metadata.gz: 57b0d6f7188867345cb64c9069b931a86f53ee7b9527c0642d1d1c1a5c26f4d05e0cff30826ab973b67611342e23830eb4925afb55e2932f03b54026387d83f8
7
+ data.tar.gz: 177baf7c0a83e4bac731e4bbdfc8e52010bddceb1b1d467b77ee4441fc5d63e4cf4a835b43f28d799b908a60b36d5b358d927d17b30eb529bd32a7193322754e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- portmone (0.0.8)
4
+ portmone (0.0.9)
5
5
  activesupport
6
6
  faraday (~> 0.9)
7
7
  money (~> 6.0)
@@ -19,22 +19,22 @@ GEM
19
19
  public_suffix (>= 2.0.2, < 4.0)
20
20
  ast (2.3.0)
21
21
  coderay (1.1.2)
22
- concurrent-ruby (1.1.4)
22
+ concurrent-ruby (1.1.5)
23
23
  crack (0.4.3)
24
24
  safe_yaml (~> 1.0.0)
25
25
  docile (1.1.5)
26
26
  faraday (0.15.4)
27
27
  multipart-post (>= 1.2, < 3)
28
28
  hashdiff (0.3.7)
29
- i18n (1.5.3)
29
+ i18n (1.6.0)
30
30
  concurrent-ruby (~> 1.0)
31
31
  json (2.1.0)
32
32
  method_source (0.9.0)
33
33
  minitest (5.11.3)
34
- money (6.13.2)
34
+ money (6.13.4)
35
35
  i18n (>= 0.6.4, <= 2)
36
36
  multi_xml (0.6.0)
37
- multipart-post (2.0.0)
37
+ multipart-post (2.1.1)
38
38
  parallel (1.12.0)
39
39
  parser (2.4.0.0)
40
40
  ast (~> 2.2)
@@ -13,4 +13,5 @@ require 'portmone/responses/base_response'
13
13
  require 'portmone/responses/generate_url'
14
14
  require 'portmone/responses/order_status'
15
15
  require 'portmone/responses/refund_order_status'
16
+ require 'portmone/responses/mobile_pay_response'
16
17
  require 'portmone/client'
@@ -2,7 +2,8 @@ module Portmone
2
2
  class Error < StandardError; end
3
3
 
4
4
  class Client
5
- BASE_URL = 'https://www.portmone.com.ua/gateway/'.freeze
5
+ API_URL = 'https://www.portmone.com.ua/gateway/'.freeze
6
+ MOBILE_API_URL = 'https://www.portmone.com.ua/r3/api/gateway/'.freeze
6
7
 
7
8
  def initialize(payee_id:,
8
9
  login:,
@@ -60,7 +61,46 @@ module Portmone
60
61
  )
61
62
  end
62
63
 
63
- private
64
+ def google_pay(token:, amount:, order_id:, currency:)
65
+ google_pay_params = {
66
+ gPayToken: token,
67
+ }
68
+ mobile_pay('GPay', google_pay_params, amount: amount, order_id: order_id, currency: currency)
69
+ end
70
+
71
+ def apple_pay(token:, amount:, order_id:, currency:, merchant_name:)
72
+ apple_pay_params = {
73
+ aPayMerchantName: merchant_name,
74
+ paymentData: token,
75
+ }
76
+ mobile_pay('APay', apple_pay_params, amount: amount, order_id: order_id, currency: currency)
77
+ end
78
+
79
+ private
80
+
81
+ def mobile_pay(payment_method, payment_system_params, amount:, order_id:, currency:)
82
+ order_params = {
83
+ billAmount: amount,
84
+ shopOrderNumber: order_id,
85
+ billCurrency: currency,
86
+ }
87
+
88
+ data = payment_system_params
89
+ .merge(order_params)
90
+ .merge(base_params)
91
+ .keep_if { |_, v| v.present? }
92
+ params = { params: { data: data }, method: payment_method, id: 1 }
93
+
94
+ make_json_request(MOBILE_API_URL, params, Portmone::Responses::MobilePayResponse)
95
+ end
96
+
97
+ def base_params
98
+ {
99
+ login: @login,
100
+ password: @password,
101
+ payeeId: @payee_id,
102
+ }
103
+ end
64
104
 
65
105
  # может возвращать как отдельный заказ по id, так и все заказы с опр. статусом или в опр. временном диапазоне
66
106
  def generic_report(shop_order_number: nil, status: nil, start_date: nil, end_date: nil)
@@ -104,16 +144,37 @@ module Portmone
104
144
 
105
145
  def send_request(**data)
106
146
  response_class = data.delete(:response_class)
107
- response = http_client.post(BASE_URL) do |req|
108
- req.body = data.merge(
109
- payee_id: @payee_id,
110
- lang: @locale,
111
- ).delete_if { |_, v| v.nil? }
147
+ payload = compact(data.merge(mandatory_params))
148
+
149
+ response = http_client.post(API_URL) do |req|
150
+ req.body = payload
151
+ end
152
+
153
+ response_class.new(response, currency: @currency, timezone: @timezone)
154
+ end
155
+
156
+ def make_json_request(url, params, response_class)
157
+ conn = Faraday.new(url: url) do |builder|
158
+ builder.response(:detailed_logger, @logger)
159
+ builder.adapter Faraday.default_adapter
160
+ end
161
+
162
+ response = conn.post do |request|
163
+ request.headers['Content-Type'] = 'application/json'
164
+ request.body = params.to_json
112
165
  end
113
166
 
114
167
  response_class.new(response, currency: @currency, timezone: @timezone)
115
168
  end
116
169
 
170
+ def mandatory_params
171
+ { payee_id: @payee_id, lang: @locale }
172
+ end
173
+
174
+ def compact(**params)
175
+ params.delete_if { |_, v| v.nil? }
176
+ end
177
+
117
178
  def http_client
118
179
  @http_client ||= Faraday.new do |builder|
119
180
  builder.request :url_encoded
@@ -0,0 +1,28 @@
1
+ class Portmone::Responses::MobilePayResponse
2
+ SUCCESS_STATUS = 'PAYED'.freeze
3
+
4
+ attr_reader :response
5
+
6
+ def initialize(faraday_response, currency:, timezone:)
7
+ @response = faraday_response
8
+ @response_body = JSON.parse(@response.body)
9
+ @currency = currency
10
+ @timezone = timezone
11
+ end
12
+
13
+ def http_status
14
+ response.status
15
+ end
16
+
17
+ def success?
18
+ @response_body['result']['status'] == SUCCESS_STATUS
19
+ end
20
+
21
+ def error_code
22
+ @response_body['result']['errorCode']
23
+ end
24
+
25
+ def error_description
26
+ @response_body['result']['error']
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Portmone
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portmone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Sviridov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-11 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,6 +192,7 @@ files:
192
192
  - lib/portmone/client.rb
193
193
  - lib/portmone/responses/base_response.rb
194
194
  - lib/portmone/responses/generate_url.rb
195
+ - lib/portmone/responses/mobile_pay_response.rb
195
196
  - lib/portmone/responses/order_status.rb
196
197
  - lib/portmone/responses/refund_order_status.rb
197
198
  - lib/portmone/transaction.rb
@@ -216,8 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  - !ruby/object:Gem::Version
217
218
  version: '0'
218
219
  requirements: []
219
- rubyforge_project:
220
- rubygems_version: 2.5.2
220
+ rubygems_version: 3.0.3
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: Ruby wrapper for Portmone payment system API