{"id":503848,"date":"2026-11-18T23:35:56","date_gmt":"2026-11-18T20:35:56","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=503848"},"modified":"2026-11-18T23:35:56","modified_gmt":"2026-11-18T20:35:56","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=503848","title":{"rendered":"Click SHOP API: \u043f\u043e\u0434\u043f\u0438\u0441\u044c, Prepare \u0438 Complete, \u0438 \u043d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043b\u043e\u0432\u0438\u0442 \u00ab\u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043e, \u0430 \u0437\u0430\u043a\u0430\u0437\u0430 \u043d\u0435\u0442\u00bb"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/articles\/1109614\/\" rel=\"noopener nofollow\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u0431\u044b\u043b Payme: \u0448\u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 JSON-RPC, \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0423 Click \u0432\u0441\u0451 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0438\u043d\u0430\u0447\u0435: \u0434\u0432\u0430 \u0448\u0430\u0433\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0448\u0435\u0441\u0442\u0438, \u043f\u043e\u0434\u043f\u0438\u0441\u044c MD5 \u0432\u043c\u0435\u0441\u0442\u043e Basic Auth, \u0441\u0443\u043c\u043c\u0430 \u0432 \u0441\u0443\u043c\u0430\u0445 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u0438\u0439\u0438\u043d\u043e\u0432 \u0438, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u2014 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u043d\u0438 \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043d\u043e \u0431\u0435\u0437 \u0447\u0435\u0433\u043e \u044f \u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b \u043f\u0440\u0438\u0451\u043c \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439: \u043d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430.<\/p>\n<h3>\u0427\u0435\u043c Click \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 Payme<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">Payme Merchant API<\/p>\n<\/th>\n<th>\n<p align=\"left\">Click SHOP API<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0430\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">JSON-RPC 2.0<\/p>\n<\/td>\n<td>\n<p align=\"left\">POST, <code>application\/x-www-form-urlencoded<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">Basic Auth, \u043a\u043b\u044e\u0447 \u043a\u0430\u0441\u0441\u044b<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>sign_string<\/code>, MD5 \u0441 <code>SECRET_KEY<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0443\u043c\u043c\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0446\u0435\u043b\u043e\u0435, \u0432 \u0442\u0438\u0439\u0438\u043d\u0430\u0445<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0434\u0440\u043e\u0431\u043d\u043e\u0435, \u0432 \u0441\u0443\u043c\u0430\u0445<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041a\u043b\u044e\u0447 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>params.id<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>click_trans_id<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0428\u0430\u0433\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">Check \u2192 Create \u2192 Perform, \u043f\u043b\u044e\u0441 Cancel, CheckTransaction, GetStatement<\/p>\n<\/td>\n<td>\n<p align=\"left\">Prepare (<code>action=0<\/code>) \u2192 Complete (<code>action=1<\/code>)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0432\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u043e\u0442 \u0436\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0448\u0438\u0431\u043a\u0430 <code>-4<\/code>, \u00abAlready paid\u00bb<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044f\u0442 \u043a\u043e\u0434 \u0441 Payme. \u041e\u0431 \u044d\u0442\u043e\u043c \u043d\u0438\u0436\u0435.<\/p>\n<h3>\u041f\u043e\u0434\u043f\u0438\u0441\u044c<\/h3>\n<p>\u0423 \u0434\u0432\u0443\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0440\u0430\u0437\u043d\u044b\u0435:<\/p>\n<pre><code>Prepare:  md5(click_trans_id + service_id + SECRET_KEY + merchant_trans_id              + amount + action + sign_time)Complete: md5(click_trans_id + service_id + SECRET_KEY + merchant_trans_id              + merchant_prepare_id + amount + action + sign_time)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<p>\u0421\u0442\u0440\u043e\u043a\u0438 \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u0440\u0438\u0448\u043b\u0438. <code>amount<\/code> \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e: \u0435\u0441\u043b\u0438 Click \u043f\u0440\u0438\u0441\u043b\u0430\u043b <code>15000.00<\/code>, \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e <code>15000.00<\/code>, \u0430 \u043d\u0435 <code>15000<\/code>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0432 \u0447\u0438\u0441\u043b\u0430 \u0438 \u0434\u0430\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441 \u0437\u0430\u043a\u0430\u0437\u043e\u043c \u0441\u0443\u043c\u043c\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u044b\u0435 \u0442\u0438\u0439\u0438\u043d\u044b \u0431\u0435\u0437 \u0443\u0447\u0430\u0441\u0442\u0438\u044f <code>float<\/code>:<\/p>\n<pre><code>function sumToTiyin(s: string): bigint {  const m = \/^(\\d+)(?:\\.(\\d{1,2}))?$\/.exec(s);  if (!m) throw new ClickError(-2);  return BigInt(m[1]) * 100n + BigInt((m[2] ?? '').padEnd(2, '0'));}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a: <code>0<\/code> \u2014 \u0443\u0441\u043f\u0435\u0445, <code>-1<\/code> \u2014 \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u044c, <code>-2<\/code> \u2014 \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430, <code>-3<\/code> \u2014 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, <code>-4<\/code> \u2014 \u0443\u0436\u0435 \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043e, <code>-5<\/code> \u2014 \u0437\u0430\u043a\u0430\u0437 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, <code>-6<\/code> \u2014 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, <code>-7<\/code> \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, <code>-8<\/code> \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0442 Click, <code>-9<\/code> \u2014 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u0430.<\/p>\n<h3>Prepare<\/h3>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 Click \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043e\u043f\u043b\u0430\u0442\u0443 \u0437\u0430 \u044d\u0442\u043e\u0442 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0443\u043c\u043c\u0443. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u043a\u0430\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d, \u0447\u0442\u043e \u0442\u043e\u0432\u0430\u0440 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438 \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442. \u041c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0432\u0430\u0440.<\/p>\n<pre><code>async function prepare(r: ClickPrepare): Promise&lt;ClickResponse&gt; {  if (!verifySign(r, { withPrepareId: false })) return err(-1);  if (r.action !== '0') return err(-3);  return db.tx(async (tx) =&gt; {    const order = await tx.findOrderForUpdate(r.merchant_trans_id);    if (!order) return err(-5);    if (order.status === 'paid') return err(-4);    if (order.amount_tiyin !== sumToTiyin(r.amount)) return err(-2);    \/\/ insert \u2026 on conflict do nothing, \u0437\u0430\u0442\u0435\u043c select: \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 Prepare \u0441 \u0442\u0435\u043c \u0436\u0435    \/\/ click_trans_id \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 merchant_prepare_id.    const t = await tx.insertOrGet('provider_txn',      { provider: 'click', external_id: r.click_trans_id },      { order_id: order.id, amount_tiyin: sumToTiyin(r.amount), state: 1, create_time: Date.now() });    if (t.state &lt; 0) return err(-9);    return ok({      click_trans_id: r.click_trans_id,      merchant_trans_id: r.merchant_trans_id,      merchant_prepare_id: t.id,    });  });}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 <code>provider_txn<\/code> \u0442\u0430 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0434\u043b\u044f Payme, \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e <code>(provider, external_id)<\/code>. \u0415\u0451 <code>id<\/code> \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <code>merchant_prepare_id<\/code>.<\/p>\n<h3>Complete<\/h3>\n<pre><code>async function complete(r: ClickComplete): Promise&lt;ClickResponse&gt; {  if (!verifySign(r, { withPrepareId: true })) return err(-1);  if (r.action !== '1') return err(-3);  return db.tx(async (tx) =&gt; {    const t = await tx.lockTxnById(Number(r.merchant_prepare_id));    if (!t || t.external_id !== r.click_trans_id) return err(-6);    if (t.state === 2) return err(-4);   \/\/ \u043f\u043e\u0432\u0442\u043e\u0440 Complete: \u00abAlready paid\u00bb    if (t.state &lt; 0) return err(-9);    if (Number(r.error) &lt; 0) {      \/\/ Click \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043b\u0430\u0442\u0451\u0436 \u043d\u0435 \u043f\u0440\u043e\u0448\u0451\u043b: \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u0443 \u0441\u0435\u0431\u044f.      await cancel(tx, t, -1, null);      return err(-9);    }    await tx.update('provider_txn', t.id, { state: 2, perform_time: Date.now() });    await tx.markOrderPaid(t.order_id, t.id);    await tx.insert('outbox', { type: 'order.paid', order_id: t.order_id });    return ok({      click_trans_id: r.click_trans_id,      merchant_trans_id: r.merchant_trans_id,      merchant_confirm_id: t.id,    });  });}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412\u043e\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441 Payme. \u041d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 <code>Complete<\/code> \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043b\u0430\u0442\u0435\u0436\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Click \u043f\u0440\u0435\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c <code>-4<\/code>, \u0430 \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0443\u0441\u043f\u0435\u0445. \u0412 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0438 \u043a SHOP API \u044d\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u044f\u043c\u043e: \u0435\u0441\u043b\u0438 Prepare \u043f\u0440\u043e\u0448\u0451\u043b \u0438 \u0434\u0435\u043d\u044c\u0433\u0438 \u0441\u043f\u0438\u0441\u0430\u043d\u044b, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 Complete \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u043a\u0440\u043e\u043c\u0435 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u2014 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0436\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0451\u043d (<code>-4<\/code>) \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0439 (<code>-9<\/code>).<\/p>\n<p>\u0418\u0437 \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430. \u0414\u0435\u043d\u044c\u0433\u0438 \u0441\u043f\u0438\u0441\u0430\u043d\u044b, \u0430 \u0442\u043e\u0432\u0430\u0440 \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u043d \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435. \u041e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 <code>Complete<\/code> \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u043d\u0435\u043b\u044c\u0437\u044f: \u0434\u0435\u043d\u044c\u0433\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0437\u0430\u0432\u0438\u0441\u043d\u0443\u0442, \u0430 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0439\u0434\u0451\u0442 \u043d\u0430 \u0440\u0443\u0447\u043d\u043e\u0439 \u0440\u0430\u0437\u0431\u043e\u0440. \u041d\u0443\u0436\u043d\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0443\u0441\u043f\u0435\u0445\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043b\u0430\u0442\u0451\u0436 \u0447\u0435\u0440\u0435\u0437 Merchant API: <code>DELETE \/v2\/merchant\/payment\/reversal\/:service_id\/:payment_id<\/code>. \u0418 \u043d\u0435 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c. \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0443 \u043e\u0442\u043c\u0435\u043d\u044b \u0436\u0451\u0441\u0442\u043a\u0438\u0435: \u043f\u043b\u0430\u0442\u0451\u0436 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d \u0438 \u043e\u043f\u043b\u0430\u0447\u0435\u043d \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0430\u0440\u0442\u043e\u0439, \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u0430\u0442\u0451\u0436 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u044f\u0446\u0430 (\u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u2014 \u043b\u0438\u0448\u044c \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u0435\u043d\u044c \u043d\u043e\u0432\u043e\u0433\u043e), \u0430 UZCARD \u0432\u043f\u0440\u0430\u0432\u0435 \u043e\u0442\u043c\u0435\u043d\u0443 \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c. \u0417\u043d\u0430\u0447\u0438\u0442, \u0441\u0432\u0435\u0440\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0432 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c.<\/p>\n<h3>\u041d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430: \u0442\u0440\u0435\u0442\u0438\u0439 \u0441\u043b\u043e\u0439<\/h3>\n<p>\u0418\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0434\u0443\u0431\u043b\u0435\u0439, \u043d\u043e \u043d\u0435 \u043e\u0442 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u043f\u0430\u043b \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0440\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u043a\u0430\u0437\u0430. \u041f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043e\u0442\u043c\u0435\u043d\u0438\u043b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0443 \u0441\u0435\u0431\u044f. \u0422\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0451 \u0441\u0442\u043e\u0438\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u043d\u043e\u0447\u044c, \u0430 \u043d\u0435 \u0440\u0430\u0437 \u0432 \u043c\u0435\u0441\u044f\u0446 \u043f\u0435\u0440\u0435\u0434 \u0430\u043a\u0442\u043e\u043c.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u2014 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0443\u0436\u0435 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442:<\/p>\n<pre><code class=\"sql\">-- 1. \u041e\u043f\u043b\u0430\u0447\u0435\u043d\u043e, \u0430 \u0437\u0430\u043a\u0430\u0437 \u043d\u0435 \u043e\u043f\u043b\u0430\u0447\u0435\u043d.select t.* from provider_txn t join orders o on o.id = t.order_id where t.state = 2 and o.status &lt;&gt; 'paid';-- 2. \u0417\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043d, \u0430 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442.select o.* from orders o where o.status = 'paid'   and not exists (select 1 from provider_txn t where t.order_id = o.id and t.state = 2);-- 3. \u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043e\u043f\u043b\u0430\u0442\u0430: \u0434\u0432\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437.select order_id, count(*) from provider_txn where state = 2 group by order_id having count(*) &gt; 1;-- 4. \u0417\u0430\u0432\u0438\u0441\u0448\u0438\u0435: \u00ab\u0441\u043e\u0437\u0434\u0430\u043d\u0430\u00bb \u0434\u043e\u043b\u044c\u0448\u0435 12 \u0447\u0430\u0441\u043e\u0432.select * from provider_txn where state = 1   and create_time &lt; (extract(epoch from now()) * 1000)::bigint - 43200000;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u0435\u0442 \u043d\u0430 \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u041a\u043b\u0438\u0435\u043d\u0442, \u0431\u0440\u043e\u0441\u0438\u0432\u0448\u0438\u0439 \u043e\u043f\u043b\u0430\u0442\u0443 \u0432 Payme, \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Click, \u0438 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e: \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0434\u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u044f \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u0438\u0437\u0440\u0435\u0434\u043a\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u043f\u043b\u0430\u0442\u0451\u0436.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u2014 \u0441\u0432\u0435\u0440\u043a\u0430 \u0441 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c. \u0423 Click \u0432 Merchant API \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430 \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u0437\u0430\u043a\u0430\u0437\u0430: <code>GET \/v2\/merchant\/payment\/status_by_mti\/:service_id\/:merchant_trans_id\/YYYY-MM-DD<\/code>, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Auth: merchant_user_id:digest:timestamp<\/code>, \u0433\u0434\u0435 <code>digest = sha1(timestamp + secret_key)<\/code>, \u0430 timestamp \u2014 Unix-\u0432\u0440\u0435\u043c\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043d\u0435 \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043a\u0430\u043a \u0443 Payme. \u0415\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u0435\u0447\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 1, 2 \u0438 4. \u0421 Payme \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435: <code>GetStatement<\/code> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u043c Payme \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441 \u0432\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0432\u0430\u0448\u0435\u0439 \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0430 \u0441\u0430\u043c\u0438 \u0432\u044b \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0435\u0441\u044c \u0441 \u0440\u0435\u0435\u0441\u0442\u0440\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u0430\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<pre><code>async function nightlyReconciliation(day: Date) {  const findings: Finding[] = [    ...(await db.many(Q_PAID_TXN_UNPAID_ORDER)).map((r) =&gt; f('paid_not_fulfilled', r)),    ...(await db.many(Q_PAID_ORDER_NO_TXN)).map((r) =&gt; f('order_without_txn', r)),    ...(await db.many(Q_DOUBLE_PAYMENT)).map((r) =&gt; f('double_payment', r)),    ...(await db.many(Q_STUCK_PENDING)).map((r) =&gt; f('stuck_pending', r)),  ];  for (const x of findings.filter((x) =&gt; x.provider === 'click')) {    x.external = await click.statusByMti(x.merchant_trans_id, day);  }  const registry = await loadProviderRegistry(day);  await archiveRaw(day, registry);                                   \/\/ \u043a\u0430\u043a \u043f\u0440\u0438\u0448\u0451\u043b, \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438  findings.push(...diffById(await db.txnsForDay(day), registry));   \/\/ \u043f\u043e ID, \u043d\u0435 \u043f\u043e \u0441\u0443\u043c\u043c\u0435  for (const x of findings) await tickets.open(x);                  \/\/ \u0437\u0430\u0434\u0430\u0447\u0430 \u0441 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0414\u0432\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u044f\u0442 \u0434\u043e\u0440\u043e\u0436\u0435 \u043a\u043e\u0434\u0430. \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0443\u043c\u043c\u0435 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: \u0434\u0432\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0432 \u043e\u0434\u043d\u0443 \u043c\u0438\u043d\u0443\u0442\u0443 \u2014 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0434\u0435\u043b\u043e. \u0418 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0440\u0435\u0435\u0441\u0442\u0440 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u043e \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d.<\/p>\n<h3>\u0427\u0435\u043a-\u043b\u0438\u0441\u0442 \u0434\u043b\u044f Click<\/h3>\n<ol>\n<li>\n<p>\u041a\u043b\u044e\u0447 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 <code>click_trans_id<\/code> \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0432 \u0431\u0430\u0437\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043f\u0438\u0441\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0435\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0437\u0430\u043a\u0430\u0437\u043e\u043c \u0432 \u0446\u0435\u043b\u044b\u0445 \u0442\u0438\u0439\u0438\u043d\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 <code>Complete<\/code> \u2014 <code>-4<\/code>; \u043d\u0430 <code>error &lt; 0<\/code> \u043e\u0442 Click \u2014 \u043e\u0442\u043c\u0435\u043d\u0430 \u0443 \u0441\u0435\u0431\u044f \u0438 <code>-9<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u0432\u0430\u0440 \u043d\u0435\u043b\u044c\u0437\u044f \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u2014 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 <code>Complete<\/code> \u0438 reversal \u0432 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c, \u0430 \u043d\u0435 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430: \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0435\u0441\u0442\u0440, \u043a\u0430\u0436\u0434\u043e\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h3>\n<ul>\n<li>\n<p>Click, SHOP API \u2014 \u0437\u0430\u043f\u0440\u043e\u0441\u044b: <a href=\"https:\/\/docs.click.uz\/shop-api\/requests\" rel=\"noopener nofollow\">https:\/\/docs.click.uz\/shop-api\/requests<\/a><\/p>\n<\/li>\n<li>\n<p>Click, SHOP API \u2014 \u043e\u0448\u0438\u0431\u043a\u0438: <a href=\"https:\/\/docs.click.uz\/shop-api\/errors\" rel=\"noopener nofollow\">https:\/\/docs.click.uz\/shop-api\/errors<\/a><\/p>\n<\/li>\n<li>\n<p>Click, Merchant API \u2014 status_by_mti, reversal, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f: <a href=\"https:\/\/docs.click.uz\/merchant-api\/requests\" rel=\"noopener nofollow\">https:\/\/docs.click.uz\/merchant-api\/requests<\/a><\/p>\n<\/li>\n<li>\n<p>Payme Business, GetStatement: <a href=\"https:\/\/developer.help.paycom.uz\/metody-merchant-api\/getstatement\" rel=\"noopener nofollow\">https:\/\/developer.help.paycom.uz\/metody-merchant-api\/getstatement<\/a><\/p>\n<\/li>\n<li>\n<p>Transactional outbox: <a href=\"https:\/\/microservices.io\/patterns\/data\/transactional-outbox.html\" rel=\"noopener nofollow\">https:\/\/microservices.io\/patterns\/data\/transactional-outbox.html<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1109616\/\">https:\/\/habr.com\/ru\/articles\/1109616\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0431\u044b\u043b Payme: \u0448\u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 JSON-RPC, \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0423 Click \u0432\u0441\u0451 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0438\u043d\u0430\u0447\u0435: \u0434\u0432\u0430 \u0448\u0430\u0433\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0448\u0435\u0441\u0442\u0438, \u043f\u043e\u0434\u043f\u0438\u0441\u044c MD5 \u0432\u043c\u0435\u0441\u0442\u043e Basic Auth, \u0441\u0443\u043c\u043c\u0430 \u0432 \u0441\u0443\u043c\u0430\u0445 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u0438\u0439\u0438\u043d\u043e\u0432 \u0438, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f.\u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u2014 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u043d\u0438 \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043d\u043e \u0431\u0435\u0437 \u0447\u0435\u0433\u043e \u044f \u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b \u043f\u0440\u0438\u0451\u043c \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439: \u043d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430.\u0427\u0435\u043c Click \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 PaymePayme Merchant APIClick SHOP API\u0424\u043e\u0440\u043c\u0430\u0442JSON-RPC 2.0POST, application\/x-www-form-urlencoded\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430Basic Auth, \u043a\u043b\u044e\u0447 \u043a\u0430\u0441\u0441\u044bsign_string, MD5 \u0441 SECRET_KEY\u0421\u0443\u043c\u043c\u0430\u0446\u0435\u043b\u043e\u0435, \u0432 \u0442\u0438\u0439\u0438\u043d\u0430\u0445\u0434\u0440\u043e\u0431\u043d\u043e\u0435, \u0432 \u0441\u0443\u043c\u0430\u0445\u041a\u043b\u044e\u0447 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438params.idclick_trans_id\u0428\u0430\u0433\u0438Check \u2192 Create \u2192 Perform, \u043f\u043b\u044e\u0441 Cancel, CheckTransaction, GetStatementPrepare (action=0) \u2192 Complete (action=1)\u041f\u043e\u0432\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0430\u0442\u043e\u0442 \u0436\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\u043e\u0448\u0438\u0431\u043a\u0430 -4, \u00abAlready paid\u00bb\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044f\u0442 \u043a\u043e\u0434 \u0441 Payme. \u041e\u0431 \u044d\u0442\u043e\u043c \u043d\u0438\u0436\u0435.\u041f\u043e\u0434\u043f\u0438\u0441\u044c\u0423 \u0434\u0432\u0443\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u0440\u0430\u0437\u043d\u044b\u0435:Prepare:  md5(click_trans_id + service_id + SECRET_KEY + merchant_trans_id              + amount + action + sign_time)Complete: md5(click_trans_id + service_id + SECRET_KEY + merchant_trans_id              + merchant_prepare_id + amount + action + sign_time)\u0421\u0442\u0440\u043e\u043a\u0438 \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u0440\u0438\u0448\u043b\u0438. amount \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0434\u043f\u0438\u0441\u044c\u044e: \u0435\u0441\u043b\u0438 Click \u043f\u0440\u0438\u0441\u043b\u0430\u043b 15000.00, \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e 15000.00, \u0430 \u043d\u0435 15000. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0432 \u0447\u0438\u0441\u043b\u0430 \u0438 \u0434\u0430\u0442\u044b.\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441 \u0437\u0430\u043a\u0430\u0437\u043e\u043c \u0441\u0443\u043c\u043c\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u044b\u0435 \u0442\u0438\u0439\u0438\u043d\u044b \u0431\u0435\u0437 \u0443\u0447\u0430\u0441\u0442\u0438\u044f float:function sumToTiyin(s: string): bigint {  const m = \/^(\\d+)(?:\\.(\\d{1,2}))?$\/.exec(s);  if (!m) throw new ClickError(-2);  return BigInt(m[1]) * 100n + BigInt((m[2] ?? &#187;).padEnd(2, &#8216;0&#8217;));}\u041a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a: 0 \u2014 \u0443\u0441\u043f\u0435\u0445, -1 \u2014 \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u044c, -2 \u2014 \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430, -3 \u2014 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, -4 \u2014 \u0443\u0436\u0435 \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043e, -5 \u2014 \u0437\u0430\u043a\u0430\u0437 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, -6 \u2014 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, -7 \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, -8 \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0442 Click, -9 \u2014 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u0430.Prepare\u041d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 Click \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043e\u043f\u043b\u0430\u0442\u0443 \u0437\u0430 \u044d\u0442\u043e\u0442 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0443\u043c\u043c\u0443. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u043a\u0430\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d, \u0447\u0442\u043e \u0442\u043e\u0432\u0430\u0440 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438 \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442. \u041c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u0437\u0434\u0435\u0441\u044c \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0432\u0430\u0440.async function prepare(r: ClickPrepare): Promise&lt;ClickResponse&gt; {  if (!verifySign(r, { withPrepareId: false })) return err(-1);  if (r.action !== &#8216;0&#8217;) return err(-3);  return db.tx(async (tx) =&gt; {    const order = await tx.findOrderForUpdate(r.merchant_trans_id);    if (!order) return err(-5);    if (order.status === &#8216;paid&#8217;) return err(-4);    if (order.amount_tiyin !== sumToTiyin(r.amount)) return err(-2);    \/\/ insert \u2026 on conflict do nothing, \u0437\u0430\u0442\u0435\u043c select: \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 Prepare \u0441 \u0442\u0435\u043c \u0436\u0435    \/\/ click_trans_id \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 merchant_prepare_id.    const t = await tx.insertOrGet(&#8216;provider_txn&#8217;,      { provider: &#8216;click&#8217;, external_id: r.click_trans_id },      { order_id: order.id, amount_tiyin: sumToTiyin(r.amount), state: 1, create_time: Date.now() });    if (t.state &lt; 0) return err(-9);    return ok({      click_trans_id: r.click_trans_id,      merchant_trans_id: r.merchant_trans_id,      merchant_prepare_id: t.id,    });  });}\u0422\u0430\u0431\u043b\u0438\u0446\u0430 provider_txn \u0442\u0430 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0434\u043b\u044f Payme, \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e (provider, external_id). \u0415\u0451 id \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f merchant_prepare_id.Completeasync function complete(r: ClickComplete): Promise&lt;ClickResponse&gt; {  if (!verifySign(r, { withPrepareId: true })) return err(-1);  if (r.action !== &#8216;1&#8217;) return err(-3);  return db.tx(async (tx) =&gt; {    const t = await tx.lockTxnById(Number(r.merchant_prepare_id));    if (!t || t.external_id !== r.click_trans_id) return err(-6);    if (t.state === 2) return err(-4);   \/\/ \u043f\u043e\u0432\u0442\u043e\u0440 Complete: \u00abAlready paid\u00bb    if (t.state &lt; 0) return err(-9);    if (Number(r.error) &lt; 0) {      \/\/ Click \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043b\u0430\u0442\u0451\u0436 \u043d\u0435 \u043f\u0440\u043e\u0448\u0451\u043b: \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u0443 \u0441\u0435\u0431\u044f.      await cancel(tx, t, -1, null);      return err(-9);    }    await tx.update(&#8216;provider_txn&#8217;, t.id, { state: 2, perform_time: Date.now() });    await tx.markOrderPaid(t.order_id, t.id);    await tx.insert(&#8216;outbox&#8217;, { type: &#8216;order.paid&#8217;, order_id: t.order_id });    return ok({      click_trans_id: r.click_trans_id,      merchant_trans_id: r.merchant_trans_id,      merchant_confirm_id: t.id,    });  });}\u0412\u043e\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441 Payme. \u041d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 Complete \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043b\u0430\u0442\u0435\u0436\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Click \u043f\u0440\u0435\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c -4, \u0430 \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0443\u0441\u043f\u0435\u0445. \u0412 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0438 \u043a SHOP API \u044d\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u044f\u043c\u043e: \u0435\u0441\u043b\u0438 Prepare \u043f\u0440\u043e\u0448\u0451\u043b \u0438 \u0434\u0435\u043d\u044c\u0433\u0438 \u0441\u043f\u0438\u0441\u0430\u043d\u044b, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 Complete \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u043a\u0440\u043e\u043c\u0435 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u2014 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0436\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0451\u043d (-4) \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0439 (-9).\u0418\u0437 \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430. \u0414\u0435\u043d\u044c\u0433\u0438 \u0441\u043f\u0438\u0441\u0430\u043d\u044b, \u0430 \u0442\u043e\u0432\u0430\u0440 \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u043d \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435. \u041e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 Complete \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u043d\u0435\u043b\u044c\u0437\u044f: \u0434\u0435\u043d\u044c\u0433\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0437\u0430\u0432\u0438\u0441\u043d\u0443\u0442, \u0430 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0439\u0434\u0451\u0442 \u043d\u0430 \u0440\u0443\u0447\u043d\u043e\u0439 \u0440\u0430\u0437\u0431\u043e\u0440. \u041d\u0443\u0436\u043d\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0443\u0441\u043f\u0435\u0445\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043b\u0430\u0442\u0451\u0436 \u0447\u0435\u0440\u0435\u0437 Merchant API: DELETE \/v2\/merchant\/payment\/reversal\/:service_id\/:payment_id. \u0418 \u043d\u0435 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c. \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0443 \u043e\u0442\u043c\u0435\u043d\u044b \u0436\u0451\u0441\u0442\u043a\u0438\u0435: \u043f\u043b\u0430\u0442\u0451\u0436 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d \u0438 \u043e\u043f\u043b\u0430\u0447\u0435\u043d \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0430\u0440\u0442\u043e\u0439, \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u0430\u0442\u0451\u0436 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u044f\u0446\u0430 (\u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u2014 \u043b\u0438\u0448\u044c \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u0435\u043d\u044c \u043d\u043e\u0432\u043e\u0433\u043e), \u0430 UZCARD \u0432\u043f\u0440\u0430\u0432\u0435 \u043e\u0442\u043c\u0435\u043d\u0443 \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c. \u0417\u043d\u0430\u0447\u0438\u0442, \u0441\u0432\u0435\u0440\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0432 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c.\u041d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430: \u0442\u0440\u0435\u0442\u0438\u0439 \u0441\u043b\u043e\u0439\u0418\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0434\u0443\u0431\u043b\u0435\u0439, \u043d\u043e \u043d\u0435 \u043e\u0442 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u043f\u0430\u043b \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0440\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u043a\u0430\u0437\u0430. \u041f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043e\u0442\u043c\u0435\u043d\u0438\u043b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0443 \u0441\u0435\u0431\u044f. \u0422\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0451 \u0441\u0442\u043e\u0438\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u043d\u043e\u0447\u044c, \u0430 \u043d\u0435 \u0440\u0430\u0437 \u0432 \u043c\u0435\u0441\u044f\u0446 \u043f\u0435\u0440\u0435\u0434 \u0430\u043a\u0442\u043e\u043c.\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u2014 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0443\u0436\u0435 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442:&#8212; 1. \u041e\u043f\u043b\u0430\u0447\u0435\u043d\u043e, \u0430 \u0437\u0430\u043a\u0430\u0437 \u043d\u0435 \u043e\u043f\u043b\u0430\u0447\u0435\u043d.select t.* from provider_txn t join orders o on o.id = t.order_id where t.state = 2 and o.status &lt;&gt; &#8216;paid&#8217;;&#8212; 2. \u0417\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043d, \u0430 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435\u0442.select o.* from orders o where o.status = &#8216;paid&#8217;   and not exists (select 1 from provider_txn t where t.order_id = o.id and t.state = 2);&#8212; 3. \u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043e\u043f\u043b\u0430\u0442\u0430: \u0434\u0432\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437.select order_id, count(*) from provider_txn where state = 2 group by order_id having count(*) &gt; 1;&#8212; 4. \u0417\u0430\u0432\u0438\u0441\u0448\u0438\u0435: \u00ab\u0441\u043e\u0437\u0434\u0430\u043d\u0430\u00bb \u0434\u043e\u043b\u044c\u0448\u0435 12 \u0447\u0430\u0441\u043e\u0432.select * from provider_txn where state = 1   and create_time &lt; (extract(epoch from now()) * 1000)::bigint &#8212; 43200000;\u0422\u0440\u0435\u0442\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u0435\u0442 \u043d\u0430 \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0443\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u041a\u043b\u0438\u0435\u043d\u0442, \u0431\u0440\u043e\u0441\u0438\u0432\u0448\u0438\u0439 \u043e\u043f\u043b\u0430\u0442\u0443 \u0432 Payme, \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Click, \u0438 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e: \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0440\u0430\u0434\u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u044f \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u0438\u0437\u0440\u0435\u0434\u043a\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u043f\u043b\u0430\u0442\u0451\u0436.\u041f\u043e\u0442\u043e\u043c \u2014 \u0441\u0432\u0435\u0440\u043a\u0430 \u0441 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c. \u0423 Click \u0432 Merchant API \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430 \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u0437\u0430\u043a\u0430\u0437\u0430: GET \/v2\/merchant\/payment\/status_by_mti\/:service_id\/:merchant_trans_id\/YYYY-MM-DD, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Auth: merchant_user_id:digest:timestamp, \u0433\u0434\u0435 digest = sha1(timestamp + secret_key), \u0430 timestamp \u2014 Unix-\u0432\u0440\u0435\u043c\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043d\u0435 \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043a\u0430\u043a \u0443 Payme. \u0415\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u0435\u0447\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 1, 2 \u0438 4. \u0421 Payme \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435: GetStatement \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u043c Payme \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441 \u0432\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0432\u0430\u0448\u0435\u0439 \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0430 \u0441\u0430\u043c\u0438 \u0432\u044b \u0441\u0432\u0435\u0440\u044f\u0435\u0442\u0435\u0441\u044c \u0441 \u0440\u0435\u0435\u0441\u0442\u0440\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u0430\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438.async function nightlyReconciliation(day: Date) {  const findings: Finding[] = [    &#8230;(await db.many(Q_PAID_TXN_UNPAID_ORDER)).map((r) =&gt; f(&#8216;paid_not_fulfilled&#8217;, r)),    &#8230;(await db.many(Q_PAID_ORDER_NO_TXN)).map((r) =&gt; f(&#8216;order_without_txn&#8217;, r)),    &#8230;(await db.many(Q_DOUBLE_PAYMENT)).map((r) =&gt; f(&#8216;double_payment&#8217;, r)),    &#8230;(await db.many(Q_STUCK_PENDING)).map((r) =&gt; f(&#8216;stuck_pending&#8217;, r)),  ];  for (const x of findings.filter((x) =&gt; x.provider === &#8216;click&#8217;)) {    x.external = await click.statusByMti(x.merchant_trans_id, day);  }  const registry = await loadProviderRegistry(day);  await archiveRaw(day, registry);                                   \/\/ \u043a\u0430\u043a \u043f\u0440\u0438\u0448\u0451\u043b, \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438  findings.push(&#8230;diffById(await db.txnsForDay(day), registry));   \/\/ \u043f\u043e ID, \u043d\u0435 \u043f\u043e \u0441\u0443\u043c\u043c\u0435  for (const x of findings) await tickets.open(x);                  \/\/ \u0437\u0430\u0434\u0430\u0447\u0430 \u0441 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c}\u0414\u0432\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u044f\u0442 \u0434\u043e\u0440\u043e\u0436\u0435 \u043a\u043e\u0434\u0430. \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0443\u043c\u043c\u0435 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: \u0434\u0432\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0441\u0443\u043c\u043c\u044b \u0432 \u043e\u0434\u043d\u0443 \u043c\u0438\u043d\u0443\u0442\u0443 \u2014 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0434\u0435\u043b\u043e. \u0418 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0440\u0435\u0435\u0441\u0442\u0440 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u043e \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438: \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d.\u0427\u0435\u043a-\u043b\u0438\u0441\u0442 \u0434\u043b\u044f Click\u041a\u043b\u044e\u0447 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 click_trans_id \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0432 \u0431\u0430\u0437\u0435.\u041f\u043e\u0434\u043f\u0438\u0441\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0435\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432.\u0421\u0443\u043c\u043c\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0437\u0430\u043a\u0430\u0437\u043e\u043c \u0432 \u0446\u0435\u043b\u044b\u0445 \u0442\u0438\u0439\u0438\u043d\u0430\u0445.\u041d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 Complete \u2014 -4; \u043d\u0430 error &lt; 0 \u043e\u0442 Click \u2014 \u043e\u0442\u043c\u0435\u043d\u0430 \u0443 \u0441\u0435\u0431\u044f \u0438 -9.\u0422\u043e\u0432\u0430\u0440 \u043d\u0435\u043b\u044c\u0437\u044f \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u2014 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 Complete \u0438 reversal \u0432 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c, \u0430 \u043d\u0435 \u043e\u0448\u0438\u0431\u043a\u0430.\u041d\u043e\u0447\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430: \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0435\u0441\u0442\u0440, \u043a\u0430\u0436\u0434\u043e\u0435 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c.\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438Click, SHOP API \u2014 \u0437\u0430\u043f\u0440\u043e\u0441\u044b: https:\/\/docs.click.uz\/shop-api\/requestsClick, SHOP API \u2014 \u043e\u0448\u0438\u0431\u043a\u0438: https:\/\/docs.click.uz\/shop-api\/errorsClick, Merchant API \u2014 status_by_mti, reversal, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f: https:\/\/docs.click.uz\/merchant-api\/requestsPayme Business, GetStatement: https:\/\/developer.help.paycom.uz\/metody-merchant-api\/getstatementTransactional outbox: https:\/\/microservices.io\/patterns\/data\/transactional-outbox.html\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1109616\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-503848","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/503848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=503848"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/503848\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=503848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=503848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=503848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}