Module: Od::Payments::PaymentMethod

Defined in:
lib/od/payments/resources/payment_method.rb

Class Method Summary collapse

Class Method Details

.attach(payment_method_id, customer_id) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/od/payments/resources/payment_method.rb', line 48

def self.attach(payment_method_id, customer_id)
  Stripe::PaymentMethod.attach(
    payment_method_id,
    { customer: customer_id }
  )
rescue Stripe::CardError => e
  raise Od::Payments::CardError.new(e.error.message, {})
rescue Stripe::StripeError => e
  raise Od::Payments::OdPaymentsError, e.error.message
end

.create(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/od/payments/resources/payment_method.rb', line 5

def self.create(params)
  case Od::Payments.adapter
  when :stripe
    Stripe::PaymentMethod.create params
  end
rescue Stripe::CardError => e
  raise Od::Payments::CardError.new(e.error.message, {})
rescue Stripe::StripeError => e
  raise Od::Payments::OdPaymentsError, e.error.message
end

.delete(payment_method_id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/od/payments/resources/payment_method.rb', line 28

def self.delete(payment_method_id)
  case Od::Payments.adapter
  when :stripe
    Stripe::PaymentMethod.detach(
      payment_method_id
    )
  end
rescue Stripe::StripeError => e
  raise Od::Payments::OdPaymentsError, e.error.message
end

.list(customer_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/od/payments/resources/payment_method.rb', line 16

def self.list(customer_id)
  case Od::Payments.adapter
  when :stripe
    Stripe::PaymentMethod.list({
                                 customer: customer_id,
                                 type: 'card'
                               })
  end
rescue Stripe::StripeError => e
  raise Od::Payments::OdPaymentsError, e.error.message
end

.show(payment_method_id) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/od/payments/resources/payment_method.rb', line 39

def self.show(payment_method_id)
  case Od::Payments.adapter
  when :stripe
    Stripe::PaymentIntent.retrieve payment_method_id
  end
rescue Stripe::StripeError => e
  raise Od::Payments::OdPaymentsError, e.error.message
end