dpickett-agcod 0.0.0 → 0.0.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.
data/agcod.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{agcod}
5
- s.version = "0.0.0"
5
+ s.version = "0.0.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Dan Pickett"]
9
- s.date = %q{2009-07-02}
9
+ s.date = %q{2009-07-14}
10
10
  s.email = %q{dpickett@enlightsolutions.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -20,8 +20,10 @@ Gem::Specification.new do |s|
20
20
  "Rakefile",
21
21
  "VERSION",
22
22
  "agcod.gemspec",
23
- "features/create_a_giftcard.feature",
23
+ "cucumber.yml",
24
+ "features/error_handling.feature",
24
25
  "features/step_definitions/agcod_steps.rb",
26
+ "features/success_certification.feature",
25
27
  "features/support/app_root/config/agcod.example.yml",
26
28
  "features/support/env.rb",
27
29
  "lib/agcod.rb",
@@ -36,6 +38,9 @@ Gem::Specification.new do |s|
36
38
  "lib/agcod/tasks.rb",
37
39
  "lib/agcod/tasks/certification.rake",
38
40
  "lib/agcod/void_gift_card_creation.rb",
41
+ "manual_features/cancel_claimed_giftcard.feature",
42
+ "manual_features/insufficient_funds.feature",
43
+ "manual_features/retry_and_http.feature",
39
44
  "tasks/agcod.rake",
40
45
  "test/agcod/configuration_test.rb",
41
46
  "test/app_root/config/agcod.yml",
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: "--require features/support/env.rb --require features/step_definitions/agcod_steps.rb"
@@ -0,0 +1,31 @@
1
+ Feature: Error Handling
2
+ As a user of the agcod service
3
+ I want to correctly handle errors
4
+ So I can get certified
5
+
6
+ Background:
7
+ Given I have access to the AGCOD web service
8
+ And I am logging transactions
9
+
10
+ Scenario: #8 Error Handling E203
11
+ Given I specify response_id "AAAEPY26ZX1BSY"
12
+ And I want to cancel request "2"
13
+ When I send the request
14
+ Then I should not receive a successful response
15
+
16
+ Scenario: #9 Error Handling E204
17
+ Given I specify response_id "A3REPY26ZX1BSY"
18
+ And I want to cancel request "2"
19
+ When I send the request
20
+ Then I should not receive a successful response
21
+
22
+ Scenario: #10 Error Handling for no currency code
23
+ Given I specify the currency of ""
24
+ And I want to send request "7"
25
+ When I send the request
26
+ Then I should not receive a successful response
27
+
28
+ Scenario: #11 Error Handling with Max Limit
29
+ Given I want to send request "8"
30
+ When I send the request
31
+ Then I should not receive a successful response
@@ -0,0 +1,47 @@
1
+ Feature: Successful Cases for Certification
2
+ As a user of the AGCOD api
3
+ I want to run certification tests that create successful responses
4
+ So that I can be authorized for production access
5
+
6
+ Background:
7
+ Given I have access to the AGCOD web service
8
+ And I am logging transactions
9
+
10
+ Scenario: #1 Successful Health Check
11
+ Given I want to send a health check request
12
+ When I send the request
13
+ Then I should receive a successful response
14
+
15
+ Scenario: #2a Successful Creation of a Gift Card for $12
16
+ Given I want to send request "1"
17
+ When I send the request
18
+ Then I should receive a successful response
19
+ And I should get a claim code
20
+
21
+ Scenario: #2b Successful Creation of a Gift Card for $999
22
+ Given I want to send request "2"
23
+ When I send the request
24
+ Then I should receive a successful response
25
+ And I should get a claim code
26
+
27
+ Scenario: #3 Sending the same Gift Card Request ID
28
+ Given I've sent request "3"
29
+ And the request was successful
30
+ And I want to create a gift card with the same request id
31
+ When I send the request
32
+ Then I should not receive a successful response
33
+
34
+ Scenario: #4 Cancel a Gift Card Successfully
35
+ Given I've sent request "4"
36
+ And the request was successful
37
+ And I want to cancel the gift card requested
38
+ When I send the request
39
+ Then I should receive a successful response
40
+
41
+ Scenario: #5 Void a Gift Card Successfully
42
+ Given I've sent request "5"
43
+ And the request was successful
44
+ And I want to void the gift card requested
45
+ When I send the request
46
+ Then I should receive a successful response
47
+
@@ -26,6 +26,8 @@ module Agcod
26
26
  if self.successful?
27
27
  @claim_code = self.xml_response.root.elements["gcClaimCode"].text
28
28
  @response_id = self.xml_response.root.elements["gcCreationResponseId"].text
29
+ else
30
+ void_on_resend
29
31
  end
30
32
  end
31
33
 
@@ -39,5 +41,47 @@ module Agcod
39
41
  "timestamp" => self.timestamp
40
42
  }.to_yaml(name)
