GithubHelp home page GithubHelp logo

2ico / wallet-pay-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dark-dao/wallet-pay-sdk

0.0 0.0 0.0 5.62 MB

SDK for https://pay.wallet.tg

License: MIT License

Shell 0.71% TypeScript 99.29%

wallet-pay-sdk's Introduction

wallet-pay-sdk

Package for using Wallet Pay API https://docs.wallet.tg/pay/

NPM Version Downloads Stats Last commit cov

Supported endpoints

Create order /wpay/store-api/v1/order

Get order preview /wpay/store-api/v1/order/preview

Get order list /wpay/store-api/v1/reconciliation/order-list

Get order amount /wpay/store-api/v1/reconciliation/order-amount

Installation

npm i wallet-pay-sdk --save

Usage examples

init wallet pay sdk

import { WalletPaySDK } from 'wallet-pay-sdk';
const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});
...

create new order

/wpay/store-api/v1/order

import { WalletPaySDK } from 'wallet-pay-sdk';
import { CreateOrderDto } from 'wallet-pay-sdk/lib/dto';
import { ECurrencyCode, ICreateOrderResponse, IResponseError } from 'wallet-pay-sdk/lib/type';

const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});

const newOrder: CreateOrderDto = {
  amount: {
    currencyCode: ECurrencyCode.TON,
    amount: '10.67',
  },
  description: 'My first order', // Description of the order
  returnUrl: 'https://example.com', //  Url to redirect after paying order
  failReturnUrl: 'https://example.com', // Url to redirect after unsuccessful order completion (expiration/cancelation/etc)
  externalId: '5cfaf283-8242-4ddd-ae00-c9ecd6966245',
  // timeoutSeconds: 200000; // If you want, you can override the value of the "timeoutSeconds" variable here
  customerTelegramUserId: 12238398, // The customer's telegram id (User_id)
};

const response: ICreateOrderResponse | IResponseError =
  await wp.createOrder(newOrder);

get order preview

/wpay/store-api/v1/order/preview

import { WalletPaySDK } from 'wallet-pay-sdk';
import { IGetOrderPreviewResponse, IResponseError } from 'wallet-pay-sdk/lib/type';

const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});

const orderId = '10797500785491970';
const response: IGetOrderPreviewResponse | IResponseError = await wp.getPreviewOrder(orderId)

get order list

/wpay/store-api/v1/reconciliation/order-list

import { WalletPaySDK } from 'wallet-pay-sdk';
import { GetOrderListDto } from 'wallet-pay-sdk/lib/dto';
import { IGetOrderListResponse, IResponseError } from 'wallet-pay-sdk/lib/type';

const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});

const params: GetOrderListDto = {
  offset: 0, // Specifying the amount of excluded from a response the first N orders
  count: 10, // Specifying the limit of orders for the request
};
const response: IGetOrderListResponse | IResponseError =
  await wp.getOrderList(params);

get order amount

/wpay/store-api/v1/reconciliation/order-amount

import { WalletPaySDK } from 'wallet-pay-sdk';
import { IGetOrderAmountResponse, IResponseError } from 'wallet-pay-sdk/lib/type';

const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});

const response: IGetOrderAmountResponse | IResponseError =
  await wp.getOrderAmount();

webhook hashes verification

import { WalletPaySDK } from 'wallet-pay-sdk';
import { IWebhook, IWebhookRequest, IWebhookRequestSign, IResponseError } from 'wallet-pay-sdk/lib/type';

const wp = new WalletPaySDK({
  apiKey: 'secret_api_key',
  timeoutSeconds: 60 * 60 * 3, // Default value = Order TTL, if the order is not paid within the timeout period
});

/**
 * Most of the data described below comes
 * when Wallet Pay calls your endpoint.
 * Only two parameters depend on you:
 * - originalUrl
 * - method
 */
const update: IWebhookRequest = {
  body: [...], // webhook request body you can see type 'IWebhook' in types file
  originalUrl: '/api/wallet-pay/webhook', // URI path exactly the same as set in the personal account
  method: 'POST',
}

const signParams: IWebhookRequestSign = {
  timestamp: '168824905680291', // HEADER: 'WalletPay-Timestamp'
  signature: 'B7gy92BjFxILVctGG32fWBDEy4WW5iGzWs1kziNFGys', // HEADER: 'WalletPay-Signature'
}
const result: boolean | IResponseError = wp.webhookVerifyHash(update, signParams)
// if return TRUE - webhook call is verificated

wallet-pay-sdk's People

Contributors

borishasikov avatar dark-dao avatar

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.