Method: Pay::LemonSqueezy::PaymentMethod.sync

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

.sync(pay_customer:, attributes:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/pay/lemon_squeezy/payment_method.rb', line 4

def self.sync(pay_customer:, attributes:)
  return unless pay_customer.subscription

  payment_method = pay_customer.default_payment_method || pay_customer.build_default_payment_method
  payment_method.processor_id ||= NanoId.generate

  attrs = {
    payment_method_type: "card",
    brand: attributes.card_brand,
    last4: attributes.card_last_four
  }

  payment_method.update!(attrs)
  payment_method
end