payture-ewallet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +51 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +184 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/payture/ewallet.rb +31 -0
- data/lib/payture/ewallet/client.rb +35 -0
- data/lib/payture/ewallet/config.rb +41 -0
- data/lib/payture/ewallet/error.rb +6 -0
- data/lib/payture/ewallet/make_pay_url.rb +15 -0
- data/lib/payture/ewallet/methods/base.rb +78 -0
- data/lib/payture/ewallet/methods/charge.rb +27 -0
- data/lib/payture/ewallet/methods/init.rb +37 -0
- data/lib/payture/ewallet/methods/pay_status.rb +26 -0
- data/lib/payture/ewallet/methods/refund.rb +29 -0
- data/lib/payture/ewallet/methods/unblock.rb +26 -0
- data/lib/payture/ewallet/responses/base.rb +34 -0
- data/lib/payture/ewallet/responses/charge.rb +11 -0
- data/lib/payture/ewallet/responses/init.rb +11 -0
- data/lib/payture/ewallet/responses/pay_status.rb +23 -0
- data/lib/payture/ewallet/responses/refund.rb +11 -0
- data/lib/payture/ewallet/version.rb +7 -0
- data/payture-ewallet.gemspec +37 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 839216877187482445448b7ee22d320cafc11478
|
4
|
+
data.tar.gz: b86b5590c806d0eb184144feaa00ed5382ee8f63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43e8c855dc8c82fa52110fc17b2ea3e1877bb1e6e1f8b40990fffbab1b75b09c7fc8dd8576470721b46e2dce411c65e91d4a6308f49e59292e6fef1dae6e1877
|
7
|
+
data.tar.gz: '0198c150786940cbc541bac07c401a97cfcd5d2ac9e5f7311e6f8edfa0a9a925f46612f79a51941996cced88e095e1cefb31779309efa9f7731443d7903a5fed'
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
Exclude:
|
6
|
+
- 'bin/*'
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/ClassAndModuleChildren:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/CyclomaticComplexity:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/PerceivedComplexity:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/GuardClause:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/IfUnlessModifier:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Metrics/LineLength:
|
30
|
+
Max: 80
|
31
|
+
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 15
|
34
|
+
|
35
|
+
Metrics/BlockLength:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/TrailingCommaInLiteral:
|
39
|
+
EnforcedStyleForMultiline: comma
|
40
|
+
|
41
|
+
Style/TrailingCommaInArguments:
|
42
|
+
EnforcedStyleForMultiline: comma
|
43
|
+
|
44
|
+
Layout/AlignParameters:
|
45
|
+
EnforcedStyle: with_fixed_indentation
|
46
|
+
|
47
|
+
Layout/MultilineMethodCallBraceLayout:
|
48
|
+
EnforcedStyle: new_line
|
49
|
+
|
50
|
+
Layout/MultilineMethodCallIndentation:
|
51
|
+
EnforcedStyle: indented
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at roman@alltmb.ru. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Roman Khrebtov
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# Payture::Ewallet
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/busfor/payture-ewallet.svg?branch=master)](https://travis-ci.org/busfor/payture-ewallet)
|
4
|
+
|
5
|
+
Simple Ruby wrapper for [Payture eWallet API](http://payture.com/integration/api/#ewallet_).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'payture-ewallet'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install payture-ewallet
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Create client
|
26
|
+
|
27
|
+
Required options are `host`, `merchant_id`, `password` and `currency`. You can get them from Payture tech support.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
payture = Payture::Ewallet.client(
|
31
|
+
host: 'sandbox.payture.com',
|
32
|
+
merchant_id: 'TestMerchant',
|
33
|
+
password: '12345',
|
34
|
+
currency: 'RUB',
|
35
|
+
)
|
36
|
+
```
|
37
|
+
|
38
|
+
You can also specify optional settings:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
payture = Payture::Ewallet.client(
|
42
|
+
host: 'sandbox.payture.com',
|
43
|
+
merchant_id: 'TestMerchant',
|
44
|
+
password: '12345',
|
45
|
+
currency: 'RUB',
|
46
|
+
timeout: 10,
|
47
|
+
open_timeout: 5,
|
48
|
+
logger: Logger.new,
|
49
|
+
)
|
50
|
+
```
|
51
|
+
|
52
|
+
### Init payment
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
response = payture.init(
|
56
|
+
# required
|
57
|
+
user_login: 'user@gmail.com',
|
58
|
+
user_password: '12345',
|
59
|
+
user_ip: '192.168.0.1',
|
60
|
+
order_id: '123',
|
61
|
+
amount: Money.new(100_00, 'RUB'),
|
62
|
+
# optional
|
63
|
+
user_phone: '+79201234567',
|
64
|
+
card_id: '123',
|
65
|
+
template: 'custom_tpl',
|
66
|
+
language: 'ru',
|
67
|
+
cheque: {
|
68
|
+
Positions: [...],
|
69
|
+
},
|
70
|
+
)
|
71
|
+
|
72
|
+
response.success?
|
73
|
+
# => true
|
74
|
+
response.session_id
|
75
|
+
# => "36a02faf-ae1b-443b-8fcc-188614390a91"
|
76
|
+
```
|
77
|
+
|
78
|
+
If response has error:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
response.error?
|
82
|
+
# => true
|
83
|
+
response.error_code
|
84
|
+
# => "DUPLICATE_ORDER_ID"
|
85
|
+
```
|
86
|
+
|
87
|
+
### Build payment URL
|
88
|
+
|
89
|
+
`session_id` contains value from previous step.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
payture.pay_url(session_id: '36a02faf-ae1b-443b-8fcc-188614390a91')
|
93
|
+
=> "https://sandbox.payture.com/vwapi/Pay?SessionId=36a02faf-ae1b-443b-8fcc-188614390a91"
|
94
|
+
```
|
95
|
+
|
96
|
+
You need to redirect user to this URL.
|
97
|
+
|
98
|
+
### Charge
|
99
|
+
|
100
|
+
After the user has paid, you can charge money from card:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
response = payture.charge(
|
104
|
+
# required
|
105
|
+
order_id: '123',
|
106
|
+
# optional
|
107
|
+
amount: Money.new(100_00, 'RUB'),
|
108
|
+
cheque: {
|
109
|
+
Positions: [...],
|
110
|
+
},
|
111
|
+
)
|
112
|
+
|
113
|
+
response.success?
|
114
|
+
# => true
|
115
|
+
response.charged_amount
|
116
|
+
# => #<Money fractional:10000 currency:RUB>
|
117
|
+
```
|
118
|
+
|
119
|
+
### Unblock
|
120
|
+
|
121
|
+
You also can unblock money if you don't need charge them:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
response = payture.unblock(
|
125
|
+
# required
|
126
|
+
order_id: '123',
|
127
|
+
amount: Money.new(100_00, 'RUB'),
|
128
|
+
)
|
129
|
+
|
130
|
+
response.success?
|
131
|
+
# => true
|
132
|
+
response.actual_amount
|
133
|
+
# => #<Money fractional:0 currency:RUB>
|
134
|
+
```
|
135
|
+
|
136
|
+
### Refund
|
137
|
+
|
138
|
+
If money already charged, you can refund them:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
response = payture.refund(
|
142
|
+
# required
|
143
|
+
order_id: '123',
|
144
|
+
amount: Money.new(80_00, 'RUB'),
|
145
|
+
# optional
|
146
|
+
cheque: {
|
147
|
+
Positions: [...],
|
148
|
+
},
|
149
|
+
)
|
150
|
+
|
151
|
+
response.success?
|
152
|
+
# => true
|
153
|
+
response.actual_amount
|
154
|
+
# => #<Money fractional:2000 currency:RUB>
|
155
|
+
```
|
156
|
+
|
157
|
+
### Payment status
|
158
|
+
|
159
|
+
For get actual payment status you can use method `pay_status`:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
response = payture.pay_status(order_id: '123')
|
163
|
+
|
164
|
+
response.success?
|
165
|
+
# => true
|
166
|
+
response.status
|
167
|
+
# => "Authorized"
|
168
|
+
response.amount
|
169
|
+
# => #<Money fractional:10000 currency:RUB>
|
170
|
+
response.card_id
|
171
|
+
# => "..."
|
172
|
+
response.user_login
|
173
|
+
# => "user@gmail.com"
|
174
|
+
```
|
175
|
+
|
176
|
+
## Contributing
|
177
|
+
|
178
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/busfor/payture-ewallet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
179
|
+
|
180
|
+
|
181
|
+
## License
|
182
|
+
|
183
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
184
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "payture/ewallet"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'multi_xml'
|
5
|
+
require 'money'
|
6
|
+
|
7
|
+
require 'payture/ewallet/version'
|
8
|
+
|
9
|
+
require 'payture/ewallet/client'
|
10
|
+
require 'payture/ewallet/config'
|
11
|
+
require 'payture/ewallet/error'
|
12
|
+
require 'payture/ewallet/make_pay_url'
|
13
|
+
require 'payture/ewallet/methods/base'
|
14
|
+
require 'payture/ewallet/methods/init'
|
15
|
+
require 'payture/ewallet/methods/charge'
|
16
|
+
require 'payture/ewallet/methods/unblock'
|
17
|
+
require 'payture/ewallet/methods/refund'
|
18
|
+
require 'payture/ewallet/methods/pay_status'
|
19
|
+
require 'payture/ewallet/responses/base'
|
20
|
+
require 'payture/ewallet/responses/init'
|
21
|
+
require 'payture/ewallet/responses/charge'
|
22
|
+
require 'payture/ewallet/responses/refund'
|
23
|
+
require 'payture/ewallet/responses/pay_status'
|
24
|
+
|
25
|
+
module Payture
|
26
|
+
module Ewallet
|
27
|
+
def self.client(**args)
|
28
|
+
Client.new(**args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
class Client
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(**options)
|
8
|
+
@config = Config.new(**options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def init(**args)
|
12
|
+
Methods::Init.new(config).call(**args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def pay_url(session_id:)
|
16
|
+
MakePayUrl.new(config).call(session_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def charge(**args)
|
20
|
+
Methods::Charge.new(config).call(**args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def unblock(**args)
|
24
|
+
Methods::Unblock.new(config).call(**args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def refund(**args)
|
28
|
+
Methods::Refund.new(config).call(**args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def pay_status(**args)
|
32
|
+
Methods::PayStatus.new(config).call(**args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
class Config
|
5
|
+
# required
|
6
|
+
attr_reader :host
|
7
|
+
attr_reader :merchant_id
|
8
|
+
attr_reader :password
|
9
|
+
attr_reader :currency
|
10
|
+
|
11
|
+
# optional
|
12
|
+
attr_reader :logger
|
13
|
+
attr_reader :timeout
|
14
|
+
attr_reader :open_timeout
|
15
|
+
|
16
|
+
def initialize(**options)
|
17
|
+
@host = options[:host]
|
18
|
+
@merchant_id = options[:merchant_id]
|
19
|
+
@password = options[:password]
|
20
|
+
@currency = options[:currency]
|
21
|
+
@logger = options[:logger]
|
22
|
+
@timeout = options[:timeout]
|
23
|
+
@open_timeout = options[:open_timeout]
|
24
|
+
|
25
|
+
check_required_fields!
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_url
|
29
|
+
"https://#{host}/vwapi"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def check_required_fields!
|
35
|
+
unless host && merchant_id && password && currency
|
36
|
+
raise ArgumentError,
|
37
|
+
'Required options: host, merchant_id, password, currency'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class Base
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(**args)
|
13
|
+
http_response = make_request(url, params(**args))
|
14
|
+
build_response(http_response)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def url
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def params
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def response_class
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
def make_request(url, params)
|
32
|
+
conn = Faraday.new do |builder|
|
33
|
+
builder.adapter Faraday.default_adapter
|
34
|
+
builder.request :url_encoded
|
35
|
+
builder.response(:logger, config.logger) if config.logger
|
36
|
+
end
|
37
|
+
conn.get(url, compact_hash(params)) do |req|
|
38
|
+
req.options.timeout = config.timeout if config.timeout
|
39
|
+
req.options.open_timeout = config.open_timeout if config.open_timeout
|
40
|
+
end
|
41
|
+
rescue Faraday::Error => e
|
42
|
+
raise Error, "#{e.class}: #{e.message}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_response(http_response)
|
46
|
+
unless http_response.success?
|
47
|
+
raise Error, "Invalid http status: #{http_response.status}"
|
48
|
+
end
|
49
|
+
|
50
|
+
body =
|
51
|
+
begin
|
52
|
+
MultiXml.parse(http_response.body).values.first
|
53
|
+
rescue MultiXml::ParseError => e
|
54
|
+
raise Error, "#{e.class}: #{e.message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
response_class.new(body, currency: config.currency)
|
58
|
+
end
|
59
|
+
|
60
|
+
def encoded_data(**params)
|
61
|
+
params_str = compact_hash(params).map { |k, v| "#{k}=#{v}" }.join(';')
|
62
|
+
CGI.escape(params_str)
|
63
|
+
end
|
64
|
+
|
65
|
+
def compact_hash(hash)
|
66
|
+
hash.select { |k, v| k && v }
|
67
|
+
end
|
68
|
+
|
69
|
+
def encoded_cheque(data)
|
70
|
+
return unless data
|
71
|
+
|
72
|
+
json_data = JSON.generate(data)
|
73
|
+
encoded_data = Base64.encode64(json_data)
|
74
|
+
encoded_data.tr("\n", '').tr('=', '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class Charge < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def url
|
9
|
+
"#{config.base_url}/Charge"
|
10
|
+
end
|
11
|
+
|
12
|
+
def params(order_id:, amount: nil, cheque: nil)
|
13
|
+
{
|
14
|
+
VWID: config.merchant_id,
|
15
|
+
Password: config.password,
|
16
|
+
OrderId: order_id,
|
17
|
+
Amount: amount&.cents,
|
18
|
+
Cheque: encoded_cheque(cheque),
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def response_class
|
23
|
+
Responses::Charge
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class Init < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def url
|
9
|
+
"#{config.base_url}/Init"
|
10
|
+
end
|
11
|
+
|
12
|
+
# rubocop:disable Metrics/ParameterLists, Metrics/LineLength, Metrics/MethodLength
|
13
|
+
def params(user_login:, user_password:, user_ip:, order_id:, amount:, **optional)
|
14
|
+
{
|
15
|
+
VWID: config.merchant_id,
|
16
|
+
DATA: encoded_data(
|
17
|
+
SessionType: 'Block',
|
18
|
+
VWUserLgn: user_login,
|
19
|
+
VWUserPsw: user_password,
|
20
|
+
IP: user_ip,
|
21
|
+
PhoneNumber: optional[:user_phone],
|
22
|
+
CardId: optional[:card_id],
|
23
|
+
OrderId: order_id,
|
24
|
+
Amount: amount.cents,
|
25
|
+
TemplateTag: optional[:template],
|
26
|
+
Language: optional[:language],
|
27
|
+
Cheque: encoded_cheque(optional[:cheque]),
|
28
|
+
),
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def response_class
|
33
|
+
Responses::Init
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class PayStatus < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def url
|
9
|
+
"#{config.base_url}/PayStatus"
|
10
|
+
end
|
11
|
+
|
12
|
+
def params(order_id:)
|
13
|
+
{
|
14
|
+
VWID: config.merchant_id,
|
15
|
+
DATA: encoded_data(
|
16
|
+
OrderId: order_id,
|
17
|
+
),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def response_class
|
22
|
+
Responses::PayStatus
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class Refund < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def url
|
9
|
+
"#{config.base_url}/Refund"
|
10
|
+
end
|
11
|
+
|
12
|
+
def params(order_id:, amount:, cheque: nil)
|
13
|
+
{
|
14
|
+
VWID: config.merchant_id,
|
15
|
+
DATA: encoded_data(
|
16
|
+
Password: config.password,
|
17
|
+
OrderId: order_id,
|
18
|
+
Amount: amount.cents,
|
19
|
+
Cheque: encoded_cheque(cheque),
|
20
|
+
),
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def response_class
|
25
|
+
Responses::Refund
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Methods
|
5
|
+
class Unblock < Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def url
|
9
|
+
"#{config.base_url}/Unblock"
|
10
|
+
end
|
11
|
+
|
12
|
+
def params(order_id:, amount:)
|
13
|
+
{
|
14
|
+
VWID: config.merchant_id,
|
15
|
+
Password: config.password,
|
16
|
+
OrderId: order_id,
|
17
|
+
Amount: amount.cents,
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def response_class
|
22
|
+
Responses::Refund
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Responses
|
5
|
+
class Base
|
6
|
+
attr_reader :body
|
7
|
+
|
8
|
+
def initialize(body, currency:)
|
9
|
+
@body = body
|
10
|
+
@currency = currency
|
11
|
+
end
|
12
|
+
|
13
|
+
def success?
|
14
|
+
body['Success'] == 'True'
|
15
|
+
end
|
16
|
+
|
17
|
+
def error?
|
18
|
+
!success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def error_code
|
22
|
+
body['ErrCode']
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def money(value)
|
28
|
+
return if value.nil? || value == ''
|
29
|
+
|
30
|
+
Money.new(value.to_i, @currency)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Payture::Ewallet
|
4
|
+
module Responses
|
5
|
+
class PayStatus < Base
|
6
|
+
def status
|
7
|
+
body['Status']
|
8
|
+
end
|
9
|
+
|
10
|
+
def amount
|
11
|
+
money(body['Amount'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def card_id
|
15
|
+
body['CardId']
|
16
|
+
end
|
17
|
+
|
18
|
+
def user_login
|
19
|
+
body['VWUserLgn']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'payture/ewallet/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'payture-ewallet'
|
9
|
+
spec.version = Payture::Ewallet::VERSION
|
10
|
+
spec.authors = ['Roman Khrebtov']
|
11
|
+
spec.email = ['roman@alltmb.ru']
|
12
|
+
|
13
|
+
spec.summary = 'Ruby wrapper for Payture eWallet API'
|
14
|
+
spec.description = 'Ruby wrapper for Payture eWallet API'
|
15
|
+
spec.homepage = 'https://github.com/busfor/payture-ewallet'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
26
|
+
spec.add_dependency 'money', '~> 6.9'
|
27
|
+
spec.add_dependency 'multi_xml', '~> 0.6'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.51'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.14'
|
35
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: payture-ewallet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman Khrebtov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: money
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_xml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.51'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.51'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.14'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.14'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.9'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.9'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
description: Ruby wrapper for Payture eWallet API
|
168
|
+
email:
|
169
|
+
- roman@alltmb.ru
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rubocop.yml"
|
176
|
+
- ".ruby-version"
|
177
|
+
- ".travis.yml"
|
178
|
+
- CODE_OF_CONDUCT.md
|
179
|
+
- Gemfile
|
180
|
+
- LICENSE.txt
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- bin/console
|
184
|
+
- bin/setup
|
185
|
+
- lib/payture/ewallet.rb
|
186
|
+
- lib/payture/ewallet/client.rb
|
187
|
+
- lib/payture/ewallet/config.rb
|
188
|
+
- lib/payture/ewallet/error.rb
|
189
|
+
- lib/payture/ewallet/make_pay_url.rb
|
190
|
+
- lib/payture/ewallet/methods/base.rb
|
191
|
+
- lib/payture/ewallet/methods/charge.rb
|
192
|
+
- lib/payture/ewallet/methods/init.rb
|
193
|
+
- lib/payture/ewallet/methods/pay_status.rb
|
194
|
+
- lib/payture/ewallet/methods/refund.rb
|
195
|
+
- lib/payture/ewallet/methods/unblock.rb
|
196
|
+
- lib/payture/ewallet/responses/base.rb
|
197
|
+
- lib/payture/ewallet/responses/charge.rb
|
198
|
+
- lib/payture/ewallet/responses/init.rb
|
199
|
+
- lib/payture/ewallet/responses/pay_status.rb
|
200
|
+
- lib/payture/ewallet/responses/refund.rb
|
201
|
+
- lib/payture/ewallet/version.rb
|
202
|
+
- payture-ewallet.gemspec
|
203
|
+
homepage: https://github.com/busfor/payture-ewallet
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
metadata: {}
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubyforge_project:
|
223
|
+
rubygems_version: 2.5.2
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: Ruby wrapper for Payture eWallet API
|
227
|
+
test_files: []
|