Skip to content

Commit

Permalink
chore: move constants outside of function
Browse files Browse the repository at this point in the history
  • Loading branch information
nhsz committed Apr 16, 2020
1 parent 336a20c commit ec93e4d
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions api/payments.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
const fetch = require('node-fetch');

const { MP_ACCESS_TOKEN, MP_BASE_URL, IMG_URL } = process.env;
const PAY_WITH_CARD = [{ id: 'ticket' }, { id: 'atm' }];
const PAY_WITH_MP = [...PAY_WITH_CARD, { id: 'debit_card' }, { id: 'credit_card' }];
const US_URL = 'https://undefinedschool.io';
const BACK_URLS = {
success: US_URL,
failure: US_URL,
pending: US_URL
};

function generatePreference({ id, title, unit_price }, paymentType) {
const PAY_WITH_CARD = [{ id: 'ticket' }, { id: 'atm' }];
const PAY_WITH_MP = [...PAY_WITH_CARD, { id: 'debit_card' }, { id: 'credit_card' }];
const US_URL = 'https://undefinedschool.io';

return {
items: [
{
id,
currency_id: 'ARS',
title,
unit_price,
quantity: 1,
picture_url: IMG_URL
}
],
back_urls: {
success: US_URL,
failure: US_URL,
pending: US_URL
},
auto_return: 'approved',
payment_methods: {
excluded_payment_types: paymentType === 'card' ? PAY_WITH_CARD : PAY_WITH_MP,
installments: 1,
default_installments: 1
const generatePreference = ({ id, title, unit_price }, paymentType) => ({
items: [
{
id,
currency_id: 'ARS',
title,
unit_price,
quantity: 1,
picture_url: IMG_URL
}
};
}
],
back_urls: BACK_URLS,
auto_return: 'approved',
payment_methods: {
excluded_payment_types: paymentType === 'card' ? PAY_WITH_CARD : PAY_WITH_MP,
installments: 1,
default_installments: 1
}
});

function generatePayment(data, paymentType) {
const preference = generatePreference(data, paymentType);
Expand Down

0 comments on commit ec93e4d

Please sign in to comment.