Class: SolidusNexio::PaymentMethod
- Inherits:
-
Spree::PaymentMethod::CreditCard
- Object
- Spree::PaymentMethod::CreditCard
- SolidusNexio::PaymentMethod
show all
- Includes:
- NexioPaymentCommons
- Defined in:
- app/models/solidus_nexio/payment_method.rb
Defined Under Namespace
Classes: ProcessResult
Instance Method Summary
collapse
#authorize, #cancel, #purchase
Instance Method Details
#capture_order_payment(payment, id, status) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/models/solidus_nexio/payment_method.rb', line 41
def capture_order_payment(payment, id, status)
return ProcessResult.new(:invalid, nil) unless payment.checkout?
if id.present? && %w[pending authOnly].include?(status)
payment.response_code = id
auto_capture? ? payment.complete! : payment.pend!
ProcessResult.new(:success, nil)
else
payment.invalidate!
ProcessResult.new(:invalid, nil)
end
end
|
#generate_token(options) ⇒ Object
59
60
61
|
# File 'app/models/solidus_nexio/payment_method.rb', line 59
def generate_token(options)
gateway.generate_token(options)
end
|
#partial_name ⇒ Object
Also known as:
method_type
54
55
56
|
# File 'app/models/solidus_nexio/payment_method.rb', line 54
def partial_name
"nexio_#{preferred_ui}"
end
|
#process_order_payment(order) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/models/solidus_nexio/payment_method.rb', line 15
def process_order_payment(order)
payment = payments.merge(order.payments).checkout.last
return ProcessResult.new(:success, :absent) unless payment
callback_url = yield payment
payment.instance_variable_set(:@nexio_callback_url, callback_url)
begin
payment.process!
ProcessResult.new(:success, nil)
rescue Spree::Core::GatewayError
redirect_url = nexio_three_d_secure_redirect_url(payment)
return ProcessResult.new(:error, error: :fail_process_payment) unless redirect_url
payment.state = :checkout
payment.save!
ProcessResult.new(:three_d_secure, {
redirect_url: redirect_url,
check_path: Engine.routes.url_helpers.payment_method_payment_state_path(self, payment)
})
ensure
payment.remove_instance_variable(:@nexio_callback_url)
end
end
|
#store(options) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/models/solidus_nexio/payment_method.rb', line 63
def store(options)
card_attrs = options[:card]
.slice(:encrypted_number, :number, :name, :month, :year)
.merge!(
brand: options[:card][:cc_type],
one_time_token: options[:one_time_token],
own_form: preferred_ui == 'own_form'
)
card = ActiveMerchant::Billing::EncryptedNexioCard.new(card_attrs)
return unless card.valid?
gateway.store(card, options.except(:card, :one_time_token))
end
|
#try_void(payment) ⇒ Object
77
78
79
|
# File 'app/models/solidus_nexio/payment_method.rb', line 77
def try_void(payment)
void(payment.response_code)
end
|