Class: ActiveMerchant::Billing::BlueSnapGateway

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

Constant Summary collapse

TRANSACTIONS =
{
  purchase: 'AUTH_CAPTURE',
  authorize: 'AUTH_ONLY',
  capture: 'CAPTURE',
  void: 'AUTH_REVERSAL',
  refund: 'REFUND'
}
CVC_CODE_TRANSLATOR =
{
  'MA' => 'M',
  'NC' => 'U',
  'ND' => 'P',
  'NM' => 'N',
  'NP' => 'S'
}
AVS_CODE_TRANSLATOR =
{
  'line1: U, zip: U, name: U' => 'I',
  'line1: U, zip: U, name: M' => 'I',
  'line1: U, zip: U, name: N' => 'I',
  'line1: U, zip: M, name: U' => 'P',
  'line1: U, zip: M, name: M' => 'P',
  'line1: U, zip: M, name: N' => 'F',
  'line1: U, zip: N, name: U' => 'O',
  'line1: U, zip: N, name: M' => 'O',
  'line1: U, zip: N, name: N' => 'O',
  'line1: M, zip: U, name: U' => 'B',
  'line1: M, zip: U, name: M' => 'B',
  'line1: M, zip: U, name: N' => 'T',
  'line1: M, zip: M, name: U' => 'M',
  'line1: M, zip: M, name: M' => 'V',
  'line1: M, zip: M, name: N' => 'H',
  'line1: M, zip: N, name: U' => 'A',
  'line1: M, zip: N, name: M' => 'O',
  'line1: M, zip: N, name: N' => 'A',
  'line1: N, zip: U, name: U' => 'C',
  'line1: N, zip: U, name: M' => 'C',
  'line1: N, zip: U, name: N' => 'C',
  'line1: N, zip: M, name: U' => 'W',
  'line1: N, zip: M, name: M' => 'L',
  'line1: N, zip: M, name: N' => 'W',
  'line1: N, zip: N, name: U' => 'N',
  'line1: N, zip: N, name: M' => 'K',
  'line1: N, zip: N, name: N' => 'N'
}
BANK_ACCOUNT_TYPE_MAPPING =
{
  'personal_checking' => 'CONSUMER_CHECKING',
  'personal_savings' => 'CONSUMER_SAVINGS',
  'business_checking' => 'CORPORATE_CHECKING',
  'business_savings' => 'CORPORATE_SAVINGS'
}
SHOPPER_INITIATOR =
%w(CUSTOMER CARDHOLDER)
STATE_CODE_COUNTRIES =
%w(US CA)

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?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ BlueSnapGateway

Returns a new instance of BlueSnapGateway.



75
76
77
78
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 75

def initialize(options = {})
  requires!(options, :api_username, :api_password)
  super
end

Instance Method Details

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



92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 92

def authorize(money, payment_method, options = {})
  commit(:authorize, options) do |doc|
    add_auth_purchase(doc, money, payment_method, options)
  end
end

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



98
99
100
101
102
103
104
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 98

def capture(money, authorization, options = {})
  commit(:capture, options, :put) do |doc|
    add_authorization(doc, authorization)
    add_order(doc, options)
    add_amount(doc, money, options) if options[:include_capture_amount] == true
  end
end

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



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

def purchase(money, payment_method, options = {})
  payment_method_details = PaymentMethodDetails.new(payment_method)

  commit(:purchase, options, :post, payment_method_details) do |doc|
    if payment_method_details.alt_transaction?
      add_alt_transaction_purchase(doc, money, payment_method_details, options)
    else
      add_auth_purchase(doc, money, payment_method, options)
    end
  end
end

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



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

def refund(money, authorization, options = {})
  options[:endpoint] = options[:merchant_transaction_id] ? "/refund/merchant/#{options[:merchant_transaction_id]}" : "/refund/#{authorization}"
  commit(:refund, options, :post) do |doc|
    add_amount(doc, money, options) if money
    %i[reason cancel_subscription tax_amount].each { |field| send_when_present(doc, field, options) }
    (doc, options)
  end
end

#scrub(transcript) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 167

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((<card-number>).+(</card-number>)), '\1[FILTERED]\2').
    gsub(%r((<security-code>).+(</security-code>)), '\1[FILTERED]\2').
    gsub(%r((<(?:public-)?account-number>).+(</(?:public-)?account-number>)), '\1[FILTERED]\2').
    gsub(%r((<(?:public-)?routing-number>).+(</(?:public-)?routing-number>)), '\1[FILTERED]\2')
end

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



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 126

def store(payment_method, options = {})
  payment_method_details = PaymentMethodDetails.new(payment_method)

  commit(:store, options, :post, payment_method_details) do |doc|
    add_personal_info(doc, payment_method, options)
    add_echeck_company(doc, payment_method) if payment_method_details.check?
    doc.send('payment-sources') do
      payment_method_details.check? ? store_echeck(doc, payment_method) : store_credit_card(doc, payment_method)
    end
    add_order(doc, options)
  end
end

#store_credit_card(doc, payment_method) ⇒ Object



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

def store_credit_card(doc, payment_method)
  doc.send('credit-card-info') do
    add_credit_card(doc, payment_method)
  end
end

#store_echeck(doc, payment_method) ⇒ Object



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

def store_echeck(doc, payment_method)
  doc.send('ecp-info') do
    doc.send('ecp') do
      add_echeck(doc, payment_method)
    end
  end
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 163

def supports_scrubbing?
  true
end

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



122
123
124
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 122

def verify(payment_method, options = {})
  authorize(0, payment_method, options)
end

#verify_credentialsObject



153
154
155
156
157
158
159
160
161
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 153

def verify_credentials
  begin
    ssl_get(url.to_s, headers(options))
  rescue ResponseError => e
    return false if e.response.code.to_i == 401
  end

  true
end

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



115
116
117
118
119
120
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 115

def void(authorization, options = {})
  commit(:void, options, :put) do |doc|
    add_authorization(doc, authorization)
    add_order(doc, options)
  end
end