Sha256: 12448c6a819f777e549895684ba0ecb35b0824fb58ce45931be8c2cd95860a24
Contents?: true
Size: 1.04 KB
Versions: 21
Compression:
Stored size: 1.04 KB
Contents
namespace :pay do namespace :payment_methods do desc "Sync default payment methods for Pay::Customers" task sync_default: :environment do Pay::Customer.find_each do |pay_customer| sync_default_payment_method(pay_customer) end end end end def sync_default_payment_method(pay_customer, retries: 2) try = 0 begin puts "Syncing Pay::Customer ##{pay_customer.id} attempt #{try + 1}: #{pay_customer.processor.titleize} #{pay_customer.processor_id}" case pay_customer.processor when "braintree" payment_method = pay_customer.customer.payment_methods.find(&:default?) Pay::Braintree::PaymentMethod.sync(payment_method.token, object: payment_method) if payment_method when "stripe" payment_method_id = pay_customer.customer.invoice_settings.default_payment_method Pay::Stripe::PaymentMethod.sync(payment_method_id) if payment_method_id when "paddle" Pay::Paddle::PaymentMethod.sync(pay_customer) end rescue sleep 0.5 try += 1 try <= retries ? retry : raise end end
Version data entries
21 entries across 21 versions & 1 rubygems