Class: Pay::PaddleBilling::PaymentMethod
- Inherits:
-
Object
- Object
- Pay::PaddleBilling::PaymentMethod
- Defined in:
- lib/pay/lemon_squeezy/payment_method.rb,
lib/pay/paddle_billing/payment_method.rb
Instance Attribute Summary collapse
-
#pay_payment_method ⇒ Object
readonly
Returns the value of attribute pay_payment_method.
Class Method Summary collapse
- .sync(pay_customer:, attributes:) ⇒ Object
- .sync_from_transaction(pay_customer:, transaction:) ⇒ Object
Instance Method Summary collapse
-
#detach ⇒ Object
Remove payment method.
-
#initialize(pay_payment_method) ⇒ PaymentMethod
constructor
A new instance of PaymentMethod.
-
#make_default! ⇒ Object
Sets payment method as default.
Constructor Details
#initialize(pay_payment_method) ⇒ PaymentMethod
Returns a new instance of PaymentMethod.
27 28 29 |
# File 'lib/pay/lemon_squeezy/payment_method.rb', line 27 def initialize(pay_payment_method) @pay_payment_method = pay_payment_method end |
Instance Attribute Details
#pay_payment_method ⇒ Object (readonly)
Returns the value of attribute pay_payment_method.
4 5 6 |
# File 'lib/pay/lemon_squeezy/payment_method.rb', line 4 def pay_payment_method @pay_payment_method end |
Class Method Details
.sync(pay_customer:, attributes:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pay/lemon_squeezy/payment_method.rb', line 8 def self.sync(pay_customer:, attributes:) details = attributes.method_details attrs = { type: details.type.downcase } case details.type.downcase when "card" attrs[:brand] = details.card.type attrs[:last4] = details.card.last4 attrs[:exp_month] = details.card.expiry_month attrs[:exp_year] = details.card.expiry_year end payment_method = pay_customer.payment_methods.find_or_initialize_by(processor_id: attributes.stored_payment_method_id) payment_method.update!(attrs) payment_method end |
.sync_from_transaction(pay_customer:, transaction:) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/pay/paddle_billing/payment_method.rb', line 8 def self.sync_from_transaction(pay_customer:, transaction:) transaction = ::Paddle::Transaction.retrieve(id: transaction) return unless transaction.status == "completed" return if transaction.payments.empty? sync(pay_customer: pay_customer, attributes: transaction.payments.first) end |
Instance Method Details
#detach ⇒ Object
Remove payment method
36 37 |
# File 'lib/pay/lemon_squeezy/payment_method.rb', line 36 def detach end |
#make_default! ⇒ Object
Sets payment method as default
32 33 |
# File 'lib/pay/lemon_squeezy/payment_method.rb', line 32 def make_default! end |