Merge pull request #1421 from automatisch/AUT-392
feat(xero): add new payments trigger
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import newBankTransactions from './new-bank-transactions';
|
||||
import newPayments from './new-payments';
|
||||
|
||||
export default [newBankTransactions];
|
||||
export default [newBankTransactions, newPayments];
|
||||
|
109
packages/backend/src/apps/xero/triggers/new-payments/index.ts
Normal file
109
packages/backend/src/apps/xero/triggers/new-payments/index.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
|
||||
type Params = {
|
||||
page: number;
|
||||
order: string;
|
||||
where?: string;
|
||||
};
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New payments',
|
||||
key: 'newPayments',
|
||||
pollInterval: 15,
|
||||
description: 'Triggers when a new payment is received.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Organization',
|
||||
key: 'organizationId',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listOrganizations',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Payment Type',
|
||||
key: 'paymentType',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
value: '',
|
||||
options: [
|
||||
{ label: 'Accounts Receivable', value: 'ACCRECPAYMENT' },
|
||||
{ label: 'Accounts Payable', value: 'ACCPAYPAYMENT' },
|
||||
{
|
||||
label: 'Accounts Receivable Credit (Refund)',
|
||||
value: 'ARCREDITPAYMENT',
|
||||
},
|
||||
{
|
||||
label: 'Accounts Payable Credit (Refund)',
|
||||
value: 'APCREDITPAYMENT',
|
||||
},
|
||||
{
|
||||
label: 'Accounts Receivable Overpayment (Refund)',
|
||||
value: 'AROVERPAYMENTPAYMENT',
|
||||
},
|
||||
{
|
||||
label: 'Accounts Receivable Prepayment (Refund)',
|
||||
value: 'ARPREPAYMENTPAYMENT',
|
||||
},
|
||||
{
|
||||
label: 'Accounts Payable Prepayment (Refund)',
|
||||
value: 'APPREPAYMENTPAYMENT',
|
||||
},
|
||||
{
|
||||
label: 'Accounts Payable Overpayment (Refund)',
|
||||
value: 'APOVERPAYMENTPAYMENT',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const paymentType = $.step.parameters.paymentType;
|
||||
|
||||
const params: Params = {
|
||||
page: 1,
|
||||
order: 'Date DESC',
|
||||
};
|
||||
|
||||
if (paymentType) {
|
||||
params.where = `PaymentType="${paymentType}"`;
|
||||
}
|
||||
|
||||
let nextPage = false;
|
||||
do {
|
||||
const { data } = await $.http.get('/api.xro/2.0/Payments', {
|
||||
params,
|
||||
});
|
||||
params.page = params.page + 1;
|
||||
|
||||
if (data.Payments?.length) {
|
||||
for (const payment of data.Payments) {
|
||||
$.pushTriggerItem({
|
||||
raw: payment,
|
||||
meta: {
|
||||
internalId: payment.PaymentID,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (data.Payments?.length === 100) {
|
||||
nextPage = true;
|
||||
} else {
|
||||
nextPage = false;
|
||||
}
|
||||
} while (nextPage);
|
||||
},
|
||||
});
|
@@ -453,6 +453,15 @@ export default defineConfig({
|
||||
{ text: 'Connection', link: '/apps/wordpress/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Xero',
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/xero/triggers' },
|
||||
{ text: 'Connection', link: '/apps/xero/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Youtube',
|
||||
collapsible: true,
|
||||
|
@@ -3,6 +3,8 @@ favicon: /favicons/xero.svg
|
||||
items:
|
||||
- name: New bank transactions
|
||||
desc: Triggers when a new bank transaction occurs.
|
||||
- name: New payments
|
||||
desc: Triggers when a new payment is received.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
|
@@ -48,5 +48,6 @@ The following integrations are currently supported by Automatisch.
|
||||
- [Typeform](/apps/typeform/triggers)
|
||||
- [Webhooks](/apps/webhooks/triggers)
|
||||
- [WordPress](/apps/wordpress/triggers)
|
||||
- [Xero](/apps/xero/triggers)
|
||||
- [Youtube](/apps/youtube/triggers)
|
||||
- [Zendesk](/apps/zendesk/actions)
|
||||
|
Reference in New Issue
Block a user