app/services/tang/fail_invoice.rb in tang-0.0.9 vs app/services/tang/fail_invoice.rb in tang-0.1.0
- old
+ new
@@ -1,20 +1,23 @@
module Tang
class FailInvoice
def self.call(stripe_invoice)
- invoice = Invoice.find_by(stripe_id: stripe_invoice.id)
+ # invoice = Invoice.find_by(stripe_id: stripe_invoice.id)
+ invoice = Invoice.from_stripe(stripe_invoice)
# create charge
charge = nil
if stripe_invoice.charge.present?
stripe_charge = Stripe::Charge.retrieve(stripe_invoice.charge)
charge = Charge.from_stripe(stripe_charge, invoice)
end
# update subscription
subscription = Subscription.find_by(stripe_id: stripe_invoice.subscription)
- subscription.fail! if !subscription.past_due?
-
+ if subscription.present?
+ subscription.fail! if !subscription.past_due?
+ end
+
return charge
end
end
end
\ No newline at end of file