Creates a new MerchantWareGateway
The gateway requires that a valid login, password, and name be passed in the options hash.
:login - The MerchantWARE SiteID.
:password - The MerchantWARE Key.
:name - The MerchantWARE Name.
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 36 36: def initialize(options = {}) 37: requires!(options, :login, :password, :name) 38: @options = options 39: super 40: end
Capture authorized funds from a credit card.
money - The amount to be captured as anInteger value in cents.
authorization - The authorization string returned from the initial authorization.
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 73 73: def capture(money, authorization, options = {}) 74: request = build_capture_request(:capture, money, authorization, options) 75: commit(:capture, request) 76: end
Refund an amount back a cardholder
money - The amount to be refunded as an Integer value in cents.
identification - The credit card you want to refund or the authorization for the existing transaction you are refunding.
options
:order_id - A unique reference for this order (required when performing a non-referenced credit)
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 99 99: def credit(money, identification, options = {}) 100: if identification.is_a?(String) 101: deprecated CREDIT_DEPRECATION_MESSAGE 102: refund(money, identification, options) 103: else 104: perform_credit(money, identification, options) 105: end 106: end
Authorize and immediately capture funds from a credit card.
money - The amount to be authorized as anInteger value in cents.
credit_card - The CreditCard details for the transaction.
options
:order_id - A unique reference for this order (required).
:billing_address - The billing address for the cardholder.
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 63 63: def purchase(money, credit_card, options = {}) 64: request = build_purchase_request(:purchase, money, credit_card, options) 65: commit(:purchase, request) 66: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 108 108: def refund(money, reference, options = {}) 109: perform_reference_credit(money, reference, options) 110: end
Void a transaction.
authorization - The authorization string returned from the initial authorization or purchase.
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 82 82: def void(authorization, options = {}) 83: reference, options[:order_id] = split_reference(authorization) 84: 85: request = soap_request(:void) do |xml| 86: add_reference(xml, reference) 87: end 88: commit(:void, request) 89: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 199 199: def add_address(xml, options) 200: if address = options[:billing_address] || options[:address] 201: xml.tag! "strAVSStreetAddress", address[:address1] 202: xml.tag! "strAVSZipCode", address[:zip] 203: end 204: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 191 191: def add_amount(xml, money, tag = "strAmount") 192: xml.tag! tag, amount(money) 193: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 174 174: def add_credentials(xml) 175: xml.tag! "strSiteId", @options[:login] 176: xml.tag! "strKey", @options[:password] 177: xml.tag! "strName", @options[:name] 178: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 206 206: def add_credit_card(xml, credit_card) 207: xml.tag! "strPAN", credit_card.number 208: xml.tag! "strExpDate", expdate(credit_card) 209: xml.tag! "strCardHolder", credit_card.name 210: xml.tag! "strCVCode", credit_card.verification_value if credit_card.verification_value? 211: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 187 187: def add_invoice(xml, options) 188: xml.tag! "strOrderNumber", options[:order_id].to_s.gsub(/[^\w]/, '').slice(0, 25) 189: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 195 195: def add_reference(xml, reference) 196: xml.tag! "strReferenceCode", reference 197: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 140 140: def build_capture_request(action, money, identification, options) 141: reference, options[:order_id] = split_reference(identification) 142: 143: request = soap_request(action) do |xml| 144: add_reference(xml, reference) 145: add_invoice(xml, options) 146: add_amount(xml, money) 147: end 148: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 129 129: def build_purchase_request(action, money, credit_card, options) 130: requires!(options, :order_id) 131: 132: request = soap_request(action) do |xml| 133: add_invoice(xml, options) 134: add_amount(xml, money) 135: add_credit_card(xml, credit_card) 136: add_address(xml, options) 137: end 138: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 262 262: def commit(action, request) 263: begin 264: data = ssl_post(URL, request, 265: "Content-Type" => 'text/xml; charset=utf-8', 266: "SOAPAction" => "http://merchantwarehouse.com/MerchantWARE/Client/TransactionRetail/#{ACTIONS[action]}" 267: ) 268: response = parse(action, data) 269: rescue ActiveMerchant::ResponseError => e 270: response = parse_error(e.response) 271: end 272: 273: Response.new(response[:success], response[:message], response, 274: :test => test?, 275: :authorization => authorization_from(response), 276: :avs_result => { :code => response["AVSResponse"] }, 277: :cvv_result => response["CVResponse"] 278: ) 279: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 180 180: def expdate(credit_card) 181: year = sprintf("%.4i", credit_card.year) 182: month = sprintf("%.2i", credit_card.month) 183: 184: "#{month}#{year[-2..-1]}" 185: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 217 217: def parse(action, data) 218: response = {} 219: xml = REXML::Document.new(data) 220: 221: root = REXML::XPath.first(xml, "//#{ACTIONS[action]}Response/#{ACTIONS[action]}Result") 222: 223: root.elements.each do |element| 224: response[element.name] = element.text 225: end 226: 227: status, code, message = response["ApprovalStatus"].split(";") 228: response[:status] = status 229: 230: if response[:success] = status == "APPROVED" 231: response[:message] = status 232: else 233: response[:message] = message 234: response[:failure_code] = code 235: end 236: 237: response 238: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 240 240: def parse_error(http_response) 241: response = {} 242: response[:http_code] = http_response.code 243: response[:http_message] = http_response.message 244: response[:success] = false 245: 246: document = REXML::Document.new(http_response.body) 247: 248: node = REXML::XPath.first(document, "//soap:Fault") 249: 250: node.elements.each do |element| 251: response[element.name] = element.text 252: end 253: 254: response[:message] = response["faultstring"].to_s.gsub("\n", " ") 255: response 256: rescue REXML::ParseException => e 257: response[:http_body] = http_response.body 258: response[:message] = "Failed to parse the failed response" 259: response 260: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 162 162: def perform_credit(money, credit_card, options) 163: requires!(options, :order_id) 164: 165: request = soap_request(:credit) do |xml| 166: add_invoice(xml, options) 167: add_amount(xml, money) 168: add_credit_card(xml, credit_card) 169: end 170: 171: commit(:credit, request) 172: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 150 150: def perform_reference_credit(money, identification, options) 151: reference, options[:order_id] = split_reference(identification) 152: 153: request = soap_request(:reference_credit) do |xml| 154: add_reference(xml, reference) 155: add_invoice(xml, options) 156: add_amount(xml, money, "strOverrideAmount") 157: end 158: 159: commit(:reference_credit, request) 160: end
# File lib/active_merchant/billing/gateways/merchant_ware.rb, line 115 115: def soap_request(action) 116: xml = Builder::XmlMarkup.new :indent => 2 117: xml.instruct! 118: xml.tag! "env:Envelope", ENV_NAMESPACES do 119: xml.tag! "env:Body" do 120: xml.tag! ACTIONS[action], "xmlns" => TX_NAMESPACE do 121: add_credentials(xml) 122: yield xml 123: end 124: end 125: end 126: xml.target! 127: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.