Class: Pay::Braintree::Webhooks::SubscriptionChargedSuccessfully

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/braintree/webhooks/subscription_charged_successfully.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pay/braintree/webhooks/subscription_charged_successfully.rb', line 7

def call(event)
  subscription = event.subscription
  return if subscription.nil?

  pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
  return unless pay_subscription.present?

  charge = subscription.transactions.first
  pay_charge = Pay::Braintree::Charge.sync(charge.id, object: charge)

  if pay_charge && Pay.send_email?(:receipt, pay_charge)
    Pay.mailer.with(pay_customer: pay_subscription.customer, pay_charge: pay_charge).receipt.deliver_later
  end
end