Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "void" functionality to BillPaymentService #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/quickbooks/service/bill_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ def delete(bill_payment)
delete_by_query_string(bill_payment)
end

def void(bill_payment, options = {})
raise Quickbooks::InvalidModelException.new(bill_payment.errors.full_messages.join(',')) unless bill_payment.valid?

xml = bill_payment.to_xml_ns(options)
url = "#{url_for_resource(model::REST_RESOURCE)}?include=void"

response = do_http_post(url, valid_xml_document(xml), {})
if response.code.to_i == 200
model.from_xml(parse_singular_entity_response(model, response.plain_body))
else
false
end
end

private

def model
Expand Down
20 changes: 20 additions & 0 deletions spec/fixtures/bill_payment_void_response_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2023-11-22T11:47:55.316-08:00">
<BillPayment domain="QBO" sparse="false">
<Id>204</Id>
<SyncToken>1</SyncToken>
<MetaData>
<CreateTime>2023-10-10T11:56:09-07:00</CreateTime>
<LastUpdatedTime>2023-11-22T11:47:46-08:00</LastUpdatedTime>
</MetaData>
<TxnDate>2023-09-19</TxnDate>
<CurrencyRef name="United States Dollar">USD</CurrencyRef>
<PrivateNote>Voided</PrivateNote>
<VendorRef name="Vendor">71</VendorRef>
<PayType>Check</PayType>
<CheckPayment>
<BankAccountRef name="Bank Account">141</BankAccountRef>
<PrintStatus>NotSet</PrintStatus>
</CheckPayment>
<TotalAmt>0</TotalAmt>
</BillPayment>
</IntuitResponse>
13 changes: 13 additions & 0 deletions spec/lib/quickbooks/service/bill_payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,17 @@

expect(response).to be true
end

it 'can void a bill_payment' do
stub_http_request(:post,
"#{@service.url_for_resource(resource)}?include=void",
["200", "OK"],
fixture("bill_payment_void_response_success.xml"))

response = @service.void(bill_payment)

expect(response).to be_truthy
expect(response.private_note).to eq('Voided')
expect(response.total).to eq(0)
end
end
Loading