lib/paynow_sdk.rb in paynow_sdk-0.1.4 vs lib/paynow_sdk.rb in paynow_sdk-0.1.6

- old
+ new

@@ -49,24 +49,24 @@ attr_accessor :success, :instructions, :has_redirect, :hash, :redirect_url, :error, :poll_url def initialize(data) @data = data - self.status = data["status"] - self.success = data["status"].downcase != "error" - self.has_redirect = data["browserurl"] - self.hash = data["hash"] + @status = data["status"] + @success = data["status"].downcase != "error" + @has_redirect = data["browserurl"] + @hash = data["hash"] - if !self.success - self.poll_url = data["pollurl"] - self.error = data["error"] + if !success + @poll_url = data["pollurl"] + @error = data["error"] end - if !self.has_redirect - self.redirect_url = data["browserurl"] + if !has_redirect + @redirect_url = data["browserurl"] end if data.include?(instructions) - self.instruction = data["instructions"] + @instruction = data["instructions"] end end end #Create a transaction @@ -142,16 +142,16 @@ url_initiate_transaction = "https://www.paynow.co.zw/interface/initiatetransaction" response = HTTParty.post(url_initiate_transaction, data) response_object = rebuild_response(response.parsed_response) if response_object.status.to_s == "error" - return InitalResponse.new(response_object) + InitalResponse.new(response_object) end if !verify_hash(response_object, integration_key) - raise HashMismatchException("Hashes do not match") + HashMismatchException("Hashes do not match") end - return InitalResponse.new(response_object) + InitalResponse.new(response_object) end def paying_mobile(payment, phone, method) # if payment.total <= 0 # raise "Transaction total cannot be less than 1" @@ -253,14 +253,16 @@ new_hash = self.ahash(response, integration_key) return old_hash == new_hash end + #building the response into a key/value pair hash def rebuild_response(response) res = {} - response.map do |key, value| - res[key] = value[0].to_s + response.each do |key, array| + array.each do |value| + res[key] = value[0].to_s + end end - - return res + res end end