# Create using payment intent

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


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

Used to attach the card to the customer after 3DS completion. [Learn more](/docs/api/3ds_card_payments) on the 3DS implementation via Chargebee APIs.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/create_using_payment_intent \
     -u {site_api_key}:\
     -d customer_id="__test__XpbTXGTSRp4MunE0" \
     -d "payment_intent[gateway_account_id]"="gw___test__5SK2lMpwSRp4Mx02v" \
     -d "payment_intent[gw_token]"="pi_1IVbmIJv9j0DyntJo1AUvK4o"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.CreateUsingPaymentIntent()
		.CustomerId("__test__XpbTXGTSRp4MunE0")
		.PaymentIntentGatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
		.PaymentIntentGwToken("pi_1IVbmIJv9j0DyntJo1AUvK4o")
		.Request();

Customer customer = result.Customer;
PaymentSource paymentSource = result.PaymentSource;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    paymentsourceAction "github.com/chargebee/chargebee-go/v3/actions/paymentsource"
    "github.com/chargebee/chargebee-go/v3/models/paymentsource"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentsourceAction.CreateUsingPaymentIntent(&paymentsource.CreateUsingPaymentIntentRequestParams{
        CustomerId : "__test__XpbTXGTSRp4MunE0",
        PaymentIntent : &paymentsource.CreateUsingPaymentIntentPaymentIntentParams{
            GatewayAccountId : "gw___test__5SK2lMpwSRp4Mx02v",
            GwToken : "pi_1IVbmIJv9j0DyntJo1AUvK4o",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### 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.PaymentSourceCreateUsingPaymentIntentRequest{
    CustomerId : "__test__XpbTXGTSRp4MunE0",
    PaymentIntent : &chargebee.PaymentSourceCreateUsingPaymentIntentPaymentIntent{
        GatewayAccountId : "gw___test__5SK2lMpwSRp4Mx02v",
        GwToken : "pi_1IVbmIJv9j0DyntJo1AUvK4o",
    },
}
  res, err := client.PaymentSource.CreateUsingPaymentIntent(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Customer := res.Customer
        PaymentSource := res.PaymentSource
    }
}
```

#### 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 = PaymentSource.createUsingPaymentIntent()
            .customerId("__test__XpbTXGTSRp4MunE0")
            .paymentIntentGatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
            .paymentIntentGwToken("pi_1IVbmIJv9j0DyntJo1AUvK4o")
            .request();

        Customer customer = result.customer();
        PaymentSource paymentSource = result.paymentSource();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.paymentSource.PaymentSource;
import com.chargebee.v4.models.paymentSource.params.PaymentSourceCreateUsingPaymentIntentParams;
import com.chargebee.v4.models.paymentSource.responses.PaymentSourceCreateUsingPaymentIntentResponse;

public class PaymentSourceCreateUsingPaymentIntent {

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

        PaymentSourceCreateUsingPaymentIntentParams.PaymentIntentParams paymentIntentParams =
            PaymentSourceCreateUsingPaymentIntentParams.PaymentIntentParams.builder()
                .gatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
                .gwToken("pi_1IVbmIJv9j0DyntJo1AUvK4o")
                .build();

        PaymentSourceCreateUsingPaymentIntentParams params = PaymentSourceCreateUsingPaymentIntentParams.builder()
            .customerId("__test__XpbTXGTSRp4MunE0")
            .paymentIntent(paymentIntentParams)
            .build();

        PaymentSourceCreateUsingPaymentIntentResponse response = client.paymentSources().createUsingPaymentIntent(params);

        Customer customer = response.getCustomer();
        PaymentSource paymentSource = response.getPaymentSource();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.paymentSource.createUsingPaymentIntent({
        customer_id: "__test__XpbTXGTSRp4MunE0",
        payment_intent: {
            gateway_account_id: "gw___test__5SK2lMpwSRp4Mx02v",
            gw_token: "pi_1IVbmIJv9j0DyntJo1AUvK4o"
        }
    });

    console.log(result);
    const customer = result.customer;
    const paymentSource = result.payment_source;
} 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->paymentSource()->createUsingPaymentIntent([
    "customer_id" => "__test__XpbTXGTSRp4MunE0",
    "payment_intent" => [
        "gateway_account_id" => "gw___test__5SK2lMpwSRp4Mx02v",
        "gw_token" => "pi_1IVbmIJv9j0DyntJo1AUvK4o"
    ]
]);
$customer = $result->customer;
$paymentSource = $result->payment_source;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentSource.create_using_payment_intent(
    cb_client.PaymentSource.CreateUsingPaymentIntentParams(
        customer_id="__test__XpbTXGTSRp4MunE0",
        payment_intent=cb_client.PaymentSource.CreateUsingPaymentIntentPaymentIntentParams(
            gateway_account_id="gw___test__5SK2lMpwSRp4Mx02v",
            gw_token="pi_1IVbmIJv9j0DyntJo1AUvK4o"
        )
    )
)
customer = response.customer
payment_source = response.payment_source
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::PaymentSource.create_using_payment_intent({
  :customer_id => "__test__XpbTXGTSRp4MunE0",
  :payment_intent => {
    :gateway_account_id => "gw___test__5SK2lMpwSRp4Mx02v",
    :gw_token => "pi_1IVbmIJv9j0DyntJo1AUvK4o"
  }
})

customer = result.customer
payment_source = result.payment_source
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517487217,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp4MunE0",
    "last_name": "Henry",
    "net_term_days": 0,
    "object": "customer",
    "payment_method": {
      "gateway": "stripe",
      "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
      "object": "payment_method",
      "reference_id": "cus_J7rVjoqwlD18Ei/pm_1IVbmIJv9j0DyntJCh6glSQB",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__XpbTXGTSRp4Q00E4",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517487229215,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517487229
  },
  "payment_source": {
    "card": {
      "brand": "visa",
      "expiry_month": 7,
      "expiry_year": 2050,
      "funding_type": "credit",
      "iin": "******",
      "last4": "3055",
      "masked_number": "************3055",
      "object": "card"
    },
    "created_at": 1517487229,
    "customer_id": "__test__XpbTXGTSRp4MunE0",
    "deleted": false,
    "gateway": "stripe",
    "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
    "id": "pm___test__XpbTXGTSRp4Q00E4",
    "issuing_country": "US",
    "object": "payment_source",
    "reference_id": "cus_J7rVjoqwlD18Ei/pm_1IVbmIJv9j0DyntJCh6glSQB",
    "resource_version": 1517487229213,
    "status": "valid",
    "type": "card",
    "updated_at": 1517487229
  }
}
```

## URL Format

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

## Input Parameters

- `customer_id` (required, string, max chars=50)
  Identifier of the customer with whom this payment source is associated.

- `replace_primary_payment_source` (optional, boolean, default=false)
  Indicates whether the primary payment source should be replaced with this payment source. In case of Create Subscription for Customer endpoint, the default value is True. Otherwise, the default value is False.

- `payment_intent` (optional, string)
  Parameters for payment\_intent
  - `id` (optional, string, max chars=150)
    Identifier for PaymentIntent generated by Chargebee.js. Applicable only when you are using Chargebee.js for completing the 3DS flow. The PaymentIntent should be in 'authorized' state while passing it here. You need not pass other PaymentIntent parameters if this is passed.
  - `gateway_account_id` (optional, string, max chars=50)
    The gateway account used for performing the 3DS flow. Applicable when you are using gateway APIs directly for completing the 3DS flow.
  - `gw_token` (optional, string, max chars=65k)
    Identifier for 3DS transaction/verification object at the gateway. Can be passed only after successfully completing the 3DS flow. Refer [3DS implementation in Chargebee](/docs/api/3ds_card_payments) to find out the gateway-specific gw\_token format. Applicable when you are using gateway APIs directly for completing the 3DS flow.
  - `payment_method_type` (optional, enumerated string)
    The list of payment method types (For example, card, ideal, sofort, bancontact, etc.) this Payment Intent is allowed to use. If payment method type is empty, Card is taken as the default type for all gateways except Razorpay.
    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`
  - `reference_id` (optional, string, max chars=65k)
    Identifier for Braintree permanent token. Applicable when you are using Braintree APIs for completing the 3DS flow.
  - `additional_info` (optional, jsonobject)
    Applicable only for Braintree gateway. Can be used only for Braintree's [Premium Fraud Management Tools](https://developer.paypal.com/braintree/articles/guides/fraud-tools/premium/overview). Pass a stringified JSON containing the `device_session_id` and `fraud_merchant_id` as an input to `fingerprint`. Here's a [sample](/docs/api/payment_parameters) to it.
  - `additional_information` (optional, jsonobject)
    -   `checkout_com`: While adding a new payment method using [permanent token](/docs/api/payment_sources/create-using-permanent-token) or passing raw card details to Checkout.com, `document` ID and `country_of_residence` are required to support payments through [dLocal](https://www.checkout.com/docs/previous/payments/payment-methods/cards/dlocal).
        
        -   `payer`: User related information.
            -   `country_of_residence`: This is required since the billing country associated with the user's payment method may not be the same as their country of residence. Hence the user's country of residence needs to be specified. The country code should be a [two-character ISO code](https://docs.checkout.com/resources/codes/country-codes).
            -   `document`: Document ID is the user's [identification number](https://docs.dlocal.com/api-documentation/payins-api-reference/country-reference#documents) based on their country.
    -   `bluesnap`: While passing raw card details to BlueSnap, if `fraud_session_id` is added, [additional validation](https://developers.bluesnap.com/docs/fraud-prevention) is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your [BlueSnap fraud session ID](https://developers.bluesnap.com/docs/fraud-prevention#section-implementing-device-data-collector) required to perform anti-fraud validation.
    -   `braintree`: While passing raw card details to Braintree, your `fraud_merchant_id` and the user's `device_session_id` can be added to perform [additional validation](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
            -   `fraud_merchant_id`: Your [merchant ID](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) for fraud detection.
    -   `chargebee_payments`: While passing raw card details to Chargebee Payments, if `fraud_session_id` is added, additional validation is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your Chargebee Payments fraud session ID required to perform anti-fraud validation.
    -   `bank_of_america`: While passing raw card details to Bank of America, your user's `device_session_id` can be added to perform additional validation and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
    -   `ecentric`: This parameter is used to verify and process payment method details in Ecentric. If the `merchant_id` parameter is included, Chargebee will vault it / perform a lookup and verification against this `merchant_id`, overriding the one configured in Chargebee. If tokens and processing occur in the same Merchant GUID, you can just skip this part.
        
        -   `merchant_id`: Merchant GUID where the card is vaulted or need to be vaulted.
    -   `ebanx`: While passing raw card details to EBANX, the user's `document` is required for some countries and `device_session_id` can be added to perform [additional validation](https://developer.ebanx.com/docs/payments/guides/features/device-fingerprint#device-fingerprint) and avoid fraudulent transactions.
        
        -   `payer`: User related information.
            -   `document`: Document is the user's identification number based on their country.
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device

## Returns

- `customer` (Customer object)
  Resource object representing customer

- `payment_source` (Payment source object)
  Resource object representing payment\_source
