Skip to content

Commit

Permalink
feat(invoice-ninja): add create payment action
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca committed Oct 13, 2023
1 parent 2159898 commit e2a54e2
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
export const fields = [
{
label: 'Client ID',
key: 'clientId',
type: 'dropdown' as const,
required: true,
description: 'The ID of the client, not the name or email address.',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listClients',
},
],
},
},
{
label: 'Payment Date',
key: 'paymentDate',
type: 'string' as const,
required: false,
description: '',
variables: true,
},
{
label: 'Invoice',
key: 'invoiceId',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listInvoices',
},
],
},
},
{
label: 'Invoice Amount',
key: 'invoiceAmount',
type: 'string' as const,
required: false,
description: '',
variables: true,
},
{
label: 'Payment Type',
key: 'paymentType',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
options: [
{ label: 'Bank Transfer', value: '1' },
{ label: 'Cash', value: '2' },
{ label: 'Debit', value: '3' },
{ label: 'ACH', value: '4' },
{ label: 'Visa Card', value: '5' },
{ label: 'MasterCard', value: '6' },
{ label: 'American Express', value: '7' },
{ label: 'Discover Card', value: '8' },
{ label: 'Diners Card', value: '9' },
{ label: 'EuroCard', value: '10' },
{ label: 'Nova', value: '11' },
{ label: 'Credit Card Other', value: '12' },
{ label: 'PayPal', value: '13' },
{ label: 'Google Wallet', value: '14' },
{ label: 'Check', value: '15' },
{ label: 'Carte Blanche', value: '16' },
{ label: 'UnionPay', value: '17' },
{ label: 'JCB', value: '18' },
{ label: 'Laser', value: '19' },
{ label: 'Maestro', value: '20' },
{ label: 'Solo', value: '21' },
{ label: 'Switch', value: '22' },
{ label: 'iZettle', value: '23' },
{ label: 'Swish', value: '24' },
{ label: 'Venmo', value: '25' },
{ label: 'Money Order', value: '26' },
{ label: 'Alipay', value: '27' },
{ label: 'Sofort', value: '28' },
{ label: 'SEPA', value: '29' },
{ label: 'GoCardless', value: '30' },
{ label: 'Bitcoin', value: '31' },
],
},
{
label: 'Transfer Reference',
key: 'transferReference',
type: 'string' as const,
required: false,
description: '',
variables: true,
},
{
label: 'Private Notes',
key: 'privateNotes',
type: 'string' as const,
required: false,
description: '',
variables: true,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import defineAction from '../../../../helpers/define-action';
import { filterProvidedFields } from '../../common/filter-provided-fields';
import { fields } from './fields';

export default defineAction({
name: 'Create payment',
key: 'createPayment',
description: 'Creates a new payment.',
arguments: fields,

async run($) {
const {
clientId,
paymentDate,
invoiceId,
invoiceAmount,
paymentType,
transferReference,
privateNotes,
} = $.step.parameters;

const bodyFields = {
client_id: clientId,
date: paymentDate,
invoices: [
{
invoice_id: invoiceId,
amount: invoiceAmount,
},
],
type_id: paymentType,
transaction_reference: transferReference,
private_notes: privateNotes,
};

const body = filterProvidedFields(bodyFields);

const response = await $.http.post('/v1/payments', body);

$.setActionItem({ raw: response.data.data });
},
});
3 changes: 2 additions & 1 deletion packages/backend/src/apps/invoice-ninja/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import createClient from './create-client';
import createInvoice from './create-invoice';
import createPayment from './create-payment';

export default [createClient, createInvoice];
export default [createClient, createInvoice, createPayment];
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import listClients from './list-clients';
import listInvoices from './list-invoices';

export default [listClients];
export default [listClients, listInvoices];
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';

export default {
name: 'List invoices',
key: 'listInvoices',

async run($: IGlobalVariable) {
const invoices: {
data: IJSONObject[];
} = {
data: [],
};

const params = {
sort: 'created_at|desc',
};

const {
data: { data },
} = await $.http.get('/v1/invoices', { params });

if (!data?.length) {
return;
}

for (const invoice of data) {
invoices.data.push({
value: invoice.id,
name: invoice.number,
});
}

return invoices;
},
};
2 changes: 2 additions & 0 deletions packages/docs/pages/apps/invoice-ninja/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ items:
desc: Creates a new client.
- name: Create invoice
desc: Creates a new invoice.
- name: Create payment
desc: Creates a new payment.
---

<script setup>
Expand Down

0 comments on commit e2a54e2

Please sign in to comment.