Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payments tinkoff c2c package #92

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2158cba
Fix typo
FreePhoenix888 Nov 1, 2022
5922f5d
Merge branch 'payments-tinkoff-c2b' into payments-tinkoff-c2c
FreePhoenix888 Nov 1, 2022
2a8cd87
Merge branch 'payments-tinkoff-c2b' into payments-tinkoff-c2c
FreePhoenix888 Nov 1, 2022
f7691bf
Add e2c code to onConfirmed
FreePhoenix888 Nov 1, 2022
100f299
Add e2c code
FreePhoenix888 Nov 1, 2022
58afcd5
Fix typo
FreePhoenix888 Nov 1, 2022
ffa8b80
Merge branch 'payments-tinkoff-c2b' into payments-tinkoff-c2c
FreePhoenix888 Nov 1, 2022
7f65244
Add c2c functions
FreePhoenix888 Nov 1, 2022
401c120
Fix typos
FreePhoenix888 Nov 1, 2022
4a1d339
Update payInBrowser
FreePhoenix888 Nov 1, 2022
8ae2725
Merge branch 'payments-tinkoff-c2b' into payments-tinkoff-c2c
FreePhoenix888 Nov 1, 2022
5f65869
Fix code
FreePhoenix888 Nov 1, 2022
2575d43
Fix
FreePhoenix888 Nov 1, 2022
64ff9fe
Add cancel
FreePhoenix888 Nov 2, 2022
043ac65
Add addCard
FreePhoenix888 Nov 2, 2022
25bfeee
Add addCard
FreePhoenix888 Nov 2, 2022
0ecc0f5
Add addCustomer
FreePhoenix888 Nov 2, 2022
e38e0a8
require crypto
FreePhoenix888 Nov 2, 2022
412422d
Add payment
FreePhoenix888 Nov 2, 2022
8ee6e29
Add init
FreePhoenix888 Nov 2, 2022
8a9dc57
Respont okay at start
FreePhoenix888 Nov 2, 2022
ea0556e
Add addCardInBrowser
FreePhoenix888 Nov 2, 2022
31b333f
Add c2c code
FreePhoenix888 Nov 2, 2022
236019b
Require crypto
FreePhoenix888 Nov 2, 2022
e6d5e40
Use c2c token
FreePhoenix888 Nov 2, 2022
f575f7e
Add getCardList
FreePhoenix888 Nov 2, 2022
ad9ef3b
Require sleep
FreePhoenix888 Nov 2, 2022
cddb1aa
Rename
FreePhoenix888 Nov 2, 2022
e0ea483
Add cancel
FreePhoenix888 Nov 2, 2022
07f7838
Make c2c workable
FreePhoenix888 Nov 3, 2022
68fde66
Create Income, StoargeClient after e2c operations
FreePhoenix888 Nov 3, 2022
4a5fcc3
Make workable
FreePhoenix888 Nov 5, 2022
a7348b4
Merge branch 'payments-tinkoff-c2b' into payments-tinkoff-c2c
FreePhoenix888 Feb 23, 2023
b85022f
Install prompt-sync for payments-tinkoff-c2c
FreePhoenix888 Feb 23, 2023
d76d3d7
Update draft
FreePhoenix888 Feb 23, 2023
366dc7b
Fix errors
FreePhoenix888 Jan 29, 2024
b3c5e02
Merge branch 'main' into payments-tinkoff-c2c
FreePhoenix888 Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions cancel.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { generateToken } = require("./deep-packages/payments/tinkoff/generateToken.cjs");
const { getError } = require("./deep-packages/payments/tinkoff/getError.cjs");
const { getUrl } = require("./deep-packages/payments/tinkoff/getUrl.cjs");
const dotenv = require('dotenv');
const dotenvExpand = require('dotenv-expand');
const crypto = require('crypto');
const axios = require('axios');

const cancel = async (options) => {
try {
const response = await axios({
method: 'post',
url: getUrl('Cancel'),
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,
};
}
};

var myEnv = dotenv.config();
dotenvExpand.expand(myEnv);

const f = async () => {
const cancelOptions = {
TerminalKey: process.env.PAYMENTS_C2B_TERMINAL_KEY,
PaymentId: 1942727609,
Amount: 3000
}

const cancelResult = await cancel(cancelOptions);
console.log({cancelResult});
}

f();

49 changes: 49 additions & 0 deletions deep-packages/insertHandler.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
exports.insertHandler = async (param) => {
console.log('insertHandler', {param})
const {deep,fileTypeLinkId, fileName, handlerName, handleName, triggerTypeLinkId, code, supportsId, handleOperationTypeLinkId, containTypeLinkId, packageId, handlerTypeLinkId} = param;
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,
},
},
});
};


