# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 40 40: def self.included(base) 41: base.default_currency = 'CAD' 42: 43: # The countries the gateway supports merchants from as 2 digit ISO country codes 44: base.supported_countries = ['CA'] 45: 46: # The card types supported by the payment gateway 47: base.supported_cardtypes = [:visa, :master, :american_express] 48: 49: # The homepage URL of the gateway 50: base.homepage_url = 'http://www.beanstream.com/' 51: 52: # The name of the gateway 53: base.display_name = 'Beanstream.com' 54: end
Only :login is required by default, which is the merchant’s merchant ID. If you’d like to perform void, capture or refund transactions then you’ll also need to add a username and password to your account under administration -> account settings -> order settings -> Use username/password validation
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 61 61: def initialize(options = {}) 62: requires!(options, :login) 63: @options = options 64: super 65: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 67 67: def capture(money, authorization, options = {}) 68: reference, amount, type = split_auth(authorization) 69: 70: post = {} 71: add_amount(post, money) 72: add_reference(post, reference) 73: add_transaction_type(post, :capture) 74: commit(post) 75: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 86 86: def credit(money, source, options = {}) 87: deprecated Gateway::CREDIT_DEPRECATION_MESSAGE 88: refund(money, source, options) 89: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 77 77: def refund(money, source, options = {}) 78: post = {} 79: reference, amount, type = split_auth(source) 80: add_reference(post, reference) 81: add_transaction_type(post, refund_action(type)) 82: add_amount(post, money) 83: commit(post) 84: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 128 128: def add_address(post, options) 129: prepare_address_for_non_american_countries(options) 130: 131: if billing_address = options[:billing_address] || options[:address] 132: post[:ordName] = billing_address[:name] 133: post[:ordEmailAddress] = options[:email] 134: post[:ordPhoneNumber] = billing_address[:phone] 135: post[:ordAddress1] = billing_address[:address1] 136: post[:ordAddress2] = billing_address[:address2] 137: post[:ordCity] = billing_address[:city] 138: post[:ordProvince] = billing_address[:state] 139: post[:ordPostalCode] = billing_address[:zip] 140: post[:ordCountry] = billing_address[:country] 141: end 142: if shipping_address = options[:shipping_address] 143: post[:shipName] = shipping_address[:name] 144: post[:shipEmailAddress] = options[:email] 145: post[:shipPhoneNumber] = shipping_address[:phone] 146: post[:shipAddress1] = shipping_address[:address1] 147: post[:shipAddress2] = shipping_address[:address2] 148: post[:shipCity] = shipping_address[:city] 149: post[:shipProvince] = shipping_address[:state] 150: post[:shipPostalCode] = shipping_address[:zip] 151: post[:shipCountry] = shipping_address[:country] 152: post[:shippingMethod] = shipping_address[:shipping_method] 153: post[:deliveryEstimate] = shipping_address[:delivery_estimate] 154: end 155: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 116 116: def add_amount(post, money) 117: post[:trnAmount] = amount(money) 118: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 186 186: def add_check(post, check) 187: # The institution number of the consumer’s financial institution. Required for Canadian dollar EFT transactions. 188: post[:institutionNumber] = check.institution_number 189: 190: # The bank transit number of the consumer’s bank account. Required for Canadian dollar EFT transactions. 191: post[:transitNumber] = check.transit_number 192: 193: # The routing number of the consumer’s bank account. Required for US dollar EFT transactions. 194: post[:routingNumber] = check.routing_number 195: 196: # The account number of the consumer’s bank account. Required for both Canadian and US dollar EFT transactions. 197: post[:accountNumber] = check.account_number 198: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 176 176: def add_credit_card(post, credit_card) 177: if credit_card 178: post[:trnCardOwner] = credit_card.name 179: post[:trnCardNumber] = credit_card.number 180: post[:trnExpMonth] = format(credit_card.month, :two_digits) 181: post[:trnExpYear] = format(credit_card.year, :two_digits) 182: post[:trnCardCvd] = credit_card.verification_value 183: end 184: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 166 166: def add_invoice(post, options) 167: post[:trnOrderNumber] = options[:order_id] 168: post[:trnComments] = options[:description] 169: post[:ordItemPrice] = amount(options[:subtotal]) 170: post[:ordShippingPrice] = amount(options[:shipping]) 171: post[:ordTax1Price] = amount(options[:tax1] || options[:tax]) 172: post[:ordTax2Price] = amount(options[:tax2]) 173: post[:ref1] = options[:custom] 174: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 120 120: def add_original_amount(post, amount) 121: post[:trnAmount] = amount 122: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 124 124: def add_reference(post, reference) 125: post[:adjId] = reference 126: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 200 200: def add_secure_profile_variables(post, options = {}) 201: post[:serviceVersion] = SP_SERVICE_VERSION 202: post[:responseFormat] = 'QS' 203: post[:cardValidation] = (options[:cardValidation].to_i == 1) || '0' 204: 205: post[:operationType] = options[:operationType] || options[:operation] || secure_profile_action(:new) 206: post[:customerCode] = options[:billing_id] || options[:vault_id] || false 207: post[:status] = options[:status] 208: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 256 256: def add_source(post, source) 257: if source.is_a?(String) or source.is_a?(Integer) 258: post[:customerCode] = source 259: else 260: card_brand(source) == "check" ? add_check(post, source) : add_credit_card(post, source) 261: end 262: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 264 264: def add_transaction_type(post, action) 265: post[:trnType] = TRANSACTIONS[action] 266: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 229 229: def commit(params, use_profile_api = false) 230: post(post_data(params,use_profile_api),use_profile_api) 231: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 248 248: def message_from(response) 249: response[:messageText] || response[:responseMessage] 250: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 210 210: def parse(body) 211: results = {} 212: if !body.nil? 213: body.split(/&/).each do |pair| 214: key,val = pair.split(/=/) 215: results[key.to_sym] = val.nil? ? nil : CGI.unescape(val) 216: end 217: end 218: 219: # Clean up the message text if there is any 220: if results[:messageText] 221: results[:messageText].gsub!(/<LI>/, "") 222: results[:messageText].gsub!(/(\.)?<br>/, ". ") 223: results[:messageText].strip! 224: end 225: 226: results 227: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 233 233: def post(data, use_profile_api=nil) 234: response = parse(ssl_post((use_profile_api ? SECURE_PROFILE_URL : URL), data)) 235: response[:customer_vault_id] = response[:customerCode] if response[:customerCode] 236: build_response(success?(response), message_from(response), response, 237: :test => test? || response[:authCode] == "TEST", 238: :authorization => authorization_from(response), 239: :cvv_result => CVD_CODES[response[:cvdId]], 240: :avs_result => { :code => (AVS_CODES.include? response[:avsId]) ? AVS_CODES[response[:avsId]] : response[:avsId] } 241: ) 242: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 268 268: def post_data(params, use_profile_api) 269: params[:requestType] = 'BACKEND' 270: if use_profile_api 271: params[:merchantId] = @options[:login] 272: params[:passCode] = @options[:secure_profile_api_key] 273: else 274: params[:username] = @options[:user] if @options[:user] 275: params[:password] = @options[:password] if @options[:password] 276: params[:merchant_id] = @options[:login] 277: end 278: params[:vbvEnabled] = '0' 279: params[:scEnabled] = '0' 280: 281: params.reject{|k, v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") 282: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 157 157: def prepare_address_for_non_american_countries(options) 158: [ options[:billing_address], options[:shipping_address] ].compact.each do |address| 159: unless ['US', 'CA'].include?(address[:country]) 160: address[:state] = '--' 161: address[:zip] = '000000' unless address[:zip] 162: end 163: end 164: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 92 92: def purchase_action(source) 93: if source.is_a?(Check) 94: :check_purchase 95: else 96: :purchase 97: end 98: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 104 104: def refund_action(type) 105: (type == TRANSACTIONS[:check_purchase]) ? :check_refund : :refund 106: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 108 108: def secure_profile_action(type) 109: PROFILE_OPERATIONS[type] || PROFILE_OPERATIONS[:new] 110: end
# File lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb, line 112 112: def split_auth(string) 113: string.split(";") 114: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.