class Pay::Paddle::PaymentMethod
Attributes
pay_payment_method[R]
Public Class Methods
new(pay_payment_method)
click to toggle source
# File lib/pay/paddle/payment_method.rb, line 47 def initialize(pay_payment_method) @pay_payment_method = pay_payment_method end
payment_method_details_for(subscription_id:)
click to toggle source
# File lib/pay/paddle/payment_method.rb, line 24 def self.payment_method_details_for(subscription_id:) subscription_user = PaddlePay::Subscription::User.list({subscription_id: subscription_id}).try(:first) payment_information = subscription_user ? subscription_user[:payment_information] : {} case payment_information[:payment_method] 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
sync(pay_customer:, attributes: nil)
click to toggle source
Paddle
doesn't provide PaymentMethod
IDs, so we have to lookup via the Customer
# File lib/pay/paddle/payment_method.rb, line 9 def self.sync(pay_customer:, attributes: nil) return unless pay_customer.subscription payment_method = pay_customer.default_payment_method || pay_customer.build_default_payment_method payment_method.processor_id ||= NanoId.generate # Lookup payment method from API unless passed in attributes ||= payment_method_details_for(subscription_id: pay_customer.subscription.processor_id) payment_method.update!(attributes) payment_method rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end
Public Instance Methods
detach()
click to toggle source
Remove payment method
# File lib/pay/paddle/payment_method.rb, line 56 def detach end
make_default!()
click to toggle source
Sets payment method as default
# File lib/pay/paddle/payment_method.rb, line 52 def make_default! end