diff --git a/lib/quickbooks/service/bill_payment.rb b/lib/quickbooks/service/bill_payment.rb index ea98d861..f1c6b984 100644 --- a/lib/quickbooks/service/bill_payment.rb +++ b/lib/quickbooks/service/bill_payment.rb @@ -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 diff --git a/spec/fixtures/bill_payment_void_response_success.xml b/spec/fixtures/bill_payment_void_response_success.xml new file mode 100644 index 00000000..f1cb9291 --- /dev/null +++ b/spec/fixtures/bill_payment_void_response_success.xml @@ -0,0 +1,20 @@ + + + 204 + 1 + + 2023-10-10T11:56:09-07:00 + 2023-11-22T11:47:46-08:00 + + 2023-09-19 + USD + Voided + 71 + Check + + 141 + NotSet + + 0 + + diff --git a/spec/lib/quickbooks/service/bill_payment_spec.rb b/spec/lib/quickbooks/service/bill_payment_spec.rb index d07ffe4f..8d61e88d 100644 --- a/spec/lib/quickbooks/service/bill_payment_spec.rb +++ b/spec/lib/quickbooks/service/bill_payment_spec.rb @@ -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