secupay_ruby 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/lib/secupay_ruby/payment.rb +0 -14
- data/lib/secupay_ruby/requests/base.rb +10 -6
- data/lib/secupay_ruby/requests/response.rb +19 -0
- data/lib/secupay_ruby/version.rb +1 -1
- data/lib/secupay_ruby.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf8db51fd28c1ac636daeea2174d8bca246c0be0
|
4
|
+
data.tar.gz: 09d8166b9a8dce63d27f392a3e3e88072234bbfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e29133e6ea114fbd2088bf14b5053866a98f39cd2301df0995e8b7ce4cf754581ae4484d0643158c49a0e0ed75d11df9e678d6ba155322dfeaad783769ef5d4
|
7
|
+
data.tar.gz: 2058314c11690d6e9dff8d1f8b63e32e8f18f3434b9b862f5fca2a12e9267519f4f7f753a72bc558079ffef7aa676a280578b9cce9b7fbb2e106e531abdcc0ac
|
data/lib/secupay_ruby/payment.rb
CHANGED
@@ -54,7 +54,6 @@ module SecupayRuby
|
|
54
54
|
@response = SecupayRuby::Requests::Init.post(api_key: api_key,
|
55
55
|
payment: self,
|
56
56
|
body: params)
|
57
|
-
raise_if_request_error
|
58
57
|
|
59
58
|
extract_response_params(INIT_FIELDS)
|
60
59
|
end
|
@@ -68,7 +67,6 @@ module SecupayRuby
|
|
68
67
|
@response = SecupayRuby::Requests::Status.post(api_key: api_key,
|
69
68
|
payment: self,
|
70
69
|
body: params)
|
71
|
-
raise_if_request_error
|
72
70
|
|
73
71
|
extract_response_params(STATUS_FIELDS)
|
74
72
|
end
|
@@ -80,7 +78,6 @@ module SecupayRuby
|
|
80
78
|
|
81
79
|
@response = SecupayRuby::Requests::Capture.post(api_key: api_key,
|
82
80
|
payment: self)
|
83
|
-
raise_if_request_error
|
84
81
|
end
|
85
82
|
|
86
83
|
def cancel
|
@@ -90,25 +87,18 @@ module SecupayRuby
|
|
90
87
|
|
91
88
|
@response = SecupayRuby::Requests::Cancel.post(api_key: api_key,
|
92
89
|
payment: self)
|
93
|
-
raise_if_request_error
|
94
90
|
end
|
95
91
|
|
96
92
|
class << self
|
97
93
|
def get_types(api_key: SecupayRuby::ApiKey::MasterKey.new)
|
98
94
|
response = SecupayRuby::Requests::GetTypes.post(api_key: api_key)
|
99
95
|
|
100
|
-
raise RequestError, response.errors if response.http_status != "200" || response.status != "ok"
|
101
|
-
|
102
96
|
response.data
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
106
100
|
private
|
107
101
|
|
108
|
-
def raise_if_request_error
|
109
|
-
raise RequestError.new @response.errors if error?
|
110
|
-
end
|
111
|
-
|
112
102
|
def raise_if_not_initiated
|
113
103
|
raise PaymentStatusError.new "Not initiated" unless hash?
|
114
104
|
end
|
@@ -123,10 +113,6 @@ module SecupayRuby
|
|
123
113
|
raise PaymentStatusError.new "Payment already initiated" if hash?
|
124
114
|
end
|
125
115
|
|
126
|
-
def error?
|
127
|
-
@response.http_status != "200" || @response.status != "ok"
|
128
|
-
end
|
129
|
-
|
130
116
|
def extract_response_params(fields)
|
131
117
|
fields.each do |field_name, param_name|
|
132
118
|
instance_variable_set("@#{field_name}", @response.data[param_name])
|
@@ -11,6 +11,8 @@ module SecupayRuby
|
|
11
11
|
autoload :Cancel, "secupay_ruby/requests/cancel"
|
12
12
|
autoload :RequestApiKey, "secupay_ruby/requests/request_api_key"
|
13
13
|
|
14
|
+
autoload :Response, "secupay_ruby/requests/response"
|
15
|
+
|
14
16
|
class Base
|
15
17
|
class << self
|
16
18
|
def post(api_key: , payment: nil, body: {})
|
@@ -60,8 +62,6 @@ module SecupayRuby
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
Response = Struct.new(:http_status, :status, :data, :errors)
|
64
|
-
|
65
65
|
def http_response
|
66
66
|
@response ||= begin
|
67
67
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
@@ -70,10 +70,14 @@ module SecupayRuby
|
|
70
70
|
|
71
71
|
json_response = JSON.parse(response.body)
|
72
72
|
|
73
|
-
Response.new(response.header.code,
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
response = SecupayRuby::Requests::Response.new(http_status: response.header.code,
|
74
|
+
status: json_response["status"],
|
75
|
+
data: json_response["data"],
|
76
|
+
errors: json_response["errors"])
|
77
|
+
|
78
|
+
raise RequestError.new(response.errors) if response.failed?
|
79
|
+
|
80
|
+
response
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SecupayRuby
|
2
|
+
module Requests
|
3
|
+
class Response
|
4
|
+
attr_accessor :http_status, :status, :data, :errors
|
5
|
+
|
6
|
+
def initialize(http_status:, status:, data:, errors:)
|
7
|
+
self.http_status = http_status
|
8
|
+
self.status = status
|
9
|
+
self.data = data
|
10
|
+
self.errors = errors
|
11
|
+
end
|
12
|
+
|
13
|
+
def failed?
|
14
|
+
http_status != "200" || status != "ok"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/secupay_ruby/version.rb
CHANGED
data/lib/secupay_ruby.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secupay_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominic Breuker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/secupay_ruby/requests/get_types.rb
|
144
144
|
- lib/secupay_ruby/requests/init.rb
|
145
145
|
- lib/secupay_ruby/requests/request_api_key.rb
|
146
|
+
- lib/secupay_ruby/requests/response.rb
|
146
147
|
- lib/secupay_ruby/requests/status.rb
|
147
148
|
- lib/secupay_ruby/version.rb
|
148
149
|
- secupay_ruby.gemspec
|