Class: SolidusStripe::Webhook::PaymentIntentSubscriber
- Inherits:
-
Object
- Object
- SolidusStripe::Webhook::PaymentIntentSubscriber
- Includes:
- Omnes::Subscriber, MoneyToStripeAmountConverter
- Defined in:
- app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb
Overview
Handlers for Stripe payment_intent events.
Constant Summary
Constants included from MoneyToStripeAmountConverter
MoneyToStripeAmountConverter::DIVISIBLE_BY_100, MoneyToStripeAmountConverter::THREE_DECIMAL_CURRENCIES, MoneyToStripeAmountConverter::ZERO_DECIMAL_CURRENCIES
Instance Method Summary collapse
-
#capture_payment(event) ⇒ Object
Captures a payment.
-
#fail_payment(event) ⇒ Object
Fails a payment.
-
#void_payment(event) ⇒ Object
Voids a payment.
Methods included from MoneyToStripeAmountConverter
#solidus_decimal_to_subunit, #solidus_subunit_to_decimal, #to_solidus_amount, #to_stripe_amount
Instance Method Details
#capture_payment(event) ⇒ Object
Captures a payment.
Marks a Solidus payment associated to a Stripe payment intent as completed, adding a log entry about the event.
In the case of a partial capture, it also synchronizes the refunds.
25 26 27 28 29 30 31 32 |
# File 'app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb', line 25 def capture_payment(event) payment = extract_payment_from_event(event) payment.with_lock do break false if payment.completed? complete_payment(payment) end && sync_refunds(event) end |
#fail_payment(event) ⇒ Object
Fails a payment.
Marks a Solidus payment associated to a Stripe payment intent as failed, adding a log entry about the event.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb', line 40 def fail_payment(event) payment = extract_payment_from_event(event) payment.with_lock do break if payment.failed? payment.failure!.tap do SolidusStripe::LogEntries.payment_log( payment, success: false, message: "Payment was marked as failed after payment_intent.failed webhook" ) end end end |
#void_payment(event) ⇒ Object
Voids a payment.
Voids a Solidus payment associated to a Stripe payment intent, adding a log entry about the event.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb', line 62 def void_payment(event) payment = extract_payment_from_event(event) reason = event.data.object.cancellation_reason payment.with_lock do break if payment.void? payment.void!.tap do SolidusStripe::LogEntries.payment_log( payment, success: true, message: "Payment was voided after payment_intent.voided webhook (#{reason})" ) end end end |