Module: Pay::Sync
- Included in:
- Braintree::Charge, Braintree::PaymentMethod, Braintree::Subscription, LemonSqueezy::Charge, LemonSqueezy::Subscription, PaddleBilling::Charge, PaddleBilling::PaymentMethod, PaddleBilling::Subscription, PaddleClassic::Subscription, Pay::Stripe::Charge, Pay::Stripe::PaymentMethod, Pay::Stripe::Subscription
- Defined in:
- lib/pay/sync.rb
Overview
Shared skeleton for the processor Charge.sync, Subscription.sync, and PaymentMethod.sync class methods
Instance Method Summary collapse
-
#find_pay_customer(processor_id) ⇒ Object
The Pay::Customer for this processor, or nil when the ID is blank or the customer isn't in the database.
-
#pay_processor ⇒ Object
"stripe" for Pay::Stripe::Charge, "paddle_billing" for Pay::PaddleBilling::Subscription, and so on.
-
#sync_with_retries(retries: 1) ⇒ Object
Runs the sync block, retrying it when a webhook and an API call race to create the same record.
Instance Method Details
#find_pay_customer(processor_id) ⇒ Object
The Pay::Customer for this processor, or nil when the ID is blank or the customer isn't in the database
20 21 22 |
# File 'lib/pay/sync.rb', line 20 def find_pay_customer(processor_id) Pay::Customer.find_by(processor: pay_processor, processor_id: processor_id) if processor_id.present? end |
#pay_processor ⇒ Object
"stripe" for Pay::Stripe::Charge, "paddle_billing" for Pay::PaddleBilling::Subscription, and so on
25 26 27 |
# File 'lib/pay/sync.rb', line 25 def pay_processor name.deconstantize.demodulize.underscore end |
#sync_with_retries(retries: 1) ⇒ Object
Runs the sync block, retrying it when a webhook and an API call race to create the same record. The block retrieves the processor's object itself when the caller didn't pass one in, so each retry gets a fresh read.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pay/sync.rb', line 7 def sync_with_retries(retries: 1) try = 0 begin yield rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique try += 1 raise if try > retries sleep 0.15 * try retry end end |