Skip to content

Commit

Permalink
Split out some specific events from the firehose events trigger so th…
Browse files Browse the repository at this point in the history
…ey can be defined better and easier to use.

payer-created
payer-updated
realtime-payment
scheduled-process
  • Loading branch information
dkarzon committed Jan 12, 2024
1 parent 0c5b2c2 commit 5231d8d
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 16 deletions.
6 changes: 3 additions & 3 deletions creates/payment_create_realtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const { BASE_URL } = require('../constants');
const { PaymentSample, PaymentOutputFields } = require('../samples/payment');
const { paymentSample, singlePaymentOutputFields } = require('../samples/sample_payment');

const createPayment = (z, bundle) => {
const options = {
Expand Down Expand Up @@ -125,8 +125,8 @@ module.exports = {
altersDynamicFields: false,
},
],
sample: PaymentSample,
outputFields: PaymentOutputFields,
sample: paymentSample,
outputFields: singlePaymentOutputFields,
},
key: 'payment_create_realtime',
noun: 'Payment',
Expand Down
6 changes: 3 additions & 3 deletions creates/payment_create_scheduled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const { BASE_URL } = require('../constants');
const { PaymentSample, PaymentOutputFields } = require('../samples/payment');
const { paymentSample, singlePaymentOutputFields } = require('../samples/sample_payment');


