Class: ActiveMerchant::Billing::BeanstreamGateway

Inherits:
Gateway
  • Object
show all
Includes:
BeanstreamCore
Defined in:
lib/active_merchant/billing/gateways/beanstream.rb

Overview

This class implements the Canadian Beanstream payment gateway. It is also named TD Canada Trust Online Mart payment gateway. To learn more about the specification of Beanstream gateway, please read the OM_Direct_Interface_API.pdf, which you can get from your Beanstream account or get from me by email.

Supported transaction types by Beanstream:

  • P - Purchase

  • PA - Pre Authorization

  • PAC - Pre Authorization Completion

Secure Payment Profiles:

BeanStream supports payment profiles (vaults). This allows you to store cc information with BeanStream and process subsequent transactions with a customer id. Secure Payment Profiles must be enabled on your account (must be done over the phone). Your API Access Passcode must be set in Administration => account settings => order settings. To learn more about storing credit cards with the Beanstream gateway, documentation can be found at developer.beanstream.com/documentation/classic-apis

To store a credit card using Beanstream’s Legato Javascript Library (developer.beanstream.com/documentation/legato) you must pass the singleUseToken in the store method’s option parameter. Example: @gateway.store(“gt6-0c78c25b-3637-4ba0-90e2-26105287f198”)

Notes

  • Adding of order products information is not implemented.

  • Ensure that country and province data is provided as a code such as “CA”, “US”, “QC”.

  • login is the Beanstream merchant ID, username and password should be enabled in your Beanstream account and passed in using the :user and :password options.

  • Test your app with your true merchant id and test credit card information provided in the api pdf document.

  • Beanstream does not allow Payment Profiles to be deleted with their API. The accounts are ‘closed’, but have to be deleted manually.

Example authorization (Beanstream PA transaction type):

 twenty = 2000
 gateway = BeanstreamGateway.new(
   :login => '100200000',
   :user => 'xiaobozz',
   :password => 'password'
 )

 credit_card = CreditCard.new(
   :number => '4030000010001234',
   :month => 8,
   :year => 2011,
   :first_name => 'xiaobo',
   :last_name => 'zzz',
   :verification_value => 137
 )
 response = gateway.authorize(twenty, credit_card,
   :order_id => '1234',
   :billing_address => {
     :name => 'xiaobo zzz',
     :phone => '555-555-5555',
     :address1 => '1234 Levesque St.',
     :address2 => 'Apt B',
     :city => 'Montreal',
     :state => 'QC',
     :country => 'CA',
     :zip => 'H2C1X8'
   },
   :email => '[email protected]',
   :subtotal => 800,
   :shipping => 100,
   :tax1 => 100,
   :tax2 => 100,
   :custom => 'reference one'
 )

Constant Summary

Constants included from BeanstreamCore

ActiveMerchant::Billing::BeanstreamCore::AVS_CODES, ActiveMerchant::Billing::BeanstreamCore::CVD_CODES, ActiveMerchant::Billing::BeanstreamCore::PERIODICITIES, ActiveMerchant::Billing::BeanstreamCore::PERIODS, ActiveMerchant::Billing::BeanstreamCore::PROFILE_OPERATIONS, ActiveMerchant::Billing::BeanstreamCore::RECURRING_OPERATION, ActiveMerchant::Billing::BeanstreamCore::RECURRING_URL, ActiveMerchant::Billing::BeanstreamCore::SECURE_PROFILE_URL, ActiveMerchant::Billing::BeanstreamCore::SP_SERVICE_VERSION, ActiveMerchant::Billing::BeanstreamCore::STATES, ActiveMerchant::Billing::BeanstreamCore::TRANSACTIONS

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods included from BeanstreamCore

#capture, #credit, included, #initialize, #refund

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #initialize, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Instance Method Details

#authorize(money, source, options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 70

