# Create a payment intent

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Creates a PaymentIntent object. This is to be used with Chargebee.js API to complete the 3DS flow for new or stored cards.

While creating, specify the appropriate gateway account and amount. Exact amount can be estimated using our [Estimate API](/docs/api/estimates).

#### Customer resource lookup and creation[](#customer-resource-lookup-and-creation)

When `[customer[id]](/docs/api/payment_intents/create-a-payment-intent#customer_id)` is provided for this operation, it is looked up by Chargebee, and if found, the payment\_intent is created for it. If not found, the `payment_intent` is created without any customer association and will be available for any customer.

##### Multiple business entities[](#multiple-business-entities)

If multiple [business entities](/docs/api/advanced-features) are created for the site, the customer resource lookup and creation happen within the [context](/docs/api/advanced-features) of the business entity [specified](/docs/api/advanced-features#mbe-header-main) in this API call. If no business entity is specified, the customer resource lookup is performed within the [site context](/docs/api/advanced-features), and if not found, the resource is created for the [default business entity](/docs/api/advanced-features) of the site.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_intents \
     -u {site_api_key}:\
     -d amount=5000 \
     -d currency_code="USD"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentIntent.Create()
		.Amount(5000)
		.CurrencyCode("USD")
		.Request();

PaymentIntent paymentIntent = result.PaymentIntent;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    paymentintentAction "github.com/chargebee/chargebee-go/v3/actions/paymentintent"
    "github.com/chargebee/chargebee-go/v3/models/paymentintent"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentintentAction.Create(&paymentintent.CreateRequestParams{
        Amount : chargebee.Int64(5000),
        CurrencyCode : "USD",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        PaymentIntent := res.PaymentIntent
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PaymentIntentCreateRequest{
    Amount : chargebee.Int64(5000),
    CurrencyCode : "USD",
}
  res, err := client.PaymentIntent.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        PaymentIntent := res.PaymentIntent
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = PaymentIntent.create()
            .amount(5000L)
            .currencyCode("USD")
            .request();

        PaymentIntent paymentIntent = result.paymentIntent();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.paymentIntent.PaymentIntent;
import com.chargebee.v4.models.paymentIntent.params.PaymentIntentCreateParams;
import com.chargebee.v4.models.paymentIntent.responses.PaymentIntentCreateResponse;

public class PaymentIntentCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PaymentIntentCreateParams params = PaymentIntentCreateParams.builder()
            .amount(5000L)
            .currencyCode("USD")
            .build();

        PaymentIntentCreateResponse response = client.paymentIntents().create(params);

        PaymentIntent paymentIntent = response.getPaymentIntent();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.paymentIntent.create({
        amount: 5000,
        currency_code: "USD"
    });

    console.log(result);
    const paymentIntent = result.payment_intent;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->paymentIntent()->create([
    "amount" => 5000,
    "currency_code" => "USD"
]);
$paymentIntent = $result->payment_intent;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentIntent.create(
    cb_client.PaymentIntent.CreateParams(
        amount=5000,
        currency_code="USD"
    )
)
payment_intent = response.payment_intent
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::PaymentIntent.create({
  :amount => 5000,
  :currency_code => "USD"
})

payment_intent = result.payment_intent
```

## Sample Response

```json
{
  "payment_intent": {
    "amount": 5000,
    "created_at": 1517501515,
    "currency_code": "USD",
    "expires_at": 1517503315,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__KyVnGlSBWTQeudG",
    "id": "__test__KyVnHhSBWTQz2Cu__test__0DZayCQMcAwDkEIPpUrGwkiyL25s7W1X",
    "modified_at": 1517501515,
    "object": "payment_intent",
    "payment_method_type": "card",
    "status": "inited"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/payment_intents

## Input Parameters

- `business_entity_id` (optional, string, max chars=50)
  Sets the context for this operation to the [business entity](/docs/api/advanced-features) specified. Applicable only when multiple business entities have been created for the site. When this parameter is provided, the operation is able to read/write data associated only to the business entity specified. When not provided, the operation can read/write data for the entire site.
  
  **Note**
  
  An alternative way of passing this parameter is by means of a [custom HTTP header](/docs/api/advanced-features).
  
  **See also**
  
  [Customer resource lookup and creation.](/docs/api/payment_intents)

- `customer_id` (optional, string, max chars=50)
  The unique identifier of the customer for whom the `payment_intent` will be created. If specified, the `payment_intent` will be used exclusively for that customer. If not specified, the `payment_intent` won't be associated with any customer and will be available for any customer.
  
  **See also**
  
  [Customer resource lookup and creation](/docs/api/payment_intents) .

- `amount` (required, in cents, min=0)
  Amount(in cents) to be authorized for 3DS flow.

- `currency_code` (required, string, max chars=3)
  The currency code (ISO 4217 format) of the amount used in transaction.

- `gateway_account_id` (optional, string, max chars=50)
  The gateway account used for performing the 3DS flow.

- `reference_id` (optional, string, max chars=200)
  Reference for payment method at gateway. Only applicable when the PaymentIntent is created for cards stored in the gateway.

- `defer_payment_method_type` (optional, boolean, default=false)
  When set to `true`, the binding of the payment method type and related fields is deferred during intent creation. As a result, fields such as `gateway_account_id`, `gateway`, `payment_method_type`, and `reference_id` provided in this request will be ignored until the intent is updated with a selected payment method.

- `payment_method_type` (optional, enumerated string, default=card)
  The payment method of this intent.
  Possible enum values:
    - `card`
      card
    - `ideal`
      ideal
    - `sofort`
      sofort
    - `bancontact`
      bancontact
    - `google_pay`
      google\_pay
    - `dotpay`
      dotpay
    - `giropay`
      giropay
    - `apple_pay`
      apple\_pay
    - `upi`
      upi
    - `netbanking_emandates`
      netbanking\_emandates
    - `paypal_express_checkout`
      paypal\_express\_checkout
    - `direct_debit`
      direct\_debit
    - `boleto`
      boleto
    - `venmo`
      Venmo
    - `amazon_payments`
      Amazon Payments
    - `pay_to`
      PayTo
    - `faster_payments`
      Faster Payments
    - `sepa_instant_transfer`
      Sepa Instant Transfer
    - `klarna_pay_now`
      Klarna Pay Now
    - `online_banking_poland`
      Online Banking Poland
    - `payconiq_by_bancontact`
      Payments made via Payconiq by Bancontact.
    - `electronic_payment_standard`
      Electronic Payment Standard
    - `kbc_payment_button`
      KBC Payment Button
    - `pay_by_bank`
      Pay By Bank
    - `trustly`
      Trustly
    - `stablecoin`
      Payments made via Stablecoin.
    - `kakao_pay`
      Payments made via Kakao Pay.
    - `naver_pay`
      Payments made via Naver Pay.
    - `revolut_pay`
      Payments made via Revolut Pay.
    - `cash_app_pay`
      Payments made via Cash App Pay.
    - `wechat_pay`
      Payments made via WeChat Pay.
    - `alipay`
      Payments made via Alipay.
    - `twint`
      Payments made via Twint
    - `go_pay`
      Payments made via GoPay
    - `grab_pay`
      Payments made via GrabPay
    - `pay_co`
      Payments made via PayCo
    - `after_pay`
      Payments made via Afterpay
    - `swish`
      Payments made via Swish
    - `payme`
      Payments made via PayMe
    - `pix`
      Pix
    - `klarna`
      Payments made via Klarna.
    - `alipay_hk`
      Payments made via Alipay HK.
    - `paypay`
      PayPay
    - `gcash`
      Payments made via GCash.
    - `south_korean_cards`
      Payments made via South Korean Cards
    - `paynow`
    - `bizum`
    - `promptpay`
    - `dana`
      Payments made via Dana.
    - `touch_n_go`
      Payments made via Touch 'n Go.
    - `tamara`
      Payments made via Tamara.
    - `qpay`
      Payments made via Qpay.
    - `ovo`
    - `momo`
    - `mercado_pago`
    - `nequi`
    - `nupay`
    - `picpay`
    - `thai_qr`
    - `blik`
    - `fpx`
    - `wero`
    - `p24`
    - `affirm_pay`
    - `rakuten_pay`

- `success_url` (optional, string, max chars=250)
  The URL the customer will be directed to once 3DS verification is successful. Applicable only when `payment_method_type` is `ideal` , `sofort` , `dotpay` or `giropay` .

- `failure_url` (optional, string, max chars=250)
  The URL the customer will be directed to when 3DS verification fails. Applicable only when `payment_method_type` is `ideal` , `sofort` , `dotpay` or `giropay` .

- `payment_method_options` (optional, jsonobject)
  Payment method-specific options for this PaymentIntent. Only `card` is supported; keys for other payment method types are ignored.
  
  -   `card`: Options for card payments.
      -   `three_d_secure`: Options for 3DS authentication.
          -   `challenge_preference`: The preferred 3DS flow. Applicable only when `payment_method_type` is `card` and 3DS is enabled for the gateway account. Supported for Stripe, Adyen, and BlueSnap; ignored for other gateways. The gateway or card issuer can override the preference.
              -   `no_preference`: Chargebee, the gateway, and the issuer decide the 3DS flow.
              -   `no_challenge`: Requests a frictionless flow without a challenge.
              -   `challenge`: Requests a challenge flow.

## Returns

- `payment_intent` (Payment intent object)
  Resource object representing payment\_intent
