Created
June 10, 2023 09:39
-
-
Save KataLoved/b567158df1c7c613e3d0e32acb3006bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'module-alias/register'; | |
| import { createHmac } from 'crypto'; | |
| import { v4 as uuidv4 } from 'uuid'; | |
| import axios from 'axios'; | |
| const SECRET_KEY = '...'; | |
| const SECOND_KEY = '...'; | |
| const SHOP_ID = '...'; | |
| function getSignature(key: string, body = {}): string { | |
| return createHmac('sha256', key).update(JSON.stringify(body)).digest('hex'); | |
| } | |
| const uuid = uuidv4(); | |
| const data: any = { | |
| sum: 10.00, | |
| orderId: uuid, | |
| shopId: SHOP_ID, | |
| expire: 30, | |
| comment: "NastyaLove | " + uuid | |
| }; | |
| (async () => { | |
| const signature = getSignature(SECRET_KEY, data); | |
| console.log(signature, JSON.stringify(data, null, 4)); | |
| const { response } = await axios.post('https://api.lava.ru/business/invoice/create', { | |
| headers: { | |
| "Accept": "application/json", | |
| "Content-Type": "application/json", | |
| "Signature": signature | |
| }, | |
| body: JSON.stringify(data) | |
| }).catch(e => e); | |
| console.log(response.data); | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| signature: 46e71e62a85f38de341a4bc0b33fe8c13337f3c23933f12fd1422fb8ab565623 | |
| data: { | |
| "sum": 10, | |
| "orderId": "d58f5fcc-fb30-4304-85eb-52655e652d34", | |
| "shopId": "...", | |
| "expire": 30, | |
| "comment": "NastyaLove | d58f5fcc-fb30-4304-85eb-52655e652d34" | |
| } | |
| response: { | |
| data: null, | |
| error: 'Поле shopId обязательно', | |
| status: 422, | |
| status_check: false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment