Class: ActiveMerchant::Billing::SagePayGateway

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

Constant Summary collapse

APPROVED =
'OK'
TRANSACTIONS =
{
  :purchase => 'PAYMENT',
  :credit => 'REFUND',
  :authorization => 'DEFERRED',
  :capture => 'RELEASE',
  :void => 'VOID',
  :abort => 'ABORT',
  :store => 'TOKEN',
  :unstore => 'REMOVETOKEN'
}
CREDIT_CARDS =
{
  :visa => "VISA",
  :master => "MC",
  :delta => "DELTA",
  :solo => "SOLO",
  :switch => "MAESTRO",
  :maestro => "MAESTRO",
  :american_express => "AMEX",
  :electron => "UKE",
  :diners_club => "DC",
  :jcb => "JCB"
}
AVS_CVV_CODE =
{
  "NOTPROVIDED" => nil,
  "NOTCHECKED" => 'X',
  "MATCHED" => 'Y',
  "NOTMATCHED" => '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?, #supports_scrubbing?, #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 = {}) ⇒ SagePayGateway

Returns a new instance of SagePayGateway.



53
54
55
56
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 53

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

Instance Method Details

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 73

def authorize(money, payment_method, options = {})
  requires!(options, :order_id)

  post = {}

  add_amount(post, money, options)
  add_invoice(post, options)
  add_payment_method(post, payment_method, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_optional_data(post, options)

  commit(:authorization, post)
end

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

You can only capture a transaction once, even if you didn’t capture the full amount the first time.



89
90
91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 89

def capture(money, identification, options = {})
  post = {}

  add_reference(post, identification)
  add_release_amount(post, money, options)

  commit(:capture, post)
end

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



120
121
122
123
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 120

def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 58

def purchase(money, payment_method, options = {})
  requires!(options, :order_id)

  post = {}

  add_amount(post, money, options)
  add_invoice(post, options)
  add_payment_method(post, payment_method, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_optional_data(post, options)

  commit(:purchase, post)
end

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

Refunding requires a new order_id to passed in, as well as a description



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 108

def refund(money, identification, options = {})
  requires!(options, :order_id, :description)

  post = {}

  add_credit_reference(post, identification)
  add_amount(post, money, options)
  add_invoice(post, options)

  commit(:credit, post)
end

#scrub(transcript) ⇒ Object



150
151
152
153
154
155
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 150

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((&?CardNumber=)\d+(&?)), '\1[FILTERED]\2').
    gsub(%r((&?CV2=)\d+(&?)), '\1[FILTERED]\2')
end

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



125
126
127
128
129
130
131
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 125

def store(credit_card, options = {})
  post = {}
  add_credit_card(post, credit_card)
  add_currency(post, 0, options)

  commit(:store, post)
end

#supports_scrubbingObject



146
147
148
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 146

def supports_scrubbing
  true
end

#unstore(token, options = {}) ⇒ Object



133
134
135
136
137
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 133

def unstore(token, options = {})
  post = {}
  add_token(post, token)
  commit(:unstore, post)
end

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



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

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

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



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

def void(identification, options = {})
  post = {}

  add_reference(post, identification)
  action = abort_or_void_from(identification)

  commit(action, post)
end