module Reji::PerformsCharges

Public Instance Methods

charge(amount, payment_method, options = {}) click to toggle source

Make a “one off” charge on the customer for the given amount.

# File lib/reji/concerns/performs_charges.rb, line 8
def charge(amount, payment_method, options = {})
  options = {
    confirmation_method: 'automatic',
    confirm: true,
    currency: preferred_currency,
  }.merge(options)

  options[:amount] = amount
  options[:payment_method] = payment_method
  options[:customer] = stripe_id if stripe_id?

  payment = Payment.new(
    Stripe::PaymentIntent.create(options, stripe_options)
  )

  payment.validate

  payment
end
refund(payment_intent, options = {}) click to toggle source

Refund a customer for a charge.

# File lib/reji/concerns/performs_charges.rb, line 29
def refund(payment_intent, options = {})
  Stripe::Refund.create(
    { payment_intent: payment_intent }.merge(options),
    stripe_options
  )
end