Class: ActiveMerchant::Billing::SagePayGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::SagePayGateway
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',
repeat: 'REPEAT'
}
- CREDIT_CARDS =
{
visa: 'VISA',
master: 'MC',
delta: 'DELTA',
maestro: 'MAESTRO',
american_express: 'AMEX',
electron: 'UKE',
diners_club: 'DC',
jcb: 'JCB'
}
- AVS_CODE =
{
'NOTPROVIDED' => nil,
'NOTCHECKED' => 'X',
'MATCHED' => 'Y',
'NOTMATCHED' => 'N'
}
- CVV_CODE =
{
'NOTPROVIDED' => 'S',
'NOTCHECKED' => 'X',
'MATCHED' => 'M',
'NOTMATCHED' => 'N'
}
- OPTIONAL_REQUEST_FIELDS =
{
paypal_callback_url: :PayPalCallbackURL,
basket: :Basket,
gift_aid_payment: :GiftAidPayment,
apply_avscv2: :ApplyAVSCV2,
apply_3d_secure: :Apply3DSecure,
account_type: :AccountType,
billing_agreement: :BillingAgreement,
basket_xml: :BasketXML,
customer_xml: :CustomerXML,
surcharge_xml: :SurchargeXML,
vendor_data: :VendorData,
language: :Language,
website: :Website,
recipient_account_number: :FIRecipientAcctNumber,
recipient_surname: :FIRecipientSurname,
recipient_postcode: :FIRecipientPostcode,
recipient_dob: :FIRecipientDoB
}
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
-
#authorize(money, payment_method, options = {}) ⇒ Object
-
#capture(money, identification, options = {}) ⇒ Object
You can only capture a transaction once, even if you didn’t capture the full amount the first time.
-
#credit(money, identification, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ SagePayGateway
constructor
A new instance of SagePayGateway.
-
#purchase(money, payment_method, options = {}) ⇒ Object
-
#refund(money, identification, options = {}) ⇒ Object
Refunding requires a new order_id to passed in, as well as a description.
-
#scrub(transcript) ⇒ Object
-
#store(credit_card, options = {}) ⇒ Object
-
#supports_scrubbing ⇒ Object
-
#unstore(token, options = {}) ⇒ Object
-
#verify(credit_card, options = {}) ⇒ Object
-
#void(identification, options = {}) ⇒ Object
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?, #supports_scrubbing?, #test?
#expdate, #format, #strftime_yyyymm
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Returns a new instance of SagePayGateway.
79
80
81
82
83
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 79
def initialize(options = {})
requires!(options, :login)
@protocol_version = options.fetch(:protocol_version, '3.00')
super
end
|
Instance Method Details
#authorize(money, payment_method, options = {}) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 103
def authorize(money, payment_method, options = {})
requires!(options, :order_id)
post = {}
add_three_ds_data(post, options)
add_stored_credentials_data(post, options)
add_override_protocol_version(options)
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.
122
123
124
125
126
127
128
129
130
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 122
def capture(money, identification, options = {})
post = {}
add_override_protocol_version(options)
add_reference(post, identification)
add_release_amount(post, money, options)
commit(:capture, post)
end
|
#credit(money, identification, options = {}) ⇒ Object
#purchase(money, payment_method, options = {}) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 85
def purchase(money, payment_method, options = {})
requires!(options, :order_id)
post = {}
add_override_protocol_version(options)
add_three_ds_data(post, options)
add_stored_credentials_data(post, options)
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((past_purchase_reference?(payment_method) ? :repeat : :purchase), post)
end
|
#refund(money, identification, options = {}) ⇒ Object
Refunding requires a new order_id to passed in, as well as a description
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 143
def refund(money, identification, options = {})
requires!(options, :order_id, :description)
post = {}
add_override_protocol_version(options)
add_related_reference(post, identification)
add_amount(post, money, options)
add_invoice(post, options)
commit(:credit, post)
end
|
#scrub(transcript) ⇒ Object
188
189
190
191
192
193
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 188
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
161
162
163
164
165
166
167
168
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 161
def store(credit_card, options = {})
post = {}
add_override_protocol_version(options)
add_credit_card(post, credit_card)
add_currency(post, 0, options)
commit(:store, post)
end
|
#supports_scrubbing ⇒ Object
184
185
186
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 184
def supports_scrubbing
true
end
|
#unstore(token, options = {}) ⇒ Object
170
171
172
173
174
175
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 170
def unstore(token, options = {})
post = {}
add_override_protocol_version(options)
add_token(post, token)
commit(:unstore, post)
end
|
#verify(credit_card, options = {}) ⇒ Object
177
178
179
180
181
182
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 177
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
132
133
134
135
136
137
138
139
140
|
# File 'lib/active_merchant/billing/gateways/sage_pay.rb', line 132
def void(identification, options = {})
post = {}
add_override_protocol_version(options)
add_reference(post, identification)
action = abort_or_void_from(identification)
commit(action, post)
end
|