feat(xero): add new payments trigger

This commit is contained in:
Rıdvan Akca
2023-11-09 11:56:48 +03:00
parent 6ea7400ff4
commit 3593cf3808
5 changed files with 123 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import newBankTransactions from './new-bank-transactions'; import newBankTransactions from './new-bank-transactions';
import newPayments from './new-payments';
export default [newBankTransactions]; export default [newBankTransactions, newPayments];

View 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);
},
});

View File

@@ -453,6 +453,15 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/wordpress/connection' }, { 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', text: 'Youtube',
collapsible: true, collapsible: true,

View File

@@ -3,6 +3,8 @@ favicon: /favicons/xero.svg
items: items:
- name: New bank transactions - name: New bank transactions
desc: Triggers when a new bank transaction occurs. desc: Triggers when a new bank transaction occurs.
- name: New payments
desc: Triggers when a new payment is received.
--- ---
<script setup> <script setup>

View File

@@ -48,5 +48,6 @@ The following integrations are currently supported by Automatisch.
- [Typeform](/apps/typeform/triggers) - [Typeform](/apps/typeform/triggers)
- [Webhooks](/apps/webhooks/triggers) - [Webhooks](/apps/webhooks/triggers)
- [WordPress](/apps/wordpress/triggers) - [WordPress](/apps/wordpress/triggers)
- [Xero](/apps/xero/triggers)
- [Youtube](/apps/youtube/triggers) - [Youtube](/apps/youtube/triggers)
- [Zendesk](/apps/zendesk/actions) - [Zendesk](/apps/zendesk/actions)