lib/active_merchant/billing/gateways/fat_zebra.rb in activemerchant-1.49.0 vs lib/active_merchant/billing/gateways/fat_zebra.rb in activemerchant-1.50.0
- old
+ new
@@ -19,12 +19,10 @@
# 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)
- @username = options[:username]
- @token = options[:token]
super
end
# To create a purchase on a credit card use:
#
@@ -37,58 +35,58 @@
post = {}
add_amount(post, money, options)
add_creditcard(post, creditcard, options)
add_extra_options(post, options)
- post[:reference] = options[:order_id]
- post[:customer_ip] = options[:ip]
+ add_order_id(post, options)
+ add_ip(post, options)
commit(:post, 'purchases', post)
end
def authorize(money, creditcard, options = {})
post = {}
add_amount(post, money, options)
add_creditcard(post, creditcard, options)
add_extra_options(post, options)
+ add_order_id(post, options)
+ add_ip(post, options)
+
post[:capture] = false
- post[:reference] = options[:order_id]
- post[:customer_ip] = options[:ip]
commit(:post, 'purchases', post)
end
def capture(money, authorization, options = {})
post = {}
add_amount(post, money, options)
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, reference)
+ def refund(money, txn_id, options={})
post = {}
add_extra_options(post, options)
- post[:amount] = money
+ add_amount(post, money, options)
post[:transaction_id] = txn_id
- post[:reference] = reference
+ 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)
+ def store(creditcard, options={})
post = {}
add_creditcard(post, creditcard)
commit(:post, "credit_cards", post)
end
@@ -123,13 +121,22 @@
def add_extra_options(post, options)
extra = {}
extra[:name] = options[:merchant] if options[:merchant]
extra[:location] = options[:merchant_location] if options[:merchant_location]
+ extra[:ecm] = "32" if options[:recurring]
post[:extra] = extra if extra.any?
end
+ def add_order_id(post, options)
+ post[:reference] = options[:order_id] || SecureRandom.hex(15)
+ end
+
+ 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
@@ -195,10 +202,10 @@
end
# Builds the auth and U-A headers for the request
def headers
{
- "Authorization" => "Basic " + Base64.strict_encode64(@username.to_s + ":" + @token.to_s).strip,
+ "Authorization" => "Basic " + Base64.strict_encode64(@options[:username].to_s + ":" + @options[:token].to_s).strip,
"User-Agent" => "Fat Zebra v1.0/ActiveMerchant #{ActiveMerchant::VERSION}"
}
end
end
end