41
43
  end
44
+
45
+ protected
46
+ def send_request
47
+ begin
48
+ super
49
+ rescue SocketError,
50
+ Timeout::Error,
51
+ ActiveResource::TimeoutError,
52
+ Errno::ECONNREFUSED,
53
+ Errno::EHOSTDOWN,
54
+ Errno::EHOSTUNREACH
55
+
56
+ attempt_to_void
57
+ end
58
+ end
59
+
60
+ def attempt_retry
61
+ #check for retry error
62
+ if self.xml_response.root.elements["Status/errorCode"] &&
63
+ self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
64
+ !@sent_retry
65
+
66
+ @sent_retry = true
67
+ submit
68
+ end
69
+ end
70
+
71
+ private
72
+ def void_on_resend
73
+ if self.xml_response.root.elements["Status/errorCode"] &&
74
+ self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
75
+ !@resend_void_sent
76
+
77
+ @resend_void_sent = true
78
+ attempt_to_void
79
+ end
80
+ end
81
+
82
+ def attempt_to_void
83
+ Agcod::VoidGiftCardCreation.new("request_id" => self.request_id).submit
84
+ end
85
+
42
86
  end
43
87
  end
data/lib/agcod/request.rb CHANGED
@@ -19,8 +19,10 @@ module Agcod
19
19
 
20
20
  send_request
21
21
 
22
- process_response
23
- log if Agcod::Configuration.logger
22
+ if @response
23
+ process_response
24
+ log if Agcod::Configuration.logger
25
+ end
24
26
  end
25
27
 
26
28
  def successful?
@@ -52,14 +54,6 @@ module Agcod
52
54
  def process_response
53
55
  parse_response
54
56
 
55
- #check for retry error
56
- if self.xml_response.root.elements["Status/errorCode"] &&
57
- self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
58
- !@sent_retry
59
-
60
- @sent_retry = true
61
- submit
62
- end
63
57
 
64
58
  @errors = []
65
59
 
@@ -79,11 +73,24 @@ module Agcod
79
73
  @xml_response ||= REXML::Document.new(self.response)
80
74
  end
81
75
 
82
- private
76
+ def attempt_retry
77
+ #check for retry error
78
+ if self.xml_response.root.elements["Status/errorCode"] &&
79
+ self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
80
+ !@sent_retry
81
+
82
+ @sent_retry = true
83
+ submit
84
+ end
85
+ end
86
+
87
+ protected
83
88
  def send_request
84
89
  #send the request
85
90
  uri = URI.parse(Agcod::Configuration.uri)
86
91
  http = Net::HTTP.new(uri.host, uri.port)
92
+ http.read_timeout = 20
93
+ http.open_timeout = 20
87
94
  http.use_ssl = true
88
95
 
89
96
  net_response, @response = http.get(uri.path + "?" + self.request)
@@ -129,7 +136,6 @@ module Agcod
129
136
 
130
137
 
131
138
  def sort_parameters(params)
132
- key_value_strings = []
133
139
  params.sort{|a, b| a[0].downcase <=> b[0].downcase }
134
140
  end
135
141
 
