lib/active_merchant/billing/gateways/cashnet.rb in activemerchant-1.124.0 vs lib/active_merchant/billing/gateways/cashnet.rb in activemerchant-1.125.0
- old
+ new
@@ -39,20 +39,20 @@
end
def purchase(money, payment_object, options = {})
post = {}
add_creditcard(post, payment_object)
- add_invoice(post, options)
+ add_invoice(post, money, options)
add_address(post, options)
add_customer_data(post, options)
commit('SALE', money, post)
end
def refund(money, identification, options = {})
post = {}
post[:origtx] = identification
- add_invoice(post, options)
+ add_invoice(post, money, options)
add_customer_data(post, options)
commit('REFUND', money, post)
end
def supports_scrubbing?
@@ -67,11 +67,10 @@
end
private
def commit(action, money, fields)
- fields[:amount] = amount(money)
url = (test? ? test_url : live_url) + CGI.escape(@options[:merchant_gateway_name])
raw_response = ssl_post(url, post_data(action, fields))
parsed_response = parse(raw_response)
return unparsable_response(raw_response) unless parsed_response
@@ -90,10 +89,11 @@
response[:result] == '0'
end
def post_data(action, parameters = {})
post = {}
+
post[:command] = action
post[:merchant] = @options[:merchant]
post[:operator] = @options[:operator]
post[:password] = @options[:password]
post[:station] = (@options[:station] || 'WEB')
@@ -108,12 +108,22 @@
post[:card_name_g] = creditcard.name
post[:fname] = creditcard.first_name
post[:lname] = creditcard.last_name
end
- def add_invoice(post, options)
+ def add_invoice(post, money, options)
post[:order_number] = options[:order_id] if options[:order_id].present?
- post[:itemcode] = (options[:item_code] || @options[:default_item_code])
+
+ if options[:item_codes].present?
+ codes_and_amounts = options[:item_codes].transform_keys { |key| key.to_s.delete('_') }
+ codes_and_amounts.each do |key, value|
+ post[key] = value if key.start_with?('itemcode')
+ post[key] = amount(value.to_i) if key.start_with?('amount')
+ end
+ else
+ post[:itemcode] = (options[:item_code] || @options[:default_item_code])
+ post[:amount] = amount(money.to_i)
+ end
end
def add_address(post, options)
if address = (options[:shipping_address] || options[:billing_address] || options[:address])
post[:addr_g] = String(address[:address1]) + ',' + String(address[:address2])