Class: ActiveMerchant::Billing::SagePayGateway

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

Constant Summary collapse

TEST_URL =
'https://test.sagepay.com/gateway/service'
LIVE_URL =
'https://live.sagepay.com/gateway/service'
SIMULATOR_URL =
'https://test.sagepay.com/Simulator'
APPROVED =
'OK'
TRANSACTIONS =
{
  :purchase => 'PAYMENT',
  :credit => 'REFUND',
  :authorization => 'DEFERRED',
  :capture => 'RELEASE',
  :void => 'VOID',
  :abort => 'ABORT'
}
CREDIT_CARDS =
{
  :visa => "VISA",
  :master => "MC",
  :delta => "DELTA",
  :solo => "SOLO",
  :switch => "MAESTRO",
  :maestro => "MAESTRO",
  :american_express => "AMEX",
  :electron => "UKE",
  :diners_club => "DC",
  :jcb => "JCB"
}
ELECTRON =
/^(424519|42496[23]|450875|48440[6-8]|4844[1-5][1-5]|4917[3-5][0-9]|491880)\d{10}(\d{3})?$/
AVS_CVV_CODE =
{
  "NOTPROVIDED" => nil, 
  "NOTCHECKED" => 'X',
  "MATCHED" => 'Y',
  "NOTMATCHED" => 'N'
}

Constants inherited from Gateway

Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ SagePayGateway

Returns a new instance of SagePayGateway.



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

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

Instance Method Details

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 81

def authorize(money, credit_card, options = {})
  requires!(options, :order_id)
  
  post = {}
  
  add_amount(post, money, options)
  add_invoice(post, options)
  add_credit_card(post, credit_card)
  add_address(post, options)
  add_customer_data(post, options)
  add_three_d_secure_flag(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.



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

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

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



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

def credit(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

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 66

def purchase(money, credit_card, options = {})
  requires!(options, :order_id)
  
  post = {}
  
  add_amount(post, money, options)
  add_invoice(post, options)
  add_credit_card(post, credit_card)
  add_address(post, options)
  add_customer_data(post, options)
  add_three_d_secure_flag(post, options)
  
  commit(:purchase, post)
end

#test?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 58

def test?
  @options[:test] || super
end

#three_d_complete(pa_res, md) ⇒ Object

Completes a 3D Secure transaction



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

def three_d_complete(pa_res, md)
  commit(:three_d_complete, 'PARes' => pa_res, 'MD' => md)
end

#three_d_secure_enabled?Boolean

Returns:

  • (Boolean)


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

def three_d_secure_enabled?
  @options[:enable_3d_secure]
end

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



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

def void(identification, options = {})
  post = {}
  
  add_reference(post, identification)
  action = abort_or_void_from(identification)

  commit(action, post)
end