Class: NetRegistry::ResponseBuilder
- Inherits:
-
Object
- Object
- NetRegistry::ResponseBuilder
- Defined in:
- lib/net_registry/response_builder.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize ⇒ ResponseBuilder
constructor
A new instance of ResponseBuilder.
-
#parse(response) ⇒ Object
parse HTTP request response body into a response object return factory itself.
-
#verify_params(params = {}) ⇒ Object
command (String): Denotes which action we’re taking.
Constructor Details
#initialize ⇒ ResponseBuilder
Returns a new instance of ResponseBuilder.
32 33 34 |
# File 'lib/net_registry/response_builder.rb', line 32 def initialize @response = NetRegistry::Response.new end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
30 31 32 |
# File 'lib/net_registry/response_builder.rb', line 30 def response @response end |
Instance Method Details
#create ⇒ Object
63 64 65 |
# File 'lib/net_registry/response_builder.rb', line 63 def create @response end |
#parse(response) ⇒ Object
parse HTTP request response body into a response object return factory itself. To get the response object, use #create method
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/net_registry/response_builder.rb', line 70 def parse(response) raise TypeError, "Response is not a string" if !response.is_a?(String) @full_response = response.split("\n").map(&:strip) if @full_response.first == "failed" # remove all spaces until the dot lines = @full_response.drop_while { |x| x != "." } if lines.empty? @response.text = @full_response[1] else lines.shift lines[0].slice!("response_text=") @response.text = lines[0] end @response.status = "failed" @response.code = -1 else @full_response.each do |line| data = line.split("=") case data.first when "card_number", "card_no" @response.transaction.card.number = data[1] when "response_text" @response.text = data[1].to_s when "amount", "total_amount" @response.transaction.amount = data[1] when "status" @response.status = data[1] when "txnref", "txn_ref" @response.transaction.reference = data[1] when "transaction_no" @response.transaction.number = data[1] when "bank_ref" @response.transaction.bank_reference = data[1] when "card_desc" @response.transaction.card.description = data[1] when "response_code" @response.code = data[1] when "card_type" @response.transaction.card.type = data[1] when "time" @response.transaction.time = data[1] when "command" @response.transaction.command = data[1] when "card_expiry" @response.transaction.card.expiry = data[1] when "result" @response.result = data[1] when "settlement_date" @response.transaction.settlement_date = data[1] when "rrn" @response.transaction.rrn = data[1] when "MID" @response.transaction.merchant_id = data[1] else end end @receipt = @full_response.drop_while { |line| !line.include?("Reciept follows") } if @receipt.include?("Reciept follows") @receipt = @receipt[1...-2] @response.transaction.receipt = @receipt.join("\n") end end self end |
#verify_params(params = {}) ⇒ Object
command (String): Denotes which action we’re taking.
Only accepts the following actions:
purchase, refund, preauth, status.
params (Hash): Variables to pass to NetRegistry
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/net_registry/response_builder.rb', line 40 def verify_params(params = {}) success = false params = process_params(params) case params[:COMMAND] when "purchase" @response.text, success = validate_purchase_params(params) when "refund" @response.text, success = validate_refund_params(params) when "preauth" @response.text, success = validate_preauth_params(params) when "status" @response.text, success = validate_status_params(params) else @response.text = "Invalid command. Only [purchase status preauth refund] are valid." success = false end @response.code = 0 if success @response.result = 0 if success @response.status = "" if success @response.success? end |