Class: ActiveMerchant::Billing::BluePayGateway

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

Constant Summary collapse

CARD_CODE_ERRORS =
%w(N S)
AVS_ERRORS =
%w(A E N R W Z)
AVS_REASON_CODES =
%w(27 45)
FIELD_MAP =
{
  'TRANS_ID' => :transaction_id,
  'STATUS' => :response_code,
  'AVS' => :avs_result_code,
  'CVV2' => :card_code,
  'AUTH_CODE' => :authorization,
  'MESSAGE' => :message,
  'REBID' => :rebid,
  'TRANS_TYPE' => :trans_type,
  'PAYMENT_ACCOUNT_MASK' => :acct_mask,
  'CARD_TYPE' => :card_type
}
REBILL_FIELD_MAP =
{
  'REBILL_ID' => :rebill_id,
  'ACCOUNT_ID' => :account_id,
  'USER_ID' => :user_id,
  'TEMPLATE_ID' => :template_id,
  'STATUS' => :status,
  'CREATION_DATE' => :creation_date,
  'NEXT_DATE' => :next_date,
  'LAST_DATE' => :last_date,
  'SCHED_EXPR' => :schedule,
  'CYCLES_REMAIN' => :cycles_remain,
  'REB_AMOUNT' => :rebill_amount,
  'NEXT_AMOUNT' => :next_amount,
  'USUAL_DATE' => :undoc_usual_date, # Not found in the bp20rebadmin API doc.
  'CUST_TOKEN' => :cust_token
}

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 inherited from Gateway

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

Methods included from CreditCardFormatting

#format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ BluePayGateway

Creates a new BluepayGateway

The gateway requires that a valid Account ID and Secret Key be passed in the options hash.

Options

  • :account_id – The BluePay gateway Account ID (REQUIRED)

  • :secret_key – The BluePay gateway Secret Key (REQUIRED)

  • :test – set to true for TEST mode or false for LIVE mode



63
64
65
66
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 63

def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Instance Method Details

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

Performs an authorization, which reserves the funds on the customer’s credit card. This does not actually take funds from the customer This is referred to an AUTH transaction in BluePay

Parameters

  • money – The amount to be authorized as an Integer value in cents.

  • payment_object – This can either be one of three things: A CreditCard object, A Check object, or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.

  • options – A hash of optional parameters.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 79