132 changes: 132 additions & 0 deletions deep-packages/insertNotificationHandler.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
exports.insertNotificationHandler = async (param) => {
console.log('insertNotificationHandler', {param})
const {deep, packageId,notificationPort, notificationRoute, portTypeLinkId, routerListeningTypeLinkId, routerTypeLinkId, routerStringUseTypeLinkId, routeTypeLinkId, handleRouteTypeLinkId, handlerTypeLinkId, supportsId, containTypeLinkId, adminId, fileTypeLinkId, handlerName, code} = param;
const insertData = {
type_id: portTypeLinkId,
number: {
data: { value: notificationPort },
},
in: {
data: [
{
type_id: routerListeningTypeLinkId,
in: {
data: {
type_id: containTypeLinkId,
from_id: packageId,
},
},
from: {
data: {
type_id: routerTypeLinkId,
in: {
data: [
{
type_id: routerStringUseTypeLinkId,
in: {
data: {
type_id: containTypeLinkId,
from_id: packageId,
string: {
data: {
value: handlerName,
},
},
},
},
string: {
data: {
value:
notificationRoute,
},
},
from: {
data: {
type_id: routeTypeLinkId,
in: {
data: {
type_id: containTypeLinkId,
from_id: packageId,
},
},
out: {
data: {
type_id: handleRouteTypeLinkId,
in: {
data: [
{
type_id: containTypeLinkId,
from_id: packageId,
}
]
},
to: {
data: {
type_id: handlerTypeLinkId,
from_id: supportsId,
in: {
data: {
type_id: containTypeLinkId,
// from_id: deep.linkId,
from_id: packageId,
string: {
data: {
value: handlerName,
},
},
},
},
to: {
data: {
type_id: fileTypeLinkId,
string: {
data: {
value: code,
},
},
in: {
data: {
type_id: containTypeLinkId,
from_id: packageId,
string: {
data: {
value: handlerName,
},
},
},
},
},
},
},
},
},
},
},
},
},
{
type_id: containTypeLinkId,
from_id: packageId,
}
],
},
},
},
}
,
{
type_id: containTypeLinkId,
from_id: packageId,
}
],
},
};
console.log(JSON.stringify({insertData},null,2))
return await deep.insert(
insertData,
{
name: 'INSERT_HANDLE_ROUTE_HIERARCHICAL',
}
)
}

15 changes: 15 additions & 0 deletions deep-packages/payments/tinkoff/_generateToken.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const crypto = require('crypto');

const _generateToken = (dataWithPassword) => {
const dataString = Object.keys(dataWithPassword)
.sort((a, b) => a.localeCompare(b))
.map(key => dataWithPassword[key])
.reduce((acc, item) => `${acc}${item}`, '');
const hash = crypto
.createHash('sha256')
.update(dataString)
.digest('hex');
return hash;
};

exports._generateToken = _generateToken;
33 changes: 33 additions & 0 deletions deep-packages/payments/tinkoff/addCard.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const axios = require('axios');
const { generateToken } = require("./generateToken.cjs");
const { getError } = require("./getError.cjs");
const { getUrl } = require("./getUrl.cjs");

const addCard = async (options) => {
try {
const response = await axios({
method: 'post',
url: getUrl('AddCard'),
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,
};
}
};

exports.addCard = addCard;
44 changes: 44 additions & 0 deletions deep-packages/payments/tinkoff/addCardInBrowser.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { sleep } = require("../../sleep.cjs");

const addCardInBrowser = async ({ page, browser, url }) => {
await page.goto(url, { waitUntil: 'networkidle2' });
await page.waitForSelector('#card-number__input');
await sleep(300);
await page.type('#card-number__input', process.env.PAYMENTS_C2B_CARD_NUMBER_SUCCESS); // card number
await sleep(300);
await page.keyboard.press('Tab');
await sleep(300);
await page.type('#card-expiration__input', process.env.PAYMENTS_C2B_CARD_EXPDATE); // expired date
await sleep(300);
await page.keyboard.press('Tab');
await sleep(300);
const needToEnterCVC = await page.evaluate(() => {
return !!document.querySelector('#cvv__input1');
});
if (needToEnterCVC) {
console.log('NEED CVC!!!!!!!');
await page.type('#cvv__input1', process.env.PAYMENTS_C2B_CARD_CVC[0]); // CVC code
await sleep(300);
await page.keyboard.press('Tab');
await sleep(300);
await page.type('#cvv__input2', process.env.PAYMENTS_C2B_CARD_CVC[1]); // CVC code
await sleep(300);
await page.keyboard.press('Tab');
await sleep(300);
await page.type('#cvv__input3', process.env.PAYMENTS_C2B_CARD_CVC[2]); // CVC code
await sleep(3000);
} else {
console.log('NO NEED CVC!!!!!!!');
}
await sleep(1000);
await page.keyboard.press('Tab');
await sleep(2000);
await page.click('.form-submit button'); // submit button
await sleep(3000);
// await sleep(100);
// await page.close();
// await sleep(100);
await browser.close();
};

exports.addCardInBrowser = addCardInBrowser;
54 changes: 54 additions & 0 deletions deep-packages/payments/tinkoff/c2c/addCard.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const axios = require('axios');
const { generateToken } = require("./generateToken.cjs");
const { getError } = require("./getError.cjs");
const { getUrl } = require("./getUrl.cjs");

const objectToFormData = (details) => {
const formBody = [];
for (const property in details) {
const encodedKey = encodeURIComponent(property);
const encodedValue = encodeURIComponent(details[property]);
formBody.push(`${encodedKey}=${encodedValue}`);
}
return formBody.join('&');
};

const addCard = async (options) => {
try {
const response = await axios({
method: 'post',
url: getUrl('AddCard'),
headers: {
'Content-Type': 'application/json',
},
data: { ...options, Token: generateToken(options) },
});

const error = getError(response.data.ErrorCode);

const d = {
error,
request: options,
response: response.data,
};
options?.log && options.log(d);

return {
error,
request: options,
response: response.data,
};
} catch (e) {
console.log(e?.response?.data);
console.log(e?.response?.status);
console.log(e?.response?.data?.Causes);
const error = getError(e?.response?.ErrorCode);
return {
error,
request: options,
response: null,
};
}
};

exports.addCard = addCard;
Loading
Loading