lib/active_merchant/billing/gateways/fat_zebra.rb in activemerchant-1.66.0 vs lib/active_merchant/billing/gateways/fat_zebra.rb in activemerchant-1.67.0

- old
+ new

@@ -12,27 +12,15 @@ self.supported_cardtypes = [:visa, :master, :american_express, :jcb] self.homepage_url = 'https://www.fatzebra.com.au/' self.display_name = 'Fat Zebra' - # Setup a new instance of the gateway. - # - # The options hash should include :username and :token - # You can find your username and token at https://dashboard.fatzebra.com.au - # Under the Your Account section def initialize(options = {}) requires!(options, :username, :token) super end - # To create a purchase on a credit card use: - # - # purchase(money, creditcard) - # - # To charge a tokenized card - # - # purchase(money, "abzy87u", :cvv => "123") def purchase(money, creditcard, options = {}) post = {} add_amount(post, money, options) add_creditcard(post, creditcard, options) @@ -63,15 +51,10 @@ add_extra_options(post, options) commit(:post, "purchases/#{CGI.escape(authorization)}/capture", post) end - # Refund a transaction - # - # amount - Integer - the amount to refund - # txn_id - String - the original transaction to be refunded - # reference - String - your transaction reference def refund(money, txn_id, options={}) post = {} add_extra_options(post, options) add_amount(post, money, options) @@ -79,13 +62,10 @@ add_order_id(post, options) commit(:post, "refunds", post) end - # Tokenize a credit card - # - # The token is returned in the Response#authorization def store(creditcard, options={}) post = {} add_creditcard(post, creditcard) commit(:post, "credit_cards", post) @@ -102,18 +82,16 @@ gsub(%r(("cvv\\":\\")\d+), '\1[FILTERED]') end private - # Add the money details to the request def add_amount(post, money, options) post[:currency] = (options[:currency] || currency(money)) post[:currency] = post[:currency].upcase if post[:currency] post[:amount] = money end - # Add the credit card details to the request def add_creditcard(post, creditcard, options = {}) if creditcard.respond_to?(:number) post[:card_number] = creditcard.number post[:card_expiry] = "#{creditcard.month}/#{creditcard.year}" post[:cvv] = creditcard.verification_value if creditcard.verification_value? @@ -132,11 +110,11 @@ def add_extra_options(post, options) extra = {} extra[:ecm] = "32" if options[:recurring] extra[:cavv] = options[:cavv] if options[:cavv] - extra[:xid] = options[:cavv] if options[:xid] + extra[:xid] = options[:xid] if options[:xid] extra[:sli] = options[:sli] if options[:sli] extra[:name] = options[:merchant] if options[:merchant] extra[:location] = options[:merchant_location] if options[:merchant_location] post[:extra] = extra if extra.any? end @@ -147,11 +125,10 @@ def add_ip(post, options) post[:customer_ip] = options[:ip] || "127.0.0.1" end - # Post the data to the gateway def commit(method, uri, parameters=nil) response = begin parse(ssl_request(method, get_url(uri), parameters.to_json, headers)) rescue ResponseError => e return Response.new(false, "Invalid Login") if(e.response.code == "401") @@ -192,11 +169,10 @@ else "Unknown Error" end end - # Parse the returned JSON, if parse errors are raised then return a detailed error. def parse(response) begin JSON.parse(response) rescue JSON::ParserError msg = 'Invalid JSON response received from Fat Zebra. Please contact support@fatzebra.com.au if you continue to receive this message.' @@ -207,16 +183,14 @@ "errors" => [msg] } end end - # Build the URL based on the AM mode and the URI def get_url(uri) base = test? ? self.test_url : self.live_url base + "/" + uri end - # Builds the auth and U-A headers for the request def headers { "Authorization" => "Basic " + Base64.strict_encode64(@options[:username].to_s + ":" + @options[:token].to_s).strip, "User-Agent" => "Fat Zebra v1.0/ActiveMerchant #{ActiveMerchant::VERSION}" }