> ## Documentation Index
> Fetch the complete documentation index at: https://docs.whop.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# CardElement

> 카드 번호, 만료일, 보안 코드 필드가 미리 배치된 엘리먼트입니다. `payments.create("card")`로 생성하고, `onChange`에서 결제 버튼을 활성화한 뒤 `payments.createConfirmationToken()`으로 확인합니다. 카드 번호는 PCI로 격리된 호스팅 필드에 유지됩니다. `layout`은 `stacked`(기본값)와 `compact`를 지원합니다.

> [!NOTE]
>
> 이 페이지는 `@whop/elements@1.10.0` 및 `@whop/elements-react@1.10.0`을 다룹니다.

*`v1.0.0`부터 지원.*

[`Payments`](https://docs.whop.com/ko/elements/latest/payments/overview) 안에 마운트됩니다. props와 콜백은 생성 옵션 또는 React props로 전달합니다.

> [!NOTE]
>
> **배타적.**`CardElement`는 이 Payments 핸들에서 `PaymentElement` 또는 `CardFields`의 대안입니다. 한 번에 하나만 마운트하세요. 다른 엘리먼트를 마운트하기 전에 제거하세요.

> [!NOTE]
>
> **`BrandingElement`를 기다립니다.** 같은 Payments 핸들에 `BrandingElement`가 마운트될 때까지 이 엘리먼트는 로딩 상태로 유지됩니다.

`WhopPayments` 스코프 안에 마운트됩니다. 세 개의 카드 입력을 하나의 단위로 제공하며, 토크나이저가 PCI로 격리하므로 번호, 만료일, 보안 코드가 앱 프로세스에 들어오지 않습니다.

결제 금액과 확인 토큰을 소유하는 `<Payments>` 안에 마운트하세요. `<Payments>` 자체는 `<WhopElements>` 안에 마운트됩니다. 폼에서 카드만 받을 때 사용하세요. 이 엘리먼트는 스스로를 수집 화면으로 등록하므로, 별도 연결 없이 `createConfirmationToken`이 이를 토큰화합니다.

```tsx React theme={null}
import { WhopElements, Payments, CardElement, BrandingElement } from "@whop/elements-react";
import { loadWhop } from "@whop/elements";

function Example() {
  return (
    <WhopElements elements={loadWhop()}>
      <Payments /* options */>
        <CardElement onChange={(e) => console.log(e)} />
        <BrandingElement />
      </Payments>
    </WhopElements>
  );
}
```

```tsx React Native theme={null}
import { CardElement, Payments } from '@whop/elements-react-native';

export function CardStep() {
  return (
    <Payments accountId="biz_xxxxxxxx" plan="plan_xxxxxxxx">
      <CardElement layout="stacked" onChange={({ complete }) => console.log(complete)} />
    </Payments>
  );
}
```

```html JavaScript theme={null}
<script src="https://cdn.whop.com/elements/amber/elements.js" data-whop-elements></script>
<script type="module">
  const payments = window.WhopElements().payments.create({ /* options */ });
  payments.create('card', { onChange: (e) => console.log(e) }).mount('#payments-card');
  payments.create('branding').mount('#payments-branding');
</script>
```

```swift Swift theme={null}
import Elements
import SwiftUI

// .whopElements(environment:) runs once at the app root. See Getting started.
struct CheckoutScreen: View {
    @State private var card = WhopCardState(isComplete: false, brand: nil)

    var body: some View {
        WhopPayments(accountID: "biz_xxxx", charge: .plan(id: "plan_xxxx")) { payments in
            ScrollView {
                VStack(alignment: .leading, spacing: 20) {
                WhopCardElement(layout: .stacked, state: $card)
                    WhopBrandingElement()
                }
                .padding()
            }
        }
    }
}
```

예시 데이터입니다. [Playground 열기](https://docs.whop.com/ko/elements/latest/payments/overview#playground).

[React Native 예제 앱의 Android에서 실행 중인 CardElement](https://app.revyl.ai/embed/97dfb742-fe50-4fe7-a817-87ea4585f159?controls=0)

## Props

**layout** `"compact" | "stacked"`

`stacked`(기본값)는 카드 번호를 만료일 및 보안 코드 위에 배치합니다. `compact`는 세 필드를 모두 한 줄에 배치합니다. 기본값은 `"stacked"`입니다.

## 이벤트

생성 옵션 또는 React props로 콜백을 전달합니다.

### `onChange`

카드 필드가 변경될 때 실행됩니다. 구매자가 세 필드를 모두 채우면 `complete`가 true가 됩니다. 이를 사용해 확인 버튼을 활성화하세요. `brand`는 감지된 카드 네트워크입니다. `funding`은 감지된 자금 유형(`credit`, `debit`, `prepaid`)이며, 번호로 식별되기 전까지는 `null`입니다. `issuingCountry`는 카드가 발급된 국가의 소문자 두 글자 코드이며, 번호로 식별되기 전까지는 `null`입니다.

**payload** `object`

**속성**

**complete** `boolean` *required*

**brand** `string` *required*

**funding** `string | null` *required*

**issuingCountry** `string | null` *required*

### `onLoaderStart`

로딩 스켈레톤이 처음 그려진 후, `onReady` 전에 실행됩니다.

### `onReady`

엘리먼트가 처음으로 완전히 그려진 후 실행됩니다.

### `onError`

엘리먼트가 로드에 실패하거나 충돌할 때 실행됩니다. 대체 화면은 계속 표시됩니다. 프로그래밍 방식으로 처리하려면 `code`를 사용하세요. `sourceKey`는 실패한 호스트 상태 소스를 식별합니다.

**e** `object`

**속성**

**message** `string` *required*

**code** `string`

**sourceKey** `string`

## 메서드

`create`가 반환한 핸들에서, 또는 React `ref`를 통해 호출합니다.

### `mount`

`target`에 엘리먼트를 마운트하고 로딩을 시작합니다. React 컴포넌트는 자동으로 마운트됩니다.

**매개변수**

**target** `string | HTMLElement` *required*

### `destroy`

엘리먼트를 제거하고 프레임과 구독을 해제합니다. 여러 번 호출해도 됩니다. React는 엘리먼트를 자동으로 제거합니다.

### `update`

마운트된 엘리먼트에 새 props를 병합합니다. React에서는 대신 컴포넌트 props를 변경하세요.

**매개변수**

**options** `Partial\<CardElementProps\>` *required*

## 스타일링

`appearance.classes`를 통해 다음 파트의 스타일을 지정합니다. 속성 이름은 카멜 케이스 또는 케밥 케이스를 사용하고 단위를 포함하세요. 페이지 스타일시트는 엘리먼트의 프레임에 적용되지 않습니다. 프레임워크는 각 선언을 삽입하기 전에 검증합니다.

| 클래스 | 대상 |
| - | - |
| `.whop-Card` | 카드 엘리먼트 루트 |
| `.whop-CardError` | 카드 구성 오류 창 |
| `.whop-CardField` | 카드 번호, 만료일 또는 보안 코드 필드 |
| `.whop-CardFieldError` | 카드 유효성 검사 메시지 |
| `.whop-CardFieldGroup` | 세로로 쌓인 카드 번호, 만료일, 보안 코드 필드 |
| `.whop-CardFieldInput` | 테두리가 있는 PCI 입력 컨테이너 |
| `.whop-CardFieldInputFocused` | 포커스된 PCI 입력 컨테이너 |
| `.whop-CardFieldInputInvalid` | 유효하지 않거나 불완전한 PCI 입력 컨테이너 |
| `.whop-CardFieldRow` | 한 줄로 배치된 카드 번호, 만료일, 보안 코드 행 |

```ts theme={null}
const payments = whop.payments.create({
  appearance: {
    classes: {
      'whop-Card': { borderRadius: '8px', fontWeight: '600' },
      'whop-CardError': { borderRadius: '8px', fontWeight: '600' },
      'whop-CardField': { borderRadius: '8px', fontWeight: '600' }
    }
  }
});

// 9 classes use this shape
payments.update({
  appearance: { classes: { 'whop-Card': { fontWeight: '700' } } }
});
```

React에서는 `<Payments>`에 `appearance`를 전달하세요. 전역으로 설정하려면 `WhopElements({ appearance })`를 사용하세요.

## 매개변수

**layout** `WhopCardElement.Layout`

`.stacked`는 번호를 만료일 및 보안 코드 위에 배치하고, `.compact`는 세 필드를 모두 한 줄에 배치합니다. 기본값은 `.stacked`입니다.

**publicKey** `String?`

고급 퍼블리셔블 키입니다. 생략하면 계정 자체의 키를 가져옵니다.

**state** `Binding\<WhopCardState\>?`

완료 여부와 감지된 브랜드를 다시 읽어옵니다.

## `WhopCardState`

선택 시 반환되는 값:

* `isComplete: Bool`: 세 필드가 모두 유효함
* `brand: String?`: 번호로 식별된 후 감지된 네트워크

## 상태

즉시 렌더링되며 구매자가 입력하는 동안 유효성을 검사합니다. 번호로 브랜드가 식별되면 브랜드가 표시됩니다. 세 필드가 모두 유효하면 `state.isComplete`가 true가 됩니다.

## 알아두면 좋은 점

* 카드만 결제 수단으로 받는다면 [`WhopPaymentElement`](https://docs.whop.com/ko/elements/latest/payments/payment#swift) 대신 사용하세요. 둘 다 마운트하면 충돌합니다. 컨트롤러는 하나의 수집 화면에서 토큰을 발급합니다.
* `createConfirmationToken(billingDetails:)`는 카드 경로에 카드 소유자 이름이 필요하므로, 이름을 전달하거나 이름을 수집하는 주소 엘리먼트를 마운트하세요.
* `publicKey`는 고급 우회 수단입니다. 생략하면 SDK가 계정의 토크나이저 키를 가져옵니다.

## 설치

```swift theme={null}
dependencies: [
    .package(url: "https://github.com/whopio/elements-swift.git", from: "0.1.0")
]
```

> [!NOTE]
>
> 컨트롤러를 생성하여 콘텐츠에 전달하는 `WhopPayments(accountID:charge:)` 스코프 안에 마운트하세요. 이메일 로그인으로 구매자가 확인되면 `payments.buyer`는 로그인한 구매자입니다. Whop은 이러한 판매의 판매 대행자이며 `createConfirmationToken`은 `WhopBrandingElement` 없이는 거부되므로, 이 엘리먼트도 화면에 있어야 합니다. 스타일은 `.whopElementsAppearance(_:)`로 지정합니다. 모듈은 지갑 SDK의 `WhopElements`가 아니라 `Elements`입니다. [시작하기](https://docs.whop.com/ko/elements/latest/getting-started.md) 및 [Appearance](https://docs.whop.com/ko/elements/latest/appearance.md)를 참고하세요.

## Props

**layout** `'stacked' | 'compact'`

`stacked`는 번호를 만료일 및 보안 코드 위에 배치합니다. `compact`는 세 필드를 모두 한 줄에 배치합니다. 기본값은 `stacked`입니다.

**onChange** `(payload: CardFieldsChangePayload) =\> void`

편집할 때마다 완료 여부와 필드별 오류와 함께 실행됩니다.

**style** `StyleProp\<ViewStyle\>`

엘리먼트의 외부 `View`에 적용됩니다. 테마 지정에는 이 화면의 모든 엘리먼트에 적용되는 프로바이더의 `appearance.parts`를 사용하는 것이 좋습니다. 현재 React Native 파트 이름은 웹의 `whop-*` 클래스 이름과 별개의 체계이므로, 웹 appearance 객체를 그대로 옮겨 쓸 수 없습니다.

**fallback** `ReactNode`

엘리먼트가 로드되는 동안 기본 스켈레톤 대신 렌더링됩니다.

**onReady** `() =\> void`

엘리먼트가 상호작용 가능해지면 한 번 실행됩니다. `<Payments>`가 이를 그룹화하므로 보통은 `<Payments>` 자체의 `onLoadingChange`를 사용하는 것이 좋습니다.

**onError** `(error: \{ message: string; code?: string \}) =\> void`

이 엘리먼트의 로드 또는 구성 실패입니다. 어떤 경우든 엘리먼트는 자체 오류 화면을 렌더링합니다.

## `CardFieldsChangePayload`

`onChange`가 반환하는 값:

* `complete: boolean`: 모든 필드가 채워지고 유효함
* `errors: Record<string, string>`: 필드별 메시지이며, `complete`가 true일 때에만 정확히 비어 있음

## 상태

퍼블리셔블 키가 확인되면 세 필드가 함께 렌더링됩니다. 세 필드가 모두 유효하면 `onChange`가 `complete`를 보고하며, 엘리먼트는 필드별 오류를 자체적으로 표시합니다.

## 알아두면 좋은 점

* 카드 번호는 절대 사용자 코드를 거치지 않습니다. 필드는 PCI로 격리된 네이티브 입력이며 SDK가 Whop에 토큰을 전달하므로, 앱은 PCI 범위 밖에 머무릅니다.
* 이 엘리먼트를 마운트하면 프로바이더의 수집 화면이 카드가 되므로, 추가 연결 없이 `createConfirmationToken`이 이를 토큰화합니다. `PaymentElement`와 함께 마운트하지 마세요. 한 번에 정확히 하나의 수집 화면만 활성화됩니다.
* 세 필드를 직접 만든 레이아웃에 배치하는 폼이라면 대신 [`CardFields`](https://docs.whop.com/ko/elements/latest/payments/cardFields)를 사용하세요.

> [!NOTE]
>
> 앱을 `<WhopElements getToken={…}>`로 한 번 감싼 다음, 엘리먼트를 `<Payments>`로 감싸 마운트하세요. [시작하기](https://docs.whop.com/ko/elements/latest/getting-started.md) 및 [Appearance](https://docs.whop.com/ko/elements/latest/appearance.md)를 참고하세요.


## Related topics

- [CardFields](https://docs.whop.com/ko/elements/latest/payments/cardFields.md)
- [Elements 시작하기](https://docs.whop.com/ko/elements/latest/getting-started.md)
- [PaymentElement](https://docs.whop.com/ko/elements/latest/payments/payment.md)
