paybox_direct 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d901596ca4dfc8d6cc31a037c6226d752d5deade
4
- data.tar.gz: bfa78c3eeceb6bbd5a002d12f0074057f50eb8dc
3
+ metadata.gz: 4560e9bb17790d500e2ad2a8846c632f276a946f
4
+ data.tar.gz: ebecf0c8f22b8f6b050d66d4863e5ee0968ed1c9
5
5
  SHA512:
6
- metadata.gz: ba3dd9e300e848cf51767c906f5b2b0be01a6497f361155320c286cebab22154d9e5bd4f0743987c6927c6d3989b0a4df30574c781a2a86d403056c49c6dc904
7
- data.tar.gz: a476ab097a23f45cd154f513b7bb3846c85674e53601b9e257fed5b86cbdde74ff9bb373c1381b3e18bf5742cd8a4550379cc4cf0b48d70f294fa18a6cd2e510
6
+ metadata.gz: bfc2e620e34d4f6d1339f787f45ef7db1c38728267abfeca187ba3b1329279bc68f8a527bef7ba2bb24a5fe4f6fe782583fca6ef5bf187b808d6fbf29c85b920
7
+ data.tar.gz: 8a018aca42b66a1d7c24abc7ad06ed936b41f5a19137bf2acb9cf2e9beef73595ca2c224f3ce782e0507ea8f99ad1038946329a5ab8262f50445a70261e3a4f2
@@ -50,13 +50,9 @@ class PayboxDirect::Request
50
50
  def execute!
51
51
  use_alt = false
52
52
  begin
53
- begin
54
- prod_url = use_alt ? PayboxDirect::PROD_FALLBACK_URL : PayboxDirect::PROD_URL
55
- uri = URI(PayboxDirect.config.is_prod ? prod_url : PayboxDirect::DEV_URL)
56
- resp = run_http_post!(uri)
57
- rescue
58
- raise PayboxDirect::ServerUnavailableError
59
- end
53
+ prod_url = use_alt ? PayboxDirect::PROD_FALLBACK_URL : PayboxDirect::PROD_URL
54
+ uri = URI(PayboxDirect.config.is_prod ? prod_url : PayboxDirect::DEV_URL)
55
+ resp = run_http_post!(uri)
60
56
  raise PayboxDirect::ServerUnavailableError if resp.code != "200"
61
57
  @fields = Rack::Utils.parse_query(resp.body)
62
58
  if !@fields.has_key?("CODEREPONSE") or @fields["CODEREPONSE"] == "00001"
@@ -71,8 +67,14 @@ class PayboxDirect::Request
71
67
  end
72
68
 
73
69
  def undo!
74
- return unless executed? and !failed?
70
+ return unless executed?
71
+ return if failed?
72
+ return unless @vars.has_key? "TYPE"
75
73
 
74
+ type = @vars["TYPE"].to_i
75
+ if type == 56
76
+ req = Request.new()
77
+ end
76
78
  @@undo_callbacks.each{ |proc| proc.call(self) }
77
79
  end
78
80
 
@@ -113,7 +115,11 @@ private
113
115
  http = self.class.http_connection(uri)
114
116
  @post_request = Net::HTTP::Post.new(uri.request_uri)
115
117
  @post_request.set_form_data(@vars)
116
- @http_resp = http.request(@post_request)
118
+ begin
119
+ @http_resp = http.request(@post_request)
120
+ rescue
121
+ raise PayboxDirect::ServerUnavailableError
122
+ end
117
123
  @is_executed = true
118
124
  @@request_callbacks.each{ |proc| proc.call(self) }
119
125
  return @http_resp
data/spec/request_spec.rb CHANGED
@@ -67,7 +67,7 @@ RSpec.describe PayboxDirect::Request do
67
67
  dev_uri = URI(PayboxDirect::DEV_URL)
68
68
 
69
69
  req = PayboxDirect::Request.new("VAR1" => "VAL1", "VAR2" => "VAL2")
70
- expect(req).to receive(:run_http_post!).with(dev_uri).and_raise(SocketError)
70
+ expect_any_instance_of(Net::HTTP).to receive(:request).and_raise(SocketError)
71
71
  expect {
72
72
  req.execute!
73
73
  }.to raise_error(PayboxDirect::ServerUnavailableError)
@@ -82,7 +82,7 @@ RSpec.describe PayboxDirect::Request do
82
82
  prod_fallback_uri = URI(PayboxDirect::PROD_FALLBACK_URL)
83
83
 
84
84
  req = PayboxDirect::Request.new("VAR1" => "VAL1", "VAR2" => "VAL2")
85
- expect(req).to receive(:run_http_post!).with(prod_uri).and_raise(SocketError)
85
+ expect(req).to receive(:run_http_post!).with(prod_uri).and_raise(PayboxDirect::ServerUnavailableError)
86
86
  expect(req).to receive(:run_http_post!).with(prod_fallback_uri) {
87
87
  OpenStruct.new({
88
88
  code: "200",
@@ -102,8 +102,8 @@ RSpec.describe PayboxDirect::Request do
102
102
  prod_fallback_uri = URI(PayboxDirect::PROD_FALLBACK_URL)
103
103
 
104
104
  req = PayboxDirect::Request.new("VAR1" => "VAL1", "VAR2" => "VAL2")
105
- expect(req).to receive(:run_http_post!).with(prod_uri).and_raise(SocketError)
106
- expect(req).to receive(:run_http_post!).with(prod_fallback_uri).and_raise(SocketError)
105
+ expect(req).to receive(:run_http_post!).with(prod_uri).and_raise(PayboxDirect::ServerUnavailableError)
106
+ expect(req).to receive(:run_http_post!).with(prod_fallback_uri).and_raise(PayboxDirect::ServerUnavailableError)
107
107
  expect {
108
108
  req.execute!
109
109
  }.to raise_error(PayboxDirect::ServerUnavailableError)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paybox_direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kévin Lesénéchal