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

# Afterpay

> Connect to Afterpay to accept buy now, pay later payments.

**Afterpay**

Afterpay is a buy now, pay later (BNPL) payment method that allows buyers to split purchases into interest-free installments. Afterpay uses a redirect flow where the buyer approves the payment on the Afterpay hosted page.

## Setup

Speak to the Afterpay account manager to obtain sandbox credentials for the
region.

## Credentials

When setting up Afterpay in the dashboard, configure the following credentials:

* **Merchant ID** - The merchant ID provided by Afterpay during setup.
* **Secret key** - The secret key provided by Afterpay during setup.

## Capabilities

This list is for guidance only. It doesn't guarantee availability or
create any rights, and the provider may need to enable some features for
your account.

## Supported countries

## Supported currencies

## Integration

The default integration for Afterpay uses a redirect to a hosted payments page.

Start by creating a new transaction with the following required fields.

```csharp C# theme={"system"}
var transaction = await client.Transactions.CreateAsync(
  transactionCreate: new TransactionCreate()
  {
    Amount = 1299,
    Currency = "USD",
    Country = "US",
    PaymentMethod =
      TransactionCreatePaymentMethod.CreateRedirectPaymentMethodCreate(
        new RedirectPaymentMethodCreate()
        {
          Method = "afterpay",
          Country = "US",
          Currency = "USD",
          RedirectUrl = "https://example.com/callback",
        }
      ),
  }
);
```

```go Go theme={"system"}
amount := int64(1299)
currency := "USD"
country := "US"
method := components.RedirectPaymentMethodCreateMethodAfterpay
redirectUrl := "https://example.com/callback"

redirectPaymentMethodCreate := components.RedirectPaymentMethodCreate{
  Method: method,
  Country: country,
  Currency: currency,
  RedirectURL: redirectUrl,
}
paymentMethod := components.CreateTransactionCreatePaymentMethodRedirectPaymentMethodCreate(redirectPaymentMethodCreate)

transactionCreate := components.TransactionCreate{
  Amount:        amount,
  Currency:      currency,
  Country:       &country,
  PaymentMethod: &paymentMethod,
}

transaction, err := client.Transactions.Create(ctx, transactionCreate, nil, nil, nil)
```

```java Java theme={"system"}
CreateTransactionResponse transactionResponse = gr4vyClient.transactions().create()
  .transactionCreate(TransactionCreate.builder()
    .amount(1299L)
    .currency("USD")
    .country("US")
    .paymentMethod(TransactionCreatePaymentMethod.of(RedirectPaymentMethodCreate.builder()
      .method(RedirectPaymentMethodCreateMethod.AFTERPAY)
      .country("US")
      .currency("USD")
      .redirectUrl("https://example.com/callback")
      .build()))
    .build())
  .call();

Transaction transaction = transactionResponse.transaction().orElse(null);
```

```php PHP theme={"system"}
$transactionCreate = new TransactionCreate(
  amount: 1299,
  currency: 'USD',
  country: 'US',
  paymentMethod: new RedirectPaymentMethodCreate(
    method: 'afterpay',
    country: 'US',
    currency: 'USD',
    redirectUrl: 'https://example.com/callback'
  )
);
$response = $client->transactions->create($transactionCreate);
$transaction = $response->transaction;
```

```python Python theme={"system"}
transaction: models.Transaction = client.transactions.create(
  amount=1299,
  currency="USD",
  country="US",
  payment_method={
    "method": "afterpay",
    "country": "US",
    "currency": "USD",
    "redirect_url": "https://example.com/callback",
  }
)
```

```ts TypeScript theme={"system"}
const transaction = await client.transactions.create({
  amount: 1299,
  currency: "USD",
  country: "US",
  paymentMethod: {
    method: "afterpay",
    country: "US",
    currency: "USD",
    redirectUrl: "https://example.com/callback"
  }
})
```

After the transaction is created, the API response includes a `payment_method.approval_url` and the status is set to `buyer_approval_pending`. The approval URL expires after 30 minutes.

```json theme={"system"}
{
  "type": "transaction",
  "id": "ea1efdd0-20f9-44d9-9b0b-0a3d71e9b625",
  "payment_method": {
    "type": "payment-method",
    "approval_url": "https://cdn.gr4vy.com/connectors/..."
  },
  "method": "afterpay"
}
```

Redirect the buyer to the `approval_url` (open in a browser or Webview), where they can complete the payment. Once the buyer approves, the transaction progresses to an `authorization_succeeded` or `capture_succeeded` state.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.