alfabank 0.1.2 → 0.2.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
- SHA1:
3
- metadata.gz: a993d7b06fd8bbcb32db85a1729763a29aebafe8
4
- data.tar.gz: 69e1f591c5d827668f9617ead8de3b95d259562c
2
+ SHA256:
3
+ metadata.gz: 240f816190cd982f668b2f7f819600e4521cbd5f3cbed3f2cbbaf5be53af13e9
4
+ data.tar.gz: ab180f05add97f32ec4e95509cd292c91ff672c389d0c2ffefb413b98e302b61
5
5
  SHA512:
6
- metadata.gz: c020e0f5ff98a2d95419e358af2913e04c51c548032a3eb3f9f0bfd5c8d90d23540002e62e3cfdab1a28ae4774bf4d586c88e5227c424d8afe170a09abdfaa3c
7
- data.tar.gz: 91f45d638d679bd6f73a04544c554ff612c324e52727b5033591d45099fcd3b0fc2150972058eae7406281d2e02e5be831528d35c0cf7083e8aed6f59f7628a5
6
+ metadata.gz: fbd34cc48a3e60914801d71e3e4e49402da7376d0238e94ebf6e927a484183ddab1341d7094a5899012661d4befd8ed661f3b084722f1abcae3c6c8d8fbae731
7
+ data.tar.gz: fa5f6349905f7b9c42f4204e6c12ac5619f7be6f4a541afa22aa8465833fc8654db58146175d293ddd90be09cc9dd9ad261ebdb6dae3b3fc7ffd6cc4b01ee02a
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.1
3
+ - 2.2.9
4
+ - 2.3.6
5
+ - 2.4.3
6
+ - 2.5.0
4
7
  before_install: gem install bundler -v 1.11.2
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Alfabank
2
- [![Build Status](https://travis-ci.org/mendab1e/alfabank.svg)](https://travis-ci.org/mendab1e/alfabank) [![Gem Version](https://badge.fury.io/rb/alfabank.svg)](https://badge.fury.io/rb/alfabank)
2
+ [![Build Status](https://travis-ci.org/mendab1e/alfabank.svg?branch=master)](https://travis-ci.org/mendab1e/alfabank) [![Gem Version](https://badge.fury.io/rb/alfabank.svg)](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
 
@@ -4,15 +4,21 @@ require "alfabank/api"
4
4
  require "alfabank/configuration"
5
5
 
6
6
  module Alfabank
7
- def register(binding_id = nil)
8
- Api::Registration.new(self).process(binding_id)
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
@@ -1,3 +1,4 @@
1
1
  require "alfabank/api/base"
2
2
  require "alfabank/api/registration"
3
3
  require "alfabank/api/status"
4
+ require "alfabank/api/payment_order_binding"
@@ -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
- if Alfabank::Configuration.mode == :test
23
- self.class::TEST_URL
24
- elsif Alfabank::Configuration.mode == :production
25
- self.class::URL
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 = "https://test.paymentgate.ru/testpayment/rest/register.do"
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(binding_id = nil)
6
+ def process(use_binding: false)
7
7
  return {url: payment.alfa_form_url} if payment.alfa_order_id
8
- @binding_id = binding_id
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: "#{Alfabank::Configuration.order_number_prefix}#{payment.id}",
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
@@ -1,10 +1,12 @@
1
1
  module Alfabank::Api
2
2
  class Status < Base
3
- TEST_URL = "https://test.paymentgate.ru/testpayment/rest/getOrderStatus.do"
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
- if response["OrderStatus"].to_i == PAID
26
- payment.update_attribute(:paid, true)
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
- userName: Alfabank::Configuration.username,
33
- password: Alfabank::Configuration.password,
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, :binding_username, :mode
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
@@ -1,3 +1,3 @@
1
1
  module Alfabank
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.2
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: 2016-02-22 00:00:00.000000000 Z
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.5.1
148
+ rubygems_version: 2.7.3
148
149
  signing_key:
149
150
  specification_version: 4
150
151
  summary: Unofficial alfabank payment gateway gem