Method: Pay::PaddleClassic::PaymentMethod.payment_method_details_for

Defined in:
app/models/pay/paddle_classic/payment_method.rb

.payment_method_details_for(subscription_id:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/pay/paddle_classic/payment_method.rb', line 20

def self.payment_method_details_for(subscription_id:)
  subscription_user = PaddleClassic.client.users.list(subscription_id: subscription_id).data.try(:first)
  payment_information = subscription_user ? subscription_user[:payment_information] : {}

  case payment_information[:payment_method]&.downcase
  when "card"
    {
      payment_method_type: :card,
      brand: payment_information[:card_type],
      last4: payment_information[:last_four_digits],
      exp_month: payment_information[:expiry_date].split("/").first,
      exp_year: payment_information[:expiry_date].split("/").last
    }
  when "paypal"
    {
      payment_method_type: :paypal,
      brand: "PayPal"
    }
  else
    {}
  end
end