openpayu 0.0.2 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +26 -21
- data/doc/EmptyResponseError.html +4 -4
- data/doc/HttpStatusException.html +4 -4
- data/doc/NotImplementedException.html +4 -4
- data/doc/OpenPayU.html +13 -13
- data/doc/OpenPayU/Configuration.html +19 -17
- data/doc/OpenPayU/Connection.html +35 -43
- data/doc/OpenPayU/Document.html +24 -228
- data/doc/OpenPayU/Documents.html +4 -4
- data/doc/OpenPayU/Documents/Request.html +5 -5
- data/doc/OpenPayU/Documents/Response.html +72 -120
- data/doc/OpenPayU/Models.html +5 -5
- data/doc/OpenPayU/Models/Address.html +5 -6
- data/doc/OpenPayU/Models/Buyer.html +5 -6
- data/doc/OpenPayU/Models/Buyer/Delivery.html +5 -6
- data/doc/OpenPayU/Models/Card.html +5 -6
- data/doc/OpenPayU/Models/Fee.html +5 -6
- data/doc/OpenPayU/Models/Model.html +122 -207
- data/doc/OpenPayU/Models/NotifyResponse.html +5 -6
- data/doc/OpenPayU/Models/Order.html +8 -9
- data/doc/OpenPayU/Models/PayMethod.html +5 -6
- data/doc/OpenPayU/Models/Product.html +5 -6
- data/doc/OpenPayU/Models/Refund.html +13 -102
- data/doc/OpenPayU/Models/ShippingMethod.html +13 -14
- data/doc/OpenPayU/Models/StatusUpdate.html +5 -6
- data/doc/OpenPayU/Models/Token.html +5 -6
- data/doc/OpenPayU/Order.html +53 -89
- data/doc/OpenPayU/Refund.html +6 -18
- data/doc/OpenPayU/Token.html +4 -4
- data/doc/WrongConfigurationError.html +4 -4
- data/doc/WrongNotifyRequest.html +4 -4
- data/doc/WrongOrderParameters.html +4 -4
- data/doc/WrongSignatureException.html +4 -4
- data/doc/_index.html +13 -31
- data/doc/class_list.html +1 -1
- data/doc/css/style.css +2 -1
- data/doc/file.README.html +38 -30
- data/doc/frames.html +1 -1
- data/doc/index.html +38 -30
- data/doc/js/app.js +7 -2
- data/doc/method_list.html +78 -120
- data/doc/top-level-namespace.html +4 -4
- data/lib/openpayu.rb +0 -1
- data/lib/openpayu/configuration.rb +1 -0
- data/lib/openpayu/connection.rb +28 -19
- data/lib/openpayu/document.rb +2 -38
- data/lib/openpayu/documents/response.rb +9 -20
- data/lib/openpayu/models/model.rb +4 -25
- data/lib/openpayu/models/order.rb +0 -1
- data/lib/openpayu/models/refund.rb +5 -27
- data/lib/openpayu/models/shipping_method.rb +2 -2
- data/lib/openpayu/order.rb +7 -25
- data/lib/openpayu/refund.rb +1 -7
- data/lib/openpayu/version.rb +1 -1
- data/openpayu_ruby.gemspec +0 -4
- data/spec/cassettes/cancel_order.yml +17 -26
- data/spec/cassettes/create_order.yml +19 -29
- data/spec/cassettes/retrieve_order.yml +18 -27
- data/spec/cassettes/update_order.yml +19 -28
- data/spec/integration/order_spec.rb +65 -78
- data/spec/openpayu.yml +2 -2
- data/spec/spec_helper.rb +5 -5
- data/spec/test_objects/order.rb +31 -56
- data/spec/unit/configuration_spec.rb +1 -1
- data/spec/unit/models/order_spec.rb +4 -34
- data/spec/unit/openpayu_spec.rb +2 -5
- metadata +55 -87
- data/lib/openpayu/xml_builder.rb +0 -23
- data/spec/cassettes/refund_order.yml +0 -100
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.7.
|
9
|
+
— Documentation by YARD 0.8.7.4
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
18
|
hasFrames = window.top.frames.main ? true : false;
|
19
19
|
relpath = '';
|
20
|
-
framesUrl = "frames.html#!"
|
20
|
+
framesUrl = "frames.html#!top-level-namespace.html";
|
21
21
|
</script>
|
22
22
|
|
23
23
|
|
@@ -105,9 +105,9 @@
|
|
105
105
|
</div>
|
106
106
|
|
107
107
|
<div id="footer">
|
108
|
-
Generated on
|
108
|
+
Generated on Thu May 29 15:13:57 2014 by
|
109
109
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
|
-
0.8.7.
|
110
|
+
0.8.7.4 (ruby-1.9.3).
|
111
111
|
</div>
|
112
112
|
|
113
113
|
</body>
|
data/lib/openpayu.rb
CHANGED
data/lib/openpayu/connection.rb
CHANGED
@@ -7,55 +7,64 @@ module OpenPayU
|
|
7
7
|
|
8
8
|
class Connection
|
9
9
|
|
10
|
-
def self.post(
|
11
|
-
uri =
|
12
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
-
http.use_ssl = true if OpenPayU::Configuration.use_ssl?
|
10
|
+
def self.post(endpoint, data)
|
11
|
+
http, uri = build_url(endpoint)
|
14
12
|
request = Net::HTTP::Post.new(uri.path)
|
13
|
+
request = authenticate(request)
|
15
14
|
request.body = data
|
16
15
|
request['Content-Type'] =
|
17
16
|
"application/#{OpenPayU::Configuration.data_format}"
|
18
|
-
request['OpenPayu-Signature'] = headers['OpenPayu-Signature']
|
19
17
|
response = http.request(request)
|
20
18
|
{ response: response, request: request }
|
21
19
|
end
|
22
20
|
|
23
|
-
def self.put(
|
24
|
-
uri =
|
25
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
-
http.use_ssl = true if OpenPayU::Configuration.use_ssl?
|
21
|
+
def self.put(endpoint, data)
|
22
|
+
http, uri = build_url(endpoint)
|
27
23
|
request = Net::HTTP::Put.new(uri.path)
|
24
|
+
request = authenticate(request)
|
28
25
|
request.body = data
|
29
26
|
request['Content-Type'] =
|
30
27
|
"application/#{OpenPayU::Configuration.data_format}"
|
31
|
-
request['OpenPayu-Signature'] = headers['OpenPayu-Signature']
|
32
28
|
response = http.request(request)
|
33
29
|
{ response: response, request: request }
|
34
30
|
end
|
35
31
|
|
36
|
-
def self.get(
|
37
|
-
common_connection(
|
32
|
+
def self.get(endpoint, data)
|
33
|
+
common_connection(endpoint, data, 'GET')
|
38
34
|
end
|
39
35
|
|
40
|
-
def self.delete(
|
41
|
-
common_connection(
|
36
|
+
def self.delete(endpoint, data)
|
37
|
+
common_connection(endpoint, data, 'DELETE')
|
42
38
|
end
|
43
39
|
|
44
40
|
private
|
45
41
|
|
46
|
-
def self.
|
47
|
-
|
42
|
+
def self.authenticate(request)
|
43
|
+
request.basic_auth(
|
44
|
+
OpenPayU::Configuration.merchant_pos_id,
|
45
|
+
OpenPayU::Configuration.signature_key
|
46
|
+
)
|
47
|
+
request
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.build_url(endpoint)
|
51
|
+
uri = URI.parse(Configuration.get_base_url + endpoint)
|
48
52
|
http = Net::HTTP.new(uri.host, uri.port)
|
49
53
|
http.use_ssl = true if OpenPayU::Configuration.use_ssl?
|
54
|
+
[http, uri]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.common_connection(endpoint, data, method)
|
58
|
+
http, uri = build_url(endpoint)
|
50
59
|
request =
|
51
60
|
if method == 'DELETE'
|
52
|
-
Net::HTTP::Delete.new(uri.request_uri
|
61
|
+
Net::HTTP::Delete.new(uri.request_uri)
|
53
62
|
else
|
54
|
-
Net::HTTP::Get.new(uri.request_uri
|
63
|
+
Net::HTTP::Get.new(uri.request_uri)
|
55
64
|
end
|
65
|
+
request = authenticate(request)
|
56
66
|
request['Content-Type'] =
|
57
67
|
"application/#{OpenPayU::Configuration.data_format}"
|
58
|
-
request['OpenPayu-Signature'] = headers['OpenPayu-Signature']
|
59
68
|
response = http.request(request)
|
60
69
|
{ response: response, request: request }
|
61
70
|
end
|
data/lib/openpayu/document.rb
CHANGED
@@ -37,9 +37,8 @@ module OpenPayU
|
|
37
37
|
raise EmptyResponseError,
|
38
38
|
"Got empty response from request: #{@request.try(:body)}"
|
39
39
|
end
|
40
|
-
if (
|
41
|
-
|
42
|
-
verify_signature(@body)
|
40
|
+
if ( response.is_a?(OpenPayU::Documents::Request) ||
|
41
|
+
%w(200 201 422 302).include?(response.code))
|
43
42
|
true
|
44
43
|
else
|
45
44
|
raise HttpStatusException,
|
@@ -48,41 +47,6 @@ module OpenPayU
|
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
def verify_signature(message)
|
52
|
-
signature = parse_signature
|
53
|
-
generated_signature = generate_signature(
|
54
|
-
message,
|
55
|
-
signature['algorithm'],
|
56
|
-
OpenPayU::Configuration.signature_key
|
57
|
-
)
|
58
|
-
if generated_signature == signature['signature']
|
59
|
-
true
|
60
|
-
else
|
61
|
-
raise WrongSignatureException,
|
62
|
-
"Invalid signature: Got message signed with:
|
63
|
-
#{signature["signature"]}. Generated signature:
|
64
|
-
#{generated_signature}"
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def parse_signature
|
70
|
-
parameters = {}
|
71
|
-
get_signature.split(';').each do |parameter|
|
72
|
-
k, v = parameter.split('=')
|
73
|
-
parameters[k] = v
|
74
|
-
end
|
75
|
-
parameters
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_signature
|
79
|
-
@response['X-OpenPayU-Signature'] ||
|
80
|
-
@response['x-openpayu-signature'] ||
|
81
|
-
@response['openpayu-signature'] ||
|
82
|
-
@response.headers['x-openpayu-signature'] ||
|
83
|
-
@response.headers['openpayu-signature']
|
84
|
-
end
|
85
|
-
|
86
50
|
def underscore_keys(hash)
|
87
51
|
deep_transform_keys(hash) { |key| key.underscore }
|
88
52
|
end
|
@@ -2,12 +2,11 @@
|
|
2
2
|
module OpenPayU
|
3
3
|
module Documents
|
4
4
|
class Response < Document
|
5
|
-
attr_accessor :parsed_data, :response, :request, :
|
5
|
+
attr_accessor :parsed_data, :response, :request, :body
|
6
6
|
|
7
|
-
def initialize(data
|
7
|
+
def initialize(data)
|
8
8
|
@response = data[:response]
|
9
9
|
@request = data[:request]
|
10
|
-
@message_name = message_name
|
11
10
|
@body = @response.body.is_a?(StringIO) ? @response.body.string :
|
12
11
|
@response.body
|
13
12
|
parse_data if verify_response
|
@@ -18,25 +17,15 @@ module OpenPayU
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def parse_data
|
21
|
-
|
22
|
-
@parsed_data = Hash.from_xml(@body)
|
23
|
-
else
|
24
|
-
@parsed_data = JSON.parse(@body)
|
25
|
-
end
|
26
|
-
if @parsed_data['OpenPayU'] && @parsed_data['OpenPayU'][@message_name]
|
27
|
-
@parsed_data = underscore_keys @parsed_data['OpenPayU'][@message_name]
|
28
|
-
elsif @parsed_data['OpenPayU']
|
29
|
-
@parsed_data = underscore_keys @parsed_data['OpenPayU']
|
30
|
-
end
|
31
|
-
@parsed_data
|
20
|
+
@parsed_data = underscore_keys JSON.parse(@body)
|
32
21
|
end
|
33
22
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
def status
|
24
|
+
@parsed_data['status']
|
25
|
+
end
|
26
|
+
|
27
|
+
def order_status
|
28
|
+
@parsed_data['orders']['orders'][1]['status']
|
40
29
|
end
|
41
30
|
|
42
31
|
Models::Order::STATUSES.each do |method|
|
@@ -7,7 +7,6 @@ module OpenPayU
|
|
7
7
|
|
8
8
|
include ActiveModel::Validations
|
9
9
|
include ActiveModel::Serializers::JSON
|
10
|
-
include ActiveModel::Serializers::Xml
|
11
10
|
|
12
11
|
attr_accessor :all_errors
|
13
12
|
|
@@ -29,26 +28,8 @@ module OpenPayU
|
|
29
28
|
prepare_keys.to_json
|
30
29
|
end
|
31
30
|
|
32
|
-
def prepare_data
|
33
|
-
|
34
|
-
generate_xml(request_type)
|
35
|
-
else
|
36
|
-
{
|
37
|
-
'OpenPayU' => {
|
38
|
-
request_type => prepare_keys(instance_values)
|
39
|
-
}
|
40
|
-
}.to_json
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def generate_xml(request_type)
|
45
|
-
'<?xml version="1.0" encoding="UTF-8"?>
|
46
|
-
<OpenPayU xmlns="http://www.openpayu.com/20/openpayu.xsd">' +
|
47
|
-
prepare_keys(instance_values).to_xml(
|
48
|
-
builder: OpenPayU::XmlBuilder.new(request_type, indent: 2),
|
49
|
-
root: request_type,
|
50
|
-
skip_types: true,
|
51
|
-
skip_instruct: true) + '</OpenPayU>'
|
31
|
+
def prepare_data
|
32
|
+
prepare_keys.to_json
|
52
33
|
end
|
53
34
|
|
54
35
|
def get_instance_values
|
@@ -59,11 +40,9 @@ module OpenPayU
|
|
59
40
|
|
60
41
|
def prepare_keys(attrs = {}, hash = get_instance_values)
|
61
42
|
hash.each_pair do |k, v|
|
62
|
-
attrs[k.camelize] =
|
43
|
+
attrs[k.camelize(:lower)] =
|
63
44
|
if v.is_a? Array
|
64
|
-
v.map
|
65
|
-
{ element.class.name.demodulize => element.prepare_keys }
|
66
|
-
end
|
45
|
+
{ k.camelize(:lower) => v.map(&:prepare_keys) }
|
67
46
|
elsif v.class.name =~ /OpenPayU::Models/
|
68
47
|
v.prepare_keys
|
69
48
|
else
|
@@ -13,7 +13,6 @@ module OpenPayU
|
|
13
13
|
:currency_code, :total_amount, presence: true
|
14
14
|
has_one_object :buyer # not required
|
15
15
|
has_one_object :fee # not required
|
16
|
-
has_many_objects :pay_methods, :pay_method # not required
|
17
16
|
has_many_objects :products, :product # not required
|
18
17
|
has_many_objects :shipping_methods, :shipping_method # not required
|
19
18
|
|
@@ -7,33 +7,11 @@ module OpenPayU
|
|
7
7
|
:description, :bank_description, :source_account_number
|
8
8
|
validates :description, :order_id, presence: true
|
9
9
|
|
10
|
-
def prepare_data
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
'OpenPayU' => {
|
16
|
-
request_type => {
|
17
|
-
'OrderId' => @order_id,
|
18
|
-
'Refund' => prepare_keys(instance_values)
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}.to_json
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def generate_xml(request_type)
|
26
|
-
'<?xml version="1.0" encoding="UTF-8"?>
|
27
|
-
<OpenPayU xmlns="http://www.openpayu.com/20/openpayu.xsd">' +
|
28
|
-
prepare_keys({
|
29
|
-
'OrderId' => @order_id,
|
30
|
-
'Refund' => prepare_keys(instance_values)
|
31
|
-
}).to_xml(
|
32
|
-
builder: OpenPayU::XmlBuilder.new(request_type, indent: 2),
|
33
|
-
root: request_type,
|
34
|
-
skip_types: true,
|
35
|
-
skip_instruct: true
|
36
|
-
) + '</OpenPayU>'
|
10
|
+
def prepare_data
|
11
|
+
{
|
12
|
+
'orderId' => @order_id,
|
13
|
+
'refund' => prepare_keys({} , instance_values.except('order_id'))
|
14
|
+
}.to_json
|
37
15
|
end
|
38
16
|
|
39
17
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
module OpenPayU
|
3
3
|
module Models
|
4
4
|
class ShippingMethod < Model
|
5
|
-
attr_accessor :country, :price, :
|
6
|
-
validates :country, :price, :
|
5
|
+
attr_accessor :country, :price, :name
|
6
|
+
validates :country, :price, :name, presence: true
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/openpayu/order.rb
CHANGED
@@ -12,12 +12,8 @@ module OpenPayU
|
|
12
12
|
# @return [Documents::Response] Response class object order
|
13
13
|
# with OrderRetrieveResponse
|
14
14
|
def self.retrieve(order_id)
|
15
|
-
url = Configuration.get_base_url + "order/#{order_id}." +
|
16
|
-
Configuration.data_format
|
17
|
-
request = Documents::Request.new(url)
|
18
15
|
Documents::Response.new(
|
19
|
-
Connection.get(
|
20
|
-
'OrderRetrieveResponse'
|
16
|
+
Connection.get("orders/#{order_id}", nil)
|
21
17
|
)
|
22
18
|
end
|
23
19
|
|
@@ -32,12 +28,8 @@ module OpenPayU
|
|
32
28
|
def self.create(order)
|
33
29
|
@order = Models::Order.new(order)
|
34
30
|
if @order.all_objects_valid?
|
35
|
-
url = Configuration.get_base_url + 'order.' + Configuration.data_format
|
36
|
-
request =
|
37
|
-
Documents::Request.new(@order.prepare_data('OrderCreateRequest'))
|
38
31
|
Documents::Response.new(
|
39
|
-
Connection.post(
|
40
|
-
'OrderCreateResponse'
|
32
|
+
Connection.post('orders', @order.prepare_data)
|
41
33
|
)
|
42
34
|
else
|
43
35
|
raise WrongOrderParameters.new(@order)
|
@@ -54,13 +46,8 @@ module OpenPayU
|
|
54
46
|
# @raise [NotImplementedException] This feature is not yet implemented
|
55
47
|
def self.status_update(status_update)
|
56
48
|
@update = OpenPayU::Models::StatusUpdate.new status_update
|
57
|
-
url = Configuration.get_base_url + "order/#{@update.order_id}/status." +
|
58
|
-
Configuration.data_format
|
59
|
-
request =
|
60
|
-
Documents::Request.new(@update.prepare_data('OrderStatusUpdateRequest'))
|
61
49
|
Documents::Response.new(
|
62
|
-
Connection.put(
|
63
|
-
'OrderStatusUpdateResponse'
|
50
|
+
Connection.put("orders/#{@update.order_id}/status", @update.prepare_data)
|
64
51
|
)
|
65
52
|
end
|
66
53
|
|
@@ -71,12 +58,8 @@ module OpenPayU
|
|
71
58
|
# @return [Documents::Response] Response class object order
|
72
59
|
# with OrderCancelResponse
|
73
60
|
def self.cancel(order_id)
|
74
|
-
url = Configuration.get_base_url + "order/#{order_id}." +
|
75
|
-
Configuration.data_format
|
76
|
-
request = Documents::Request.new(url)
|
77
61
|
Documents::Response.new(
|
78
|
-
Connection.delete(
|
79
|
-
'OrderCancelResponse'
|
62
|
+
Connection.delete("orders/#{order_id}", nil)
|
80
63
|
)
|
81
64
|
end
|
82
65
|
|
@@ -89,8 +72,7 @@ module OpenPayU
|
|
89
72
|
# @raise [WrongNotifyRequest] when generated response is empty
|
90
73
|
def self.consume_notification(request)
|
91
74
|
response = Documents::Response.new(
|
92
|
-
{ response: request, request: nil }
|
93
|
-
'OrderNotifyRequest'
|
75
|
+
{ response: request, request: nil }
|
94
76
|
)
|
95
77
|
if !response.nil?
|
96
78
|
response
|
@@ -109,9 +91,9 @@ module OpenPayU
|
|
109
91
|
def self.build_notify_response(request_id)
|
110
92
|
response = Models::NotifyResponse.new({
|
111
93
|
res_id: request_id,
|
112
|
-
status: { '
|
94
|
+
status: { 'statusCode' => 'SUCCESS' }
|
113
95
|
})
|
114
|
-
response.prepare_data
|
96
|
+
response.prepare_data
|
115
97
|
end
|
116
98
|
|
117
99
|
end
|
data/lib/openpayu/refund.rb
CHANGED
@@ -12,14 +12,8 @@ module OpenPayU
|
|
12
12
|
# with RefundCreateResponse
|
13
13
|
def self.create(data)
|
14
14
|
refund = Models::Refund.new(data)
|
15
|
-
url = Configuration.get_base_url + "order/#{refund.order_id}/refund." +
|
16
|
-
OpenPayU::Configuration.data_format
|
17
|
-
request = Documents::Request.new(
|
18
|
-
refund.prepare_data('RefundCreateRequest')
|
19
|
-
)
|
20
15
|
@response = Documents::Response.new(
|
21
|
-
Connection.post(
|
22
|
-
'RefundCreateResponse'
|
16
|
+
Connection.post("orders/#{refund.order_id}/refund", refund.prepare_data)
|
23
17
|
)
|
24
18
|
end
|
25
19
|
end
|
data/lib/openpayu/version.rb
CHANGED
data/openpayu_ruby.gemspec
CHANGED
@@ -22,13 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
if RUBY_VERSION < "1.9.3"
|
25
|
-
spec.add_development_dependency "activemodel", '~> 3.2'
|
26
|
-
spec.add_development_dependency "activesupport", '~> 3.2'
|
27
25
|
spec.add_runtime_dependency "activemodel", '~> 3.2'
|
28
26
|
spec.add_runtime_dependency "activesupport", '~> 3.2'
|
29
27
|
else
|
30
|
-
spec.add_development_dependency "activemodel"
|
31
|
-
spec.add_development_dependency "activesupport"
|
32
28
|
spec.add_runtime_dependency "activemodel"
|
33
29
|
spec.add_runtime_dependency "activesupport"
|
34
30
|
end
|