Socket
Socket
Sign inDemoInstall

at.p2pkassa.sdk

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    at.p2pkassa.sdk

SDK for P2PKassa


Version published
Maintainers
1
Install size
8.50 kB
Created

Readme

Source

Intro

This is an SDK for P2PKassa for Typescript.

Usage

if(!process.env.PROJECT_ID){
  throw new Error('PROJECT_ID environment variable not found!')
}
if(!process.env.API_TOKEN){
  throw new Error('API_TOKEN environment variable not found!')
}

if(Number.isNaN(Number(process.env.PROJECT_ID))){
  throw new Error("PROJECT_ID environment variable must be a number")
}

const orderId = 100200300; // Must be a number for P2PKassa
const amount = 100;

const sdk = new P2PKassaSDK(Number(process.env.PROJECT_ID), process.env.API_TOKEN);
const invoice = await sdk.createInvoice(orderId, amount, "RUB");
console.log(invoice.link);

In this case uuid will be placed inside data.uuid property of generated invoice and must be gotten later from data.uuid property

import {randomUUID} from "node:crypto";

if (!process.env.PROJECT_ID) {
  throw new Error('PROJECT_ID environment variable not found!')
}
if (!process.env.API_TOKEN) {
  throw new Error('API_TOKEN environment variable not found!')
}

if (Number.isNaN(Number(process.env.PROJECT_ID))) {
  throw new Error("PROJECT_ID environment variable must be a number")
}

const orderId = randomUUID(); // Must be a number for P2PKassa
const amount = 100;

const sdk = new P2PKassaSDK(Number(process.env.PROJECT_ID), process.env.API_TOKEN);
const invoice = await sdk.createInvoiceUuid(orderId, amount, "RUB");
console.log(invoice.link);

Checking webhook

if(!process.env.PROJECT_ID){
  throw new Error('PROJECT_ID environment variable not found!')
}
if(!process.env.API_TOKEN){
  throw new Error('API_TOKEN environment variable not found!')
}

if(Number.isNaN(Number(process.env.PROJECT_ID))){
  throw new Error("PROJECT_ID environment variable must be a number")
}

const app = express();
const sdk = new P2PKassaSDK(Number(process.env.PROJECT_ID), process.env.API_TOKEN);

app.post('/p2pkassa/webhook', async (req, res) => {
  const webhookData = await req.json();
  if(!sdk.checkWebhook(webhookData)){
    res.sendStatus(403);
    return;
  }
  
  // Webhook are valid
  console.log(webhookData)
});

app.listen(process.env.PORT || 3000);

Keywords

FAQs

Last updated on 06 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc