oschadbank 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -32
- data/lib/oschadbank/client.rb +1 -1
- data/lib/oschadbank/constants.rb +50 -36
- data/lib/oschadbank/errors.rb +6 -0
- data/lib/oschadbank/params_builder.rb +20 -20
- data/lib/oschadbank/response.rb +13 -2
- data/lib/oschadbank/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d28a742d941bc588bf8fef5df6e3f332d9676ef5
|
4
|
+
data.tar.gz: 7499b5cade156829a2bafb722c7ba2d62d69b45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36734ff6da0eff6797761fc07537ead77838b979a5505e257d3a5a16eaf3f8b4826e3a7849bd938fbb1816c165cc6c377bc1434ea4de2ff37ba00358d73d1ba8
|
7
|
+
data.tar.gz: db8ecbb14570856b1c44b8186eeb0876d992163961dc63e27ec1d4d69fdc5f8bbd3ae8e30dcc1d2ebc618d4431bc30a36929d3c71cbfdcd7014fa6fbf5561d6e
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Oschadbank
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/oschadbank.svg)](https://badge.fury.io/rb/oschadbank)
|
4
|
+
[![Build Status](https://travis-ci.org/busfor/oschadbank.svg?branch=master)](https://travis-ci.org/busfor/oschadbank)
|
5
|
+
|
3
6
|
Ruby wrapper for Oschadbank.ua API
|
4
7
|
|
5
8
|
## Installation
|
@@ -48,22 +51,22 @@ params = client.pre_auth_params(
|
|
48
51
|
description: 'Payment description',
|
49
52
|
back_url: 'http://www.my-shop.com/back/url',
|
50
53
|
)
|
51
|
-
# => {
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
54
|
+
# => {"TRTYPE"=>"0",
|
55
|
+
# "TERMINAL"=>"123",
|
56
|
+
# "MERCHANT"=>"456",
|
57
|
+
# "MERCH_NAME"=>"Shop name",
|
58
|
+
# "MERCH_URL"=>"www.my-shop.com",
|
59
|
+
# "MERCH_GMT"=>"+3",
|
60
|
+
# "COUNTRY"=>"UA",
|
61
|
+
# "EMAIL"=>"example@my-shop.com",
|
62
|
+
# "TIMESTAMP"=>"20160718093533",
|
63
|
+
# "NONCE"=>"c82f595aef2ead17103c806b701e994c",
|
64
|
+
# "ORDER"=>"123456",
|
65
|
+
# "CURRENCY"=>"UAH",
|
66
|
+
# "AMOUNT"=>"100.5",
|
67
|
+
# "DESC"=>"Payment description",
|
68
|
+
# "BACKREF"=>"http://www.my-shop.com/back/link",
|
69
|
+
# "P_SIGN"=>"040a2920ec647e901756349491bb0167fa184747"}
|
67
70
|
|
68
71
|
params = client.auth_params(
|
69
72
|
order_id: 123456,
|
@@ -72,22 +75,22 @@ params = client.auth_params(
|
|
72
75
|
description: 'Payment description',
|
73
76
|
back_url: 'http://www.my-shop.com/back/url',
|
74
77
|
)
|
75
|
-
# => {
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
78
|
+
# => {"TRTYPE"=>"1",
|
79
|
+
# "TERMINAL"=>"123",
|
80
|
+
# "MERCHANT"=>"456",
|
81
|
+
# "MERCH_NAME"=>"Shop name",
|
82
|
+
# "MERCH_URL"=>"www.my-shop.com",
|
83
|
+
# "MERCH_GMT"=>"+3",
|
84
|
+
# "COUNTRY"=>"UA",
|
85
|
+
# "EMAIL"=>"example@my-shop.com",
|
86
|
+
# "TIMESTAMP"=>"20160718093707",
|
87
|
+
# "NONCE"=>"4a6de0a53f759469042ce3fb08accb13",
|
88
|
+
# "ORDER"=>"123456",
|
89
|
+
# "CURRENCY"=>"UAH",
|
90
|
+
# "AMOUNT"=>"100.5",
|
91
|
+
# "DESC"=>"Payment description",
|
92
|
+
# "BACKREF"=>"http://www.my-shop.com/back/link",
|
93
|
+
# "P_SIGN"=>"73e7a49bf4b729f5c66c160117e05d6b1f3a1f3e"}
|
91
94
|
```
|
92
95
|
|
93
96
|
To complete payment after pre-authorization request:
|
data/lib/oschadbank/client.rb
CHANGED
data/lib/oschadbank/constants.rb
CHANGED
@@ -11,47 +11,61 @@ module Oschadbank
|
|
11
11
|
|
12
12
|
MAC_PARAMS_ORDER = {
|
13
13
|
auth: [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
'AMOUNT',
|
15
|
+
'CURRENCY',
|
16
|
+
'ORDER',
|
17
|
+
'DESC',
|
18
|
+
'MERCH_NAME',
|
19
|
+
'MERCH_URL',
|
20
|
+
'MERCHANT',
|
21
|
+
'TERMINAL',
|
22
|
+
'EMAIL',
|
23
|
+
'TRTYPE',
|
24
|
+
'COUNTRY',
|
25
|
+
'MERCH_GMT',
|
26
|
+
'TIMESTAMP',
|
27
|
+
'NONCE',
|
28
|
+
'BACKREF',
|
29
29
|
].freeze,
|
30
30
|
charge: [
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
'ORDER',
|
32
|
+
'AMOUNT',
|
33
|
+
'CURRENCY',
|
34
|
+
'RRN',
|
35
|
+
'INT_REF',
|
36
|
+
'TRTYPE',
|
37
|
+
'TERMINAL',
|
38
|
+
'BACKREF',
|
39
|
+
'TIMESTAMP',
|
40
|
+
'NONCE',
|
41
41
|
].freeze,
|
42
42
|
refund: [
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
'ORDER',
|
44
|
+
'ORG_AMOUNT',
|
45
|
+
'AMOUNT',
|
46
|
+
'CURRENCY',
|
47
|
+
'RRN',
|
48
|
+
'INT_REF',
|
49
|
+
'TRTYPE',
|
50
|
+
'TERMINAL',
|
51
|
+
'BACKREF',
|
52
|
+
'TIMESTAMP',
|
53
|
+
'NONCE',
|
54
54
|
].freeze,
|
55
|
+
response: [
|
56
|
+
'TERMINAL',
|
57
|
+
'TRTYPE',
|
58
|
+
'ORDER',
|
59
|
+
'AMOUNT',
|
60
|
+
'CURRENCY',
|
61
|
+
'Result',
|
62
|
+
'RC',
|
63
|
+
'AuthCode',
|
64
|
+
'RRN',
|
65
|
+
'IntRef',
|
66
|
+
'TIMESTAMP',
|
67
|
+
'NONCE',
|
68
|
+
].freeze
|
55
69
|
}.freeze
|
56
70
|
|
57
71
|
RESULT_MESSAGES = {
|
data/lib/oschadbank/errors.rb
CHANGED
@@ -3,14 +3,14 @@ module Oschadbank
|
|
3
3
|
include Constants
|
4
4
|
|
5
5
|
REQUEST_PARAMS = {
|
6
|
-
amount:
|
7
|
-
org_amount:
|
8
|
-
currency:
|
9
|
-
order_id:
|
10
|
-
description:
|
11
|
-
rrn:
|
12
|
-
int_ref:
|
13
|
-
back_url:
|
6
|
+
amount: 'AMOUNT',
|
7
|
+
org_amount: 'ORG_AMOUNT',
|
8
|
+
currency: 'CURRENCY',
|
9
|
+
order_id: 'ORDER',
|
10
|
+
description: 'DESC',
|
11
|
+
rrn: 'RRN',
|
12
|
+
int_ref: 'INT_REF',
|
13
|
+
back_url: 'BACKREF',
|
14
14
|
}.freeze
|
15
15
|
|
16
16
|
def initialize(client, request_type, params)
|
@@ -21,28 +21,28 @@ module Oschadbank
|
|
21
21
|
|
22
22
|
def build
|
23
23
|
result = {
|
24
|
-
TRTYPE
|
25
|
-
TERMINAL
|
26
|
-
MERCHANT
|
27
|
-
MERCH_NAME
|
28
|
-
MERCH_URL
|
29
|
-
MERCH_GMT
|
30
|
-
COUNTRY
|
31
|
-
EMAIL
|
32
|
-
TIMESTAMP
|
33
|
-
NONCE
|
24
|
+
'TRTYPE' => tr_type,
|
25
|
+
'TERMINAL' => @client.terminal_id.to_s,
|
26
|
+
'MERCHANT' => @client.merchant_id.to_s,
|
27
|
+
'MERCH_NAME' => @client.merchant_name.to_s,
|
28
|
+
'MERCH_URL' => @client.merchant_url.to_s,
|
29
|
+
'MERCH_GMT' => @client.merchant_gmt.to_s,
|
30
|
+
'COUNTRY' => @client.country_code.to_s,
|
31
|
+
'EMAIL' => @client.email.to_s,
|
32
|
+
'TIMESTAMP' => timestamp,
|
33
|
+
'NONCE' => nonce,
|
34
34
|
}
|
35
35
|
|
36
36
|
@params.each do |key, value|
|
37
37
|
key = REQUEST_PARAMS[key] || key
|
38
38
|
value = value.to_s
|
39
|
-
value = value.encode('CP1251', 'UTF-8') if key ==
|
39
|
+
value = value.encode('CP1251', 'UTF-8') if key == 'DESC'
|
40
40
|
result[key] = value
|
41
41
|
end
|
42
42
|
|
43
43
|
result.delete_if { |_k, v| v.empty? }
|
44
44
|
|
45
|
-
result[
|
45
|
+
result['P_SIGN'] = mac_signature(result)
|
46
46
|
|
47
47
|
result
|
48
48
|
end
|
data/lib/oschadbank/response.rb
CHANGED
@@ -2,10 +2,12 @@ module Oschadbank
|
|
2
2
|
class Response
|
3
3
|
include Constants
|
4
4
|
|
5
|
-
def initialize(params)
|
5
|
+
def initialize(client, params)
|
6
|
+
@client = client
|
6
7
|
@params = params
|
7
8
|
|
8
9
|
check_required!
|
10
|
+
check_signature!
|
9
11
|
end
|
10
12
|
|
11
13
|
def request_type
|
@@ -67,12 +69,21 @@ module Oschadbank
|
|
67
69
|
private
|
68
70
|
|
69
71
|
def check_required!
|
70
|
-
required_params =
|
72
|
+
required_params = %w(Order Result RC TRTYPE P_SIGN)
|
71
73
|
required_params.each do |param|
|
72
74
|
raise ParamRequred.new(param) if @params[param].to_s.empty?
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
78
|
+
def check_signature!
|
79
|
+
params = @params.dup
|
80
|
+
signature = params.delete('P_SIGN')
|
81
|
+
|
82
|
+
valid_signature = MacBuilder.new(:response, @client.mac_key, params).build
|
83
|
+
|
84
|
+
raise InvalidSignature unless signature == valid_signature
|
85
|
+
end
|
86
|
+
|
76
87
|
def result_code
|
77
88
|
@params['Result'].to_s
|
78
89
|
end
|
data/lib/oschadbank/version.rb
CHANGED