Class: SolidusStripe::PaymentMethod
- Inherits:
-
Spree::PaymentMethod
- Object
- Spree::PaymentMethod
- SolidusStripe::PaymentMethod
- Defined in:
- app/models/solidus_stripe/payment_method.rb
Instance Attribute Summary collapse
-
#preferred_webhook_endpoint_signing_secret The webhook endpoint signing secret(Thewebhookendpointsigningsecret) ⇒ Object
for this payment method.
Class Method Summary collapse
-
.intent_id_for_payment(payment) ⇒ Object
TODO: re-evaluate the need for this and think of ways to always go throught the intent classes.
-
.refund_reason ⇒ Spree::RefundReason
The reason used for refunds generated from Stripe.
- .with_slug(slug) ⇒ Object
Instance Method Summary collapse
- #assign_slug ⇒ Object
- #gateway_class ⇒ Object
- #partial_name ⇒ Object (also: #cart_partial_name, #product_page_partial_name, #risky_partial_name)
- #payment_profiles_supported? ⇒ Boolean
- #payment_source_class ⇒ Object
-
#previous_sources(order) ⇒ Object
The method that should be used is "Spree::PaymentMethod#reusable_sources".
- #source_required? ⇒ Boolean
- #stripe_dashboard_url(intent_id) ⇒ Object
Instance Attribute Details
#preferred_webhook_endpoint_signing_secret The webhook endpoint signing secret(Thewebhookendpointsigningsecret) ⇒ Object
for this payment method.
12 |
# File 'app/models/solidus_stripe/payment_method.rb', line 12 preference :webhook_endpoint_signing_secret, :string |
Class Method Details
.intent_id_for_payment(payment) ⇒ Object
TODO: re-evaluate the need for this and think of ways to always go throught the intent classes.
61 62 63 64 65 66 67 |
# File 'app/models/solidus_stripe/payment_method.rb', line 61 def self.intent_id_for_payment(payment) return unless payment payment.transaction_id || SolidusStripe::PaymentIntent.where( order: payment.order, payment_method: payment.payment_method )&.pick(:stripe_intent_id) end |
.refund_reason ⇒ Spree::RefundReason
Returns the reason used for refunds generated from Stripe.
25 26 27 28 29 |
# File 'app/models/solidus_stripe/payment_method.rb', line 25 def self.refund_reason Spree::RefundReason.find_by!( name: SolidusStripe.configuration.refund_reason_name ) end |
.with_slug(slug) ⇒ Object
56 57 58 |
# File 'app/models/solidus_stripe/payment_method.rb', line 56 def self.with_slug(slug) where(id: SlugEntry.where(slug: slug).select(:payment_method_id)) end |
Instance Method Details
#assign_slug ⇒ Object
78 79 80 81 82 83 84 |
# File 'app/models/solidus_stripe/payment_method.rb', line 78 def assign_slug # If there's only one payment method, we can use a default slug. slug = preferred_test_mode ? 'test' : 'live' if self.class.count == 1 slug = SecureRandom.hex(16) while SlugEntry.exists?(slug: slug) || slug.nil? create_slug_entry!(slug: slug) end |
#gateway_class ⇒ Object
47 48 49 |
# File 'app/models/solidus_stripe/payment_method.rb', line 47 def gateway_class Gateway end |
#partial_name ⇒ Object Also known as: cart_partial_name, product_page_partial_name, risky_partial_name
31 32 33 |
# File 'app/models/solidus_stripe/payment_method.rb', line 31 def partial_name "stripe" end |
#payment_profiles_supported? ⇒ Boolean
51 52 53 54 |
# File 'app/models/solidus_stripe/payment_method.rb', line 51 def payment_profiles_supported? # We actually support them, but not in the way expected by Solidus and its ActiveMerchant legacy. false end |
#payment_source_class ⇒ Object
43 44 45 |
# File 'app/models/solidus_stripe/payment_method.rb', line 43 def payment_source_class PaymentSource end |
#previous_sources(order) ⇒ Object
Start using the correct method to get a user's previous sources
The method that should be used is "Spree::PaymentMethod#reusable_sources". However, in the dedicated partial source form, the reusable_sources are assigned to "previous_cards": https://github.com/solidusio/solidus/blob/e9debb976e2228bb0b7a8eff4894e0556fc15cc8/backend/app/views/spree/admin/payments/_form.html.erb#L31 This name is inaccurate and too specific because, in our case, a payment-source/stripe-payment-method have many different possible types: https://stripe.com/docs/api/payment_methods/object#payment_method_object-type
For more details: https://github.com/solidusio/solidus/issues/5014
98 99 100 101 102 103 104 |
# File 'app/models/solidus_stripe/payment_method.rb', line 98 def previous_sources(order) if order.user_id order.user.wallet.wallet_payment_sources.map(&:payment_source) else [] end end |
#source_required? ⇒ Boolean
39 40 41 |
# File 'app/models/solidus_stripe/payment_method.rb', line 39 def source_required? true end |
#stripe_dashboard_url(intent_id) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/models/solidus_stripe/payment_method.rb', line 69 def stripe_dashboard_url(intent_id) path_prefix = '/test' if preferred_test_mode case intent_id when /^pi_/ "https://dashboard.stripe.com#{path_prefix}/payments/#{intent_id}" end end |