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',
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, 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, #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


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

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

Instance Method Details

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


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

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

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


79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 79

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

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


67
68
69
70
71
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 67

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

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


86
87
88
89
90
91
92
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 86

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

#scrub(transcript) ⇒ Object


131
132
133
134
135
136
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 131

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

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


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

def store(credit_card, options = {})
  commit(:store) do |doc|
    add_personal_info(doc, credit_card, options)
    doc.send("payment-sources") do
      doc.send("credit-card-info") do
        add_credit_card(doc, credit_card)
      end
    end
    add_order(doc, options)
  end
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

127
128
129
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 127

def supports_scrubbing?
  true
end

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


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

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

#verify_credentialsObject


117
118
119
120
121
122
123
124
125
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 117

def verify_credentials
  begin
    ssl_get("#{url}/nonexistent", headers)
  rescue ResponseError => e
    return false if e.response.code.to_i == 401
  end

  true
end

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


94
95
96
97
98
99
# File 'lib/active_merchant/billing/gateways/blue_snap.rb', line 94

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