# Create using gateway temporary token

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


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

This API offers an alternative way to create a payment source using a single-use gateway temporary token, which is generally provided by your payment gateway. In the case of Stripe, this temporary token is generated according to the instruction detailed in [Stripe documentation](https://stripe.com/docs/api/tokens/create_card).

Storing card after successful 3DS completion is not supported in this API. Use [create using Payment Intent API](/docs/api/payment_sources/create-using-payment-intent) under Payment source to store the card after successful 3DS flow completion.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/payment_sources/create_using_temp_token \
     -u {site_api_key}:\
     -d gateway_account_id="gw___test__5SK2lMpwSRp4Mx02v" \
     -d customer_id="__test__XpbTXGTSRp4QZ1EK" \
     -d type="CARD" \
     -d tmp_token="tok_1IVbmWJv9j0DyntJuLTiAhzK"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PaymentSource.CreateUsingTempToken()
		.GatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
		.CustomerId("__test__XpbTXGTSRp4QZ1EK")
		.Type(TypeEnum.Card)
		.TmpToken("tok_1IVbmWJv9j0DyntJuLTiAhzK")
		.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"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := paymentsourceAction.CreateUsingTempToken(&paymentsource.CreateUsingTempTokenRequestParams{
        GatewayAccountId : "gw___test__5SK2lMpwSRp4Mx02v",
        CustomerId : "__test__XpbTXGTSRp4QZ1EK",
        Type : enum.TypeCard,
        TmpToken : "tok_1IVbmWJv9j0DyntJuLTiAhzK",
    }).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.PaymentSourceCreateUsingTempTokenRequest{
    GatewayAccountId : "gw___test__5SK2lMpwSRp4Mx02v",
    CustomerId : "__test__XpbTXGTSRp4QZ1EK",
    Type : chargebee.TypeCard,
    TmpToken : "tok_1IVbmWJv9j0DyntJuLTiAhzK",
}
  res, err := client.PaymentSource.CreateUsingTempToken(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.createUsingTempToken()
            .gatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
            .customerId("__test__XpbTXGTSRp4QZ1EK")
            .type(Type.CARD)
            .tmpToken("tok_1IVbmWJv9j0DyntJuLTiAhzK")
            .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.PaymentSourceCreateUsingTempTokenParams;
import com.chargebee.v4.models.paymentSource.responses.PaymentSourceCreateUsingTempTokenResponse;

public class PaymentSourceCreateUsingTempToken {

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

        PaymentSourceCreateUsingTempTokenParams params = PaymentSourceCreateUsingTempTokenParams.builder()
            .gatewayAccountId("gw___test__5SK2lMpwSRp4Mx02v")
            .customerId("__test__XpbTXGTSRp4QZ1EK")
            .type(PaymentSourceCreateUsingTempTokenParams.Type.CARD)
            .tmpToken("tok_1IVbmWJv9j0DyntJuLTiAhzK")
            .build();

        PaymentSourceCreateUsingTempTokenResponse response = client.paymentSources().createUsingTempToken(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.createUsingTempToken({
        gateway_account_id: "gw___test__5SK2lMpwSRp4Mx02v",
        customer_id: "__test__XpbTXGTSRp4QZ1EK",
        type: "card",
        tmp_token: "tok_1IVbmWJv9j0DyntJuLTiAhzK"
    });

    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()->createUsingTempToken([
    "gateway_account_id" => "gw___test__5SK2lMpwSRp4Mx02v",
    "customer_id" => "__test__XpbTXGTSRp4QZ1EK",
    "type" => "card",
    "tmp_token" => "tok_1IVbmWJv9j0DyntJuLTiAhzK"
]);
$customer = $result->customer;
$paymentSource = $result->payment_source;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PaymentSource.create_using_temp_token(
    cb_client.PaymentSource.CreateUsingTempTokenParams(
        gateway_account_id="gw___test__5SK2lMpwSRp4Mx02v",
        customer_id="__test__XpbTXGTSRp4QZ1EK",
        type=chargebee.Type.CARD,
        tmp_token="tok_1IVbmWJv9j0DyntJuLTiAhzK"
    )
)
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_temp_token({
  :gateway_account_id => "gw___test__5SK2lMpwSRp4Mx02v",
  :customer_id => "__test__XpbTXGTSRp4QZ1EK",
  :type => "CARD",
  :tmp_token => "tok_1IVbmWJv9j0DyntJuLTiAhzK"
})

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

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517487231,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "Mark",
    "id": "__test__XpbTXGTSRp4QZ1EK",
    "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_J7rVykqiooX1ng/card_1IVbmWJv9j0DyntJS7Bzo5q5",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__XpbTXGTSRp4R8ZEN",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517487233590,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517487233
  },
  "payment_source": {
    "card": {
      "brand": "visa",
      "expiry_month": 5,
      "expiry_year": 2022,
      "first_name": "MyCard",
      "funding_type": "credit",
      "iin": "******",
      "last4": "4242",
      "last_name": "testing",
      "masked_number": "************4242",
      "object": "card"
    },
    "created_at": 1517487233,
    "customer_id": "__test__XpbTXGTSRp4QZ1EK",
    "deleted": false,
    "gateway": "stripe",
    "gateway_account_id": "gw___test__5SK2lMpwSRp4Mx02v",
    "id": "pm___test__XpbTXGTSRp4R8ZEN",
    "issuing_country": "US",
    "object": "payment_source",
    "reference_id": "cus_J7rVykqiooX1ng/card_1IVbmWJv9j0DyntJS7Bzo5q5",
    "resource_version": 1517487233588,
    "status": "valid",
    "type": "card",
    "updated_at": 1517487233
  }
}
```

## URL Format

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

## Input Parameters

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

- `gateway_account_id` (optional, string, max chars=50)
  The gateway account to which the payment source is associated.

- `type` (required, enumerated string)
  Type of payment source.
  Possible enum values:
    - `card`
      Card based payment including credit cards and debit cards. Details about the card can be obtained from the card resource.
    - `paypal_express_checkout`
      Payments made via PayPal Express Checkout.
    - `amazon_payments`
      Payments made via Amazon Payments.
    - `direct_debit`
      Represents bank account for which the direct debit or ACH agreement/mandate is created.
    - `generic`
      Payments made via Generic Payment Method.
    - `alipay`
      Payments made via Alipay.
      
      This payment source is deprecated.
    - `unionpay`
      Payments made via UnionPay.
    - `apple_pay`
      Payments made via Apple Pay.
    - `wechat_pay`
      Payments made via WeChat Pay.
      
      This payment source is deprecated.
    - `ideal`
      Payments made via iDEAL.
    - `google_pay`
      Payments made via Google Pay.
    - `sofort`
      Payments made via Sofort.
    - `bancontact`
      Payments made via Bancontact Card.
    - `giropay`
      Payments made via giropay.
    - `dotpay`
      Payments made via Dotpay.
    - `upi`
      UPI Payments.
    - `netbanking_emandates`
      Netbanking (eMandates) Payments.
    - `venmo`
      Payments made via Venmo
    - `pay_to`
      Payments made via PayTo
    - `faster_payments`
      Payments made via Faster Payments
    - `sepa_instant_transfer`
      Payments made via Sepa Instant Transfer
    - `automated_bank_transfer`
      Represents virtual bank account using which the payment will be done.
    - `klarna_pay_now`
      Payments made via Klarna Pay Now
    - `online_banking_poland`
      Payments made via 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.
    - `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`
      Payments made via Pix
    - `klarna`
      Payments made via Klarna.
    - `alipay_hk`
      Payments made via Alipay HK.
    - `paypay`
      Payments made via 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`

- `tmp_token` (required, string, max chars=65k)
  Single-use token created by payment gateways. In Stripe, a single-use token is created for Apple Pay Wallet, card details or direct debit. In Braintree, a nonce is created for Apple Pay Wallet, PayPal, or card details. In Authorize.net, a nonce is created for card details. In Adyen, an encrypted data is created from the card details.

- `issuing_country` (optional, string, max chars=50)
  2-letter (alpha2) ISO country code. Indicates your customer's payment method country of issuance. Applicable for PayPal via Braintree.

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

- `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://docs.checkout.com/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
