diff --git a/deep-packages/insertHandler.cjs b/deep-packages/insertHandler.cjs new file mode 100644 index 00000000..6570cf31 --- /dev/null +++ b/deep-packages/insertHandler.cjs @@ -0,0 +1,47 @@ +const insertHandler = async ({deep,fileTypeLinkId, fileName, handlerName, handleName, triggerTypeLinkId, code, supportsId, handleOperationTypeLinkId, containTypeLinkId, packageId, handlerTypeLinkId}) => { + return await deep.insert({ + type_id: fileTypeLinkId, + in: { + data: [ + { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: fileName } }, + }, + { + from_id: supportsId, + type_id: handlerTypeLinkId, + in: { + data: [ + { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: handlerName } }, + }, + { + type_id: handleOperationTypeLinkId, + from_id: triggerTypeLinkId, + in: { + data: [ + { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: handleName } }, + }, + ], + }, + }, + ], + }, + }, + ], + }, + string: { + data: { + value: code, + }, + }, + }); + }; + + exports.insertHandler = insertHandler; \ No newline at end of file diff --git a/deep-packages/insertNotificationHandler.cjs b/deep-packages/insertNotificationHandler.cjs new file mode 100644 index 00000000..6ab1941e --- /dev/null +++ b/deep-packages/insertNotificationHandler.cjs @@ -0,0 +1,85 @@ +const insertNotificationHandler = async ({deep, notificationPort, notificationRoute, portTypeId, routerListeningTypeId, routerTypeId, routerStringUseTypeId, routeTypeId, handleRouteTypeId, handlerTypeId, supportsId, containTypeId, adminId, fileTypeId, handlerName, code}) => { +return await deep.insert( + { + type_id: portTypeId, + number: { + data: { value: notificationPort }, + }, + in: { + data: { + type_id: routerListeningTypeId, + from: { + data: { + type_id: routerTypeId, + in: { + data: { + type_id: routerStringUseTypeId, + string: { + data: { + value: + notificationRoute, + }, + }, + from: { + data: { + type_id: routeTypeId, + out: { + data: { + type_id: handleRouteTypeId, + to: { + data: { + type_id: handlerTypeId, + from_id: supportsId, + in: { + data: { + type_id: containTypeId, + // from_id: deep.linkId, + from_id: adminId, + string: { + data: { + value: handlerName, + }, + }, + }, + }, + to: { + data: { + type_id: fileTypeId, + string: { + data: { + value: code, + }, + }, + in: { + data: { + type_id: containTypeId, + from_id: packageId, + string: { + data: { + value: handlerName, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + name: 'INSERT_HANDLE_ROUTE_HIERARCHICAL', + } + ) +} + +exports.insertNotificationHandler = insertNotificationHandler; \ No newline at end of file diff --git a/deep-packages/sleep.cjs b/deep-packages/sleep.cjs new file mode 100644 index 00000000..2f580a86 --- /dev/null +++ b/deep-packages/sleep.cjs @@ -0,0 +1,3 @@ +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + +exports.sleep = sleep; \ No newline at end of file diff --git a/insert-handler.cjs b/insert-handler.cjs new file mode 100644 index 00000000..e906ad5f --- /dev/null +++ b/insert-handler.cjs @@ -0,0 +1,66 @@ +({ deep, data: { newLink, triggeredByLinkId } }) => { + const timestamp = Date.now(); + + const containTypeLinkId = deep.id('@deep-foundation/core', 'Contain'); + + const reservedIds = deep.reserve(2); + + const logLinkInsertData = { + id: reservedIds[0], + type_id: deep.id("@deep-foundation/logger", "LogLink"), + ...(newLink.from_id && {from_id: newLink.from_id}), + ...(newLink.to_id && {from_id: newLink.to_id}), + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + const logInsertInsertData = { + id: reservedIds[1], + type_id: deep.id("@deep-foundation/logger", "LogInsert"), + from_id: logLinkInsertData.id, + to_id: newLink.id, + number: timestamp, // TODO: number field must be of type MutationInsertLink or smth like this, but not number. Issue: https://github.com/deep-foundation/deeplinks/issues/80 + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + const logTypeLinkInsertData = { + type_id: deep.id("@deep-foundation/logger", "LogType"), + from_id: logLinkInsertData.id, + to_id: newLink.type_id, + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + const logSubjectLinkInsertData = { + type_id: deep.id("@deep-foundation/logger", "LogSubject"), + from_id: triggeredByLinkId, + to_id: logInsertInsertData.id, + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + deep.insert([ + logLinkInsertData, + logInsertInsertData, + logTypeLinkInsertData, + logSubjectLinkInsertData, + logSubjectLinkInsertData + ]) +} \ No newline at end of file diff --git a/logger.cjs b/logger.cjs new file mode 100644 index 00000000..21abbf9e --- /dev/null +++ b/logger.cjs @@ -0,0 +1,394 @@ +require('react'); +require('graphql'); +require('lodash'); +require('subscriptions-transport-ws'); +const dotenv = require('dotenv'); +const { generateApolloClient } = require('@deep-foundation/hasura/client'); +const { DeepClient } = require('@deep-foundation/deeplinks/imports/client'); +const { + minilinks, + Link, +} = require('@deep-foundation/deeplinks/imports/minilinks'); +const crypto = require('crypto'); +const axios = require('axios'); +const uniqid = require('uniqid'); +const { expect } = require('chai'); +const { get } = require('lodash'); +const { default: links } = require('@deep-foundation/deeplinks/imports/router/links'); +const { insertHandler } = require('./deep-packages/insertHandler.cjs'); +const { sleep } = require('./deep-packages/sleep.cjs'); +const fs = require('fs'); + +const PACKAGE_NAME = "@deep-foundation/logger"; + +console.log(`Installing ${PACKAGE_NAME} package.`); + + +const createdLinkIds = []; + +const main = async () => { + + const installPackage = async () => { + const apolloClient = generateApolloClient({ + path: "localhost:3006/gql" || '', // <<= HERE PATH TO UPDATE + ssl: !!~"localhost:3006/gql".indexOf('localhost') + ? false + : true, + // admin token in prealpha deep secret key + // token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsibGluayJdLCJ4LWhhc3VyYS1kZWZhdWx0LXJvbGUiOiJsaW5rIiwieC1oYXN1cmEtdXNlci1pZCI6IjI2MiJ9LCJpYXQiOjE2NTYxMzYyMTl9.dmyWwtQu9GLdS7ClSLxcXgQiKxmaG-JPDjQVxRXOpxs', + }); + + const unloginedDeep = new DeepClient({ apolloClient }); + const guest = await unloginedDeep.guest(); + const guestDeep = new DeepClient({ deep: unloginedDeep, ...guest }); + const admin = await guestDeep.login({ + linkId: await guestDeep.id('deep', 'admin'), + }); + const deep = new DeepClient({ deep: guestDeep, ...admin }); + + const dockerSupportsJs = await deep.id( + '@deep-foundation/core', + 'dockerSupportsJs' + ); + const handlerTypeLinkId = await deep.id('@deep-foundation/core', 'Handler'); + const handleInsertTypeLinkId = await deep.id('@deep-foundation/core', 'HandleInsert'); + const handleUpdateTypeLinkId = await deep.id('@deep-foundation/core', 'HandleUpdate'); + const handleDeleteTypeLinkId = await deep.id('@deep-foundation/core', 'HandleDelete'); + + const containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain'); + const typeTypeLinkId = await deep.id('@deep-foundation/core', 'Type'); + const packageTypeLinkId = await deep.id('@deep-foundation/core', 'Package'); + const anyTypeLinkId = await deep.id('@deep-foundation/core', 'Any'); + const syncTextFileTypeLinkId = await deep.id('@deep-foundation/core', 'SyncTextFile'); + const joinTypeLinkId = await deep.id('@deep-foundation/core', 'Join'); + const plv8SupportsJsId = await deep.id('@deep-foundation/core', 'plv8SupportsJs'); + const userTypeLinkId = await deep.id('@deep-foundation/core', 'User'); + + + + const { data: [{ id: packageId }] } = await deep.insert({ + type_id: packageTypeLinkId, + string: { data: { value: PACKAGE_NAME } }, + in: { + data: [ + { + type_id: containTypeLinkId, + from_id: deep.linkId + }, + ] + }, + out: { + data: [ + { + type_id: joinTypeLinkId, + to_id: await deep.id('deep', 'users', 'packages'), + }, + { + type_id: joinTypeLinkId, + to_id: await deep.id('deep', 'admin'), + }, + ] + }, + }); + + console.log({ packageId }); + + const { + data: [{ id: logLinkTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: anyTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogLink' } }, + }, + }, + }); + console.log({ logLinkTypeLinkId: logLinkTypeLinkId }); + + const { + data: [{ id: logInsertTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: logLinkTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogInsert' } }, + }, + }, + }); + console.log({ logInsertTypeLinkId }); + + const { + data: [{ id: logUpdateTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: anyTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogUpdate' } }, + }, + }, + }); + console.log({ logUpdateTypeLinkId }); + + const { + data: [{ id: logDeleteTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: logLinkTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogDelete' } }, + }, + }, + }); + console.log({ logDeleteTypeLinkId }); + + const { + data: [{ id: logTypeTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: anyTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogType' } }, + }, + }, + }); + console.log({ logTypeTypeLinkId }); + + const { + data: [{ id: logSubjectTypeLinkId }], + } = await deep.insert({ + type_id: typeTypeLinkId, + from_id: userTypeLinkId, + to_id: anyTypeLinkId, + in: { + data: { + type_id: containTypeLinkId, + from_id: packageId, // before created package + string: { data: { value: 'LogSubject' } }, + }, + }, + }); + console.log({ logLinkTypeLinkId: logLinkTypeLinkId }); + + + const insertHandlerId = await insertHandler( + { + code: fs.readFileSync('./insert-handler.cjs', {encoding: 'utf-8'}), + fileName: "insertHandlerFile", + handlerName: "insertHandler", + handleName: "insertHandle", + handleOperationTypeLinkId: handleInsertTypeLinkId, + supportsId: plv8SupportsJsId, + triggerTypeLinkId: anyTypeLinkId , + containTypeLinkId, + deep, + fileTypeLinkId: syncTextFileTypeLinkId, + handlerTypeLinkId, + packageId + } + ); + console.log({ insertHandlerId }); + + const updateHandlerId = await insertHandler( + { + code: fs.readFileSync('./update-handler.cjs', {encoding: 'utf-8'}), + fileName: "updateHandlerFile", + handlerName: "updateHandler", + handleName: "updateHandle", + handleOperationTypeLinkId: handleUpdateTypeLinkId, + supportsId: plv8SupportsJsId, + triggerTypeLinkId: anyTypeLinkId, + containTypeLinkId, + deep, + fileTypeLinkId: syncTextFileTypeLinkId, + handlerTypeLinkId, + packageId, + } + ); + console.log({ updateHandlerId }); + + const deleteHandlerId = await insertHandler( + { + code: +` +({ deep, data: { oldLink, triggeredByLinkId } }) => { + + const timestamp = Date.now(); + + const { data: [{ id: logInsertId }] } = deep.select({ + type_id: deep.id("@deep-foundation/logger", "LogInsert"), + to_id: oldLink.id + }) + + const { data: [{ id: logLinkLinkId }] } = deep.select({ + type_id: deep.id("@deep-foundation/logger", "LogLink"), + id: logInsertId.from_id, + }); + const { data: [{ id: logDeleteLinkId }] } = deep.insert({ + type_id: deep.id("@deep-foundation/logger", "LogDelete"), + from_id: logLinkLinkId, + to_id: oldLink.id, + number: timestamp, + }); + + const { data: [{ id: logSubjectLinkId }] } = deep.insert({ + type_id: deep.id("@deep-foundation/logger", "LogSubject"), + from_id: triggeredByLinkId, + to_id: logDeleteLinkId, + }); +} +`.trim() + , + fileName: "deleteHandlerFile", + handlerName: "deleteHandler", + handleName: "deleteHandle", + handleOperationTypeLinkId: handleDeleteTypeLinkId, + supportsId: plv8SupportsJsId, + triggerTypeLinkId: /* TODO: anyTypeLinkId */ triggerTypeLinkId, + containTypeLinkId, + deep, + fileTypeLinkId: syncTextFileTypeLinkId, + handlerTypeLinkId, + packageId + } + ); + console.log({ deleteHandlerId }); + + const createdTestLinkIds = []; + const callTests = async () => { + // TODO: const {data: [{id: customTypeLinkId}]} = await deep.Delete({ + // type_id: typeTypeLinkId, + // from_id: anyTypeLinkId, + // to_id: anyTypeLinkId + // }); + // console.log({ customTypeLinkId }); + // createdTestLinkIds.push(customTypeLinkId) + // createdLinkIds.push(customTypeLinkId) + + const { data: [{ id: linkId }] } = await deep.insert({ + type_id: /* TODO: customTypeLinkId*/ triggerTypeLinkId, + }); + console.log({ linkId }); + createdTestLinkIds.push(linkId) + createdLinkIds.push(linkId) + + var logInsertId; + for (let i = 0; i < 10; i++) { + const { data } = await deep.select({ + type_id: logInsertTypeLinkId, + to_id: linkId + }); + if (data.length > 0) { + logInsertId = data[0].id; + break; + } + await sleep(1000); + } + console.log({ logInsertId }); + expect(logInsertId).to.not.be.equal(undefined); + + var logLinkId; + for (let i = 0; i < 10; i++) { + const { data } = await deep.select({ + type_id: logLinkTypeLinkId, + from_id: linkId.from_id, + to_id: linkId.to_id + }); + if (data.length > 0) { + logLinkId = data[0].id; + break; + } + await sleep(1000); + } + console.log({ logLinkId }); + expect(logLinkId).to.not.be.equal(undefined); + + var logTypeLinkId; + for (let i = 0; i < 10; i++) { + const { data } = await deep.select({ + type_id: logTypeTypeLinkId, + from_id: logLinkId, + to_id: /*customTypeLinkId*/ triggerTypeLinkId + }); + if (data.length > 0) { + logTypeLinkId = data[0].id; + break; + } + await sleep(1000); + } + console.log({ logTypeLinkId }); + expect(logTypeLinkId).to.not.be.equal(undefined); + + await deep.insert({ link_id: linkId, value: "string" }, { table: "strings" }); + + var logUpdateId; + for (let i = 0; i < 10; i++) { + const { data } = await deep.select({ + type_id: logUpdateTypeLinkId, + from_id: deep.linkId, + to_id: logInsertId + }); + if (data.length > 0) { + logUpdateId = data[0].id; + break; + } + await sleep(1000); + } + console.log({ logUpdateId }); + expect(logUpdateId).to.not.be.equal(undefined); + + await deep.delete({ + id: linkId + }); + + var logDeleteId; + for (let i = 0; i < 10; i++) { + const { data } = await deep.select({ + type_id: logDeleteTypeLinkId, + from_id: deep.linkId, + to_id: logInsertId + }); + if (data.length > 0) { + logDeleteId = data[0].id; + break; + } + await sleep(1000); + } + console.log({ logDeleteId }); + expect(logDeleteId).to.not.be.equal(undefined); + + } + await callTests().then(() => { + // TODO: deep.delete(createdTestLinkIds); + }, error => { + console.error(error) + // TODO: deep.delete(createdLinkIds); + }); + } + + await installPackage().catch(error => { + console.error(error) + // TODO: deep.delete(createdLinkIds); + }); +}; + +main(); diff --git a/package-lock.json b/package-lock.json index 00c816fc..04bf70b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3190,6 +3190,11 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" }, + "dotenv-expand": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-9.0.0.tgz", + "integrity": "sha512-uW8Hrhp5ammm9x7kBLR6jDfujgaDarNA02tprvZdyrJ7MpdzD1KyrIHG4l+YoC2fJ2UcdFdNWNWIjt+sexBHJw==" + }, "duplexify": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz", diff --git a/package.json b/package.json index d9a048cf..9d85ef3a 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "concurrently": "^5.3.0", "cross-env": "^7.0.3", "del": "^6.0.0", + "dotenv-expand": "^9.0.0", "gulp": "^4.0.2", "gulp-run-command": "^0.0.10", "i": "^0.3.6", diff --git a/test.cjs b/test.cjs new file mode 100644 index 00000000..6ad8e1cb --- /dev/null +++ b/test.cjs @@ -0,0 +1,196 @@ +const crypto = require('crypto'); +const axios = require('axios'); +const dotenv = require('dotenv'); +const dotenvExpand = require('dotenv-expand'); +const uniqid = require('uniqid'); +const {payInBrowser} = require("./deep-packges/payments/tinkoff/payInBrowser.cjs"); +const puppeteer = require('puppeteer'); + + + +var myEnv = dotenv.config(); +dotenvExpand.expand(myEnv); + +const CUSTOMER_KEY = "4xf3366al8af85a4"; + +const f = async () => { + console.log("process.env.PAYMENTS_C2B_TERMINAL_PASSWORD", process.env.PAYMENTS_C2B_TERMINAL_PASSWORD) + + const errorsConverter = { + 7: 'Покупатель не найден', + 53: 'Обратитесь к продавцу', + 99: 'Платеж отклонен', + 100: 'Повторите попытку позже', + 101: 'Не пройдена идентификация 3DS', + 102: 'Операция отклонена, пожалуйста обратитесь в интернет-магазин или воспользуйтесь другой картой', + 103: 'Повторите попытку позже', + 119: 'Превышено кол-во запросов на авторизацию', + 191: 'Некорректный статус договора, обратитесь к вашему менеджеру', + 1001: 'Свяжитесь с банком, выпустившим карту, чтобы провести платеж', + 1003: 'Неверный merchant ID', + 1004: 'Карта украдена. Свяжитесь с банком, выпустившим карту', + 1005: 'Платеж отклонен банком, выпустившим карту', + 1006: 'Свяжитесь с банком, выпустившим карту, чтобы провести платеж', + 1007: 'Карта украдена. Свяжитесь с банком, выпустившим карту', + 1008: 'Платеж отклонен, необходима идентификация', + 1012: 'Такие операции запрещены для этой карты', + 1013: 'Повторите попытку позже', + 1014: 'Карта недействительна. Свяжитесь с банком, выпустившим карту', + 1015: 'Попробуйте снова или свяжитесь с банком, выпустившим карту', + 1019: 'Платеж отклонен — попробуйте снова', + 1030: 'Повторите попытку позже', + 1033: 'Истек срок действия карты. Свяжитесь с банком, выпустившим карту', + 1034: 'Попробуйте повторить попытку позже', + 1038: 'Превышено количество попыток ввода ПИН-кода', + 1039: 'Платеж отклонен — счет не найден', + 1041: 'Карта утеряна. Свяжитесь с банком, выпустившим карту', + 1043: 'Карта украдена. Свяжитесь с банком, выпустившим карту', + 1051: 'Недостаточно средств на карте', + 1053: 'Платеж отклонен — счет не найден', + 1054: 'Истек срок действия карты', + 1055: 'Неверный ПИН', + 1057: 'Такие операции запрещены для этой карты', + 1058: 'Такие операции запрещены для этой карты', + 1059: 'Подозрение в мошенничестве. Свяжитесь с банком, выпустившим карту', + 1061: 'Превышен дневной лимит платежей по карте', + 1062: 'Платежи по карте ограничены', + 1063: 'Операции по карте ограничены', + 1064: 'Проверьте сумму', + 1065: 'Превышен дневной лимит транзакций', + 1075: 'Превышено число попыток ввода ПИН-кода', + 1076: 'Платеж отклонен — попробуйте снова', + 1077: 'Коды не совпадают — попробуйте снова', + 1080: 'Неверный срок действия', + 1082: 'Неверный CVV', + 1086: 'Платеж отклонен — не получилось подтвердить ПИН-код', + 1088: 'Ошибка шифрования. Попробуйте снова', + 1089: 'Попробуйте повторить попытку позже', + 1091: 'Банк, выпустивший карту недоступен для проведения авторизации', + 1092: 'Платеж отклонен — попробуйте снова', + 1093: 'Подозрение в мошенничестве. Свяжитесь с банком, выпустившим карту', + 1094: 'Системная ошибка', + 1096: 'Повторите попытку позже', + 9999: 'Внутренняя ошибка системы', + }; + + const getError = (errorCode) => + errorCode === '0' ? undefined : errorsConverter[errorCode] || 'broken'; + + const getUrl = (method) => + `${process.env.PAYMENTS_C2B_URL}/${method}`; + +const _generateToken = (dataWithPassword) => { + const dataString = Object.keys(dataWithPassword) + .sort((a, b) => a.localeCompare(b)) + .map((key) => dataWithPassword[key]) + .reduce((acc, item) => `${acc}${item}`, ''); + console.log({ dataString }); + const hash = crypto.createHash('sha256').update(dataString).digest('hex'); + console.log({ hash }); + return hash; + }; + + const generateToken = (data) => { + const { Receipt, DATA, Shops, ...restData } = data; + const dataWithPassword = { + ...restData, + Password: process.env.PAYMENTS_C2B_TERMINAL_PASSWORD, + }; + console.log({ dataWithPassword }); + return _generateToken(dataWithPassword); + }; + + const init = async (options) => { + try { + const response = await axios({ + method: 'post', + url: getUrl('Init'), + headers: { + 'Content-Type': 'application/json', + }, + data: { ...options, Token: generateToken(options) }, + }); + + const error = getError(response.data.ErrorCode); + + return { + error, + request: options, + response: response.data, + }; + } catch (error) { + return { + error, + request: options, + response: null, + }; + } + }; + + const options = { + TerminalKey: process.env.PAYMENTS_C2B_TERMINAL_KEY, + OrderId: uniqid(), + CustomerKey: CUSTOMER_KEY, + PayType: 'T', + Amount: 5500, + Description: 'Test shopping', + Language: 'ru', + Recurrent: 'Y', + DATA: { + Email: process.env.PAYMENTS_C2B_PHONE, + Phone: process.env.PAYMENTS_C2B_EMAIL, + // "DefaultCard": 10495015 + } + }; + console.log({options}); + + const getCardList = async (options) => { + try { + const response = await axios({ + method: 'post', + url: getUrl('GetCardList'), + headers: { + 'Content-Type': 'application/json', + }, + data: { ...options, Token: generateToken(options) }, + }); + + const error = getError(response.data.ErrorCode || '0'); + + return { + error, + request: options, + response: response.data, + }; + } catch (error) { + return { + error, + request: options, + response: null, + }; + } + }; + + + + + let initResult = await init(options); + console.log({initResult}); + + const getCardListOptions = { + TerminalKey: process.env.PAYMENTS_C2B_TERMINAL_KEY, + CustomerKey: CUSTOMER_KEY, + }; + + console.log(await getCardList(getCardListOptions)); + + const browser = await puppeteer.launch({ args: [/*'--no-sandbox'*/] }); + const page = await browser.newPage(); + await payInBrowser({ + browser, + page, + url: initResult.response.PaymentURL, + }); +} + +f(); \ No newline at end of file diff --git a/update-handler.js b/update-handler.js new file mode 100644 index 00000000..27d0ef41 --- /dev/null +++ b/update-handler.js @@ -0,0 +1,71 @@ +({ deep, data: { newLink, triggeredByLinkId } }) => { + const timestamp = Date.now(); + + const containTypeLinkId = deep.id('@deep-foundation/core', 'Contain'); + + const valueTypeLinkId = deep.id("@deep-foundation/core", "Value"); + const containToValueTypeLinkSelectQuery = { + type_id: containTypeLinkId, + to: { + in: { + type_id: valueTypeLinkId, + from_id: newLink.type_id, + } + } + }; + const { data: [containLinkToValueType] } = deep.select(containToValueTypeLinkSelectQuery); + if(!containLinkToValueType) { + throw new Error(`Query ${JSON.stringify(containToValueTypeLinkSelectQuery)} has not found a link`); + } + const specificValueTypeLinkId = containLinkToValueType.to_id; + + const reservedIds = deep.reserve(3); + + const logValueLinkInsertData = { + id: reservedIds[0], + type_id: deep.id("@deep-foundation/core", "Value"), + from_id: newLink.type_id, + to_id: deep.id("@deep-foundation/core", specificValueTypeLinkId), + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + [containLinkToValueType.value.value]: { + data: { value: newLink.value.value } + } + }; + + const logUpdateInsertData = { + id: reservedIds[1], + type_id: deep.id("@deep-foundation/logger", "LogUpdate"), + from_id: logValueLinkInsertData.id, + to_id: newLink.id, + number: timestamp, + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + const logSubjectInsertData = { + type_id: deep.id("@deep-foundation/logger", "LogSubject"), + from_id: triggeredByLinkId, + to_id: logUpdateInsertData.id, + in: { + data: { + type_id: containTypeLinkId, + from_id: triggeredByLinkId, + }, + }, + }; + + await deep.insert([ + logValueLinkInsertData, + logUpdateInsertData, + logSubjectInsertData + ]) +} \ No newline at end of file