Merge pull request #1339 from automatisch/AUT-328
feat(invoice-ninja): add create payment action
This commit is contained in:
@@ -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,
|
||||
},
|
||||
];
|
@@ -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 });
|
||||
},
|
||||
});
|
@@ -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];
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import listClients from './list-clients';
|
||||
import listInvoices from './list-invoices';
|
||||
|
||||
export default [listClients];
|
||||
export default [listClients, listInvoices];
|
||||
|
@@ -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;
|
||||
},
|
||||
};
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user