Skip to content

Commit

Permalink
fix(netsuite): Fix netsuite payment payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Nov 11, 2024
1 parent 9fda024 commit 06d5433
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
18 changes: 7 additions & 11 deletions app/services/integrations/aggregator/payments/payloads/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ def body
'type' => 'customerpayment',
'isDynamic' => true,
'columns' => {
'customer' => integration_customer.external_customer_id
'customer' => integration_customer.external_customer_id,
'payment' => amount(payment.amount_cents, resource: invoice),
'autoapply' => true
},
'lines' => [
'applyTransactions' => [
{
'sublistId' => 'apply',
'lineItems' => [
{
# If the invoice is not synced yet, lets raise an error and retry. (doc: nil is an invalid request)
'doc' => integration_invoice&.external_id,
'apply' => true,
'amount' => amount(payment.amount_cents, resource: invoice)
}
]
'internalId' => integration_invoice&.external_id,
'apply' => true,
'amount' => amount(payment.amount_cents, resource: invoice)
}
],
'options' => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Integrations::Aggregator::Payments::Payloads::Netsuite do
let(:payload) { described_class.new(integration:, payment:) }
let(:integration_customer) { create(:netsuite_customer, integration:, customer:) }
let(:integration) { create(:netsuite_integration, organization:) }
let(:customer) { create(:customer, organization:) }
let(:organization) { create(:organization) }
let(:payment) { create(:payment, payable: invoice, amount_cents: 100) }
let(:integration_invoice) { create(:integration_resource, syncable: invoice) }

let(:invoice) do
create(
:invoice,
customer:,
organization:,
coupons_amount_cents: 2000,
prepaid_credit_amount_cents: 4000,
credit_notes_amount_cents: 6000,
taxes_amount_cents: 200,
issuing_date: DateTime.new(2024, 7, 8)
)
end

let(:body) do
{
'type' => 'customerpayment',
'isDynamic' => true,
'columns' => {
'customer' => integration_customer.external_customer_id,
'payment' => payment.amount_cents / 100.0,
'autoapply' => true
},
'applyTransactions' => [
{
'internalId' => integration_invoice&.external_id,
'apply' => true,
'amount' => payment.amount_cents / 100.0
}
],
'options' => {
'ignoreMandatoryFields' => false
}
}
end

before do
integration_customer
integration_invoice
end

describe '#body' do
subject(:body_call) { payload.body }

it 'returns payload body' do
expect(subject).to eq(body)
end
end
end

0 comments on commit 06d5433

Please sign in to comment.