mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 02:09:05 +03:00
оплата через корзину
This commit is contained in:
parent
4412de2cf4
commit
cdbb0cc162
9
.babelrc
Normal file
9
.babelrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": [
|
||||
"last 5 versions"
|
||||
]
|
||||
}]
|
||||
]
|
||||
}
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
@ -1,3 +0,0 @@
|
||||
[.ShellClassInfo]
|
||||
IconFile=C:\Program Files\FolderPainter\Icons\Pack_01\04.ico
|
||||
IconIndex=0
|
||||
@ -14,16 +14,21 @@ module.exports = function(server, db, qiwiApi) {
|
||||
amount = data.amount.value;
|
||||
|
||||
if (status === 'PAID') {
|
||||
const ids = query.item_id.split('and');
|
||||
const findBill = await db.collection('buyers').findOne({bill_id: query.bill_id});
|
||||
if(findBill == null) {
|
||||
// выдаем данные и создаем покупателя
|
||||
const item = await db.collection('info').findOne({"_id": ObjectID(query.item_id)}),
|
||||
data = item.data,
|
||||
invoiceResult = data.splice(-1, 1);
|
||||
const result = [];
|
||||
//выдаем данные и создаем покупателя
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const item = await db.collection('info').findOne({"_id": ObjectID(ids[i])}),
|
||||
data = item.data;
|
||||
result.push(data.splice(-1, 1));
|
||||
|
||||
db.collection('info').updateOne({"_id": ObjectID(ids[i])}, {$set: {data: data}});
|
||||
}
|
||||
|
||||
db.collection('info').updateOne({"_id": ObjectID(query.item_id)}, {$set: {data: data}})
|
||||
db.collection('buyers').insertOne({bill_id, email, method, date, amount});
|
||||
res.send(invoiceResult);
|
||||
res.send(result);
|
||||
} else {
|
||||
res.send('Этот заказ уже был оплачен. Данные были высланы покупателю.');
|
||||
}
|
||||
@ -33,7 +38,8 @@ module.exports = function(server, db, qiwiApi) {
|
||||
res.send('Время жизни счета истекло. Счет не оплачен');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.render('main/404');
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -3,25 +3,32 @@ const ObjectID = require('mongodb').ObjectID;
|
||||
module.exports = function(server, db, qiwiApi) {
|
||||
server.put('/payment', async (req, res) => {
|
||||
// проверяем товар на его наличие
|
||||
const item = await db.collection('info').findOne({"_id": ObjectID(req.body.items[0].id)});
|
||||
if (item.data.length > 0) {
|
||||
const ids = req.body.items.map(item => item.id);
|
||||
const titles = req.body.items.map(item => item.title).join(',');
|
||||
let empty = false;
|
||||
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const item = await db.collection('info').findOne({"_id": ObjectID(req.body.items[i].id)});
|
||||
if (item.data.length === 0) empty = i;
|
||||
}
|
||||
if (empty === false) {
|
||||
const billId = qiwiApi.generateId();
|
||||
const fields = {
|
||||
amount: req.body.totalPrice,
|
||||
currency: 'RUB',
|
||||
comment: `Оплата товара "${req.body.items[0].title}" Счёт: ${billId}`,
|
||||
comment: `Оплата товара "${titles}" Счёт: ${billId}`,
|
||||
expirationDateTime: qiwiApi.getLifetimeByDay(),
|
||||
customFields: {
|
||||
themeCode: 'Sergei-YaS7mIY0CQe'
|
||||
},
|
||||
email: req.body.email,
|
||||
successUrl: `https://polar-peak-95205.herokuapp.com/success?bill_id=${billId}&item_id=${req.body.items[0].id}&payment=qiwi`
|
||||
successUrl: `https://polar-peak-95205.herokuapp.com/success?bill_id=${billId}&item_id=${ids.join('and')}&payment=qiwi`
|
||||
}
|
||||
qiwiApi.createBill(billId, fields).then((data) => {
|
||||
res.send(data);
|
||||
});
|
||||
} else {
|
||||
res.send('Товара нет в наличии.');
|
||||
res.send(`Товара "${req.body.items[empty].title}" нет в наличии`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -16,7 +16,7 @@ const methodOverride = require('method-override');
|
||||
const multer = require('multer');
|
||||
const QiwiBillPaymentsAPI = require('@qiwi/bill-payments-node-js-sdk');
|
||||
|
||||
const SECRET_KEY = 'eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6ImlsYzZ5Yy0wMCIsInVzZXJfaWQiOiI3OTMxMjc2NDY3NCIsInNlY3JldCI6ImFkZWJmMWU2NjYyMmJjZTViODE2NzE3YTU4ZmJkZDc1NTUwNzMyYWI5NGY2OTU0ZTg5NjljNjUzMGZkM2U0M2YifX0=';
|
||||
const SECRET_KEY = '/';
|
||||
const qiwiApi = new QiwiBillPaymentsAPI(SECRET_KEY);
|
||||
|
||||
MongoClient.connect(db_config.url, {useNewUrlParser: true, useUnifiedTopology: true})
|
||||
|
||||
4
dist/public/js/admin.js
vendored
4
dist/public/js/admin.js
vendored
File diff suppressed because one or more lines are too long
4
dist/public/js/main.js
vendored
4
dist/public/js/main.js
vendored
File diff suppressed because one or more lines are too long
@ -25,9 +25,6 @@
|
||||
.email-field
|
||||
label(for='email') Ваш E-mail
|
||||
input(required='' type='text' name='email')
|
||||
.phone-field
|
||||
label(for="phone") Номер QIWI
|
||||
input(required='' type='text' name='phone')
|
||||
.payment-field
|
||||
label(for='payment') Способ оплаты
|
||||
select(name='payment')
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Modal } from "../core/modal";
|
||||
import { insertCount } from "../other/counter";
|
||||
import axios from "axios";
|
||||
|
||||
export class CartModal extends Modal {
|
||||
constructor(id, open, close, {items}) {
|
||||
@ -65,7 +66,7 @@ export class CartModal extends Modal {
|
||||
this.$el.querySelector(`#${id}`).innerHTML = `${totalPrice.toFixed(2)}₽`;
|
||||
}
|
||||
|
||||
makePay(e) {
|
||||
async makePay(e) {
|
||||
e.preventDefault();
|
||||
const payInfo = {items: this.items.cart.map(item => {
|
||||
return {
|
||||
@ -78,10 +79,10 @@ export class CartModal extends Modal {
|
||||
payInfo.items.forEach(item => totalPrice += parseFloat(item.price));
|
||||
payInfo.totalPrice = Math.round(totalPrice * 100) / 100;
|
||||
payInfo.payMethod = this.$el.querySelector('.payment-field input').value;
|
||||
payInfo.phone = this.$el.querySelector('.phone-field input').value;
|
||||
payInfo.email = this.$el.querySelector('.email-field input').value;
|
||||
|
||||
console.log('Pay info:', payInfo);
|
||||
const response = await axios.put('/payment', payInfo);
|
||||
response.data.payUrl ? document.location.href = response.data.payUrl : alert(response.data);
|
||||
}
|
||||
|
||||
defaultBtnColor(id) {
|
||||
|
||||
@ -40,6 +40,7 @@ export class PayModal extends Modal {
|
||||
}
|
||||
payInfo.payMethod = this.$el.querySelector('.payment-field input').value;
|
||||
payInfo.email = this.$el.querySelector('.email-field input').value;
|
||||
|
||||
const response = await axios.put('/payment', payInfo);
|
||||
response.data.payUrl ? document.location.href = response.data.payUrl : alert(response.data);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user