> For the complete documentation index, see [llms.txt](https://portex-app.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://portex-app.gitbook.io/docs/sdk/payment.md).

# Payment

![portex.pay](/files/v1UWJix13nacNKNLJnlu)

## Features

* customizable payment goods
* serverless payment process
* payment status tracking
* payment exception handling

## API Documentation

* open payment dialog

```typescript
pay(
    options: PaymentOptions,
    callback?: (result: InvoiceClosedResult) => void,
): Promise<PaymentResult>
```

* query payment order

```typescript
queryOrder(orderId: string): Promise<OrderResult>
```

* resume payment

```typescript
resumePayment(
    callback?: (result: InvoiceClosedResult) => void,
): Promise<null | PaymentResult>
```

* check pending payment

```typescript
hasPendingPayment(): boolean
```

## Interface

```typescript
interface PaymentOptions {
	tg_use_id: string // telegram user id
	amount: number // amount in rubles
	label: string // label
	title: string // title
	description: string // description
	payload?: string // payload
	photo_height?: number // photo height
	photo_width?: number // photo width
	photo_size?: number // photo size
	photo_url?: string // photo url
	callback_url?: string // callback url
}

interface PaymentResult {
	tg_payment_id: number // telegram payment id
	tg_payment_url: string // telegram payment url
}

interface InvoiceClosedResult {
	orderId: number // order id
	status: 'failed' | 'paid' | 'cancelled' | 'pending' // status
}

interface OrderResult {
	amount: number // amount in rubles
	application_id: string // application id
	description: string // description
	label: string // label
	payload: string // payload
	status: number // status
	status_description: string // status description
	tg_payment_id: string // telegram payment id
	tg_use_id: string // telegram user id
	title: string // title
}
```

## Example

```typescript
const portex = new Portex({
	appId: 'your-app-id',
})

await portex.init()

const requiredObject = {
	tg_use_id: portex.webApp.initDataUnsafe.user.id,
	amount: 1,
	label: 'item',
	title: 'Book',
	description: 'Magic book',
}

const result = await portex.pay(
	{
		...requiredObject,
		payload: 'your-payload',
		photo_url: 'https://your-photo-url.com',
	},
	(result) => {
		if (portex.hasPendingPayment()) {
			// payment is pending or cancelled
		} else {
			// payment is paid
			// get payment result
			const paymentResult = await portex.queryOrder(result.orderId)
		}
	}
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://portex-app.gitbook.io/docs/sdk/payment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
