> For the complete documentation index, see [llms.txt](https://qubic.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://qubic.gitbook.io/docs/guides/qubic-connect-sdk/checkout-and-payment.md).

# 結帳與支付

## Payment types

```typescript
// asset
enum BuyStatus {
  SUCCESS = 'SUCCESS',
  WAIT_PAYMENT = 'WAIT_PAYMENT',
  FAILED = 'FAILED',
}
interface PayCallbackInput {
  successRedirectUrl: string;
  failureRedirectUrl: string;
  pendingRedirectUrl: string;
}
```

## buyAssetAndCreateCheckout

購買 NFT 並產生結帳連結 URL

```typescript
async function buyAssetAndCreateCheckout(
  assetBuyInput: AssetBuyInput,
  options?: AssetBuyOptions,
): Promise<AssetBuyResponse | null>;

interface AssetBuyInput {
  requestId: string;
  asset: AssetSaleInput;
  payCallback: PayCallbackInput;
  test?: boolean; // default false
  option?: AssetBuyOptionInput;
}

interface AssetSaleInput {
  assetVariantId: string;
  quantity: number;
  price: string;
  currency: CurrencyForAsset;
}

enum CurrencyForAsset {
  ETH = 'ETH',
  TWD = 'TWD',
  MATIC = 'MATIC',
}

interface AssetBuyOptionInput {
  beGift?: boolean;
  privateSaleCode?: string;
}

interface AssetBuyOptions {
  locale?: PaymentLocale;
}

interface AssetBuyResponse {
  assetBuy: AssetBuyInfo;
}

enum CheckoutPaymentType {
  UNSELECTED = 'UNSELECTED',
  FREE = 'FREE',
  CREDIT_CARD = 'CREDIT_CARD',
  TRANSFER = 'TRANSFER',
  CRYPTO = 'CRYPTO',
}

enum UnavailablePaymentReason {
  GAS_PRICE_SURGE
  PAYMENT_LIMIT_EXCEEDED
  EXCHANGE_PRICE_FAILED
  PAYMENT_MAINTENANCE
}

type UnavailablePayment {
  type: CheckoutPaymentType!
  reason: UnavailablePaymentReason!
}

interface AssetBuyInfo {
  status: BuyStatus;
  orderId: string;
  paymentUrl: string;
  paymentTypes: [CheckoutPaymentType!]!
  unavailablePayments: [UnavailablePayment!]!
}
```

**Example**

```typescript
const response = await qubicConnect.buyAssetAndCreateCheckout(assetBuyInput, { locale: 'zh' });

window.location.href = response.assetBuy.paymentUrl;
```


---

# 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://qubic.gitbook.io/docs/guides/qubic-connect-sdk/checkout-and-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.
