-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(invoice-ninja): add create payment action
- Loading branch information
1 parent
2159898
commit e2a54e2
Showing
6 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
packages/backend/src/apps/invoice-ninja/actions/create-payment/fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; |
42 changes: 42 additions & 0 deletions
42
packages/backend/src/apps/invoice-ninja/actions/create-payment/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
35 changes: 35 additions & 0 deletions
35
packages/backend/src/apps/invoice-ninja/dynamic-data/list-invoices/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters