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.
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, non_fractional_currency?, #scrub, 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



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

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.



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

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)
  post[:TRANS_TYPE]  = 'AUTH'
  commit('AUTH_ONLY', money, post)
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)



290
291
292
293
294
295
296
297
298
299
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 290

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.



120
121
122
123
124
125
126
127
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 120

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)
end

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



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 175

def credit(money, payment_object, options = {})
  if(payment_object && 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[:NAME1] = (options[:first_name] ? 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)
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.,



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

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)
  post[:TRANS_TYPE]  = 'SALE'
  commit('AUTH_CAPTURE', money, post)
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.



226
227
228
229
230
231
232
233
234
235
236
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 226

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.



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

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[:NAME1] = (options[:first_name] ? 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)
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)



245
246
247
248
249
250
251
252
253
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 245

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

#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.



268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 268

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.



135
136
137
138
139
140
# File 'lib/active_merchant/billing/gateways/blue_pay.rb', line 135

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