Skip to content

Instantly share code, notes, and snippets.

@boucher
Created August 31, 2011 18:47
Show Gist options
  • Save boucher/1184353 to your computer and use it in GitHub Desktop.
Save boucher/1184353 to your computer and use it in GitHub Desktop.
def pay(make_request=true)
return if @invoice.paid
@invoice.frozen_at ||= Time.stamp
roll_in_old_invoices
unless too_small? || @invoice.is_rollover?
log_ann("Invoice payer about to attempt payment for invoice: #{@invoice.token}")
@invoice.attempted_at = Time.stamp
if make_request
ch, paid = try_charge_request
else
ch, paid = try_charge_direct
end
@invoice.charge, @invoice.paid = ch, paid
InvoiceCharge.create(@invoice.token, ch, @source)
ch && paid ? recurring_payment_succeeded : recurring_payment_failed
end
<<<<<<< HEAD
DeprecatedLog.log_internal_event('invoice-pay-attempt',
:merchant => @invoice.merchant,
:invoice => {:token => @invoice.token, :amount => @invoice.amount},
:mailable => false,
:customer => {:token => @invoice.customer})
end
def close_if_not_payable
if @invoice.closed_at
raise InvoiceClosedException
elsif close_for = reason_for_closing
=======
@invoice.save
end
def process(make_request=true)
if close_for = reason_for_closing
log_ann("Invoice payer about to close invoice: #{@invoice.token}")
>>>>>>> master
@invoice.closed_at = Time.stamp
@invoice.closed_for = close_for
@invoice.save
raise InvoiceShouldCloseException.new(close_for)
elsif close_for = reason_for_closing_for_automatic_retries
@invoice.closed_for_automatic_retries = true
@invoice.closed_for_automatic_retries_for = Invoice.closed_customer_delinquent
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment