Skip to content

Commit

Permalink
upgraded node-dominos-pizza-api, which required nodejs upgrade. also …
Browse files Browse the repository at this point in the history
…updated tooling
  • Loading branch information
rkoval committed Apr 24, 2022
1 parent 8440ba5 commit 61bba77
Show file tree
Hide file tree
Showing 14 changed files with 6,229 additions and 4,558 deletions.
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
bower_components
**/node_modules
__snapshots__/
35 changes: 35 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parser": "@babel/eslint-parser",
parserOptions: {
requireConfigFile: false,
sourceType: "module",
ecmaFeatures: {
globalReturn: false,
},
},
"extends": "eslint:recommended",
"globals": {},
"env": {
"node": true,
"es6": true
},
"plugins": [],
"rules": {
"strict": 0,
"curly": [2, "multi-line", "consistent"],
"no-multi-assign": 2,
"no-debugger": 1, // disallow use of debugger
"no-unused-vars": [1, { "args": "none", "varsIgnorePattern": "^(Promise|_)$" }],
"no-control-regex": 0,
"no-use-before-define": ["error", {"functions": false, classes: false, "variables": true}],
"prefer-promise-reject-errors": 2,
"no-undef": 2,
"no-mixed-spaces-and-tabs": 0, // disallow mixed spaces and tabs for indentation
"no-console": 0, // disallow use of console (off by default in the node environment)
"comma-dangle": 0,
"object-shorthand": [1, "properties"],
"prefer-template": 1,
"array-callback-return": 2, // https://eslint.org/docs/2.0.0/rules/array-callback-return
"prefer-const": 2,
}
}
8 changes: 0 additions & 8 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v9.1.0
v18.0.0
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
dist
data.json
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": false,
"jsxBracketSameLine": false,
"semi": true,
"requirePragma": false,
"arrowParens": "always",
"overrides": [
{
"files": ["*.js", "*.jsx", "*.svg"],
"options": {
"parser": "babel"
}
},
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:9.1.0-wheezy
FROM node:18.0.0-bullseye

EXPOSE 3003
WORKDIR /opt/ryankoval.pizza
Expand Down
23 changes: 12 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const serveStatic = require('serve-static');
const logger = require('morgan');
const bodyParser = require('body-parser');
const compression = require('compression');
const routes = require('./routes');
import express from 'express';
import path from 'path';
import favicon from 'serve-favicon';
import serveStatic from 'serve-static';
import logger from 'morgan';
import bodyParser from 'body-parser';
import compression from 'compression';
import routes from './routes.js';
import {fileURLToPath} from 'url';

const app = express();
const root = path.join(__dirname, '..');
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');

app.set('port', process.env.PORT || 3003);
app.set('view engine', 'jade');
Expand All @@ -26,7 +27,7 @@ setupStatic('bower_components', 'confetti.js');
setupStatic('bower_components', 'lodash', 'dist');

app.use(logger('combined'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({extended: true}));
app.use(compression());

const isDev = process.env.NODE_ENV !== 'production';
Expand All @@ -44,7 +45,7 @@ app.listen(port, function () {
app.use(function clientErrorHandler(err, req, res, next) {
console.error(err);
const locals = {
error: 'Uh oh! Something went unexpectedly wrong. I guess that means no pizza ... 😞'
error: 'Uh oh! Something went unexpectedly wrong. I guess that means no pizza ... 😞',
};
res.status(500).render('index', locals);
});
98 changes: 52 additions & 46 deletions lib/paymentService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const config = require('config');
const paypal = require('paypal-rest-sdk');
const request = require('request');
const { _ } = require('lodash');
import config from 'config';
import paypal from 'paypal-rest-sdk';

const paypalConfig = config.get('paypal');
const PAYPAL_APP_ID = paypalConfig.get('clientId');
Expand All @@ -18,78 +16,86 @@ if (isDev) {
}

paypal.configure({
'mode': paypalMode,
'client_id': PAYPAL_APP_ID,
'client_secret': PAYPAL_APP_SECRET
mode: paypalMode,
client_id: PAYPAL_APP_ID,
client_secret: PAYPAL_APP_SECRET,
});

const redirectHost = paypalConfig.get('redirectHost');

const createPaymentJson = (amount) => {
return {
"intent": "authorize",
"payer": {
"payment_method": "paypal"
intent: 'authorize',
payer: {
payment_method: 'paypal',
},
"redirect_urls": {
"return_url": `${redirectHost}/authorized?approved=true`,
"cancel_url": `${redirectHost}/authorized?approved=false`
redirect_urls: {
return_url: `${redirectHost}/authorized?approved=true`,
cancel_url: `${redirectHost}/authorized?approved=false`,
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": amount,
"currency": "USD",
"quantity": 1
}]
transactions: [
{
item_list: {
items: [
{
name: 'item',
sku: 'item',
price: amount,
currency: 'USD',
quantity: 1,
},
],
},
amount: {
currency: 'USD',
total: amount,
},
description: '4 my pizza dood! plz accept & thx',
},
"amount": {
"currency": "USD",
"total": amount
},
"description": "4 my pizza dood! plz accept & thx"
}]
],
};
};

const createPayment = (amount) => {
return new Promise((resolve, reject) => {
if (!amount) {
reject(new Error('amount was undefined!'))
reject(new Error('amount was undefined!'));
} else {
paypal.payment.create(createPaymentJson('' + amount), function (error, payment) {
paypal.payment.create(createPaymentJson(`${amount}`), function (error, payment) {
if (error) {
reject(error);
} else {
console.log("payment created");
resolve(payment)
console.log('payment created');
resolve(payment);
}
});
}
});
};

const executePayment = ({ paymentId, PayerID }) => {
const executePayment = ({paymentId, PayerID}) => {
return (info) => {
return new Promise((resolve, reject) => {
paypal.payment.execute(paymentId, {
payer_id: PayerID
}, (error, response) => {
if (error) {
reject(error);
} else {
info.payment = response;
console.log("payment executed!", info)
resolve(info);
paypal.payment.execute(
paymentId,
{
payer_id: PayerID,
},
(error, response) => {
if (error) {
reject(error);
} else {
info.payment = response;
console.log('payment executed!', info);
resolve(info);
}
}
});
);
});
}
};
};

module.exports = {
export default {
createPayment,
executePayment
executePayment,
};
Loading

0 comments on commit 61bba77

Please sign in to comment.