@@ -0,0 +1,13 @@
1
+ Feature: Cancel claimed Gift Card Error Handling
2
+ As a user of the agcod service
3
+ I want to handle when I attempt to cancel a claimed gift card
4
+ So I can get certified
5
+
6
+ Background:
7
+ Given I have access to the AGCOD web service
8
+ And I am logging transactions
9
+
10
+ Scenario: Claimed Gift Card
11
+ Given I want to cancel request "1"
12
+ When I send the request
13
+ Then I should not receive a successful response
@@ -0,0 +1,13 @@
1
+ Feature: Insufficient Funds
2
+ As a user of the agcod service
3
+ I want to handle when I have insufficient funds appropriately
4
+ So I can get certified
5
+
6
+ Background:
7
+ Given I have access to the AGCOD web service
8
+ And I am logging transactions
9
+
10
+ Scenario: Insufficient Funds
11
+ Given I want to send request "6"
12
+ And I send the request
13
+ Then I should not receive a successful response
@@ -0,0 +1,46 @@
1
+ Feature: Retry responses and HTTP Errors
2
+ As a user of AGCOD
3
+ I want to properly handle retry responses and HTTP errors
4
+ So that I can get certified
5
+
6
+ Background:
7
+ Given I have access to the AGCOD web service
8
+ And I am logging transactions
9
+
10
+ Scenario: #12 RESEND creation request
11
+ Given I want to send request "9"
12
+ When I send the request
13
+ Then I should not receive a successful response
14
+
15
+ Scenario: #13 RESEND cancel request
16
+ Given I want to cancel request "2"
17
+ When I send the request
18
+ Then I should not receive a successful response
19
+
20
+ Scenario: #14 HTTP error
21
+ Given I want to send request "10"
22
+ When I send the request
23
+ Then I should not receive a successful response
24
+
25
+ Scenario: #15 HTTP Void Error
26
+ Given I want to void request "10"
27
+ When I send the request
28
+ Then I should not receive a successful response
29
+
30
+ Scenario: #16 HTTP Cancel Error
31
+ Given I want to cancel request "3"
32
+ When I send the request
33
+ Then I should not receive a successful response
34
+
35
+ Scenario: #17 minimum amount
36
+ Given I want to send request "11"
37
+ When I send the request
38
+ Then I should not receive a successful response
39
+
40
+ Scenario: #17b $12 gift card
41
+ Given I want to send request "12"
42
+ When I send the request
43
+ Then I should receive a successful resposne
44
+
45
+
46
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-agcod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-02 00:00:00 -07:00
12
+ date: 2009-07-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,8 +30,10 @@ files:
30
30
  - Rakefile
31
31
  - VERSION
32
32
  - agcod.gemspec
33
- - features/create_a_giftcard.feature
33
+ - cucumber.yml
34
+ - features/error_handling.feature
34
35
  - features/step_definitions/agcod_steps.rb
36
+ - features/success_certification.feature
35
37
  - features/support/app_root/config/agcod.example.yml
36
38
  - features/support/env.rb
37
39
  - lib/agcod.rb
@@ -46,6 +48,9 @@ files:
46
48
  - lib/agcod/tasks.rb
47
49
  - lib/agcod/tasks/certification.rake
48
50
  - lib/agcod/void_gift_card_creation.rb
51
+ - manual_features/cancel_claimed_giftcard.feature
52
+ - manual_features/insufficient_funds.feature
53
+ - manual_features/retry_and_http.feature
49
54
  - tasks/agcod.rake
50
55
  - test/agcod/configuration_test.rb
51
56
  - test/app_root/config/agcod.yml
@@ -1,11 +0,0 @@
1
- Feature: As a user of the AGCOD web service
2
- I want create a gift card
3
- So that I can remit payment to a third party
4
-
5
- Scenario: Pay someone $35 successfully
6
- Given I have access to the AGCOD web service
7
- And I want to create a gift card in the amount of $35.00
8
- When I send the request
9
- Then it should be successful
10
- And I should get a response id
11
- And I should get a claim code