def authorize(money, source, options = {})
  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_source(post, source)
  add_address(post, options)
  add_transaction_type(post, :authorization)
  add_customer_ip(post, options)
  add_recurring_payment(post, options)
  commit(post)
end

#cancel_recurring(options = {}) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 144

def cancel_recurring(options = {})
  ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE

  post = {}
  add_recurring_operation_type(post, :cancel)
  add_recurring_service(post, options)
  recurring_commit(post)
end

#delete(vault_id) ⇒ Object Also known as: unstore

can’t actually delete a secure profile with the supplicated API. This function sets the status of the profile to closed ©. Closed profiles will have to removed manually.



177
178
179
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 177

def delete(vault_id)
  update(vault_id, false, {:status => 'C'})
end

#interacObject



153
154
155
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 153

def interac
  @interac ||= BeanstreamInteracGateway.new(@options)
end

#purchase(money, source, options = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 82

def purchase(money, source, options = {})
  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_source(post, source)
  add_address(post, options)
  add_transaction_type(post, purchase_action(source))
  add_customer_ip(post, options)
  add_recurring_payment(post, options)
  commit(post)
end

#recurring(money, source, options = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 118

def recurring(money, source, options = {})
  ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE

  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_credit_card(post, source)
  add_address(post, options)
  add_transaction_type(post, purchase_action(source))
  add_recurring_type(post, options)
  commit(post)
end

#scrub(transcript) ⇒ Object



204
205
206
207
208
209
210
211
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 204

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(/(&?password=)[^&\s]*(&?)/, '\1[FILTERED]\2').
    gsub(/(&?passcode=)[^&\s]*(&?)/, '\1[FILTERED]\2').
    gsub(/(&?trnCardCvd=)\d*(&?)/, '\1[FILTERED]\2').
    gsub(/(&?trnCardNumber=)\d*(&?)/, '\1[FILTERED]\2')
end

#store(payment_method, options = {}) ⇒ Object

To match the other stored-value gateways, like TrustCommerce, store and unstore need to be defined

When passing a single-use token the :name option is required



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 161

def store(payment_method, options = {})
  post = {}
  add_address(post, options)

  if payment_method.respond_to?(:number)
    add_credit_card(post, payment_method)
  else
    post[:singleUseToken] = payment_method
  end
  add_secure_profile_variables(post, options)

  commit(post, true)
end

#success?(response) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 114

def success?(response)
  response[:trnApproved] == '1' || response[:responseCode] == '1'
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 200

def supports_scrubbing?
  true
end

#update(vault_id, payment_method, options = {}) ⇒ Object

Update the values (such as CC expiration) stored at the gateway. The CC number must be supplied in the CreditCard object.



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 186

def update(vault_id, payment_method, options = {})
  post = {}
  add_address(post, options)
  if payment_method.respond_to?(:number)
    add_credit_card(post, payment_method)
  else
    post[:singleUseToken] = payment_method
  end
  options[:vault_id] = vault_id
  options[:operation] = secure_profile_action(:modify)
  add_secure_profile_variables(post, options)
  commit(post, true)
end

#update_recurring(amount, source, options = {}) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 131

def update_recurring(amount, source, options = {})
  ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE

  post = {}
  add_recurring_amount(post, amount)
  add_recurring_invoice(post, options)
  add_credit_card(post, source)
  add_address(post, options)
  add_recurring_operation_type(post, :update)
  add_recurring_service(post, options)
  recurring_commit(post)
end

#verify(source, options = {}) ⇒ Object



107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 107

def verify(source, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, source, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#void(authorization, options = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/beanstream.rb', line 94

def void(authorization, options = {})
  reference, amount, type = split_auth(authorization)
  if type == TRANSACTIONS[:authorization]
    capture(0, authorization, options)
  else
    post = {}
    add_reference(post, reference)
    add_original_amount(post, amount)
    add_transaction_type(post, void_action(type))
    commit(post)
  end
end