> ## 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.

# Håndter svindel

> Tilføj dine egne betalingsregler oven på Whops svindelkontroller for at blokere eller gennemgå risikable checkouts.

En svigagtig betaling koster dig pengene, et [tvistgebyr på \$15](https://docs.whop.com/da/manage-your-business/manage-payments/manage-disputes.md) og en dårligere [tvistrate](https://docs.whop.com/da/trust-and-safety/account-health/managing-dispute-rates.md). Whop screener checkouts med sine egne svindelkontroller. Betalingsregler tilføjer dit eget lag ovenpå: betingelser, du skriver, og en handling, Whop udfører, når en checkout matcher dem alle.

Regler kører efter Whops kontroller og lemper dem aldrig. En betaling, Whop blokerer, forbliver blokeret.

## Fire måder, en regel kan handle på

| Handling | Hvad der sker | Når flere regler matcher |
| - | - | - |
| `block` | Betalingen afvises før autorisation. Køberen ser en generisk afvisning. | Vinder over `review` og `enforce_3ds` |
| `review` | Et kvalificeret kort autoriseres uden capture. Automatisk capture planlægges til 48 timer efter autorisationen. Du kan capture eller annullere den tidligere. Ikke-understøttede metoder springer gennemgangen over og fortsætter gennem normal betalingsbehandling. | Vinder over `enforce_3ds` |
| `enforce_3ds` | Køberen bekræfter betalingen hos sin bank via 3D Secure. | Laveste prioritet |
| `allow` | Betalingen springer dine andre regler over. Den springer aldrig Whops kontroller over. | Vinder over alle tre |

En regel kan læse `risk_score`, `amount_in_usd`, `card_country`, `card_bin`, `customer_email` og `ip_address`. `card_bin` er Bank Identification Number for det kort, der blev brugt til betalingen: de første seks cifre i kortnummeret. [List fields](https://docs.whop.com/da/api-reference/payment-rules/list-fields.md) returnerer de operatorer og værdier, hvert felt accepterer.

Når du er i tvivl, så udfordr i stedet for at blokere. En blokering afviser også rigtige købere, der matcher, mens en udfordring lader dem bevise, at de er kortholderen.

> [!NOTE]
>
> Kør disse eksempler i et betroet servermiljø med `WHOP_API_KEY` angivet.
> Genbrug imports og klientopsætning fra det første eksempel for dit sprog.

## Bloker den åbenlyse svindel

Start med det mønster, du ser oftest i dine [tvister](https://docs.whop.com/da/developer/guides/refunds-and-disputes.md). Denne regel blokerer en betaling, som Whop scorer 85 eller højere, på et kort udstedt uden for USA.

```typescript TypeScript theme={null}
import { WhopClient } from "@whop/sdk";

const client = new WhopClient({ token: process.env.WHOP_API_KEY });

const rule = await client.paymentRules.create({
	account_id: "biz_xxxxxxxxxxxxx",
	name: "Block high-risk cards from outside the US",
	action: "block",
	conditions: {
		all: [
			{ field: "risk_score", operator: "gte", value: 85 },
			{ field: "card_country", operator: "neq", value: "US" },
		],
	},
});

console.log(rule.id); // prule_xxxxxxxxxxxxx
```

```python Python theme={null}
import os
from whop_sdk import Whop
from whop_sdk.payment_rules import (
    CreatePaymentRulesRequestConditions,
    CreatePaymentRulesRequestConditionsAllItem,
)

client = Whop(token=os.environ["WHOP_API_KEY"])

rule = client.payment_rules.create(
    account_id="biz_xxxxxxxxxxxxx",
    name="Block high-risk cards from outside the US",
    action="block",
    conditions=CreatePaymentRulesRequestConditions(
        all_=[
            CreatePaymentRulesRequestConditionsAllItem(field="risk_score", operator="gte", value=85),
            CreatePaymentRulesRequestConditionsAllItem(field="card_country", operator="neq", value="US"),
        ],
    ),
)

print(rule.id)  # prule_xxxxxxxxxxxxx
```

```ruby Ruby theme={null}
require "whop_sdk"

client = Whop_sdk::Client.new(token: ENV.fetch("WHOP_API_KEY"))

rule = client.payment_rules.create(
  account_id: "biz_xxxxxxxxxxxxx",
  name: "Block high-risk cards from outside the US",
  action: "block",
  conditions: {
    all: [
      { field: "risk_score", operator: "gte", value: 85 },
      { field: "card_country", operator: "neq", value: "US" }
    ]
  }
)

puts rule.id # prule_xxxxxxxxxxxxx
```

```rust Rust theme={null}
use whop_sdk::prelude::*;

let config = ClientConfig {
    token: Some(std::env::var("WHOP_API_KEY").unwrap()),
    ..Default::default()
};
let client = Whop::new(config).expect("Failed to build client");

let rule = client
    .payment_rules
    .create(
        &CreatePaymentRulesRequest {
            name: "Block high-risk cards from outside the US".to_string(),
            action: CreatePaymentRulesRequestAction::Block,
            conditions: CreatePaymentRulesRequestConditions {
                all: vec![
                    CreatePaymentRulesRequestConditionsAllItem {
                        field: CreatePaymentRulesRequestConditionsAllItemField::RiskScore,
                        operator: CreatePaymentRulesRequestConditionsAllItemOperator::Gte,
                        value: PaymentRuleConditionValue::Integer(85),
                    },
                    CreatePaymentRulesRequestConditionsAllItem {
                        field: CreatePaymentRulesRequestConditionsAllItemField::CardCountry,
                        operator: CreatePaymentRulesRequestConditionsAllItemOperator::Neq,
                        value: PaymentRuleConditionValue::String("US".to_string()),
                    },
                ],
                ..Default::default()
            },
            account_id: Some("biz_xxxxxxxxxxxxx".to_string()),
            metadata: None,
        },
        None,
    )
    .await?;

println!("{}", rule.id); // prule_xxxxxxxxxxxxx
```

```go Go theme={null}
import (
    "context"
    "fmt"
    "log"
    "os"

    whopsdk "github.com/whopio/whopsdk-go/v2"
    "github.com/whopio/whopsdk-go/v2/client"
    "github.com/whopio/whopsdk-go/v2/option"
)

client := client.NewWhop(option.WithToken(os.Getenv("WHOP_API_KEY")))

rule, err := client.PaymentRules.Create(context.TODO(), &whopsdk.CreatePaymentRulesRequest{
    AccountID: whopsdk.String("biz_xxxxxxxxxxxxx"),
    Name:      "Block high-risk cards from outside the US",
    Action:    whopsdk.CreatePaymentRulesRequestActionBlock,
    Conditions: &whopsdk.CreatePaymentRulesRequestConditions{
        All: []*whopsdk.CreatePaymentRulesRequestConditionsAllItem{
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldRiskScore,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorGte,
                Value:    &whopsdk.PaymentRuleConditionValue{Integer: 85},
            },
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldCardCountry,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorNeq,
                Value:    &whopsdk.PaymentRuleConditionValue{String: "US"},
            },
        },
    },
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(rule.ID) // prule_xxxxxxxxxxxxx
```

```java Java theme={null}
import com.whop.api.WhopApiClient;
import com.whop.api.resources.paymentrules.requests.CreatePaymentRulesRequest;
import com.whop.api.resources.paymentrules.types.*;
import com.whop.api.types.PaymentRuleConditionValue;
import java.util.List;

var client = WhopApiClient.builder()
    .token(System.getenv("WHOP_API_KEY"))
    .build();

var rule = client.paymentRules().create(
    CreatePaymentRulesRequest.builder()
        .accountId("biz_xxxxxxxxxxxxx")
        .name("Block high-risk cards from outside the US")
        .action(CreatePaymentRulesRequestAction.BLOCK)
        .conditions(CreatePaymentRulesRequestConditions.builder()
            .all(List.of(
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.RISK_SCORE)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.GTE)
                    .value(PaymentRuleConditionValue.of(85))
                    .build(),
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.CARD_COUNTRY)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.NEQ)
                    .value(PaymentRuleConditionValue.of("US"))
                    .build()
            ))
            .build())
        .build()
);
System.out.println(rule.getId());
```

```swift Swift theme={null}
import Foundation
import WhopSDK

let client = Whop(token: ProcessInfo.processInfo.environment["WHOP_API_KEY"]!)

let rule = try await client.paymentRules.create(
    request: .init(
        accountId: "biz_xxxxxxxxxxxxx",
        action: .block,
        conditions: .init(all: [
            .init(
                field: .riskScore,
                operator: .gte,
                value: .int(85)
            ),
            .init(
                field: .cardCountry,
                operator: .neq,
                value: .string("US")
            )
        ]),
        name: "Block high-risk cards from outside the US"
    )
)
print(rule.id)
```

```bash cURL theme={null}
curl "https://api.whop.com/api/v1/payment_rules" \
  -H "Authorization: Bearer $WHOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "biz_xxxxxxxxxxxxx",
    "name": "Block high-risk cards from outside the US",
    "action": "block",
    "conditions": {
      "all": [
        { "field": "risk_score", "operator": "gte", "value": 85 },
        { "field": "card_country", "operator": "neq", "value": "US" }
      ]
    }
  }'
```

Send altid `account_id`. Uden den havner reglen på den konto, din legitimation som standard peger på, hvilket er let at tage fejl af for en platform, der administrerer flere. Regler udgives til checkout hvert minut, så en ny eller ændret regel begynder at gælde inden for et par minutter.

> [!NOTE]
>
> Påkrævet tilladelse: `payment:manage` for at skrive regler, `payment:basic:read` for at
> læse dem. Tilføj tilladelser via [guiden til
> tilladelser](https://docs.whop.com/da/developer/guides/permissions.md).

## Udfordr store ordrer

En stor ordre fra et stjålet kort er den chargeback, du allermindst ønsker. En stor ordre fra en rigtig kunde er det salg, du allermindst vil miste. En 3D Secure-udfordring skiller de to ad, og betalingen registrerer `three_ds_verified: true`, når køberen består.

`enforce_3ds` springes over, men registreres stadig på betalingen, når checkouten ikke kan bære en udfordring. Det omfatter betalinger uden for sessionen såsom fornyelser, varianter, der angiver deres eget 3D Secure-niveau, betalinger uden kort og kort, som processoren ikke kan udfordre. American Express udfordres kun ved betalinger i USD.

```typescript TypeScript theme={null}
await client.paymentRules.create({
	account_id: "biz_xxxxxxxxxxxxx",
	name: "Challenge orders over $500",
	action: "enforce_3ds",
	conditions: {
		all: [{ field: "amount_in_usd", operator: "gte", value: 500 }],
	},
});
```

```python Python theme={null}
client.payment_rules.create(
    account_id="biz_xxxxxxxxxxxxx",
    name="Challenge orders over $500",
    action="enforce_3ds",
    conditions=CreatePaymentRulesRequestConditions(
        all_=[CreatePaymentRulesRequestConditionsAllItem(field="amount_in_usd", operator="gte", value=500)],
    ),
)
```

```ruby Ruby theme={null}
client.payment_rules.create(
  account_id: "biz_xxxxxxxxxxxxx",
  name: "Challenge orders over $500",
  action: "enforce_3ds",
  conditions: {
    all: [{ field: "amount_in_usd", operator: "gte", value: 500 }]
  }
)
```

```rust Rust theme={null}
client
    .payment_rules
    .create(
        &CreatePaymentRulesRequest {
            name: "Challenge orders over $500".to_string(),
            action: CreatePaymentRulesRequestAction::Enforce3Ds,
            conditions: CreatePaymentRulesRequestConditions {
                all: vec![CreatePaymentRulesRequestConditionsAllItem {
                    field: CreatePaymentRulesRequestConditionsAllItemField::AmountInUsd,
                    operator: CreatePaymentRulesRequestConditionsAllItemOperator::Gte,
                    value: PaymentRuleConditionValue::Integer(500),
                }],
                ..Default::default()
            },
            account_id: Some("biz_xxxxxxxxxxxxx".to_string()),
            metadata: None,
        },
        None,
    )
    .await?;
```

```go Go theme={null}
_, err = client.PaymentRules.Create(context.TODO(), &whopsdk.CreatePaymentRulesRequest{
    AccountID: whopsdk.String("biz_xxxxxxxxxxxxx"),
    Name:      "Challenge orders over $500",
    Action:    whopsdk.CreatePaymentRulesRequestActionEnforce3Ds,
    Conditions: &whopsdk.CreatePaymentRulesRequestConditions{
        All: []*whopsdk.CreatePaymentRulesRequestConditionsAllItem{
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldAmountInUsd,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorGte,
                Value:    &whopsdk.PaymentRuleConditionValue{Integer: 500},
            },
        },
    },
})
if err != nil {
    log.Fatal(err)
}
```

```java Java theme={null}
var rule = client.paymentRules().create(
    CreatePaymentRulesRequest.builder()
        .accountId("biz_xxxxxxxxxxxxx")
        .name("Challenge orders over $500")
        .action(CreatePaymentRulesRequestAction.valueOf("enforce_3ds"))
        .conditions(CreatePaymentRulesRequestConditions.builder()
            .all(List.of(
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.AMOUNT_IN_USD)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.GTE)
                    .value(PaymentRuleConditionValue.of(500))
                    .build()
            ))
            .build())
        .build()
);
System.out.println(rule.getId());
```

```swift Swift theme={null}
let rule = try await client.paymentRules.create(
    request: .init(
        accountId: "biz_xxxxxxxxxxxxx",
        action: .enforce3ds,
        conditions: .init(all: [
            .init(
                field: .amountInUsd,
                operator: .gte,
                value: .int(500)
            )
        ]),
        name: "Challenge orders over $500"
    )
)
print(rule.id)
```

```bash cURL theme={null}
curl "https://api.whop.com/api/v1/payment_rules" \
  -H "Authorization: Bearer $WHOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "biz_xxxxxxxxxxxxx",
    "name": "Challenge orders over $500",
    "action": "enforce_3ds",
    "conditions": {
      "all": [
        { "field": "amount_in_usd", "operator": "gte", "value": 500 }
      ]
    }
  }'
```

## Gennemgå en betaling, før du opkræver den

En `review`-regel autoriserer en kvalificeret kortbetaling uden at capture den. Køberen gennemfører checkout og får adgang til medlemskabet ved autorisationen. Brug den til ordrer, du leverer manuelt, eller til et mønster, der er risikabelt, men ikke med sikkerhed svindel. Whop capturer automatisk 48 timer senere, medmindre du handler først:

* [Capture](https://docs.whop.com/da/api-reference/payments/capture-payment.md) for at indkassere pengene. Betalingen bliver `paid`, og Whop sender `payment.succeeded`, dit signal til at levere ordren.
* [Void](https://docs.whop.com/da/api-reference/payments/void-payment.md) for at frigive reservationen. Whop tilbagekalder adgangen, returnerer reserveret lager og sender `payment.canceled`.

Whop sender `payment.authorized`, når reservationen starter, og også ved autorisationer anmodet via API'et. En reserveret betaling har `status: "authorized"` med `substatus: "requires_capture"`. [Hent betalingsstatussen](https://docs.whop.com/da/api-reference/payments/retrieve-payment-status.md) for at få `auto_capture_at`.

Denne regel reserverer kortbetalinger på mindst \$250, hvor kortet er udstedt uden for USA.

```typescript TypeScript theme={null}
await client.paymentRules.create({
	account_id: "biz_xxxxxxxxxxxxx",
	name: "Review large orders from abroad",
	action: "review",
	conditions: {
		all: [
			{ field: "amount_in_usd", operator: "gte", value: 250 },
			{ field: "card_country", operator: "neq", value: "US" },
		],
	},
});
```

```python Python theme={null}
client.payment_rules.create(
    account_id="biz_xxxxxxxxxxxxx",
    name="Review large orders from abroad",
    action="review",
    conditions=CreatePaymentRulesRequestConditions(
        all_=[
            CreatePaymentRulesRequestConditionsAllItem(field="amount_in_usd", operator="gte", value=250),
            CreatePaymentRulesRequestConditionsAllItem(field="card_country", operator="neq", value="US"),
        ],
    ),
)
```

```ruby Ruby theme={null}
client.payment_rules.create(
  account_id: "biz_xxxxxxxxxxxxx",
  name: "Review large orders from abroad",
  action: "review",
  conditions: {
    all: [
      { field: "amount_in_usd", operator: "gte", value: 250 },
      { field: "card_country", operator: "neq", value: "US" }
    ]
  }
)
```

```rust Rust theme={null}
client
    .payment_rules
    .create(
        &CreatePaymentRulesRequest {
            name: "Review large orders from abroad".to_string(),
            action: CreatePaymentRulesRequestAction::Review,
            conditions: CreatePaymentRulesRequestConditions {
                all: vec![
                    CreatePaymentRulesRequestConditionsAllItem {
                        field: CreatePaymentRulesRequestConditionsAllItemField::AmountInUsd,
                        operator: CreatePaymentRulesRequestConditionsAllItemOperator::Gte,
                        value: PaymentRuleConditionValue::Integer(250),
                    },
                    CreatePaymentRulesRequestConditionsAllItem {
                        field: CreatePaymentRulesRequestConditionsAllItemField::CardCountry,
                        operator: CreatePaymentRulesRequestConditionsAllItemOperator::Neq,
                        value: PaymentRuleConditionValue::String("US".to_string()),
                    },
                ],
                ..Default::default()
            },
            account_id: Some("biz_xxxxxxxxxxxxx".to_string()),
            metadata: None,
        },
        None,
    )
    .await?;
```

```go Go theme={null}
_, err = client.PaymentRules.Create(context.TODO(), &whopsdk.CreatePaymentRulesRequest{
    AccountID: whopsdk.String("biz_xxxxxxxxxxxxx"),
    Name:      "Review large orders from abroad",
    Action:    whopsdk.CreatePaymentRulesRequestActionReview,
    Conditions: &whopsdk.CreatePaymentRulesRequestConditions{
        All: []*whopsdk.CreatePaymentRulesRequestConditionsAllItem{
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldAmountInUsd,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorGte,
                Value:    &whopsdk.PaymentRuleConditionValue{Integer: 250},
            },
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldCardCountry,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorNeq,
                Value:    &whopsdk.PaymentRuleConditionValue{String: "US"},
            },
        },
    },
})
if err != nil {
    log.Fatal(err)
}
```

```java Java theme={null}
var rule = client.paymentRules().create(
    CreatePaymentRulesRequest.builder()
        .accountId("biz_xxxxxxxxxxxxx")
        .name("Review large orders from abroad")
        .action(CreatePaymentRulesRequestAction.REVIEW)
        .conditions(CreatePaymentRulesRequestConditions.builder()
            .all(List.of(
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.AMOUNT_IN_USD)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.GTE)
                    .value(PaymentRuleConditionValue.of(250))
                    .build(),
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.CARD_COUNTRY)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.NEQ)
                    .value(PaymentRuleConditionValue.of("US"))
                    .build()
            ))
            .build())
        .build()
);
System.out.println(rule.getId());
```

```swift Swift theme={null}
let rule = try await client.paymentRules.create(
    request: .init(
        accountId: "biz_xxxxxxxxxxxxx",
        action: .review,
        conditions: .init(all: [
            .init(
                field: .amountInUsd,
                operator: .gte,
                value: .int(250)
            ),
            .init(
                field: .cardCountry,
                operator: .neq,
                value: .string("US")
            )
        ]),
        name: "Review large orders from abroad"
    )
)
print(rule.id)
```

```bash cURL theme={null}
curl "https://api.whop.com/api/v1/payment_rules" \
  -H "Authorization: Bearer $WHOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "biz_xxxxxxxxxxxxx",
    "name": "Review large orders from abroad",
    "action": "review",
    "conditions": {
      "all": [
        { "field": "amount_in_usd", "operator": "gte", "value": 250 },
        { "field": "card_country", "operator": "neq", "value": "US" }
      ]
    }
  }'
```

Når du har gennemgået ordren, kan du capture den via betalings-ID'et:

```typescript TypeScript theme={null}
await client.payments.capture({ id: "pay_xxxxxxxxxxxxx" });
```

```python Python theme={null}
client.payments.capture(id="pay_xxxxxxxxxxxxx")
```

```ruby Ruby theme={null}
client.payments.capture(id: "pay_xxxxxxxxxxxxx")
```

```rust Rust theme={null}
client.payments.capture("pay_xxxxxxxxxxxxx", None).await?;
```

```go Go theme={null}
_, err = client.Payments.Capture(context.TODO(), &whopsdk.CapturePaymentsRequest{
    ID: "pay_xxxxxxxxxxxxx",
})
if err != nil {
    log.Fatal(err)
}
```

```java Java theme={null}
client.payments().capture("pay_xxxxxxxxxxxxx");
```

```swift Swift theme={null}
_ = try await client.payments.capture(id: "pay_xxxxxxxxxxxxx")
```

```bash cURL theme={null}
curl -X POST "https://api.whop.com/api/v1/payments/pay_xxxxxxxxxxxxx/capture" \
  -H "Authorization: Bearer $WHOP_API_KEY"
```

Eller annullere den:

```typescript TypeScript theme={null}
await client.payments.void({ id: "pay_xxxxxxxxxxxxx" });
```

```python Python theme={null}
client.payments.void(id="pay_xxxxxxxxxxxxx")
```

```ruby Ruby theme={null}
client.payments.void(id: "pay_xxxxxxxxxxxxx")
```

```rust Rust theme={null}
client.payments.void("pay_xxxxxxxxxxxxx", None).await?;
```

```go Go theme={null}
_, err = client.Payments.Void(context.TODO(), &whopsdk.VoidPaymentsRequest{
    ID: "pay_xxxxxxxxxxxxx",
})
if err != nil {
    log.Fatal(err)
}
```

```java Java theme={null}
client.payments().void_("pay_xxxxxxxxxxxxx");
```

```swift Swift theme={null}
_ = try await client.payments.void(id: "pay_xxxxxxxxxxxxx")
```

```bash cURL theme={null}
curl -X POST "https://api.whop.com/api/v1/payments/pay_xxxxxxxxxxxxx/void" \
  -H "Authorization: Bearer $WHOP_API_KEY"
```

### Begrænsninger ved gennemgang

* **Kun kort i sessionen kan reserveres.** Apple Pay, Google Pay, bank, saldo og betalinger uden for sessionen såsom fornyelser springer gennemgangen over. Matchet registreres stadig i `payment_rule_matches`.
* **Betalinger oprettet med `capture: false` beholder deres egen tidsplan.** En gennemgangsregel tilsidesætter den aldrig.
* **Capture er alt eller intet.** Refunder bagefter for at returnere en del af beløbet.
* **Købere har produktet, før du beslutter dig.** Giv dem besked, hvis du annullerer.

## Hold betroede købere i gang

En `allow`-regel undtager købere, du har tillid til, fra dine regler for blokering, gennemgang og udfordring.

```typescript TypeScript theme={null}
await client.paymentRules.create({
	account_id: "biz_xxxxxxxxxxxxx",
	name: "Trusted customers",
	action: "allow",
	conditions: {
		all: [
			{
				field: "customer_email",
				operator: "in",
				value: ["ava@example.com", "noah@example.com"],
			},
		],
	},
});
```

```python Python theme={null}
client.payment_rules.create(
    account_id="biz_xxxxxxxxxxxxx",
    name="Trusted customers",
    action="allow",
    conditions=CreatePaymentRulesRequestConditions(
        all_=[
            CreatePaymentRulesRequestConditionsAllItem(
                field="customer_email",
                operator="in",
                value=["ava@example.com", "noah@example.com"],
            )
        ],
    ),
)
```

```ruby Ruby theme={null}
client.payment_rules.create(
  account_id: "biz_xxxxxxxxxxxxx",
  name: "Trusted customers",
  action: "allow",
  conditions: {
    all: [
      { field: "customer_email", operator: "in", value: ["ava@example.com", "noah@example.com"] }
    ]
  }
)
```

```rust Rust theme={null}
client
    .payment_rules
    .create(
        &CreatePaymentRulesRequest {
            name: "Trusted customers".to_string(),
            action: CreatePaymentRulesRequestAction::Allow,
            conditions: CreatePaymentRulesRequestConditions {
                all: vec![CreatePaymentRulesRequestConditionsAllItem {
                    field: CreatePaymentRulesRequestConditionsAllItemField::CustomerEmail,
                    operator: CreatePaymentRulesRequestConditionsAllItemOperator::In,
                    value: PaymentRuleConditionValue::StringList(vec![
                        "ava@example.com".to_string(),
                        "noah@example.com".to_string(),
                    ]),
                }],
                ..Default::default()
            },
            account_id: Some("biz_xxxxxxxxxxxxx".to_string()),
            metadata: None,
        },
        None,
    )
    .await?;
```

```go Go theme={null}
_, err = client.PaymentRules.Create(context.TODO(), &whopsdk.CreatePaymentRulesRequest{
    AccountID: whopsdk.String("biz_xxxxxxxxxxxxx"),
    Name:      "Trusted customers",
    Action:    whopsdk.CreatePaymentRulesRequestActionAllow,
    Conditions: &whopsdk.CreatePaymentRulesRequestConditions{
        All: []*whopsdk.CreatePaymentRulesRequestConditionsAllItem{
            {
                Field:    whopsdk.CreatePaymentRulesRequestConditionsAllItemFieldCustomerEmail,
                Operator: whopsdk.CreatePaymentRulesRequestConditionsAllItemOperatorIn,
                Value: &whopsdk.PaymentRuleConditionValue{
                    StringList: []string{"ava@example.com", "noah@example.com"},
                },
            },
        },
    },
})
if err != nil {
    log.Fatal(err)
}
```

```java Java theme={null}
var rule = client.paymentRules().create(
    CreatePaymentRulesRequest.builder()
        .accountId("biz_xxxxxxxxxxxxx")
        .name("Trusted customers")
        .action(CreatePaymentRulesRequestAction.ALLOW)
        .conditions(CreatePaymentRulesRequestConditions.builder()
            .all(List.of(
                CreatePaymentRulesRequestConditionsAllItem.builder()
                    .field(CreatePaymentRulesRequestConditionsAllItemField.CUSTOMER_EMAIL)
                    .operator(CreatePaymentRulesRequestConditionsAllItemOperator.IN)
                    .value(PaymentRuleConditionValue.of(List.of("ava@example.com", "noah@example.com")))
                    .build()
            ))
            .build())
        .build()
);
System.out.println(rule.getId());
```

```swift Swift theme={null}
let rule = try await client.paymentRules.create(
    request: .init(
        accountId: "biz_xxxxxxxxxxxxx",
        action: .allow,
        conditions: .init(all: [
            .init(
                field: .customerEmail,
                operator: .`in`,
                value: .stringArray(["ava@example.com", "noah@example.com"])
            )
        ]),
        name: "Trusted customers"
    )
)
print(rule.id)
```

```bash cURL theme={null}
curl "https://api.whop.com/api/v1/payment_rules" \
  -H "Authorization: Bearer $WHOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "biz_xxxxxxxxxxxxx",
    "name": "Trusted customers",
    "action": "allow",
    "conditions": {
      "all": [
        { "field": "customer_email", "operator": "in", "value": ["ava@example.com", "noah@example.com"] }
      ]
    }
  }'
```

## Stram en regel

Hvad en regel gør, ligger fast, når den er oprettet, så de betalinger, den afgjorde, fortsat henviser til den regel, der afgjorde dem. For at ændre dens handling eller betingelser skal du [erstatte](https://docs.whop.com/da/api-reference/payment-rules/replace-a-payment-rule.md) den: den gamle regel slettes, og en efterfølger med et nyt ID arver dens navn, `metadata` og aktive tilstand. Her hæves blokeringsgrænsen fra 85 til 90, efter at den fangede for mange rigtige købere.

```typescript TypeScript theme={null}
const successor = await client.paymentRules.replace({
	id: "prule_xxxxxxxxxxxxx",
	action: "block",
	conditions: {
		all: [
			{ field: "risk_score", operator: "gte", value: 90 },
			{ field: "card_country", operator: "neq", value: "US" },
		],
	},
});

console.log(successor.id); // a new prule_ ID
```

```python Python theme={null}
from whop_sdk.payment_rules import (
    ReplacePaymentRulesRequestConditions,
    ReplacePaymentRulesRequestConditionsAllItem,
)

successor = client.payment_rules.replace(
    id="prule_xxxxxxxxxxxxx",
    action="block",
    conditions=ReplacePaymentRulesRequestConditions(
        all_=[
            ReplacePaymentRulesRequestConditionsAllItem(field="risk_score", operator="gte", value=90),
            ReplacePaymentRulesRequestConditionsAllItem(field="card_country", operator="neq", value="US"),
        ],
    ),
)

print(successor.id)  # a new prule_ ID
```

```ruby Ruby theme={null}
successor = client.payment_rules.replace(
  id: "prule_xxxxxxxxxxxxx",
  action: "block",
  conditions: {
    all: [
      { field: "risk_score", operator: "gte", value: 90 },
      { field: "card_country", operator: "neq", value: "US" }
    ]
  }
)

puts successor.id # a new prule_ ID
```

```rust Rust theme={null}
let successor = client
    .payment_rules
    .replace(
        &"prule_xxxxxxxxxxxxx".to_string(),
        &ReplacePaymentRulesRequest {
            action: ReplacePaymentRulesRequestAction::Block,
            conditions: ReplacePaymentRulesRequestConditions {
                all: vec![
                    ReplacePaymentRulesRequestConditionsAllItem {
                        field: ReplacePaymentRulesRequestConditionsAllItemField::RiskScore,
                        operator: ReplacePaymentRulesRequestConditionsAllItemOperator::Gte,
                        value: PaymentRuleConditionValue::Integer(90),
                    },
                    ReplacePaymentRulesRequestConditionsAllItem {
                        field: ReplacePaymentRulesRequestConditionsAllItemField::CardCountry,
                        operator: ReplacePaymentRulesRequestConditionsAllItemOperator::Neq,
                        value: PaymentRuleConditionValue::String("US".to_string()),
                    },
                ],
                ..Default::default()
            },
        },
        None,
    )
    .await?;

println!("{}", successor.id); // a new prule_ ID
```

```go Go theme={null}
successor, err := client.PaymentRules.Replace(context.TODO(), &whopsdk.ReplacePaymentRulesRequest{
    ID:     "prule_xxxxxxxxxxxxx",
    Action: whopsdk.ReplacePaymentRulesRequestActionBlock,
    Conditions: &whopsdk.ReplacePaymentRulesRequestConditions{
        All: []*whopsdk.ReplacePaymentRulesRequestConditionsAllItem{
            {
                Field:    whopsdk.ReplacePaymentRulesRequestConditionsAllItemFieldRiskScore,
                Operator: whopsdk.ReplacePaymentRulesRequestConditionsAllItemOperatorGte,
                Value:    &whopsdk.PaymentRuleConditionValue{Integer: 90},
            },
            {
                Field:    whopsdk.ReplacePaymentRulesRequestConditionsAllItemFieldCardCountry,
                Operator: whopsdk.ReplacePaymentRulesRequestConditionsAllItemOperatorNeq,
                Value:    &whopsdk.PaymentRuleConditionValue{String: "US"},
            },
        },
    },
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(successor.ID) // a new prule_ ID
```

```java Java theme={null}
import com.whop.api.resources.paymentrules.requests.ReplacePaymentRulesRequest;

var successor = client.paymentRules().replace(
    "prule_xxxxxxxxxxxxx",
    ReplacePaymentRulesRequest.builder()
        .action(ReplacePaymentRulesRequestAction.BLOCK)
        .conditions(ReplacePaymentRulesRequestConditions.builder()
            .all(List.of(
                ReplacePaymentRulesRequestConditionsAllItem.builder()
                    .field(ReplacePaymentRulesRequestConditionsAllItemField.RISK_SCORE)
                    .operator(ReplacePaymentRulesRequestConditionsAllItemOperator.GTE)
                    .value(PaymentRuleConditionValue.of(90))
                    .build(),
                ReplacePaymentRulesRequestConditionsAllItem.builder()
                    .field(ReplacePaymentRulesRequestConditionsAllItemField.CARD_COUNTRY)
                    .operator(ReplacePaymentRulesRequestConditionsAllItemOperator.NEQ)
                    .value(PaymentRuleConditionValue.of("US"))
                    .build()
            ))
            .build())
        .build()
);
System.out.println(successor.getId());
```

```swift Swift theme={null}
let successor = try await client.paymentRules.replace(
    id: "prule_xxxxxxxxxxxxx",
    request: .init(
        action: .block,
        conditions: .init(all: [
            .init(
                field: .riskScore,
                operator: .gte,
                value: .int(90)
            ),
            .init(
                field: .cardCountry,
                operator: .neq,
                value: .string("US")
            )
        ])
    )
)
print(successor.id)
```

```bash cURL theme={null}
curl "https://api.whop.com/api/v1/payment_rules/prule_xxxxxxxxxxxxx/replace" \
  -H "Authorization: Bearer $WHOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "block",
    "conditions": {
      "all": [
        { "field": "risk_score", "operator": "gte", "value": 90 },
        { "field": "card_country", "operator": "neq", "value": "US" }
      ]
    }
  }'
```

[Deaktiver](https://docs.whop.com/da/api-reference/payment-rules/deactivate-a-payment-rule.md) en regel for at sætte den på pause, og [aktivér](https://docs.whop.com/da/api-reference/payment-rules/activate-a-payment-rule.md) den for at genoptage. [Slet](https://docs.whop.com/da/api-reference/payment-rules/delete-a-payment-rule.md) den for at udfase den. Den kan stadig læses med `status: "deleted"`.

## Mål effekten

Hver betaling angiver i `payment_rule_matches` de regler, der matchede den, med det navn, reglen havde på det tidspunkt.

```json theme={null}
{
	"id": "pay_xxxxxxxxxxxxx",
	"substatus": "blocked",
	"risk_score": 91,
	"payment_rule_matches": [
		{
			"id": "prule_xxxxxxxxxxxxx",
			"name": "Block high-risk cards from outside the US",
			"action": "block"
		}
	]
}
```

Tvister på betalinger uden match betyder, at en regel er for snæver. En regel, der matcher langt flere betalinger, end du mistede, er for bred. For totaler over tid kan [Stats API'ets](https://docs.whop.com/da/developer/guides/stats.md) metrikker `payment_rule_matches` og `payment_rule_matched_volume` opdeles efter `payment_rule_ids` eller `action`.

## Næste trin

> [card] [Reference for betalingsregler](https://docs.whop.com/da/api-reference/payment-rules/list-payment-rules.md)
>
> Alle endpoints, parametre og svarfelter.

> [card] [Refusioner og tvister](https://docs.whop.com/da/developer/guides/refunds-and-disputes.md)
>
> Reager på de chargebacks, der stadig slipper igennem.


## Related topics

- [Oversigt over betalinger](https://docs.whop.com/da/developer/payments/overview.md)
- [Fakturaer](https://docs.whop.com/da/developer/guides/invoices.md)
- [Payment Rules API](https://docs.whop.com/da/api-reference/payment-rules/payment-rule.md)
