Class: Pay::PaddleClassic::PaymentMethod
Class Method Summary
collapse
Instance Method Summary
collapse
find_by_processor_and_id, pay_processor_for, #payment_processor
Class Method Details
.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
|
.sync(pay_customer:, attributes: nil) ⇒ Object
Paddle doesn’t provide PaymentMethod IDs, so we have to lookup via the Customer
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/models/pay/paddle_classic/payment_method.rb', line 5
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
attributes ||= payment_method_details_for(subscription_id: pay_customer.subscription.processor_id)
payment_method.update!(attributes)
payment_method
rescue ::Paddle::Error => e
raise Pay::PaddleClassic::Error, e
end
|
Instance Method Details
#detach ⇒ Object
46
47
|
# File 'app/models/pay/paddle_classic/payment_method.rb', line 46
def detach
end
|
#make_default! ⇒ Object
43
44
|
# File 'app/models/pay/paddle_classic/payment_method.rb', line 43
def make_default!
end
|