Skip to content

Commit

Permalink
[email protected]'s change on OpenFn.org
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Dec 17, 2019
1 parent ecd382a commit 9b8951c
Showing 1 changed file with 81 additions and 83 deletions.
164 changes: 81 additions & 83 deletions jobs/02b-initiate-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 8,90 @@
// iterating through the array of registrants and making a separate request
// for each one ==============================================================
each(
state.response.body[0], (index, value) => {
console.log(value)
post(
`${state.configuration.mifosUrl}/channel/transactions`,
{
authentication: state.configuration.mifosAuth,
headers: {
'content-type': 'application/json',
'X-Tenant-Identifier': 'tn03',
},
// Can we send an array of payments to make in a single request?
// body: state.data.registrants.map(r => {
// console.log(`Initiating payment for ${r.name}.`);
// return {
// payer: { msisdn: state.configuration.mifosAcct },
// payee: { msisdn: r.phone },
// amount: r.amount,
// };
// }),
body: state => {
return {
payer: {
partyIdInfo: {
partyIdType: 'MSISDN',
partyIdentifier: '27710203999',
},
},
payee: {
partyIdInfo: {
partyIdType: 'MSISDN',
partyIdentifier: state.data.msisdn,
},
},
amountType: 'SEND',
transactionType: {
scenario: 'PAYMENT',
initiator: 'PAYER',
initiatorType: 'CONSUMER',
},
amount: {
currency: 'USD',
amount: state.data.salary / 52,
},
};
},
state.response.body[0],
post(
`${state.configuration.mifosUrl}/channel/transactions`,
{
authentication: state.configuration.mifosAuth,
headers: {
'content-type': 'application/json',
'X-Tenant-Identifier': 'tn03',
},
state => {
const today=new Date();
console.log(JSON.stringify(state.response.body));
state.data.person_payments = {
'form[person_payments][0][0][fields][id]': 'person_payments|0',
'form[person_payments][0][0][fields][parent]': 'person|' state.data.person_id,
'form[person_payments][0][0][fields][date][day]': today.getDate(),
'form[person_payments][0][0][fields][date][month]': today.getMonth() 1,
'form[person_payments][0][0][fields][date][year]': today.getFullYear(),
'form[person_payments][0][0][fields][amount]': state => {
return state.data.salary / 52;
},
'form[person_payments][0][0][fields][status]': state => {
if (state.data.success === true) {
return 'initiated';
}
return 'failed';
// Can we send an array of payments to make in a single request?
// body: state.data.registrants.map(r => {
// console.log(`Initiating payment for ${r.name}.`);
// return {
// payer: { msisdn: state.configuration.mifosAcct },
// payee: { msisdn: r.phone },
// amount: r.amount,
// };
// }),
body: state => {
return {
payer: {
partyIdInfo: {
partyIdType: 'MSISDN',
partyIdentifier: '27710203999',
},
},
};
console.log(state.data.person_payments)
// =====================================================================
// Create "initiated" payments in iHRIS with their mifos external IDs ==
post(state.configuration.ihrisUrl '/manage/person_payments', {
authentication: state.configuration.ihrisAuth,
formData: state => {
state.data.person_payments.submit_type = 'confirm';
return state.data.person_payments;
payee: {
partyIdInfo: {
partyIdType: 'MSISDN',
partyIdentifier: state.data.msisdn,
},
},
});
post(state.configuration.ihrisUrl '/manage/person_payments', {
authentication: state.configuration.ihrisAuth,
formData: state => {
state.data.person_payments.submit_type = 'save';
return state.data.person_payments;
amountType: 'SEND',
transactionType: {
scenario: 'PAYMENT',
initiator: 'PAYER',
initiatorType: 'CONSUMER',
},
options: {
successCodes: [302],
amount: {
currency: 'USD',
amount: state.data.salary / 52,
},
});
}
)
}
};
},
},
state => {
const today=new Date();
console.log(JSON.stringify(state.response.body));
state.data.person_payments = {
'form[person_payments][0][0][fields][id]': 'person_payments|0',
'form[person_payments][0][0][fields][parent]': 'person|' state.data.person_id,
'form[person_payments][0][0][fields][date][day]': today.getDate(),
'form[person_payments][0][0][fields][date][month]': today.getMonth() 1,
'form[person_payments][0][0][fields][date][year]': today.getFullYear(),
'form[person_payments][0][0][fields][amount]': state => {
return state.data.salary / 52;
},
'form[person_payments][0][0][fields][status]': state => {
if (state.data.success === true) {
return 'initiated';
}
return 'failed';
},
};
console.log(state.data.person_payments)
// =====================================================================
// Create "initiated" payments in iHRIS with their mifos external IDs ==
post(state.configuration.ihrisUrl '/manage/person_payments', {
authentication: state.configuration.ihrisAuth,
formData: state => {
state.data.person_payments.submit_type = 'confirm';
return state.data.person_payments;
},
});
post(state.configuration.ihrisUrl '/manage/person_payments', {
authentication: state.configuration.ihrisAuth,
formData: state => {
state.data.person_payments.submit_type = 'save';
return state.data.person_payments;
},
options: {
successCodes: [302],
},
});
}
)
);

0 comments on commit 9b8951c

Please sign in to comment.