1.5.1 • Published 2 months ago

wallet-pay-sdk v1.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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 = {
  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 result = await wp.createOrder(newOrder); // { response?: ICreateOrderResponse, error?: any }


if (result?.error) {
  throw result?.error;
} else {
  // success ...
}

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 result = await wp.getPreviewOrder(orderId) // { response?: IGetOrderPreviewResponse, error?: any }

if (result?.error) {
  throw result?.error;
} else {
  // success ...
}

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 } 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 result = await wp.getOrderList(params); // { response?: IGetOrderListResponse, error?: any }

if (result?.error) {
  throw result?.error;
} else {
  // success ...
}

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 result = await wp.getOrderAmount(); // { response?: IGetOrderAmountResponse, error?: any }

if (result?.error) {
  throw result?.error;
} else {
  // success ...
}

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
1.5.1

2 months ago

1.3.6

2 months ago

1.5.0

2 months ago

1.4.0

2 months ago

1.3.5

2 months ago

1.3.4

2 months ago

1.3.2

2 months ago

1.2.3

3 months ago

1.3.1

3 months ago

1.2.2

3 months ago

1.3.0

3 months ago

1.1.2

3 months ago

1.1.0

6 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.1-development

9 months ago

0.0.0-development

9 months ago