Class: SolidusSixSaferpay::Gateway
- Inherits:
-
Object
- Object
- SolidusSixSaferpay::Gateway
show all
- Includes:
- Spree::RouteAccess
- Defined in:
- lib/solidus_six_saferpay/gateway.rb
Instance Method Summary
collapse
-
#authorize(amount, saferpay_payment, options = {}) ⇒ Object
-
#capture(_amount, transaction_id, options = {}) ⇒ Object
-
#credit(amount_cents, transaction_id, options = {}) ⇒ Object
aliased to #refund for compatibility with solidus internals.
-
#initialize(options = {}) ⇒ Gateway
constructor
A new instance of Gateway.
-
#initialize_payment(order, payment_method) ⇒ Object
-
#inquire(saferpay_payment, options = {}) ⇒ Object
-
#purchase(amount, saferpay_payment, options = {}) ⇒ Object
-
#refund(amount_cents, transaction_id, options = {}) ⇒ Object
-
#try_void(payment) ⇒ Object
-
#void(transaction_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Gateway
Returns a new instance of Gateway.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 6
def initialize(options = {})
SixSaferpay.configure do |config|
config.customer_id = options.fetch(:customer_id) { ENV.fetch('SIX_SAFERPAY_CUSTOMER_ID') }
config.terminal_id = options.fetch(:terminal_id) { ENV.fetch('SIX_SAFERPAY_TERMINAL_ID') }
config.username = options.fetch(:username) { ENV.fetch('SIX_SAFERPAY_USERNAME') }
config.password = options.fetch(:password) { ENV.fetch('SIX_SAFERPAY_PASSWORD') }
config.base_url = options.fetch(:base_url) { ENV.fetch('SIX_SAFERPAY_BASE_URL') }
config.css_url = options.fetch(:css_url) { ENV.fetch('SIX_SAFERPAY_CSS_URL') }
end
end
|
Instance Method Details
#authorize(amount, saferpay_payment, options = {}) ⇒ Object
31
32
33
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 31
def authorize(amount, saferpay_payment, options = {})
raise NotImplementedError, "must be implemented in PaymentPageGateway or TransactionGateway"
end
|
#capture(_amount, transaction_id, options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 43
def capture(_amount, transaction_id, options={})
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
payment_capture = SixSaferpay::SixTransaction::Capture.new(transaction_reference: transaction_reference)
capture_response = SixSaferpay::Client.post(payment_capture)
response(
true,
"Saferpay Payment Capture response: #{capture_response.to_h}",
capture_response,
{ authorization: capture_response.capture_id }
)
rescue SixSaferpay::Error => e
handle_error(e, capture_response)
end
|
#credit(amount_cents, transaction_id, options = {}) ⇒ Object
aliased to #refund for compatibility with solidus internals
82
83
84
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 82
def credit(amount_cents, transaction_id, options = {})
refund(amount_cents, transaction_id, options)
end
|
#initialize_payment(order, payment_method) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 18
def initialize_payment(order, payment_method)
initialize_response = SixSaferpay::Client.post(
interface_initialize_object(order, payment_method)
)
response(
true,
"Saferpay Initialize Checkout response: #{initialize_response.to_h}",
initialize_response,
)
rescue SixSaferpay::Error => e
handle_error(e, initialize_response)
end
|
#inquire(saferpay_payment, options = {}) ⇒ Object
35
36
37
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 35
def inquire(saferpay_payment, options = {})
raise NotImplementedError, "must be implemented in PaymentPageGateway or TransactionGateway"
end
|
#purchase(amount, saferpay_payment, options = {}) ⇒ Object
39
40
41
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 39
def purchase(amount, saferpay_payment, options = {})
capture(amount, saferpay_payment.transaction_id, options)
end
|
#refund(amount_cents, transaction_id, options = {}) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 86
def refund(amount_cents, transaction_id, options = {})
payment = Spree::Payment.find_by!(response_code: transaction_id)
saferpay_amount = SixSaferpay::Amount.new(value: amount_cents, currency_code: payment.currency)
saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
if refund_response = SixSaferpay::Client.post(payment_refund)
capture(amount_cents, refund_response.transaction.id, options)
end
rescue SixSaferpay::Error => e
handle_error(e, refund_response)
end
|
#try_void(payment) ⇒ Object
75
76
77
78
79
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 75
def try_void(payment)
if payment.checkout? && payment.transaction_id
void(payment.transaction_id, originator: self)
end
end
|
#void(transaction_id, options = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/solidus_six_saferpay/gateway.rb', line 60
def void(transaction_id, options = {})
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
payment_cancel = SixSaferpay::SixTransaction::Cancel.new(transaction_reference: transaction_reference)
cancel_response = SixSaferpay::Client.post(payment_cancel)
response(
true,
"Saferpay Payment Cancel response: #{cancel_response.to_h}",
cancel_response
)
rescue SixSaferpay::Error => e
handle_error(e, cancel_response)
end
|