const createPayment = (z, bundle) => {
Expand Down Expand Up @@ -73,8 +73,8 @@ module.exports = {
altersDynamicFields: false,
},
],
sample: PaymentSample,
outputFields: PaymentOutputFields,
sample: paymentSample,
outputFields: singlePaymentOutputFields,
},
key: 'payment_create_scheduled',
noun: 'Payment',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinch-payments",
"version": "1.0.4",
"version": "1.1.0",
"description": "Pinch is a PCI Compliant, Australian payments platform offering automated Bank Account Direct Debit and Credit Card payments for standard and repeating invoices or standalone transactions.",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions samples/sample_payer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
id: "pyr_XXXXXXXXXXXXXX",
firstName: "John",
lastName: "Smith",
emailAddress: "[email protected]",
mobileNumber: null,
streetAddress: null,
suburb: null,
postcode: null,
state: null,
country: null,
companyName: null,
metadata: ""
}
47 changes: 38 additions & 9 deletions samples/payment.js → samples/sample_payment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const PaymentSample = {
const paymentSample = {
id: 'pmt_XXXXXXXXXXXXXX',
attemptId: 'att_XXXXXXXX',
amount: 1000,
Expand Down Expand Up @@ -29,7 +29,11 @@ const PaymentSample = {
companyRegistrationNumber: null,
metadata: null,
},
subscription: null,
subscription: {
id: "sub_XXXXXXXXXXXXXX",
planId: "pln_XXXXXXXXXXXXXX",
planName: "Monthly Payments"
},
attempts: [
{
id: 'att_XXXXXXXX',
Expand Down Expand Up @@ -77,8 +81,7 @@ const PaymentSample = {
metadata: null,
};


const PaymentOutputFields = [
const corePaymentOutputFields = [
{ key: 'id', type: 'string' },
{ key: 'attemptId', type: 'string' },
{ key: 'amount', type: 'integer' },
Expand All @@ -105,7 +108,14 @@ const PaymentOutputFields = [
{ key: 'payer__companyName', type: 'string' },
{ key: 'payer__companyRegistrationNumber', type: 'string' },
{ key: 'payer__metadata', dict: true },
{ key: 'subscription' },
{ key: 'subscription__id', type: 'string' },
{ key: 'subscription__planId', type: 'string' },
{ key: 'subscription__planName', type: 'string' },
{ key: 'metadata', dict: true },
];

const singlePaymentOutputFields = [
...corePaymentOutputFields,
{ key: 'attempts[]id', type: 'string' },
{ key: 'attempts[]amount', type: 'integer' },
{ key: 'attempts[]currency', type: 'string' },
Expand Down Expand Up @@ -141,11 +151,30 @@ const PaymentOutputFields = [
{ key: 'attempts[]fees__convertedTotalFee', type: 'number' },
{ key: 'attempts[]fees__convertedCurrency', type: 'string' },
{ key: 'attempts[]fees__conversionRate', type: 'number' },
{ key: 'attempts[]status' },
{ key: 'metadata', dict: true },
{ key: 'attempts[]status' }
];

const eventSinglePaymentOutputFields = () => {
var eventPaymentOutputs = [];
corePaymentOutputFields.forEach(field => {
var fieldClone = structuredClone(field);
fieldClone.key = 'data__payment__' + fieldClone.key;
eventPaymentOutputs.push(fieldClone);
});
};

const eventProcessedPaymentsOutputFields = () => {
var eventPaymentOutputs = [];
corePaymentOutputFields.forEach(field => {
var fieldClone = structuredClone(field);
fieldClone.key = 'data__payments[]' + fieldClone.key;
eventPaymentOutputs.push(fieldClone);
});
};

module.exports = {
PaymentSample,
PaymentOutputFields
paymentSample,
singlePaymentOutputFields,
eventSinglePaymentOutputFields,
eventProcessedPaymentsOutputFields
};
54 changes: 54 additions & 0 deletions triggers/evt_payer_created.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { BASE_URL } = require('../constants');
const samplePayer = require('../samples/sample_issue');

const perform = (z, bundle) => {
const options = {
url: `${BASE_URL}/${bundle.authData.environment}/events`,
method: 'GET',
headers: { },
params: {
page: bundle.meta.page + 1,
eventType: 'payer-created',
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.data;
return results.data;
});
};

module.exports = {
operation: {
perform: perform,
canPaginate: true,
inputFields: [],
sample: {
id: 'evt_XXXXXXXXXXXXXX',
type: 'payer-created',
eventDate: '2024-01-01T01:01:00Z',
metadata: { payerName: "John Smith" },
data: {
payer: samplePayer
}
},
outputFields: [
{ key: 'id', type: 'string' },
{ key: 'type', type: 'string' },
{ key: 'eventDate', type: 'datetime' },
{ key: 'metadata', dict: true },
{ key: 'data__payer__id', type: 'string' },
{ key: 'data__payer__firstName', type: 'string' },
{ key: 'data__payer__lastName', type: 'string' },
{ key: 'data__payer__emailAddress', type: 'string' },
{ key: 'data__payer__companyName', type: 'string' }
],
},
key: 'evt_payer_created',
noun: 'Event',
display: {
label: 'Payer Created Event',
description: 'Triggers when a Payer is created.'
},
};
54 changes: 54 additions & 0 deletions triggers/evt_payer_updated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { BASE_URL } = require('../constants');
const samplePayer = require('../samples/sample_issue');

const perform = (z, bundle) => {
const options = {
url: `${BASE_URL}/${bundle.authData.environment}/events`,
method: 'GET',
headers: { },
params: {
page: bundle.meta.page + 1,
eventType: 'payer-updated',
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.data;
return results.data;
});
};

module.exports = {
operation: {
perform: perform,
canPaginate: true,
inputFields: [],
sample: {
id: 'evt_XXXXXXXXXXXXXX',
type: 'payer-updated',
eventDate: '2024-01-01T01:01:00Z',
metadata: { payerName: "John Smith" },
data: {
payer: samplePayer
}
},
outputFields: [
{ key: 'id', type: 'string' },
{ key: 'type', type: 'string' },
{ key: 'eventDate', type: 'datetime' },
{ key: 'metadata', dict: true },
{ key: 'data__payer__id', type: 'string' },
{ key: 'data__payer__firstName', type: 'string' },
{ key: 'data__payer__lastName', type: 'string' },
{ key: 'data__payer__emailAddress', type: 'string' },
{ key: 'data__payer__companyName', type: 'string' }
],
},
key: 'evt_payer_updated',
noun: 'Event',
display: {
label: 'Payer Updated Event',
description: 'Triggers when a Payer is updated.'
},
};
47 changes: 47 additions & 0 deletions triggers/evt_realtime_payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { BASE_URL } = require('../constants');
const { PaymentSample, eventSinglePaymentOutputFields } = require('../samples/sample_payment');

const perform = (z, bundle) => {
const options = {
url: `${BASE_URL}/${bundle.authData.environment}/events`,
method: 'GET',
headers: { },
params: {
page: bundle.meta.page + 1,
eventType: 'realtime-payment',
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.data;
return results.data;
});
};

module.exports = {
operation: {
perform: perform,
canPaginate: true,
inputFields: [],
sample: {
id: 'evt_XXXXXXXXXXXXXX',
type: 'realtime-payment',
eventDate: '2024-01-01T01:01:00Z',
metadata: {
status: "approved",
amount: 1000
},
data: {
payment: PaymentSample
}
},
outputFields: eventSinglePaymentOutputFields(),
},
key: 'evt_realtime_payment',
noun: 'Event',
display: {
label: 'Realtime Payment Event',
description: 'Triggers when a realtime Payment occurs.'
},
};
49 changes: 49 additions & 0 deletions triggers/evt_scheduled_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { BASE_URL } = require('../constants');
const { paymentSample, eventProcessedPaymentsOutputFields } = require('../samples/sample_payment');

const perform = (z, bundle) => {
const options = {
url: `${BASE_URL}/${bundle.authData.environment}/events`,
method: 'GET',
headers: { },
params: {
page: bundle.meta.page + 1,
eventType: 'scheduled-process',
},
};

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.data;
return results.data;
});
};

module.exports = {
operation: {
perform: perform,
canPaginate: true,
inputFields: [],
sample: {
id: 'evt_XXXXXXXXXXXXXX',
type: 'scheduled-process',
eventDate: '2024-01-01T01:01:00Z',
metadata: {
status: "approved",
amount: 1000
},
data: {
payments: [
paymentSample
]
}
},
outputFields: eventProcessedPaymentsOutputFields,
},
key: 'evt_scheduled_process',
noun: 'Event',
display: {
label: 'Scheduled Process Event',
description: 'Triggers when a Scheduled Payments are processed.'
},
};

0 comments on commit 5231d8d

Please sign in to comment.