Skip to content

Commit

Permalink
fix: update formatting & not valid versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwitr0 committed Sep 18, 2023
1 parent 38b07d9 commit a5455a1
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 159 deletions.
4 changes: 2 additions & 2 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.0"
}
".": "1.0.1"
}
318 changes: 163 additions & 155 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# Wallet Pay client for TS/JS
It's a client for [Wallet Pay](https://wallet.tg) API written in TypeScript.

It's a client for [Wallet Pay](https://wallet.tg) API written in TypeScript.

## Installation

```bash
npm install @mdwitr0/telegram-wallet-pay
npm install telegram-wallet-pay
```

## Usage

Create a new instance of `WalletPay` class and pass the token as a parameter. You can get the token on [Wallet Pay](https://wallet.tg).

```typescript
import { WalletPay } from '@mdwitr0/telegram-wallet-pay';
import { WalletPay } from "telegram-wallet-pay";

const wallet = new WalletPay('Store token');
const wallet = new WalletPay("Store token");
```

Create a new order using `createOrder` method. You can pass the `order` object as a parameter.

<details>
<summary>Order object interface:</summary>

Expand Down Expand Up @@ -73,185 +76,187 @@ export interface CreateOrderRequest {
}

export interface MoneyAmount {
/**
* Currency code
* @type {string}
* @memberof MoneyAmount
*/
currencyCode: CurrencyCodeEnum;
/**
* Big decimal string representation
* @type {string}
* @memberof MoneyAmount
*/
amount: string;
/**
* Currency code
* @type {string}
* @memberof MoneyAmount
*/
currencyCode: CurrencyCodeEnum;
/**
* Big decimal string representation
* @type {string}
* @memberof MoneyAmount
*/
amount: string;
}
```

</details>

```typescript
import { WalletPay } from '@mdwitr0/telegram-wallet-pay';
import { WalletPay } from "telegram-wallet-pay";

async function main() {
const wallet = new WalletPay('Store token');

const order = await wallet.createOrder({
"amount": {
"currencyCode": "USD",
"amount": "1.00"
},
"description": "VPN for 1 month",
"returnUrl": "https://t.me/wallet",
"failReturnUrl": "https://t.me/wallet",
"customData": "client_ref=4E89",
"externalId": "ORD-5023-4E89",
"timeoutSeconds": 10800,
"customerTelegramUserId": 0
});

console.log(order);
// Response:
// {
// "status": "SUCCESS",
// "message": "",
// "data": {
// "id": 2703383946854401,
// "status": "ACTIVE",
// "number": "9aeb581c",
// "amount": {},
// "createdDateTime": "2019-08-24T14:15:22Z",
// "expirationDateTime": "2019-08-24T14:15:22Z",
// "completedDateTime": "2019-08-24T14:15:22Z",
// "payLink": "https://t.me/wallet?startattach=wpay_order_2703383946854401",
// "directPayLink": "https://t.me/wallet/start?startapp=wpay_order-orderId__2703383946854401"
// }
// }

const wallet = new WalletPay("Store token");

const order = await wallet.createOrder({
amount: {
currencyCode: "USD",
amount: "1.00",
},
description: "VPN for 1 month",
returnUrl: "https://t.me/wallet",
failReturnUrl: "https://t.me/wallet",
customData: "client_ref=4E89",
externalId: "ORD-5023-4E89",
timeoutSeconds: 10800,
customerTelegramUserId: 0,
});

console.log(order);
// Response:
// {
// "status": "SUCCESS",
// "message": "",
// "data": {
// "id": 2703383946854401,
// "status": "ACTIVE",
// "number": "9aeb581c",
// "amount": {},
// "createdDateTime": "2019-08-24T14:15:22Z",
// "expirationDateTime": "2019-08-24T14:15:22Z",
// "completedDateTime": "2019-08-24T14:15:22Z",
// "payLink": "https://t.me/wallet?startattach=wpay_order_2703383946854401",
// "directPayLink": "https://t.me/wallet/start?startapp=wpay_order-orderId__2703383946854401"
// }
// }
}
```

<details>
<summary>Response order interface:</summary>

```ts
export interface CreateOrderResponse {
/**
* `SUCCESS` - new order created; `data` is present. `ALREADY` - order with completely same parameters including externalId already exists; `data` is present. `CONFLICT` - order with different parameters but same externalId already exists; `data` is absent. `ACCESS_DENIED` - you're not permitted to create orders, contact support in this case; `data` is absent. `INVALID_REQUEST` - we failed to handle your request, check that all required fields sent properly. `INTERNAL_ERROR` - unexpected error on our side
* @type {string}
* @memberof CreateOrderResponse
*/
status: OrderStatusEnum;
/**
* Verbose reason of non-success result
* @type {string}
* @memberof CreateOrderResponse
*/
message?: string;
/**
*
* @type {OrderPreview}
* @memberof CreateOrderResponse
*/
data?: OrderPreview;
/**
* `SUCCESS` - new order created; `data` is present. `ALREADY` - order with completely same parameters including externalId already exists; `data` is present. `CONFLICT` - order with different parameters but same externalId already exists; `data` is absent. `ACCESS_DENIED` - you're not permitted to create orders, contact support in this case; `data` is absent. `INVALID_REQUEST` - we failed to handle your request, check that all required fields sent properly. `INTERNAL_ERROR` - unexpected error on our side
* @type {string}
* @memberof CreateOrderResponse
*/
status: OrderStatusEnum;
/**
* Verbose reason of non-success result
* @type {string}
* @memberof CreateOrderResponse
*/
message?: string;
/**
*
* @type {OrderPreview}
* @memberof CreateOrderResponse
*/
data?: OrderPreview;
}

export interface OrderPreview {
/**
* Order id
* @type {string}
* @memberof OrderPreview
*/
id: string;
/**
*
* @type {OrderStatus}
* @memberof OrderPreview
*/
status: OrderStatus;
/**
*
* @type {OrderNumber}
* @memberof OrderPreview
*/
number: OrderNumber;
/**
*
* @type {MoneyAmount}
* @memberof OrderPreview
*/
amount: MoneyAmount;
/**
* ISO-8601 date time when order was created
* @type {Date}
* @memberof OrderPreview
*/
createdDateTime: Date;
/**
* ISO-8601 date time when order timeout expires
* @type {Date}
* @memberof OrderPreview
*/
expirationDateTime: Date;
/**
* ISO-8601 date time when order was completed (paid/expired/etc)
* @type {Date}
* @memberof OrderPreview
*/
completedDateTime?: Date;
/**
* URL to be shown to the payer by the store. Сan be used in 'Telegram Bot' only. **Important:** this link can be opened ONLY in dialog with Telegram-bot specified in your Store, ONLY by user with `telegramUserId` specified in the Order.
* @type {string}
* @memberof OrderPreview
*/
payLink: string;
/**
* URL to be shown to the payer by the store. Can be used in 'Telegram Bot' and 'Telegram Web App'. **Important:** this link can be opened ONLY in dialog with Telegram-bot specified in your Store, ONLY by user with `telegramUserId` specified in the Order.
* @type {string}
* @memberof OrderPreview
*/
directPayLink: string;
/**
* Order id
* @type {string}
* @memberof OrderPreview
*/
id: string;
/**
*
* @type {OrderStatus}
* @memberof OrderPreview
*/
status: OrderStatus;
/**
*
* @type {OrderNumber}
* @memberof OrderPreview
*/
number: OrderNumber;
/**
*
* @type {MoneyAmount}
* @memberof OrderPreview
*/
amount: MoneyAmount;
/**
* ISO-8601 date time when order was created
* @type {Date}
* @memberof OrderPreview
*/
createdDateTime: Date;
/**
* ISO-8601 date time when order timeout expires
* @type {Date}
* @memberof OrderPreview
*/
expirationDateTime: Date;
/**
* ISO-8601 date time when order was completed (paid/expired/etc)
* @type {Date}
* @memberof OrderPreview
*/
completedDateTime?: Date;
/**
* URL to be shown to the payer by the store. Сan be used in 'Telegram Bot' only. **Important:** this link can be opened ONLY in dialog with Telegram-bot specified in your Store, ONLY by user with `telegramUserId` specified in the Order.
* @type {string}
* @memberof OrderPreview
*/
payLink: string;
/**
* URL to be shown to the payer by the store. Can be used in 'Telegram Bot' and 'Telegram Web App'. **Important:** this link can be opened ONLY in dialog with Telegram-bot specified in your Store, ONLY by user with `telegramUserId` specified in the Order.
* @type {string}
* @memberof OrderPreview
*/
directPayLink: string;
}

export enum OrderStatusEnum {
SUCCESS = "SUCCESS",
ALREADY = "ALREADY",
CONFLICT = "CONFLICT",
ACCESSDENIED = "ACCESS_DENIED",
INVALIDREQUEST = "INVALID_REQUEST",
INTERNALERROR = "INTERNAL_ERROR",
SUCCESS = "SUCCESS",
ALREADY = "ALREADY",
CONFLICT = "CONFLICT",
ACCESSDENIED = "ACCESS_DENIED",
INVALIDREQUEST = "INVALID_REQUEST",
INTERNALERROR = "INTERNAL_ERROR",
}
```

</details>

Get order by id using `getOrderPreview` method. You can pass the `orderId` as a parameter.

```ts
import { WalletPay } from '@mdwitr0/telegram-wallet-pay';
import { WalletPay } from "telegram-wallet-pay";

async function main() {
const wallet = new WalletPay('Store token');
const order = await wallet.getOrderPreview('Order id');
console.log(order);
// Response:
// {
// "status": "SUCCESS",
// "message": "",
// "data": {
// "id": 2703383946854401,
// "status": "ACTIVE",
// "number": "9aeb581c",
// "amount": {
// "currencyCode": "USD",
// "amount": "1.00"
// },
// "createdDateTime": "2019-08-24T14:15:22Z",
// "expirationDateTime": "2019-08-24T14:15:22Z",
// "completedDateTime": "2019-08-24T14:15:22Z",
// "payLink": "https://t.me/wallet?startattach=wpay_order_2703383946854401",
// "directPayLink": "https://t.me/wallet/start?startapp=wpay_order-orderId__2703383946854401"
// }
// }
const wallet = new WalletPay("Store token");

const order = await wallet.getOrderPreview("Order id");

console.log(order);
// Response:
// {
// "status": "SUCCESS",
// "message": "",
// "data": {
// "id": 2703383946854401,
// "status": "ACTIVE",
// "number": "9aeb581c",
// "amount": {
// "currencyCode": "USD",
// "amount": "1.00"
// },
// "createdDateTime": "2019-08-24T14:15:22Z",
// "expirationDateTime": "2019-08-24T14:15:22Z",
// "completedDateTime": "2019-08-24T14:15:22Z",
// "payLink": "https://t.me/wallet?startattach=wpay_order_2703383946854401",
// "directPayLink": "https://t.me/wallet/start?startapp=wpay_order-orderId__2703383946854401"
// }
// }
}
```

Expand Down Expand Up @@ -360,4 +365,7 @@ export interface WebhookPayload {
orderCompletedDateTime: Date;
}
```
</details>

</details>

Other methods are similar to the methods described above.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5455a1

Please sign in to comment.