From 35616983e9018d20c17c96c15677d0010796d66e Mon Sep 17 00:00:00 2001 From: Dean Perry Date: Wed, 18 Oct 2023 13:45:36 +0100 Subject: [PATCH] Fix issue with Paddle Billing Charges when there's no payment details (#872) * Only grab/set payment method details if there is a payment on a paddle transaction * standardrb fix --- lib/pay/paddle/charge.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/pay/paddle/charge.rb b/lib/pay/paddle/charge.rb index 1cf04a66..dd95b468 100644 --- a/lib/pay/paddle/charge.rb +++ b/lib/pay/paddle/charge.rb @@ -37,19 +37,21 @@ def self.sync(charge_id, object: nil, try: 0, retries: 1) subscription: pay_customer.subscriptions.find_by(processor_id: object.subscription_id) } - case object.payment.method_details.type.downcase - when "card" - attrs[:payment_method_type] = "card" - attrs[:brand] = details.card.type - attrs[:exp_month] = details.card.expiry_month - attrs[:exp_year] = details.card.expiry_year - attrs[:last4] = details.card.last4 - when "paypal" - attrs[:payment_method_type] = "paypal" - end + if object.payment + case object.payment.method_details.type.downcase + when "card" + attrs[:payment_method_type] = "card" + attrs[:brand] = details.card.type + attrs[:exp_month] = details.card.expiry_month + attrs[:exp_year] = details.card.expiry_year + attrs[:last4] = details.card.last4 + when "paypal" + attrs[:payment_method_type] = "paypal" + end - # Update customer's payment method - Pay::Paddle::PaymentMethod.sync(pay_customer: pay_customer, attributes: object.payments.first) + # Update customer's payment method + Pay::Paddle::PaymentMethod.sync(pay_customer: pay_customer, attributes: object.payments.first) + end # Update or create the charge if (pay_charge = pay_customer.charges.find_by(processor_id: object.id))