Giter Club home page Giter Club logo

tinkoff's Introduction

Tinkoff Payments Provider

Install

yarn add @atlantis-lab/tinkoff-api

Initialize purchase example

import { Tinkoff } from '@atlantis-lab/tinkoff-api'

const tinkoff = new Tinkoff({
  password: process.env.TINKOFF_PASSWORD,
  terminalKey: process.env.TINKOFF_TERMINAL_KEY,
})

const response = await tinkoff.api.payments.Init({
  OrderId: 1,
  Amount: 2000,
})

// ..logic

Tinkoff request verifing example

import http        from 'http'
import { Tinkoff } from '@atlantis-lab/tinkoff-api'
const tinkoff = new Tinkoff({
  password: process.env.TINKOFF_PASSWORD,
  terminalKey: process.env.TINKOFF_TERMINAL_KEY,
})
const downloadJSONBody = async (request: http.IncomingMessage) => {
  const chunks: Buffer[] = []
  for await (const chunk of request) {
    chunks.push(chunk)
  }
  const rawBody = Buffer.concat(chunks)
  const serializedBody = rawBody.toJSON()
  return serializedBody
}
const rejectRequest = (response: http.ServerResponse) => {
  response.statusCode = 400
  response.end()
}
const resolveRequest = (response: http.ServerResponse) => {
  response.statusCode = 200
  response.end('OK')
}
const requestHandler: http.RequestListener = (request, response) => {
  const body = await downloadJSONBody(request)
  const verified = tinkoff.security.verifyRequest(body)
  verified ? resolveRequest(response) : rejectRequest(response)
}
const server = http.createServer(requestHandler)
server.listen(process.env.APPLICATION_PORT)

tinkoff's People

Contributors

dependabot[bot] avatar renovate-bot avatar talentumtuum avatar torinasakura avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

tinkoff's Issues

[chore] yarn v2 migration

Какого рода задача?

Мигриация проекта на пакетный менеджер yarn v2

Что и где будем менять?

to be continued

[bug] request-verifier-guard cant find TinkoffService in DI container

Описание бага

Не разрешаются зависимости RequestVerifierGuard пакета nestjs-tinkoff

Ожидаемое поведение

Зависимости разрешаются

Материалы

Nest could not find TinkoffService element (this provider does not exist in the current context)

  15 | 
  16 |   onModuleInit() {
> 17 |     this.ref.get(TinkoffService)
     |              ^
  18 |   }
  19 | }
  20 | 

  at InstanceLinksHost.get (../../node_modules/@nestjs/testing/node_modules/@nestjs/core/injector/instance-links-host.js:24:19)
  at Object.find (../../node_modules/@nestjs/testing/node_modules/@nestjs/core/injector/module-ref.js:38:55)
  at Object.get (../../node_modules/@nestjs/testing/node_modules/@nestjs/core/injector/module.js:339:28)
  at RequestVerifierGuard.onModuleInit (src/guards/request-verifier.guard.ts:17:14)
  at MapIterator.iteratee (../../node_modules/@nestjs/testing/node_modules/@nestjs/core/hooks/on-module-init.hook.js:22:43)
  at MapIterator.next (../../node_modules/iterare/src/map.ts:9:39)
  at IteratorWithOperators.next (../../node_modules/iterare/src/iterate.ts:19:28)
      at Function.from (<anonymous>)
  at IteratorWithOperators.toArray (../../node_modules/iterare/src/iterate.ts:227:22)
  at callOperator (../../node_modules/@nestjs/testing/node_modules/@nestjs/core/hooks/on-module-init.hook.js:23:10)

Что делать?

Нужно дать guard'е контекст нашего модуля
Похожая проблема решалась тут https://github.com/nestjs/passport/blob/master/lib/auth.guard.ts#L26

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.