def authorize(money, payment_object, options = {})
  post = {}
  add_payment_method(post, payment_object)
  add_invoice(post, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_rebill(post, options) if options[:rebill]
  add_duplicate_override(post, options)
  add_stored_credential(post, options)
  post[:TRANS_TYPE] = 'AUTH'
  commit('AUTH_ONLY', money, post, options)
end

#cancel_recurring(rebill_id) ⇒ Object

Cancel a recurring payment.

This transaction cancels an existing recurring billing.

Parameters

  • rebill_id – A string containing the rebill_id of the recurring billing that you wish to cancel/stop (REQUIRED)



295
296
297
298
299
300
301
302
303
304
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 295

def cancel_recurring(rebill_id)
  ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE

  post = {}
  requires!(rebill_id)
  post[:REBILL_ID]         = rebill_id
  post[:TRANS_TYPE]        = 'SET'
  post[:STATUS]            = 'stopped'
  commit('rebill', 'nil', post)
end

#capture(money, identification, options = {}) ⇒ Object

Captures the funds from an authorize transaction. This is referred to a CAPTURE transaction in BluePay

Parameters

  • money – The amount to be captured as an Integer value in cents.

  • identification – The Master ID, or token, returned from the previous authorize transaction.



123
124
125
126
127
128
129
130
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 123

def capture(money, identification, options = {})
  post = {}
  add_address(post, options)
  add_customer_data(post, options)
  post[:MASTER_ID] = identification
  post[:TRANS_TYPE] = 'CAPTURE'
  commit('PRIOR_AUTH_CAPTURE', money, post, options)
end

#credit(money, payment_object, options = {}) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 179

def credit(money, payment_object, options = {})
  if payment_object&.kind_of?(String)
    ActiveMerchant.deprecated 'credit should only be used to credit a payment method'
    return refund(money, payment_object, options)
  end

  post = {}
  post[:PAYMENT_ACCOUNT] = ''
  add_payment_method(post, payment_object)
  post[:TRANS_TYPE] = 'CREDIT'
  post[:DOC_TYPE] = options[:doc_type] if options[:doc_type]

  post[:NAME1] = options[:first_name] || ''
  post[:NAME2] = options[:last_name] if options[:last_name]
  post[:ZIP] = options[:zip] if options[:zip]
  add_invoice(post, options)
  add_address(post, options)
  add_customer_data(post, options)
  commit('CREDIT', money, post, options)
end

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

Perform a purchase, which is essentially an authorization and capture in a single operation. This is referred to a SALE transaction in BluePay

Parameters

  • money – The amount to be purchased as an Integer value in cents.

  • payment_object – This can either be one of three things: A CreditCard object, A Check object, or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.

  • options – A hash of optional parameters.,



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 103

def purchase(money, payment_object, options = {})
  post = {}
  add_payment_method(post, payment_object)
  add_invoice(post, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_rebill(post, options) if options[:rebill]
  add_duplicate_override(post, options)
  add_stored_credential(post, options)
  post[:TRANS_TYPE] = 'SALE'
  commit('AUTH_CAPTURE', money, post, options)
end

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

Options

  • :rebill_start_date is a string that tells the gateway when to start the rebill. (REQUIRED) Has two valid formats: “YYYY-MM-DD HH:MM:SS” Hours, minutes, and seconds are optional. “XX UNITS” Relative date as explained below. Marked from the time of the transaction (i.e.: 10 DAYS, 1 MONTH, 1 YEAR)

  • :rebill_expression is the period of time in-between rebillings. (REQUIRED) It uses the same “XX UNITS” format as rebill_start_date, explained above. Optional parameters include:

  • rebill_cycles: Number of times to rebill. Don’t send or set to nil for infinite rebillings (or until canceled).

  • rebill_amount: Amount to rebill. Defaults to amount of transaction for rebillings.

    For example, to charge the customer $19.95 now and then charge $39.95 in 60 days every 3 months for 5 times, the options hash would be as follows: :rebill_start_date => ‘60 DAYS’, :rebill_expression => ‘3 MONTHS’, :rebill_cycles => ‘5’, :rebill_amount => ‘39.95’ A money object of 1995 cents would be passed into the ‘money’ parameter.



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 231

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

  requires!(options, :rebill_start_date, :rebill_expression)
  options[:rebill] = true
  if money
    purchase(money, payment_object, options)
  else
    authorize(money, payment_object, options)
  end
end

#refund(money, identification, options = {}) ⇒ Object

Performs a credit.

This transaction indicates that money should flow from the merchant to the customer.

Parameters

  • money – The amount to be credited to the customer as an Integer value in cents.

  • payment_object – This can either be one of three things: A CreditCard object, A Check object, or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction. If the payment_object is a token, then the transaction type will reverse a previous capture or purchase transaction, returning the funds to the customer. If the amount is nil, a full credit will be processed. This is referred to a REFUND transaction in BluePay. If the payment_object is either a CreditCard or Check object, then the transaction type will be an unmatched credit placing funds in the specified account. This is referred to a CREDIT transaction in BluePay.

  • options – A hash of parameters.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 159

def refund(money, identification, options = {})
  if identification && !identification.kind_of?(String)
    ActiveMerchant.deprecated 'refund should only be used to refund a referenced transaction'
    return credit(money, identification, options)
  end

  post = {}
  post[:PAYMENT_ACCOUNT] = ''
  post[:MASTER_ID]  = identification
  post[:TRANS_TYPE] = 'REFUND'
  post[:DOC_TYPE] = options[:doc_type] if options[:doc_type]
  post[:NAME1] = options[:first_name] || ''
  post[:NAME2] = options[:last_name] if options[:last_name]
  post[:ZIP] = options[:zip] if options[:zip]
  add_invoice(post, options)
  add_address(post, options)
  add_customer_data(post, options)
  commit('CREDIT', money, post, options)
end

#scrub(transcript) ⇒ Object



310
311
312
313
314
315
316
317
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 310

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((&?card_num=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?CARD_CVV2=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?PAYMENT_ACCOUNT=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?TAMPER_PROOF_SEAL=)[^&"]*)i, '\1[FILTERED]')
end

#status_recurring(rebill_id) ⇒ Object

View a recurring payment

This will pull data associated with a current recurring billing

Parameters

  • rebill_id – A string containing the rebill_id of the recurring billing that is already active (REQUIRED)



250
251
252
253
254
255
256
257
258
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 250

def status_recurring(rebill_id)
  ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE

  post = {}
  requires!(rebill_id)
  post[:REBILL_ID] = rebill_id
  post[:TRANS_TYPE] = 'GET'
  commit('rebill', 'nil', post)
end

#supports_scrubbingObject



306
307
308
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 306

def supports_scrubbing
  true
end

#update_recurring(options = {}) ⇒ Object

Update a recurring payment’s details.

This transaction updates an existing recurring billing

Options

  • :rebill_id – The 12 digit rebill ID used to update a particular rebilling cycle. (REQUIRED)

  • :rebill_amount – A string containing the new rebilling amount.

  • :rebill_next_date – A string containing the new rebilling next date.

  • :rebill_expression – A string containing the new rebilling expression.

  • :rebill_cycles – A string containing the new rebilling cycles.

  • :rebill_next_amount – A string containing the next rebilling amount to charge the customer. This ONLY affects the next scheduled charge; all other rebillings will continue at the regular (rebill_amount) amount. Take a look above at the recurring_payment method for similar examples on how to use.



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 273

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

  post = {}
  requires!(options, :rebill_id)
  post[:REBILL_ID]          = options[:rebill_id]
  post[:TRANS_TYPE]         = 'SET'
  post[:REB_AMOUNT]         = amount(options[:rebill_amount]) if options[:rebill_amount]
  post[:NEXT_DATE]          = options[:rebill_next_date]
  post[:REB_EXPR]           = options[:rebill_expression]
  post[:REB_CYCLES]         = options[:rebill_cycles]
  post[:NEXT_AMOUNT]        = options[:rebill_next_amount]
  commit('rebill', 'nil', post)
end

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

Void a previous transaction This is referred to a VOID transaction in BluePay

Parameters

  • identification - The Master ID, or token, returned from a previous authorize transaction.



138
139
140
141
142
143
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 138

def void(identification, options = {})
  post = {}
  post[:MASTER_ID] = identification
  post[:TRANS_TYPE] = 'VOID'
  commit('VOID', nil, post, options)
end