Skip to content

Commit fdc1a8f

Browse files
committed
Merge pull request stripe-ruby-mock#59 from okcwest/invoice-pay-support
add support for Invoice#pay [closes stripe-ruby-mock#57]
2 parents 68995ab + 441698c commit fdc1a8f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/stripe_mock/request_handlers/invoices.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def Invoices.included(klass)
66
klass.add_handler 'post /v1/invoices', :new_invoice
77
klass.add_handler 'get /v1/invoices/(.*)', :get_invoice
88
klass.add_handler 'get /v1/invoices', :list_invoices
9+
klass.add_handler 'post /v1/invoices/(.*)/pay', :pay_invoice
910
end
1011

1112
def new_invoice(route, method_url, params, headers)
@@ -31,6 +32,13 @@ def get_invoice(route, method_url, params, headers)
3132
assert_existance :invoice, $1, invoices[$1]
3233
invoices[$1] ||= Data.mock_invoice(:id => $1)
3334
end
35+
36+
def pay_invoice(route, method_url, params, headers)
37+
route =~ method_url
38+
assert_existance :invoice, $1, invoices[$1]
39+
invoices[$1] ||= Data.mock_invoice(:id => $1)
40+
invoices[$1].merge!(:paid => true, :attempted => true, :charge => 'ch_1fD6uiR9FAA2zc')
41+
end
3442

3543
end
3644
end

spec/shared_stripe_examples/invoice_examples.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,20 @@
5151
end
5252
end
5353

54+
context "paying an invoice" do
55+
before do
56+
@invoice = Stripe::Invoice.create
57+
@invoice.pay
58+
end
59+
60+
it 'updates attempted and paid flags' do
61+
expect(@invoice.attempted).to be_true
62+
expect(@invoice.paid).to be_true
63+
end
64+
65+
it 'sets the charge attribute' do
66+
expect(@invoice.charge).to be_a String
67+
expect(@invoice.charge.length).to be > 0
68+
end
69+
end
5470
end

0 commit comments

Comments
 (0)