Method: Pay::Stripe::Billable#add_payment_method

Defined in:
lib/pay/stripe/billable.rb

#add_payment_method(payment_method_id, default: false) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pay/stripe/billable.rb', line 99

def add_payment_method(payment_method_id, default: false)
  customer unless processor_id?
  payment_method = ::Stripe::PaymentMethod.attach(payment_method_id, {customer: processor_id}, stripe_options)

  if default
    ::Stripe::Customer.update(processor_id, {
      invoice_settings: {
        default_payment_method: payment_method.id
      }
    }, stripe_options)
  end

  save_payment_method(payment_method, default: default)
rescue ::Stripe::StripeError => e
  raise Pay::Stripe::Error, e
end