alfabank 0.1.2 → 0.2.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 +5 -5
- data/.travis.yml +4 -1
- data/README.md +1 -1
- data/lib/alfabank.rb +10 -4
- data/lib/alfabank/api.rb +1 -0
- data/lib/alfabank/api/base.rb +9 -5
- data/lib/alfabank/api/payment_order_binding.rb +29 -0
- data/lib/alfabank/api/registration.rb +11 -17
- data/lib/alfabank/api/status.rb +14 -11
- data/lib/alfabank/configuration.rb +16 -1
- data/lib/alfabank/version.rb +1 -1
- data/lib/generators/alfabank/templates/config/initializers/alfabank.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 240f816190cd982f668b2f7f819600e4521cbd5f3cbed3f2cbbaf5be53af13e9
|
4
|
+
data.tar.gz: ab180f05add97f32ec4e95509cd292c91ff672c389d0c2ffefb413b98e302b61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd34cc48a3e60914801d71e3e4e49402da7376d0238e94ebf6e927a484183ddab1341d7094a5899012661d4befd8ed661f3b084722f1abcae3c6c8d8fbae731
|
7
|
+
data.tar.gz: fa5f6349905f7b9c42f4204e6c12ac5619f7be6f4a541afa22aa8465833fc8654db58146175d293ddd90be09cc9dd9ad261ebdb6dae3b3fc7ffd6cc4b01ee02a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Alfabank
|
2
|
-
[](https://travis-ci.org/mendab1e/alfabank) [](https://badge.fury.io/rb/alfabank)
|
2
|
+
[](https://travis-ci.org/mendab1e/alfabank) [](https://badge.fury.io/rb/alfabank)
|
3
3
|
|
4
4
|
This gem provides support for the API of [Alfabank acquiring gateway](https://engine.paymentgate.ru/ecommerce/).
|
5
5
|
|
data/lib/alfabank.rb
CHANGED
@@ -4,15 +4,21 @@ require "alfabank/api"
|
|
4
4
|
require "alfabank/configuration"
|
5
5
|
|
6
6
|
module Alfabank
|
7
|
-
def register(
|
8
|
-
Api::Registration.new(self).process(
|
7
|
+
def register(use_binding: false)
|
8
|
+
Api::Registration.new(self).process(use_binding: use_binding)
|
9
9
|
end
|
10
10
|
|
11
|
-
def check_status
|
12
|
-
Api::Status.new(self).process
|
11
|
+
def check_status(use_binding: false)
|
12
|
+
Api::Status.new(self).process(use_binding: use_binding)
|
13
|
+
end
|
14
|
+
|
15
|
+
def payment_order_binding(binding_id)
|
16
|
+
Api::PaymentOrderBinding.new(self).process(binding_id)
|
13
17
|
end
|
14
18
|
|
15
19
|
class << self
|
20
|
+
attr_accessor :logger
|
21
|
+
|
16
22
|
def setup(&block)
|
17
23
|
yield Configuration
|
18
24
|
end
|
data/lib/alfabank/api.rb
CHANGED
data/lib/alfabank/api/base.rb
CHANGED
@@ -2,7 +2,7 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Alfabank::Api
|
4
4
|
class Base
|
5
|
-
attr_reader :payment
|
5
|
+
attr_reader :payment, :use_binding
|
6
6
|
|
7
7
|
def initialize(payment)
|
8
8
|
@payment = payment
|
@@ -19,10 +19,14 @@ module Alfabank::Api
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def url
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
Alfabank::Configuration.mode == :production ? self.class::URL : self.class::TEST_URL
|
23
|
+
end
|
24
|
+
|
25
|
+
def credentials
|
26
|
+
if use_binding
|
27
|
+
Alfabank::Configuration.binding_credentials
|
28
|
+
else
|
29
|
+
Alfabank::Configuration.common_credentials
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Alfabank::Api
|
2
|
+
class PaymentOrderBinding < Base
|
3
|
+
TEST_URL = 'https://web.rbsuat.com/ab/rest/paymentOrderBinding.do'
|
4
|
+
URL = "https://engine.paymentgate.ru/payment/rest/paymentOrderBinding.do"
|
5
|
+
|
6
|
+
def process(binding_id)
|
7
|
+
fail 'alfa_order_id is nil' if payment.alfa_order_id.nil?
|
8
|
+
@binding_id = binding_id
|
9
|
+
|
10
|
+
process_response(make_request.parsed_response)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def process_response(response)
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_params
|
20
|
+
params = {
|
21
|
+
userName: Alfabank::Configuration.binding_username,
|
22
|
+
password: Alfabank::Configuration.binding_password,
|
23
|
+
bindingId: @binding_id,
|
24
|
+
mdOrder: payment.alfa_order_id
|
25
|
+
}
|
26
|
+
params.map { |k, v| "#{k}=#{v}" }.join('&')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module Alfabank::Api
|
2
2
|
class Registration < Base
|
3
|
-
TEST_URL =
|
3
|
+
TEST_URL = 'https://web.rbsuat.com/ab/rest/register.do'
|
4
4
|
URL = "https://engine.paymentgate.ru/payment/rest/register.do"
|
5
5
|
|
6
|
-
def process(
|
6
|
+
def process(use_binding: false)
|
7
7
|
return {url: payment.alfa_form_url} if payment.alfa_order_id
|
8
|
-
@
|
8
|
+
@use_binding = use_binding
|
9
9
|
|
10
10
|
process_response(make_request.parsed_response)
|
11
|
-
rescue
|
12
|
-
{error: 'Internal server error'}
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
@@ -24,24 +22,15 @@ module Alfabank::Api
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def generate_params
|
27
|
-
params =
|
28
|
-
userName: Alfabank::Configuration.username,
|
29
|
-
password: Alfabank::Configuration.password,
|
25
|
+
params = credentials.merge(
|
30
26
|
description: payment.description,
|
31
27
|
language: Alfabank::Configuration.language,
|
32
|
-
orderNumber:
|
28
|
+
orderNumber: order_number,
|
33
29
|
amount: payment.price * 100,
|
34
30
|
currency: Alfabank::Configuration.currency,
|
35
31
|
clientId: payment.user_id,
|
36
32
|
returnUrl: Alfabank::Configuration.return_url
|
37
|
-
|
38
|
-
|
39
|
-
if @binding_id
|
40
|
-
params.merge!(
|
41
|
-
userName: Alfabank::Configuration.binding_username,
|
42
|
-
bindingId: @binding_id
|
43
|
-
)
|
44
|
-
end
|
33
|
+
)
|
45
34
|
|
46
35
|
params.map { |k, v| "#{k}=#{v}" }.join('&')
|
47
36
|
end
|
@@ -52,5 +41,10 @@ module Alfabank::Api
|
|
52
41
|
alfa_form_url: response["formUrl"]
|
53
42
|
)
|
54
43
|
end
|
44
|
+
|
45
|
+
def order_number
|
46
|
+
number = payment.to_order_number rescue payment.id
|
47
|
+
"#{Alfabank::Configuration.order_number_prefix}#{number}"
|
48
|
+
end
|
55
49
|
end
|
56
50
|
end
|
data/lib/alfabank/api/status.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Alfabank::Api
|
2
2
|
class Status < Base
|
3
|
-
TEST_URL =
|
3
|
+
TEST_URL = 'https://web.rbsuat.com/ab/rest/getOrderStatus.do'
|
4
4
|
URL = "https://engine.paymentgate.ru/payment/rest/getOrderStatus.do"
|
5
5
|
PAID = 2
|
6
6
|
|
7
|
-
def process
|
7
|
+
def process(use_binding: false)
|
8
|
+
@use_binding = use_binding
|
9
|
+
|
8
10
|
response = make_request.parsed_response
|
9
11
|
process_response(response)
|
10
12
|
|
@@ -15,24 +17,25 @@ module Alfabank::Api
|
|
15
17
|
error_code: response["ErrorCode"].to_i,
|
16
18
|
error_message: response["ErrorMessage"]
|
17
19
|
}
|
18
|
-
rescue
|
19
|
-
{error_message: 'Internal server error'}
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def process_response(response)
|
25
|
-
|
26
|
-
|
25
|
+
return unless response["OrderStatus"].to_i == PAID
|
26
|
+
|
27
|
+
payment.paid = true
|
28
|
+
payment.card_number = response["Pan"] if payment.respond_to?(:card_number)
|
29
|
+
if payment.respond_to?(:binding_id)
|
30
|
+
payment.binding_id = response["bindingId"]
|
27
31
|
end
|
32
|
+
payment.save(validate: false)
|
28
33
|
end
|
29
34
|
|
30
35
|
def generate_params
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
orderId: payment.alfa_order_id
|
35
|
-
}.map { |k, v| "#{k}=#{v}" }.join('&')
|
36
|
+
credentials.merge(orderId: payment.alfa_order_id).map do |k, v|
|
37
|
+
"#{k}=#{v}"
|
38
|
+
end.join('&')
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -2,7 +2,22 @@ module Alfabank
|
|
2
2
|
class Configuration
|
3
3
|
class << self
|
4
4
|
attr_accessor :username, :password, :language, :return_url
|
5
|
-
attr_accessor :currency, :order_number_prefix, :
|
5
|
+
attr_accessor :currency, :order_number_prefix, :mode
|
6
|
+
attr_accessor :binding_username, :binding_password
|
7
|
+
|
8
|
+
def binding_credentials
|
9
|
+
{
|
10
|
+
userName: binding_username,
|
11
|
+
password: binding_password
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def common_credentials
|
16
|
+
{
|
17
|
+
userName: username,
|
18
|
+
password: password
|
19
|
+
}
|
20
|
+
end
|
6
21
|
end
|
7
22
|
end
|
8
23
|
end
|
data/lib/alfabank/version.rb
CHANGED
@@ -6,5 +6,8 @@ Alfabank.setup do |config|
|
|
6
6
|
config.currency = Alfabank::Currency::RUB
|
7
7
|
config.order_number_prefix = 'payment-'
|
8
8
|
config.binding_username = 'binding_username'
|
9
|
+
config.binding_password = 'binding_password'
|
9
10
|
config.mode = :test # :production
|
10
11
|
end
|
12
|
+
|
13
|
+
Alfabank.logger = Rails.logger
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alfabank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timur Yanberdin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/alfabank.rb
|
115
115
|
- lib/alfabank/api.rb
|
116
116
|
- lib/alfabank/api/base.rb
|
117
|
+
- lib/alfabank/api/payment_order_binding.rb
|
117
118
|
- lib/alfabank/api/registration.rb
|
118
119
|
- lib/alfabank/api/status.rb
|
119
120
|
- lib/alfabank/configuration.rb
|
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.7.3
|
148
149
|
signing_key:
|
149
150
|
specification_version: 4
|
150
151
|
summary: Unofficial alfabank payment gateway gem
|