lib/agcod/create_gift_card.rb in dpickett-agcod-0.0.0 vs lib/agcod/create_gift_card.rb in dpickett-agcod-0.0.1
- old
+ new
@@ -24,10 +24,12 @@
def process_response
super
if self.successful?
@claim_code = self.xml_response.root.elements["gcClaimCode"].text
@response_id = self.xml_response.root.elements["gcCreationResponseId"].text
+ else
+ void_on_resend
end
end
attr_reader :claim_code, :response_id, :value
@@ -37,7 +39,49 @@
"claim_code" => self.claim_code,
"value" => self.value,
"timestamp" => self.timestamp
}.to_yaml(name)
end
+
+ protected
+ def send_request
+ begin
+ super
+ rescue SocketError,
+ Timeout::Error,
+ ActiveResource::TimeoutError,
+ Errno::ECONNREFUSED,
+ Errno::EHOSTDOWN,
+ Errno::EHOSTUNREACH
+
+ attempt_to_void
+ end
+ end
+
+ def attempt_retry
+ #check for retry error
+ if self.xml_response.root.elements["Status/errorCode"] &&
+ self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
+ !@sent_retry
+
+ @sent_retry = true
+ submit
+ end
+ end
+
+ private
+ def void_on_resend
+ if self.xml_response.root.elements["Status/errorCode"] &&
+ self.xml_response.root.elements["Status/errorCode"].text == "E100" &&
+ !@resend_void_sent
+
+ @resend_void_sent = true
+ attempt_to_void
+ end
+ end
+
+ def attempt_to_void
+ Agcod::VoidGiftCardCreation.new("request_id" => self.request_id).submit
+ end
+
end
end