@ozdao/prometheus-framework 0.2.40 → 0.2.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. package/dist/events.server.js +9 -0
  2. package/dist/events.server.mjs +9 -0
  3. package/dist/files.server.js +4 -1
  4. package/dist/files.server.mjs +4 -1
  5. package/dist/prometheus-framework/src/components/Button/Button.vue.cjs +1 -1
  6. package/dist/prometheus-framework/src/components/Button/Button.vue.js +2 -225
  7. package/dist/prometheus-framework/src/components/Button/Button.vue2.cjs +1 -1
  8. package/dist/prometheus-framework/src/components/Button/Button.vue2.js +225 -2
  9. package/dist/prometheus-framework/src/components/Checkbox/Checkbox.vue.cjs +1 -1
  10. package/dist/prometheus-framework/src/components/Checkbox/Checkbox.vue.js +2 -61
  11. package/dist/prometheus-framework/src/components/Checkbox/Checkbox.vue2.cjs +1 -1
  12. package/dist/prometheus-framework/src/components/Checkbox/Checkbox.vue2.js +61 -2
  13. package/dist/prometheus-framework/src/components/Countdown/Countdown.vue.cjs +1 -1
  14. package/dist/prometheus-framework/src/components/Countdown/Countdown.vue.js +26 -28
  15. package/dist/prometheus-framework/src/components/Field/Field.vue.cjs +1 -1
  16. package/dist/prometheus-framework/src/components/Field/Field.vue.js +2 -76
  17. package/dist/prometheus-framework/src/components/Field/Field.vue2.cjs +1 -1
  18. package/dist/prometheus-framework/src/components/Field/Field.vue2.js +76 -2
  19. package/dist/prometheus-framework/src/components/Popup/Popup.vue.cjs +1 -1
  20. package/dist/prometheus-framework/src/components/Popup/Popup.vue.js +2 -70
  21. package/dist/prometheus-framework/src/components/Popup/Popup.vue2.cjs +1 -1
  22. package/dist/prometheus-framework/src/components/Popup/Popup.vue2.js +70 -2
  23. package/dist/prometheus-framework/src/components/Select/Select.vue.cjs +1 -1
  24. package/dist/prometheus-framework/src/components/Select/Select.vue.js +2 -95
  25. package/dist/prometheus-framework/src/components/Select/Select.vue2.cjs +1 -1
  26. package/dist/prometheus-framework/src/components/Select/Select.vue2.js +95 -2
  27. package/dist/prometheus-framework/src/components/Tab/Tab.vue.cjs +1 -1
  28. package/dist/prometheus-framework/src/components/Tab/Tab.vue.js +2 -44
  29. package/dist/prometheus-framework/src/components/Tab/Tab.vue2.cjs +1 -1
  30. package/dist/prometheus-framework/src/components/Tab/Tab.vue2.js +44 -2
  31. package/dist/prometheus-framework/src/modules/auth/components/layouts/Auth.vue.cjs +1 -1
  32. package/dist/prometheus-framework/src/modules/auth/components/layouts/Auth.vue.js +3 -3
  33. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.cjs +1 -1
  34. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.js +1 -1
  35. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterPassword.vue.cjs +1 -1
  36. package/dist/prometheus-framework/src/modules/auth/components/pages/EnterPassword.vue.js +3 -3
  37. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.cjs +1 -1
  38. package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.js +3 -3
  39. package/dist/prometheus-framework/src/modules/auth/components/pages/ResetPassword.vue.cjs +1 -1
  40. package/dist/prometheus-framework/src/modules/auth/components/pages/ResetPassword.vue.js +3 -3
  41. package/dist/prometheus-framework/src/modules/auth/components/pages/SignIn.vue.cjs +1 -1
  42. package/dist/prometheus-framework/src/modules/auth/components/pages/SignIn.vue.js +3 -3
  43. package/dist/prometheus-framework/src/modules/auth/components/pages/SignUp.vue.cjs +1 -1
  44. package/dist/prometheus-framework/src/modules/auth/components/pages/SignUp.vue.js +3 -3
  45. package/dist/prometheus-framework/src/modules/community/components/layouts/Community.vue.cjs +1 -1
  46. package/dist/prometheus-framework/src/modules/community/components/layouts/Community.vue.js +3 -3
  47. package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.cjs +1 -1
  48. package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.js +24 -23
  49. package/dist/prometheus-framework/src/modules/constructor/components/elements/Embed.vue.cjs +1 -1
  50. package/dist/prometheus-framework/src/modules/constructor/components/elements/Embed.vue.js +1 -1
  51. package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue.cjs +1 -5
  52. package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue.js +2 -65
  53. package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue2.cjs +5 -1
  54. package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue2.js +65 -2
  55. package/dist/prometheus-framework/src/modules/constructor/components/sections/Constructor.vue.cjs +1 -1
  56. package/dist/prometheus-framework/src/modules/constructor/components/sections/Constructor.vue.js +2 -2
  57. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonJoin.vue.cjs +1 -1
  58. package/dist/prometheus-framework/src/modules/events/components/elements/ButtonJoin.vue.js +1 -1
  59. package/dist/prometheus-framework/src/modules/events/components/layouts/layoutEvents.vue.cjs +1 -1
  60. package/dist/prometheus-framework/src/modules/events/components/layouts/layoutEvents.vue.js +1 -1
  61. package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.cjs +1 -1
  62. package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.js +125 -81
  63. package/dist/prometheus-framework/src/modules/events/components/pages/Event.vue.cjs +3 -3
  64. package/dist/prometheus-framework/src/modules/events/components/pages/Event.vue.js +65 -56
  65. package/dist/prometheus-framework/src/modules/events/components/pages/Events.vue.cjs +1 -1
  66. package/dist/prometheus-framework/src/modules/events/components/pages/Events.vue.js +3 -3
  67. package/dist/prometheus-framework/src/modules/events/components/sections/HeroEvent.vue.cjs +1 -1
  68. package/dist/prometheus-framework/src/modules/events/components/sections/HeroEvent.vue.js +67 -53
  69. package/dist/prometheus-framework/src/modules/events/components/sections/SectionMainGuest.vue.cjs +2 -2
  70. package/dist/prometheus-framework/src/modules/events/components/sections/SectionMainGuest.vue.js +48 -37
  71. package/dist/prometheus-framework/src/modules/events/components/sections/SectionPreviousEvents.vue.cjs +1 -1
  72. package/dist/prometheus-framework/src/modules/events/components/sections/SectionPreviousEvents.vue.js +71 -57
  73. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
  74. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.js +3 -3
  75. package/dist/prometheus-framework/src/modules/gallery/components/sections/GalleryWithCategories.vue.cjs +1 -1
  76. package/dist/prometheus-framework/src/modules/gallery/components/sections/GalleryWithCategories.vue.js +3 -3
  77. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.cjs +1 -1
  78. package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.js +1 -1
  79. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.cjs +1 -1
  80. package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.js +2 -2
  81. package/dist/prometheus-framework/src/modules/orders/components/pages/EditOrder.vue.cjs +1 -1
  82. package/dist/prometheus-framework/src/modules/orders/components/pages/EditOrder.vue.js +1 -1
  83. package/dist/prometheus-framework/src/modules/orders/components/pages/Orders.vue.cjs +1 -1
  84. package/dist/prometheus-framework/src/modules/orders/components/pages/Orders.vue.js +1 -1
  85. package/dist/prometheus-framework/src/modules/orders/components/sections/FormOrderDetails.vue.cjs +1 -1
  86. package/dist/prometheus-framework/src/modules/orders/components/sections/FormOrderDetails.vue.js +2 -2
  87. package/dist/prometheus-framework/src/modules/orders/store/shopcart.cjs +1 -1
  88. package/dist/prometheus-framework/src/modules/orders/store/shopcart.js +20 -11
  89. package/dist/prometheus-framework/src/modules/organizations/components/blocks/DepartmentMemberModify.vue.cjs +1 -1
  90. package/dist/prometheus-framework/src/modules/organizations/components/blocks/DepartmentMemberModify.vue.js +2 -2
  91. package/dist/prometheus-framework/src/modules/organizations/components/elements/ButtonToggleMembership.vue.cjs +1 -1
  92. package/dist/prometheus-framework/src/modules/organizations/components/elements/ButtonToggleMembership.vue.js +1 -1
  93. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.cjs +1 -1
  94. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.js +6 -6
  95. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.cjs +1 -1
  96. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.js +1 -1
  97. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
  98. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.js +5 -5
  99. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organizations.vue.cjs +1 -1
  100. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organizations.vue.js +1 -1
  101. package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.cjs +1 -1
  102. package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.js +3 -3
  103. package/dist/prometheus-framework/src/modules/organizations/components/sections/FeedDepartments.vue.cjs +1 -1
  104. package/dist/prometheus-framework/src/modules/organizations/components/sections/FeedDepartments.vue.js +1 -1
  105. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.cjs +1 -1
  106. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.js +3 -3
  107. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersList.vue.cjs +1 -1
  108. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersList.vue.js +1 -1
  109. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
  110. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.js +5 -5
  111. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
  112. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.js +2 -2
  113. package/dist/prometheus-framework/src/modules/products/components/blocks/ImagesThumbnails.vue.cjs +1 -1
  114. package/dist/prometheus-framework/src/modules/products/components/blocks/ImagesThumbnails.vue.js +1 -1
  115. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
  116. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.js +2 -2
  117. package/dist/prometheus-framework/src/modules/products/components/pages/Leftovers.vue.cjs +1 -1
  118. package/dist/prometheus-framework/src/modules/products/components/pages/Leftovers.vue.js +1 -1
  119. package/dist/prometheus-framework/src/modules/products/components/pages/Product.vue.cjs +1 -1
  120. package/dist/prometheus-framework/src/modules/products/components/pages/Product.vue.js +22 -19
  121. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.cjs +1 -1
  122. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.js +6 -6
  123. package/dist/prometheus-framework/src/modules/products/components/pages/ProductsBackoffice.vue.cjs +1 -1
  124. package/dist/prometheus-framework/src/modules/products/components/pages/ProductsBackoffice.vue.js +1 -1
  125. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.cjs +1 -1
  126. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.js +3 -3
  127. package/dist/prometheus-framework/src/modules/products/components/sections/FilterProducts.vue.cjs +1 -1
  128. package/dist/prometheus-framework/src/modules/products/components/sections/FilterProducts.vue.js +1 -1
  129. package/dist/prometheus-framework/src/modules/products/components/sections/SectionProduct.vue.cjs +1 -1
  130. package/dist/prometheus-framework/src/modules/products/components/sections/SectionProduct.vue.js +31 -28
  131. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.cjs +1 -1
  132. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.js +3 -3
  133. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.cjs +1 -1
  134. package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.js +2 -2
  135. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileBlogposts.vue.cjs +1 -1
  136. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileBlogposts.vue.js +1 -1
  137. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.cjs +1 -1
  138. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.js +3 -3
  139. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEvents.vue.cjs +1 -1
  140. package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEvents.vue.js +1 -1
  141. package/dist/prometheus-framework/src/modules/wallet/components/pages/Wallet.vue.cjs +1 -1
  142. package/dist/prometheus-framework/src/modules/wallet/components/pages/Wallet.vue.js +78 -80
  143. package/dist/style.css +1 -1
  144. package/package.json +1 -1
  145. package/src/components/Countdown/Countdown.vue +4 -3
  146. package/src/components/Header/Header.vue +2 -0
  147. package/src/modules/community/components/layouts/Community.vue +2 -2
  148. package/src/modules/community/components/pages/CreateBlogPost.vue +1 -0
  149. package/src/modules/constructor/components/sections/Constructor.vue +1 -1
  150. package/src/modules/events/components/pages/EditEvent.vue +48 -3
  151. package/src/modules/events/components/pages/Event.vue +16 -8
  152. package/src/modules/events/components/sections/HeroEvent.vue +32 -28
  153. package/src/modules/events/components/sections/SectionMainGuest.vue +3 -2
  154. package/src/modules/events/components/sections/SectionPreviousEvents.vue +22 -15
  155. package/src/modules/events/models/event.model.js +9 -0
  156. package/src/modules/files/middlewares/server/middlewareBusboy.js +13 -2
  157. package/src/modules/marketplace/components/layouts/Marketplace.vue +1 -1
  158. package/src/modules/orders/store/shopcart.js +21 -5
  159. package/src/modules/payments/controller/payments.controller.js +54 -200
  160. package/src/modules/payments/controller/payments.tinkoff.controller.js +242 -0
  161. package/src/modules/payments/models/payment.model.js +22 -0
  162. package/src/modules/payments/routes/payments.routes.js +4 -25
  163. package/src/modules/payments/routes/payments.tinkoff.routes.js +58 -0
  164. package/src/modules/products/components/pages/Product.vue +3 -1
  165. package/src/modules/products/components/sections/SectionProduct.vue +3 -0
  166. package/src/modules/products/controllers/products.controller.js +188 -109
  167. package/src/modules/products/models/product.model.js +1 -0
  168. package/src/modules/wallet/components/pages/Wallet.vue +72 -87
  169. package/src/modules/wallet/controllers/crypto.controller.js +79 -0
  170. package/src/modules/wallet/models/wallet.model.js +27 -0
  171. /package/src/modules/{orders/models/payment.model.js → payments/models/payment.tinkoff.model.js} +0 -0
