assist-ruby-sdk 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +158 -0
- data/Rakefile +6 -0
- data/assist-ruby-sdk.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/assist-ruby-sdk.rb +1 -0
- data/lib/assist.rb +30 -0
- data/lib/assist/api_methods.rb +14 -0
- data/lib/assist/checkvalue_generator.rb +21 -0
- data/lib/assist/configuration.rb +41 -0
- data/lib/assist/exception/api_error.rb +6 -0
- data/lib/assist/exception/configuration_error.rb +6 -0
- data/lib/assist/params_helper.rb +29 -0
- data/lib/assist/payment_interface.rb +81 -0
- data/lib/assist/version.rb +3 -0
- data/lib/assist/web_services/base.rb +74 -0
- data/lib/assist/web_services/cancel_order.rb +25 -0
- data/lib/assist/web_services/order_status.rb +57 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3883c3e887eaf73ad1dcfe5da8f9ce9b6ab0cb2
|
4
|
+
data.tar.gz: 2beceb1e99a1b5cda2f36a973a4b3cd122639f25
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3c4b0ab0c5754eef0b8712b856ba55450215d35df231d228c26599ee7a1405fbefa5ffbc224ef03f815168bb4a190b497364b1b4253e172a38300b19706ea3f
|
7
|
+
data.tar.gz: 28b58d6b470b1d0e4d2d0420761dd0a32d0df52c441117ac77cba5c8585d7b82ec18aed849ce74552903c69d7cb1ed49bb64fe6ff067c1c17586cec3d9601959
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at anton@chumakoff.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Anton Chumakov
|
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,158 @@
|
|
1
|
+
# Assist eCommerce Ruby SDK
|
2
|
+
|
3
|
+
The Assist Ruby SDK provides Ruby APIs to create, process and manage payments via [Assist online payment service provider](http://www.assist.ru/).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* Creating payments
|
8
|
+
* Instance payments
|
9
|
+
* Delayed payments
|
10
|
+
* Recurring payments
|
11
|
+
* Receiving status by order number
|
12
|
+
* Canceling payments
|
13
|
+
|
14
|
+
Read the documentation [[EN](http://www.assist.ru/files/TechNEW_ENG.pdf) | [RU](http://www.assist.ru/files/TechNew.pdf)] for more information about Assist's features.
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
- Ruby 1.9 or above
|
19
|
+
- Bundler
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'assist-ruby-sdk'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install assist-ruby-sdk
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Sample Rails application <https://github.com/chumakoff/assist-ruby-sample>
|
40
|
+
|
41
|
+
### Configuration
|
42
|
+
|
43
|
+
You have to configure Assist before using it.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Assist.setup do |config|
|
47
|
+
config.login = "login"
|
48
|
+
config.password = "password"
|
49
|
+
config.merchant_id = "111111"
|
50
|
+
config.mode = :test # or :production
|
51
|
+
# Provide secret word in order to activate check value (MD5) verification.
|
52
|
+
# Make sure that the secret word is set in merchant's Personal account settings.
|
53
|
+
config.secret_word = "secret_word"
|
54
|
+
|
55
|
+
# Payment methods.
|
56
|
+
# All payment methods are allowed by default. Specify this option only if you need to limit them.
|
57
|
+
#
|
58
|
+
# Default:
|
59
|
+
# config.payment_methods = {card: true, ym: true, wm: true, qiwi: {mts: true, megafon: true, beeline: true, tele2: true}}
|
60
|
+
#
|
61
|
+
# Allow payments using credit card and QIWI(Megafon):
|
62
|
+
# config.payment_methods = {card: true, wm: false, qiwi: {mts: false, megafon: true}}
|
63
|
+
# Methods that are not present in the hash are considered as false.
|
64
|
+
#
|
65
|
+
# Allow payments using WebMoney and QIWI:
|
66
|
+
# config.payment_methods = {wm: true, qiwi: true}
|
67
|
+
config.payment_methods = {card: true}
|
68
|
+
|
69
|
+
# The following options are not mandatory. If not specified,
|
70
|
+
# merchant's settings in Personal account will be used (options should be enabled)
|
71
|
+
config.success_url = "https://example.org/payment/success"
|
72
|
+
config.fail_url = "https://example.org/payment/fail"
|
73
|
+
# In the case when `success_url` and `fail_url` are the same, specify `return_url` instead.
|
74
|
+
# config.return_url = "https://example.org/payment/return"
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Creating payments
|
79
|
+
|
80
|
+
In order to create a payment a user is redirected to the Assist payment page with necessary payment parameters:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# `order_number` - order number in the merchant payment system
|
84
|
+
# `order_amount` - payment amount, in original currency
|
85
|
+
# `extra_params` - hash of any other parameters (default = {}).
|
86
|
+
url = Assist.payment_url(order_number, order_amount, extra_params)
|
87
|
+
```
|
88
|
+
See "List of the authorized request parameters" in the documentation [[EN](http://www.assist.ru/files/TechNEW_ENG.pdf) | [RU](http://www.assist.ru/files/TechNew.pdf)].
|
89
|
+
|
90
|
+
### Checking payment status
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# `order_number` - order number in the merchant payment system
|
94
|
+
order_number = 999
|
95
|
+
order_status = Assist.order_status(order_number, extra_params)
|
96
|
+
|
97
|
+
# with extra parameters
|
98
|
+
extra_params = {}
|
99
|
+
order_status = Assist.order_status(order_number, extra_params)
|
100
|
+
|
101
|
+
order_status.status # => "Approved"
|
102
|
+
order_status.billnumber # => "5775486652369300"
|
103
|
+
|
104
|
+
# all response parameters
|
105
|
+
order_status.result # => [{:ordernumber=>"999", :billnumber=>"5775486652369300",
|
106
|
+
# :orderamount=>"111.00", :ordercurrency=>"RUB",
|
107
|
+
# :orderstate=>"Approved", :packetdate=>"28.09.2016 23:32",
|
108
|
+
# :signature=>nil}]
|
109
|
+
|
110
|
+
# raw http response returned from Assist server (in XML format)
|
111
|
+
order_status.original_response # => #<Net::HTTPOK 200 OK readbody=true>
|
112
|
+
```
|
113
|
+
|
114
|
+
See "Receiving status by order number" and "OrderState field values" in the documentation for more information.
|
115
|
+
|
116
|
+
### Canceling payment
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
# `billnumber` - number of payment in Assist
|
120
|
+
billnumber = "5775486652369300"
|
121
|
+
result = Assist.cancel_order(billnumber)
|
122
|
+
|
123
|
+
# with extra parameters
|
124
|
+
extra_params = {}
|
125
|
+
result = Assist.cancel_order(billnumber, extra_params)
|
126
|
+
|
127
|
+
# response
|
128
|
+
result.result # => {:ordernumber=>"999", :responsecode=>"AS000",
|
129
|
+
# :recommendation=>nil, :orderdate=>"28.09.2016 23:31:00",
|
130
|
+
# :amount=>"111.00", :currency=>"RUB", :billnumber=>"5775486652369300",
|
131
|
+
# ...
|
132
|
+
# }
|
133
|
+
|
134
|
+
# raw http response returned from Assist server (in XML format)
|
135
|
+
order_status.original_response # => #<Net::HTTPOK 200 OK readbody=true>
|
136
|
+
```
|
137
|
+
|
138
|
+
## API Errors
|
139
|
+
|
140
|
+
When Assist API returns failure response, assist-ruby-sdk raises Assist::Exception::APIError containing error description and error codes.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
begin
|
144
|
+
# Invalid API Request
|
145
|
+
rescue Assist::Exception::APIError => e
|
146
|
+
e.message # => "Assist API error: firstcode=10, secondcode=201
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
See "Codes of automated interfaces" in the documentation for more information about error codes.
|
151
|
+
|
152
|
+
## Contributing
|
153
|
+
|
154
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chumakoff/assist-ecommerce-sdk-ruby.
|
155
|
+
|
156
|
+
## License
|
157
|
+
|
158
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'assist/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "assist-ruby-sdk"
|
8
|
+
spec.version = Assist::VERSION
|
9
|
+
spec.authors = ["Anton Chumakov"]
|
10
|
+
spec.email = ["anton@chumakoff.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Assist Online Payment System SDK for Ruby.}
|
13
|
+
spec.description = %q{The Assist Ruby SDK provides Ruby APIs to create, process and manage payments.}
|
14
|
+
spec.homepage = "https://github.com/chumakoff/assist-ecommerce-sdk-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "assist"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "assist"
|
data/lib/assist.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "assist/configuration"
|
2
|
+
require "assist/payment_interface"
|
3
|
+
require "assist/api_methods"
|
4
|
+
require 'assist/exception/configuration_error'
|
5
|
+
|
6
|
+
module Assist
|
7
|
+
extend ApiMethods
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def payment_url(*args)
|
11
|
+
PaymentInterface.new(*args).url
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
self.config = Configuration.new
|
16
|
+
yield config
|
17
|
+
config.validate!
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
return @config if @config
|
22
|
+
|
23
|
+
raise Exception::ConfigurationError, "Configuration is not set"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_writer :config
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'assist/web_services/order_status'
|
2
|
+
require 'assist/web_services/cancel_order'
|
3
|
+
|
4
|
+
module Assist
|
5
|
+
module ApiMethods
|
6
|
+
def order_status(*args)
|
7
|
+
WebServices::OrderStatus.new(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def cancel_order(*args)
|
11
|
+
WebServices::CancelOrder.new(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Assist
|
4
|
+
module CheckvalueGenerator
|
5
|
+
PARAM_NAMES = [:merchant_id, :ordernumber, :orderamount,
|
6
|
+
:ordercurrency, :orderstate].freeze
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def generate_checkvalue(attrs, separator = ';')
|
11
|
+
Digest::MD5.hexdigest(
|
12
|
+
(
|
13
|
+
Digest::MD5.hexdigest(Assist.config.secret_word) +
|
14
|
+
Digest::MD5.hexdigest(
|
15
|
+
PARAM_NAMES.map(&attrs.method(:[])).compact.join(separator)
|
16
|
+
)
|
17
|
+
).upcase
|
18
|
+
).upcase
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'assist/exception/configuration_error'
|
2
|
+
|
3
|
+
module Assist
|
4
|
+
class Configuration
|
5
|
+
ENDPOINTS = {production: "https://paysecure.ru",
|
6
|
+
test: "https://test.paysecure.ru"}.freeze
|
7
|
+
|
8
|
+
REQUIRED_OPTIONS = [:merchant_id, :login, :password, :mode].freeze
|
9
|
+
|
10
|
+
ALLOWED_OPTIONS = [:return_url, :success_url, :fail_url,
|
11
|
+
:payment_methods, :secret_word].freeze
|
12
|
+
|
13
|
+
attr_accessor(*(REQUIRED_OPTIONS + ALLOWED_OPTIONS))
|
14
|
+
|
15
|
+
def [](opt_name)
|
16
|
+
public_send(opt_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate!
|
20
|
+
missing_options = REQUIRED_OPTIONS.select { |opt| self[opt].nil? }
|
21
|
+
return if missing_options.empty?
|
22
|
+
|
23
|
+
raise Exception::ConfigurationError,
|
24
|
+
"Missing configuration options: #{missing_options.join(', ')}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def endpoint
|
28
|
+
ENDPOINTS[test_mode? ? :test : :production]
|
29
|
+
end
|
30
|
+
|
31
|
+
def checkvalue?
|
32
|
+
!secret_word.to_s.strip.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def test_mode?
|
38
|
+
mode.to_sym != :production
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Assist
|
2
|
+
module ParamsHelper
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def normalize_keys(hash)
|
10
|
+
new_hash = {}
|
11
|
+
hash.each { |key, val| new_hash[normalize(key)] = val }
|
12
|
+
new_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def normalize(value)
|
16
|
+
self.class.normalize(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def normalize(value)
|
21
|
+
value.downcase.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
def normalize_block
|
25
|
+
proc { |value| normalize(value) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'assist/checkvalue_generator'
|
3
|
+
require 'assist/params_helper'
|
4
|
+
|
5
|
+
module Assist
|
6
|
+
class PaymentInterface
|
7
|
+
include CheckvalueGenerator
|
8
|
+
include ParamsHelper
|
9
|
+
|
10
|
+
SERVICE_PATH = "/pay/order.cfm".freeze
|
11
|
+
|
12
|
+
PERMITTED_EXTRA_PARAMS = %w(
|
13
|
+
OrderCurrency Language OrderComment Lastname Firstname Middlename
|
14
|
+
Email Address HomePhone WorkPhone MobilePhone Fax Country State City
|
15
|
+
Zip MobileDevice URL_RETURN URL_RETURN_OK URL_RETURN_NO
|
16
|
+
CardPayment YMPayment WMPayment QIWIPayment
|
17
|
+
QIWIMtsPayment QIWIMegafonPayment QIWIBeelinePayment QIWITele2Payment
|
18
|
+
).map(&normalize_block).freeze
|
19
|
+
|
20
|
+
PAYMENT_METHODS_MAPPING = {card: :cardpayment, ym: :ympayment,
|
21
|
+
wm: :wmpayment, qiwi: :qiwipayment}.freeze
|
22
|
+
QIWI_METHODS_MAPPING =
|
23
|
+
{
|
24
|
+
mts: :qiwimtspayment, megafon: :qiwimegafonpayment,
|
25
|
+
beeline: :qiwibeelinepayment, tele2: :qiwitele2payment
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
def initialize(order_number, order_amount, extra_params = {})
|
29
|
+
extra_params = normalize_keys(extra_params)
|
30
|
+
extra_params.keep_if { |key| PERMITTED_EXTRA_PARAMS.include?(key) }
|
31
|
+
|
32
|
+
params.merge!(extra_params)
|
33
|
+
params.merge!(ordernumber: order_number, orderamount: order_amount)
|
34
|
+
|
35
|
+
return unless Assist.config.checkvalue?
|
36
|
+
params[:checkvalue] = generate_checkvalue(params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
uri = URI(Assist.config.endpoint + SERVICE_PATH)
|
41
|
+
uri.query = URI.encode_www_form(params)
|
42
|
+
uri.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def params
|
48
|
+
@params ||= default_params
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_params
|
52
|
+
attrs = {merchant_id: Assist.config.merchant_id}
|
53
|
+
{
|
54
|
+
return_url: :url_return,
|
55
|
+
success_url: :url_return_ok,
|
56
|
+
fail_url: :url_return_no
|
57
|
+
}.each do |key, value|
|
58
|
+
attrs[value] = Assist.config[key] if Assist.config[key]
|
59
|
+
end
|
60
|
+
|
61
|
+
attrs.merge!(payment_methods_params) if Assist.config.payment_methods
|
62
|
+
attrs
|
63
|
+
end
|
64
|
+
|
65
|
+
def payment_methods_params
|
66
|
+
attrs = {}
|
67
|
+
|
68
|
+
PAYMENT_METHODS_MAPPING.each do |key, value|
|
69
|
+
attrs[value] = 0 unless Assist.config.payment_methods[key]
|
70
|
+
end
|
71
|
+
|
72
|
+
if Assist.config.payment_methods[:qiwi].is_a?(Hash)
|
73
|
+
QIWI_METHODS_MAPPING.each do |key, value|
|
74
|
+
attrs[value] = 0 unless Assist.config.payment_methods[:qiwi][key]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
attrs
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'assist/exception/api_error'
|
5
|
+
require 'assist/params_helper'
|
6
|
+
|
7
|
+
module Assist
|
8
|
+
module WebServices
|
9
|
+
class Base
|
10
|
+
include ParamsHelper
|
11
|
+
|
12
|
+
def initialize(extra_params)
|
13
|
+
extra_params =
|
14
|
+
normalize_keys(extra_params)
|
15
|
+
.keep_if { |k| self.class::PERMITTED_EXTRA_PARAMS.include?(k) }
|
16
|
+
@params = default_params.merge(extra_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def result
|
20
|
+
@result ||= parse_result
|
21
|
+
end
|
22
|
+
|
23
|
+
def original_response
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :params
|
30
|
+
|
31
|
+
def default_params
|
32
|
+
{
|
33
|
+
merchant_id: Assist.config.merchant_id,
|
34
|
+
login: Assist.config.login,
|
35
|
+
password: Assist.config.password,
|
36
|
+
format: 3
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def response
|
41
|
+
return @response if @response
|
42
|
+
|
43
|
+
uri = URI(Assist.config.endpoint + self.class::SERVICE_PATH)
|
44
|
+
@response = Net::HTTP.post_form(uri, params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def response_xml
|
48
|
+
return @response_xml if @response_xml
|
49
|
+
|
50
|
+
if response.code != '200'
|
51
|
+
raise Exception::APIError,
|
52
|
+
"Invalid response: code=#{response.code}"
|
53
|
+
end
|
54
|
+
|
55
|
+
xml = REXML::Document.new(response.body)
|
56
|
+
check_response!(xml)
|
57
|
+
@response_xml = xml
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_response!(xml)
|
61
|
+
attrs = xml.elements["result"].attributes
|
62
|
+
return if attrs["firstcode"].to_s == '0'
|
63
|
+
|
64
|
+
raise Exception::APIError,
|
65
|
+
"Assist API error: firstcode=#{attrs['firstcode']}, \
|
66
|
+
secondcode=#{attrs['secondcode']}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse_result
|
70
|
+
raise NotImplementedError, "Must be implemented by subtypes"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'assist/web_services/base'
|
2
|
+
|
3
|
+
module Assist
|
4
|
+
module WebServices
|
5
|
+
class CancelOrder < Base
|
6
|
+
SERVICE_PATH = "/cancel/cancel.cfm".freeze
|
7
|
+
|
8
|
+
PERMITTED_EXTRA_PARAMS = %w(
|
9
|
+
Amount Currency CancelReason Language ClientIP
|
10
|
+
).map(&normalize_block).freeze
|
11
|
+
|
12
|
+
def initialize(billnumber, extra_params = {})
|
13
|
+
super(extra_params)
|
14
|
+
@params[:billnumber] = billnumber
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_result
|
20
|
+
last_result = response_xml.elements.each("result/orders/order") {}.last
|
21
|
+
Hash[last_result.elements.map { |e| [normalize(e.name), e.text] }]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'assist/web_services/base'
|
2
|
+
require 'assist/checkvalue_generator'
|
3
|
+
|
4
|
+
module Assist
|
5
|
+
module WebServices
|
6
|
+
class OrderStatus < Base
|
7
|
+
include CheckvalueGenerator
|
8
|
+
|
9
|
+
SERVICE_PATH = "/orderstate/orderstate.cfm".freeze
|
10
|
+
|
11
|
+
PERMITTED_EXTRA_PARAMS = %w(
|
12
|
+
StartYear StartMonth StartDay StartHour StartMin
|
13
|
+
EndYear EndMonth EndDay EndHour EndMin
|
14
|
+
).map(&normalize_block).freeze
|
15
|
+
|
16
|
+
def initialize(order_number, extra_params = {})
|
17
|
+
super(extra_params)
|
18
|
+
@params[:ordernumber] = order_number
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
result.last.fetch(:orderstate)
|
23
|
+
end
|
24
|
+
|
25
|
+
def billnumber
|
26
|
+
result.last.fetch(:billnumber)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_result
|
32
|
+
result =
|
33
|
+
response_xml.elements.each("result/order") {}.map do |el|
|
34
|
+
Hash[el.elements.map { |e| [normalize(e.name), e.text] }]
|
35
|
+
end
|
36
|
+
verify_checkvalue!(result.last) if Assist.config.checkvalue?
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def verify_checkvalue!(attrs)
|
41
|
+
checkvalue = attrs.delete(:checkvalue)
|
42
|
+
hash = {}
|
43
|
+
|
44
|
+
[:orderamount, :ordercurrency, :orderstate].each do |attr_name|
|
45
|
+
hash[attr_name] = attrs[attr_name]
|
46
|
+
end
|
47
|
+
|
48
|
+
[:merchant_id, :ordernumber].each do |attr_name|
|
49
|
+
hash[attr_name] = params[attr_name]
|
50
|
+
end
|
51
|
+
|
52
|
+
return if checkvalue == generate_checkvalue(hash, '')
|
53
|
+
raise Exception::APIError, "Wrong checkvalue"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assist-ruby-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Chumakov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
69
|
+
description: The Assist Ruby SDK provides Ruby APIs to create, process and manage
|
70
|
+
payments.
|
71
|
+
email:
|
72
|
+
- anton@chumakoff.com
|
73
|
+
executables:
|
74
|
+
- console
|
75
|
+
- setup
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- CODE_OF_CONDUCT.md
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- assist-ruby-sdk.gemspec
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- lib/assist-ruby-sdk.rb
|
91
|
+
- lib/assist.rb
|
92
|
+
- lib/assist/api_methods.rb
|
93
|
+
- lib/assist/checkvalue_generator.rb
|
94
|
+
- lib/assist/configuration.rb
|
95
|
+
- lib/assist/exception/api_error.rb
|
96
|
+
- lib/assist/exception/configuration_error.rb
|
97
|
+
- lib/assist/params_helper.rb
|
98
|
+
- lib/assist/payment_interface.rb
|
99
|
+
- lib/assist/version.rb
|
100
|
+
- lib/assist/web_services/base.rb
|
101
|
+
- lib/assist/web_services/cancel_order.rb
|
102
|
+
- lib/assist/web_services/order_status.rb
|
103
|
+
homepage: https://github.com/chumakoff/assist-ecommerce-sdk-ruby
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Assist Online Payment System SDK for Ruby.
|
127
|
+
test_files: []
|