Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request datadryad#282 from ryscher/invoicer-auto-advance
Browse files Browse the repository at this point in the history
Invoicer auto advance
  • Loading branch information
sfisher committed Sep 30, 2019
2 parents 14eea2d + 9b8125c commit 8970a4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions stash_engine/lib/stash/payments/invoicer.rb
Expand Up @@ -26,10 +26,9 @@ def charge_user_via_invoice
return unless customer_id.present?
create_invoice_items_for_dpc(customer_id)
invoice = create_invoice(customer_id)
invoice.auto_advance = true
resource.identifier.invoice_id = invoice.id
resource.identifier.save
invoice.finalize_invoice
invoice.send_invoice
end

# For a journal, generate an invoice item for the DPC.
Expand Down Expand Up @@ -118,15 +117,18 @@ def create_invoice_items_for_dpc(customer_id)

def create_invoice(customer_id)
Stripe::Invoice.create(
auto_advance: true,
collection_method: 'send_invoice',
customer: customer_id,
days_until_due: 30,
description: 'Dryad deposit ' + resource.identifier.to_s + ', ' + resource.title,
metadata: { 'curator' => curator.name }
)
end

def create_customer(author)
Stripe::Customer.create(
description: author.author_standard_name,
name: author.author_standard_name,
email: author.author_email
)
end
Expand Down
2 changes: 1 addition & 1 deletion stash_engine/spec/unit/stash/payments/invoicer_spec.rb
Expand Up @@ -34,7 +34,7 @@ module Payments
@cust_id = '9999'
fake_invoice_item = OpenStruct.new(customer: @cust_id, amount: '99.99', currency: 'usd', description: 'Data Processing Charge')
fake_invoice = OpenStruct.new(customer: @cust_id, description: 'Dryad deposit',
metadata: { curator: 'The Curator' }, finalize_invoice: 'STRIPE1234')
metadata: { curator: 'The Curator' }, send_invoice: 'STRIPE1234')
fake_customer = OpenStruct.new(id: @cust_id, email: @author.author_email, description: @author.author_standard_name)

@invoicer = Invoicer.new(resource: @resource, curator: @curator)
Expand Down

0 comments on commit 8970a4b

Please sign in to comment.