Skip to content

Commit

Permalink
Merge pull request #10 from Codefied/FINTECHQB-2573-add-void-billpaym…
Browse files Browse the repository at this point in the history
…ent-feature

Add "void" action to BillPayment
  • Loading branch information
andymond authored Dec 8, 2023
2 parents dd300ed + 025b733 commit 3c0500e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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

0 comments on commit 3c0500e

Please sign in to comment.