@@ -3,239 +3,93 @@ var jwt = require("jsonwebtoken");
3
3
  var axios = require('axios');
4
4
  var bcrypt = require("bcryptjs");
5
5
  var crypto = require('crypto');
6
- const { v4: uuidv4 } = require('uuid');
7
6
 
8
- var TerminalKey = process.env.TINKOFF_TERMINAL_KEY;
9
- var TerminalPassword = process.env.TINKOFF_TERMINAL_PASSWORD;
7
+ const QRCode = require('qrcode');
10
8
 
11
9
  const controllerFactory = (db) => {
12
10
  const Payment = db.payment;
11
+ const Wallet = db.wallet;
13
12
  const Order = db.order;
14
13
 
15
- const getAll = (req, res) => {
16
- Payment.find({}).sort({'createdAt': 'desc'}).exec((err, paymentes) => {
17
- // If error
18
- if (err) {return res.status(500).send({ message: err }); }
19
- // If not found
20
- if (!paymentes) {return res.status(404).send({ message: "Paymentes not found." }); }
21
- // If succes
22
- res.status(200).send(paymentes);
23
- });
24
- };
25
-
26
14
  const create = (req, res) => {
27
- console.log(req.body)
28
- Payment.create({
29
- type: req.body.type,
30
- order: req.body.order,
31
- positions: req.body.positions
32
- }, (err, payment) => {
33
- if (err) {return res.status(500).send({ message: err }); }
34
- if (!payment) {return res.status(404).send({ message: "Something wrong when updating product. (with files)" }); }
35
- res.status(200).send(payment);
36
- })
37
- };
15
+ const { amount, positions, userId } = req.body;
38
16
 
39
- const get = (req, res) => {
40
- Payment.findOne({ _id: req.params._id }).exec((err, payment) => {
41
- // If error
42
- if (err) {return res.status(500).send({ message: err }); }
43
- // If not found
44
- if (!payment) {return res.status(404).send({ message: "Payment not found." }); }
45
- // If succes
46
- res.status(200).send(payment);
47
- });
48
- };
17
+ const newPayment = new Payment({ amount, positions, user: userId });
18
+ await newPayment.save();
49
19
 
50
- const update = (req, res) => {
20
+ const qrData = `PaymentID:${newPayment._id};Amount:${amount}`;
21
+ const qrCode = await QRCode.toDataURL(qrData);
22
+
23
+ res.send({ qrCode, paymentId: newPayment._id });
24
+ };
51
25
 
52
- Payment.findOneAndUpdate({ PaymentId: req.params._id }, req.body, { new: true, upsert: true}).exec((err, payment) => {
26
+ const read = (req, res) => {
27
+ Payment.find({}).sort({'createdAt': 'desc'}).exec((err, paymentes) => {
53
28
  // If error
54
29
  if (err) {return res.status(500).send({ message: err }); }
55
30
  // If not found
56
- if (!payment) {return res.status(404).send({ message: "Payment not found." }); }
31
+ if (!paymentes) {return res.status(404).send({ message: "Paymentes not found." }); }
57
32
  // If succes
58
- res.status(200).send(payment);
33
+ res.status(200).send(paymentes);
59
34
  });
60
35
  };
61
36
 
62
- const deletePayment = (req, res) => {
63
- Payment.findOneAndDelete({_id: req.params._id}, (err, payment) => {
64
- if (err) {return res.status(500).send({ message: err }); }
65
- if (!payment) {return res.status(404).send({ message: "Something wrong when deleting payment." }); }
66
- res.status(200).send(payment);
67
- })
68
- };
69
-
70
- function createToken (request) {
71
- request = Object.entries(request).map(function(key) {
72
- return { [key[0]]: key[1] }
73
- })
74
- request.push({Password: TerminalPassword})
75
- request.sort(function(a, b){
76
- if(Object.keys(a)[0] < Object.keys(b)[0]) { return -1; }
77
- if(Object.keys(a)[0] > Object.keys(b)[0]) { return 1; }
78
- return 0;
79
- })
80
- const requestContacted = request.map(function(key) {
81
- return Object.values(key)[0]
82
- }).join("")
83
-
84
- const hash = crypto.createHash('sha256').update(requestContacted).digest('hex');
85
-
86
- return hash
87
- }
88
- const newpayment = (req, res) => {
89
- // Data for payment init
90
- console.log(req.body.phone);
91
- // Send request to Tinkoff
92
- axios.post('https://securepay.tinkoff.ru/v2/Init', {
93
- TerminalKey: TerminalKey,
94
- Amount: '350000',
95
- OrderId: req.body._id,
96
- Recurrent: 'y',
97
- PayType: "О",
98
- CustomerKey: req.body.phone,
99
- Description: 'Оплата в интернет-магазине',
100
- Data: {
101
- phone: req.body.phone,
102
- },
103
- // SuccessURL: 'http://tandem.ohmybike.ru/rent/' + OrderId,
104
- // FailURL: 'http://tandem.ohmybike.ru/account'
105
- // SuccessURL: 'http://localhost:8082/rent/' + OrderId,
106
- // FailURL: 'http://localhost:8082/account'
107
- }).then(function(response) {
108
- const payment = new Payment(response.data);
109
- payment.save((err, payment) => {
110
- if (err) {
111
- res.status(500).send({ message: err });
112
- return;
113
- }
114
-
115
- payment.save(err => {
116
- if (err) {
117
- res.status(500).send({ message: err });
118
- return;
119
- }
120
- res.send(response.data);
121
- });
122
- })
123
- }).catch(function(error) {
124
- res.send(error);
125
- })
126
-
127
- };
128
- const setpayment = (req, res) => {
129
- // Data for payment
130
- const payment = new Payment({
131
- OrderId: req.body.OrderId,
132
- Success: req.body.Success,
133
- Status: req.body.Status,
134
- PaymentId: req.body.PaymentId,
135
- ErrorCode: req.body.ErrorCode,
136
- Message: req.body.Message,
137
- Details: req.body.Details
138
- });
139
- // Wright to db
140
- console.log(payment)
37
+ const update = (req, res) => {
38
+ const session = await mongoose.startSession();
39
+ session.startTransaction();
40
+ try {
41
+ const { paymentId, walletId } = req.body; // Теперь мы работаем с walletId
141
42
 
142
- payment.save((err, payment) => {
143
- if (err) {
144
- res.status(500).send({ message: err });
145
- return;
43
+ const payment = await Payment.findById(paymentId).session(session);
44
+
45
+ if (!payment) {
46
+ throw new Error('Payment not found');
47
+ }
48
+ if (payment.status !== 'pending') {
49
+ throw new Error('Payment is not in a pending state');
146
50
  }
147
51
 
148
- payment.save(err => {
149
- if (err) {
150
- res.status(500).send({ message: err });
151
- return;
152
- }
52
+ const wallet = await Wallet.findById(walletId).session(session);
153
53
 
154
- res.send({ message: "Payment was created successfully!" });
155
- });
156
- })
157
- };
158
- const getstatus = (req, res) => {
159
- console.log(req.body.order)
160
- Payment.findOne({
161
- OrderId: req.body.order
162
- })
163
- .sort({createdAt: -1})
164
- .exec((err, payment) => {
165
- if (err) {
166
- res.status(500).send({ message: err });
167
- return;
168
- }
169
- if (!payment) {
170
- return res.status(404).send({ message: "Payment Not found." });
54
+ if (!wallet) {
55
+ throw new Error('Wallet not found');
171
56
  }
172
57
 
173
-
174
- if (payment.Status === 'CONFIRMED') {
175
- console.log(payment.Status)
176
- console.log(req.body.order)
177
- Order.findOneAndUpdate({ _id: req.body.order, status: 'Подтвержден' }, {$set: {status: "Ожидает отправки"}},{ new: true}).catch(function(error) {
178
- res.status(500).send(error);
179
- });
58
+ if (wallet.amount < payment.amount) {
59
+ throw new Error('Insufficient funds');
180
60
  }
181
61
 
182
- axios.post('https://securepay.tinkoff.ru/v2/GetState', {
183
- TerminalKey: TerminalKey,
184
- PaymentId: payment.PaymentId,
185
- Token: createToken({TerminalKey: TerminalKey, PaymentId: payment.PaymentId})
186
- }).then(function(response) {
187
- payment.Status = response.data.Status
188
- payment.save()
189
- res.send(response.data);
190
- }).catch(function(error) {
191
- res.status(500).send(error);
192
- });
193
- });
62
+ // Списание средств с кошелька
63
+ wallet.amount -= payment.amount;
64
+ await wallet.save({ session });
65
+
66
+ // Обновление статуса платежа
67
+ payment.status = 'completed';
68
+ await payment.save({ session });
69
+
70
+ await session.commitTransaction();
71
+ res.send('Payment processed successfully');
72
+ } catch (error) {
73
+ await session.abortTransaction();
74
+ res.status(500).send(error.message);
75
+ } finally {
76
+ session.endSession();
77
+ }
194
78
  };
195
79
 
196
- const addcustomer = (req, res) => {
197
- console.log(req.body)
198
-
199
- axios.post('https://securepay.tinkoff.ru/v2/AddCustomer', {
200
- TerminalKey: TerminalKey,
201
- CustomerKey: req.body,
202
- Token: createToken({TerminalKey: TerminalKey, CustomerKey: req.body.phone})
203
- })
204
- .then(function(response) {
205
- res.send(response.data);
206
- })
207
- .catch(function(error) {
208
- res.status(500).send(error);
209
- });
210
- }
211
-
212
- const getcustomercards = (req, res) => {
213
- axios.post('https://securepay.tinkoff.ru/v2/GetCardList', {
214
- TerminalKey: TerminalKey,
215
- CustomerKey: req.body.phone,
216
- Token: createToken({TerminalKey: TerminalKey, CustomerKey: req.body.phone})
217
- })
218
- .then(function(response) {
219
- console.log(response.data)
220
- res.send(response.data);
80
+ const deletePayment = (req, res) => {
81
+ Payment.findOneAndDelete({_id: req.params._id}, (err, payment) => {
82
+ if (err) {return res.status(500).send({ message: err }); }
83
+ if (!payment) {return res.status(404).send({ message: "Something wrong when deleting payment." }); }
84
+ res.status(200).send(payment);
221
85
  })
222
- .catch(function(error) {
223
- res.status(500).send(error);
224
- });
225
- }
86
+ };
226
87
 
227
88
  return {
228
- getAll,
229
89
  create,
230
- get,
90
+ read,
231
91
  update,
232
92
  delete: deletePayment,
233
- createToken,
234
- newpayment,
235
- setpayment,
236
- getstatus,
237
- addcustomer,
238
- getcustomercards
239
93
  };
240
94
  };
241
95
 
@@ -0,0 +1,242 @@
1
+
2
+ var jwt = require("jsonwebtoken");
3
+ var axios = require('axios');
4
+ var bcrypt = require("bcryptjs");
5
+ var crypto = require('crypto');
6
+ const { v4: uuidv4 } = require('uuid');
7
+
8
+ var TerminalKey = process.env.TINKOFF_TERMINAL_KEY;
9
+ var TerminalPassword = process.env.TINKOFF_TERMINAL_PASSWORD;
10
+
11
+ const controllerFactory = (db) => {
12
+ const Payment = db.payment;
13
+ const Order = db.order;
14
+
15
+ const getAll = (req, res) => {
16
+ Payment.find({}).sort({'createdAt': 'desc'}).exec((err, paymentes) => {
17
+ // If error
18
+ if (err) {return res.status(500).send({ message: err }); }
19
+ // If not found
20
+ if (!paymentes) {return res.status(404).send({ message: "Paymentes not found." }); }
21
+ // If succes
22
+ res.status(200).send(paymentes);
23
+ });
24
+ };
25
+
26
+ const create = (req, res) => {
27
+ console.log(req.body)
28
+ Payment.create({
29
+ type: req.body.type,
30
+ order: req.body.order,
31
+ positions: req.body.positions
32
+ }, (err, payment) => {
33
+ if (err) {return res.status(500).send({ message: err }); }
34
+ if (!payment) {return res.status(404).send({ message: "Something wrong when updating product. (with files)" }); }
35
+ res.status(200).send(payment);
36
+ })
37
+ };
38
+
39
+ const get = (req, res) => {
40
+ Payment.findOne({ _id: req.params._id }).exec((err, payment) => {
41
+ // If error
42
+ if (err) {return res.status(500).send({ message: err }); }
43
+ // If not found
44
+ if (!payment) {return res.status(404).send({ message: "Payment not found." }); }
45
+ // If succes
46
+ res.status(200).send(payment);
47
+ });
48
+ };
49
+
50
+ const update = (req, res) => {
51
+
52
+ Payment.findOneAndUpdate({ PaymentId: req.params._id }, req.body, { new: true, upsert: true}).exec((err, payment) => {
53
+ // If error
54
+ if (err) {return res.status(500).send({ message: err }); }
55
+ // If not found
56
+ if (!payment) {return res.status(404).send({ message: "Payment not found." }); }
57
+ // If succes
58
+ res.status(200).send(payment);
59
+ });
60
+ };
61
+
62
+ const deletePayment = (req, res) => {
63
+ Payment.findOneAndDelete({_id: req.params._id}, (err, payment) => {
64
+ if (err) {return res.status(500).send({ message: err }); }
65
+ if (!payment) {return res.status(404).send({ message: "Something wrong when deleting payment." }); }
66
+ res.status(200).send(payment);
67
+ })
68
+ };
69
+
70
+ function createToken (request) {
71
+ request = Object.entries(request).map(function(key) {
72
+ return { [key[0]]: key[1] }
73
+ })
74
+ request.push({Password: TerminalPassword})
75
+ request.sort(function(a, b){
76
+ if(Object.keys(a)[0] < Object.keys(b)[0]) { return -1; }
77
+ if(Object.keys(a)[0] > Object.keys(b)[0]) { return 1; }
78
+ return 0;
79
+ })
80
+ const requestContacted = request.map(function(key) {
81
+ return Object.values(key)[0]
82
+ }).join("")
83
+
84
+ const hash = crypto.createHash('sha256').update(requestContacted).digest('hex');
85
+
86
+ return hash
87
+ }
88
+ const newpayment = (req, res) => {
89
+ // Data for payment init
90
+ console.log(req.body.phone);
91
+ // Send request to Tinkoff
92
+ axios.post('https://securepay.tinkoff.ru/v2/Init', {
93
+ TerminalKey: TerminalKey,
94
+ Amount: '350000',
95
+ OrderId: req.body._id,
96
+ Recurrent: 'y',
97
+ PayType: "О",
98
+ CustomerKey: req.body.phone,
99
+ Description: 'Оплата в интернет-магазине',
100
+ Data: {
101
+ phone: req.body.phone,
102
+ },
103
+ // SuccessURL: 'http://tandem.ohmybike.ru/rent/' + OrderId,
104
+ // FailURL: 'http://tandem.ohmybike.ru/account'
105
+ // SuccessURL: 'http://localhost:8082/rent/' + OrderId,
106
+ // FailURL: 'http://localhost:8082/account'
107
+ }).then(function(response) {
108
+ const payment = new Payment(response.data);
109
+ payment.save((err, payment) => {
110
+ if (err) {
111
+ res.status(500).send({ message: err });
112
+ return;
113
+ }
114
+
115
+ payment.save(err => {
116
+ if (err) {
117
+ res.status(500).send({ message: err });
118
+ return;
119
+ }
120
+ res.send(response.data);
121
+ });
122
+ })
123
+ }).catch(function(error) {
124
+ res.send(error);
125
+ })
126
+
127
+ };
128
+ const setpayment = (req, res) => {
129
+ // Data for payment
130
+ const payment = new Payment({
131
+ OrderId: req.body.OrderId,
132
+ Success: req.body.Success,
133
+ Status: req.body.Status,
134
+ PaymentId: req.body.PaymentId,
135
+ ErrorCode: req.body.ErrorCode,
136
+ Message: req.body.Message,
137
+ Details: req.body.Details
138
+ });
139
+ // Wright to db
140
+ console.log(payment)
141
+
142
+ payment.save((err, payment) => {
143
+ if (err) {
144
+ res.status(500).send({ message: err });
145
+ return;
146
+ }
147
+
148
+ payment.save(err => {
149
+ if (err) {
150
+ res.status(500).send({ message: err });
151
+ return;
152
+ }
153
+
154
+ res.send({ message: "Payment was created successfully!" });
155
+ });
156
+ })
157
+ };
158
+ const getstatus = (req, res) => {
159
+ console.log(req.body.order)
160
+ Payment.findOne({
161
+ OrderId: req.body.order
162
+ })
163
+ .sort({createdAt: -1})
164
+ .exec((err, payment) => {
165
+ if (err) {
166
+ res.status(500).send({ message: err });
167
+ return;
168
+ }
169
+ if (!payment) {
170
+ return res.status(404).send({ message: "Payment Not found." });
171
+ }
172
+
173
+
174
+ if (payment.Status === 'CONFIRMED') {
175
+ console.log(payment.Status)
176
+ console.log(req.body.order)
177
+ Order.findOneAndUpdate({ _id: req.body.order, status: 'Подтвержден' }, {$set: {status: "Ожидает отправки"}},{ new: true}).catch(function(error) {
178
+ res.status(500).send(error);
179
+ });
180
+ }
181
+
182
+ axios.post('https://securepay.tinkoff.ru/v2/GetState', {
183
+ TerminalKey: TerminalKey,
184
+ PaymentId: payment.PaymentId,
185
+ Token: createToken({TerminalKey: TerminalKey, PaymentId: payment.PaymentId})
186
+ }).then(function(response) {
187
+ payment.Status = response.data.Status
188
+ payment.save()
189
+ res.send(response.data);
190
+ }).catch(function(error) {
191
+ res.status(500).send(error);
192
+ });
193
+ });
194
+ };
195
+
196
+ const addcustomer = (req, res) => {
197
+ console.log(req.body)
198
+
199
+ axios.post('https://securepay.tinkoff.ru/v2/AddCustomer', {
200
+ TerminalKey: TerminalKey,
201
+ CustomerKey: req.body,
202
+ Token: createToken({TerminalKey: TerminalKey, CustomerKey: req.body.phone})
203
+ })
204
+ .then(function(response) {
205
+ res.send(response.data);
206
+ })
207
+ .catch(function(error) {
208
+ res.status(500).send(error);
209
+ });
210
+ }
211
+
212
+ const getcustomercards = (req, res) => {
213
+ axios.post('https://securepay.tinkoff.ru/v2/GetCardList', {
214
+ TerminalKey: TerminalKey,
215
+ CustomerKey: req.body.phone,
216
+ Token: createToken({TerminalKey: TerminalKey, CustomerKey: req.body.phone})
217
+ })
218
+ .then(function(response) {
219
+ console.log(response.data)
220
+ res.send(response.data);
221
+ })
222
+ .catch(function(error) {
223
+ res.status(500).send(error);
224
+ });
225
+ }
226
+
227
+ return {
228
+ getAll,
229
+ create,
230
+ get,
231
+ update,
232
+ delete: deletePayment,
233
+ createToken,
234
+ newpayment,
235
+ setpayment,
236
+ getstatus,
237
+ addcustomer,
238
+ getcustomercards
239
+ };
240
+ };
241
+
242
+ module.exports = controllerFactory;
@@ -0,0 +1,22 @@
1
+ module.exports = (db) => {
2
+
3
+ const PaymentSchema = new db.mongoose.Schema({
4
+ creator: {
5
+ type: db.mongoose.Schema.Types.ObjectId,
6
+ ref: 'User',
7
+ },
8
+ owner: {
9
+ type: db.mongoose.Schema.Types.ObjectId,
10
+ ref: 'User',
11
+ }
12
+ }, {
13
+ timestamps: {
14
+ currentTime: () => Date.now()
15
+ }
16
+ });
17
+
18
+ const Payment = db.mongoose.model("Payment", PaymentSchema);
19
+
20
+ return Payment;
21
+ };
22
+
@@ -12,42 +12,21 @@ module.exports = function(app, db) {
12
12
  next();
13
13
  });
14
14
 
15
- app.post(
16
- "/payment/newpayment",
17
- controller.newpayment,
18
- );
19
- app.post(
20
- "/payment/getstatus",
21
- controller.getstatus
22
- );
23
- app.post(
24
- "/payment/addcustomer",
25
- controller.addcustomer
26
- );
27
- app.post(
28
- "/payment/getcustomercards",
29
- controller.getcustomercards
30
- );
31
15
 
32
- app.get(
16
+ app.post(
33
17
  "/payments",
34
- controller.getAll
18
+ controller.create
35
19
  );
36
-
20
+
37
21
  app.get(
38
22
  "/payments/:_id",
39
- controller.get
23
+ controller.read
40
24
  );
41
25
 
42
26
  app.post(
43
27
  "/payments/:_id",
44
28
  controller.update
45
29
  );
46
-
47
- app.post(
48
- "/payments",
49
- controller.create
50
- );
51
30
 
52
31
  app.delete(
53
32
  "/payments/:_id",
@@ -0,0 +1,58 @@
1
+ // Factories
2
+ const controllerFactory = require("../controllers/payments.controller");
3
+ // Middlewares
4
+ const middlewareFactory = require('@pf/src/modules/middlewares/server');
5
+ // Routes
6
+ module.exports = function(app, db) {
7
+ const controller = controllerFactory(db);
8
+ const { verifySignUp, verifyUser } = middlewareFactory(db);
9
+
10
+ app.use(function(req, res, next) {
11
+ res.header("Access-Control-Allow-Headers", "Access-Control-Allow-Origin: *", "x-access-token, Origin, Content-Type, Accept");
12
+ next();
13
+ });
14
+
15
+ app.post(
16
+ "/payment/newpayment",
17
+ controller.newpayment,
18
+ );
19
+ app.post(
20
+ "/payment/getstatus",
21
+ controller.getstatus
22
+ );
23
+ app.post(
24
+ "/payment/addcustomer",
25
+ controller.addcustomer
26
+ );
27
+ app.post(
28
+ "/payment/getcustomercards",
29
+ controller.getcustomercards
30
+ );
31
+
32
+ app.get(
33
+ "/payments",
34
+ controller.getAll
35
+ );
36
+
37
+ app.get(
38
+ "/payments/:_id",
39
+ controller.get
40
+ );
41
+
42
+ app.post(
43
+ "/payments/:_id",
44
+ controller.update
45
+ );
46
+
47
+ app.post(
48
+ "/payments",
49
+ controller.create
50
+ );
51
+
52
+ app.delete(
53
+ "/payments/:_id",
54
+ controller.delete
55
+ );
56
+
57
+ };
58
+
@@ -1,7 +1,8 @@
1
1
  <template>
2
2
  <div class="flex flex-column w-100 o-hidden gap-thin pd-thin">
3
3
  <!-- <Breadcrumbs class="bg-grey radius-big pd-small"/> -->
4
- <SectionProduct v-if="product" :product="product" class="pos-relative"/>
4
+ {{product.quantity}}
5
+ <SectionProduct v-if="product" :product="product" :user="auth.state.user" class="pos-relative"/>
5
6
 
6
7
  <PopularProducts />
7
8
  </div>
@@ -22,6 +23,7 @@
22
23
  import { useI18n } from 'vue-i18n'
23
24
  import { useMeta } from 'vue-meta'
24
25
 
26
+ import * as auth from '@pf/src/modules/auth/store/auth';
25
27
  import * as products from '@pf/src/modules/products/store/products';
26
28
  import * as categories from '@pf/src/modules/products/store/categories';
27
29
 
@@ -123,6 +123,9 @@ const props = defineProps({
123
123
  type: Object,
124
124
  required: true
125
125
  },
126
+ user: {
127
+ type: String,
128
+ },
126
129
  recommendation: {
127
130
  type: String
128
131
  }