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

# Configuring Managed JIT Funding

> Learn about Managed Just-in-Time (JIT) Funding, including funding sources, card product configuration, and notifications.

export const EndpointCard = ({method = "API", title, children, href, arrow = true}) => {
  const METHOD_STYLES = {
    GET: {
      bg: "mint-bg-green-400/20 dark:mint-bg-green-400/20",
      text: "mint-text-green-700 dark:mint-text-green-400",
      border: "mint-border-green-300 dark:mint-border-green-700"
    },
    POST: {
      bg: "mint-bg-blue-400/20 dark:mint-bg-blue-400/20",
      text: "mint-text-blue-700 dark:mint-text-blue-400"
    },
    PUT: {
      bg: "mint-bg-yellow-400/20 dark:mint-bg-yellow-400/20",
      text: "mint-text-yellow-700 dark:mint-text-yellow-400"
    },
    PATCH: {
      bg: "mint-bg-orange-400/20 dark:mint-bg-orange-400/20",
      text: "mint-text-orange-700 dark:mint-text-orange-400"
    },
    DELETE: {
      bg: "mint-bg-red-400/20 dark:mint-bg-red-400/20",
      text: "mint-text-red-700 dark:mint-text-red-400"
    },
    API: {
      bg: "mint-bg-black",
      text: "mint-text-white"
    }
  };
  const MethodBadge = ({method}) => {
    const style = METHOD_STYLES[method?.toUpperCase()] ?? METHOD_STYLES.GET;
    return <span className={`
          method-pill rounded-lg font-semibold px-1.5 py-0.5 text-xs leading-5 ${style.bg} ${style.text}`}>
        {method?.toUpperCase()}
      </span>;
  };
  const content = <div className="group flex items-center gap-4 border border-gray-200 dark:border-gray-700 rounded-xl p-5 hover:border-gray-400 dark:hover:border-gray-500 hover:shadow-md transition-all cursor-pointer">
      {}
      <div className="shrink-0">
        <MethodBadge method={method} />
      </div>
      {}
      <div className="flex-1 min-w-0">
        <p className="font-semibold text-gray-900 dark:text-white text-sm leading-snug">{title}</p>
        {children && <p className="mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2">{children}</p>}
      </div>
    </div>;
  if (!href) return content;
  return <a href={href} className="block no-underline border-b-0 mb-2">
      {content}
    </a>;
};

You can programmatically fund accounts at transaction time by configuring your cards to use Managed Just-in-Time (JIT) Funding. A card configured for Managed JIT Funding requires a card product associated with a program funding source.

<Note>
  **Note**\
  The sandbox environment allows you to create and configure the resources required for a Managed JIT Funding setup. To implement these configurations in a production environment, contact your Marqeta representative.
</Note>

At the end of this guide, you should understand:

* The role of the program funding source in Managed JIT Funding.

* How to create a card for an account funded by Managed JIT Funding.

* How to simulate a transaction with a card.

<h2 id="_prerequisites">
  Prerequisites
</h2>

* Read the [Core API Quick Start](/developer-guides/core-api-quick-start/).

* Read [About Just-in-Time Funding](/developer-guides/about-jit-funding/).

<h2 id="_concepts">
  Concepts
</h2>

<h3 id="_jit_funding">
  JIT Funding
</h3>

JIT Funding automates the loading of funds into accounts in real time during the transaction process. In a Managed JIT Funding setup, the Marqeta platform handles all authorization decisions using [spend controls](/developer-guides/controlling-spending/) configured at the card product or card level. Funds are drawn from the program funding source of the card product.

For more information about JIT Funding, see [About Just-in-Time Funding](/developer-guides/about-jit-funding/).

For more information about spend controls, see [Controlling Spending](/developer-guides/controlling-spending/).

<h3 id="_the_program_funding_source">
  The program funding source
</h3>

A program funding source represents a bank account from which funds are drawn for JIT-funded transactions. In the sandbox environment, each program funding source simulates funds for your test transactions. In a production environment, each program funding source draws from the bank account you set up in conjunction with Marqeta.

<Note>
  **Note**\
  Your program funding source must be approved by Marqeta and the issuing bank. If you are using a third-party service to collect user funds, Marqeta and the issuing bank require specific reporting to ensure compliance with all rules and regulations. Contact your Marqeta representative for more information.
</Note>

For a complete description of the `/fundingsources/program` endpoint, see [Program Funding Sources](/core-api/program-funding-sources/).

<h3 id="_card_product_configuration">
  Card product configuration
</h3>

A card product defines the attributes and behaviors of a set of cards. Managed JIT Funding setups require you to create a card product associated with a program funding source. Each card product can have a single funding source, which funds all transactions conducted using an associated card.

<Tip>
  **Tip**\
  You can create and configure card products in the sandbox environment. To create a new card product in production, contact your Marqeta representative for more information.
</Tip>

For a complete description of the `/cardproducts` endpoint, see [Card Products](/core-api/card-products/).

<h2 id="_tutorial">
  Tutorial
</h2>

The following tutorial walks you through creating and testing the resources required for a Managed JIT Funding setup. In this scenario, you will create a card configured for Managed JIT Funding, use it to simulate a transaction, and review the transaction record.

Some steps include a code block with a JSON-formatted sample message body. To follow along with the tutorial, you must sign in to Marqeta.com. For each step, copy the code sample and paste it into the body field of the provided inline widget. Replace any placeholder text with your sample data, then select **Submit Request**.

For the sake of clarity and simplicity, this tutorial does not include steps for creating spend controls. For a tutorial on creating spend controls, see [the Controlling Spending tutorial](/developer-guides/controlling-spending/#_tutorial).

<h3 id="_step_1_create_a_program_funding_source">
  Step 1 — Create a program funding source
</h3>

To define the bank account from which funds are drawn for transactions, create a program funding source.

Send a `POST` request to the `/fundingsources/program` endpoint to create a new program funding source.

```json JSON lines wrap theme={null}
{
  "token": "**YOUR FUNDING SOURCE TOKEN**",
  "name": "**YOUR FUNDING SOURCE NAME**"
}
```

{/* <EndpointCard
href="/core-api/program-funding-sources/postFundingsourcesProgram"
title="Creates a program funding source"
path="/fundingsources/program"
method="post"
/> */}

<h3 id="_step_2_create_a_card_product">
  Step 2 — Create a card product
</h3>

To define attributes and behaviors for a set of cards, create a card product. The `program_funding_source` object defines the funding source used by the card product. In this scenario, you’ll use the program funding source you created in Step 1.

Send a `POST` request to the `/cardproducts` endpoint to create a new card product.

```json JSON expandable lines wrap theme={null}
{
  "start_date": "2020-05-01",
  "token": "**YOUR CARD PRODUCT TOKEN**",
  "name": "Example Card Product",
  "config": {
      "fulfillment": {
      "payment_instrument": "VIRTUAL_PAN"
     },
    "poi": {
      "ecommerce": true,
      "atm": true
    },
    "card_life_cycle": {
      "activate_upon_issue": true
    },
    "jit_funding": {
      "program_funding_source": {
        "funding_source_token": "**YOUR FUNDING SOURCE TOKEN**",
        "refunds_destination": "PROGRAM_FUNDING_SOURCE",
        "enabled": true
      }
    }
  }
}
```

{/* <EndpointCard
href="/core-api/card-products/postCardproducts"
title="Creates a card product"
path="/cardproducts"
method="post"
/> */}

<h3 id="_step_3_create_a_user">
  Step 3 — Create a user
</h3>

Before you create a new card, you must create a user who will own the card.

Send a `POST` request to the `/users` endpoint to create a new user.

```json JSON lines wrap theme={null}
{
  "token": "**YOUR USER TOKEN**"
}
```

{/* <EndpointCard
href="/core-api/users/#post_users"
title="Creates a user"
path="/users"
method="post"
/> */}

<h3 id="_step_4_create_a_card">
  Step 4 — Create a card
</h3>

To enable the user to spend funds, create a card. Use the card product and user tokens you created in this tutorial.

Send a `POST` request to the `/cards` endpoint to create a new card.

```json JSON lines wrap theme={null}
{
  "token": "**YOUR CARD TOKEN**",
  "user_token": "**YOUR USER TOKEN**",
  "card_product_token": "**YOUR CARD PRODUCT TOKEN**"
}
```

{/* <EndpointCard
href="/core-api/cards/postCards"
title="Creates a card"
path="/cards"
method="post"
/> */}

<h3 id="_step_5_simulate_a_transaction">
  Step 5 — Simulate a transaction
</h3>

Now that you have created a card, you can use it to simulate a transaction. Use the card token you created in this tutorial.

Send a `POST` request to the `/simulations/cardtransactions/authorization` endpoint to simulate a transaction.

In the `webhook.endpoint` field, include a URL that points to a webhook endpoint on your system or another mock endpoint you create. (You can use a mock endpoint service like [https://www.beeceptor.com](https://www.beeceptor.com) to receive webhook notifications from the sandbox environment.)

```json JSON lines wrap theme={null}
{
  "amount": "10.00",
  "card_token": "**YOUR CARD TOKEN**",
  "card_acceptor": {
    "mid": "11111",
    "name": "Aegis Fleet Services",
    "street_address": "111 Main St",
    "city": "Berkeley",
    "state": "CA",
    "zip": "94702",
    "country_code": "USA"
  },
  "network": "VISA",
  "webhook": {
    "endpoint": "**YOUR ENDPOINT URL**",
    "username": "my_username",
    "password": "My_passw0rd"
  }
}
```

<h3 id="_step_6_review_the_transaction">
  Step 6 — Review the transaction
</h3>

After you simulate the transaction, your webhook endpoint should receive a notification message containing the details of the transaction, including the Marqeta platform’s funding decision.

The following is a sample transaction notification based on the transaction you simulated in the previous step. Note that it includes a `gpa_order` object, which indicates that this transaction used JIT Funding. The `gpa_order.funding.source.type` field is "program", meaning that this transaction used Managed JIT Funding.

The transaction also contains the tokens of the user, card, and funding source you created.

```json JSON expandable lines wrap theme={null}
{
     "type": "authorization",
     "state": "PENDING",
     "token": "75136bd3-4cde-4ed9-9a50-a552d925f8f8",
     "user_token": "**YOUR USER TOKEN**",
     "acting_user_token": "**YOUR USER TOKEN**",
     "card_token": "**YOUR CARD TOKEN**",
     "gpa": {
         "currency_code": "USD",
         "ledger_balance": 10,
         "available_balance": 0,
         "credit_balance": 0,
         "pending_credits": 0,
         "impacted_amount": -10,
         "balances": {
             "USD": {
                 "currency_code": "USD",
                 "ledger_balance": 10,
                 "available_balance": 0,
                 "credit_balance": 0,
                 "pending_credits": 0,
                 "impacted_amount": -10
             }
         }
     },
     "gpa_order": {
         "token": "9ea36f5b-0485-423f-9f1b-291034e01358",
         "amount": 10,
         "created_time": "2020-08-01T00:04:34Z",
         "last_modified_time": "2020-08-01T00:04:34Z",
         "transaction_token": "ba8a631d-7b9b-4a15-90a3-4a111dfa1b76",
         "state": "PENDING",
         "response": {
             "code": "0000",
             "memo": "Approved or completed successfully"
         },
         "funding": {
             "amount": 10,
             "source": {
                 "type": "program",
                 "token": "**YOUR FUNDING SOURCE TOKEN**",
                 "active": true,
                 "name": "**YOUR FUNDING SOURCE NAME**",
                 "is_default_account": false,
                 "created_time": "2020-08-01T00:01:56Z",
                 "last_modified_time": "2020-08-01T00:01:56Z"
             }
         },
         "funding_source_token": "**YOUR FUNDING SOURCE TOKEN**",
         "user_token": "**YOUR USER TOKEN**",
         "currency_code": "USD"
     },
     "duration": 237,
     "created_time": "2020-08-01T00:04:34Z",
     "user_transaction_time": "2020-08-01T00:04:34Z",
     "settlement_date": "2020-08-01T00:00:00Z",
     "request_amount": 10,
     "amount": 10,
     "issuer_interchange_amount": 0,
     "currency_code": "USD",
     "approval_code": "631494",
     "response": {
         "code": "0000",
         "memo": "Approved or completed successfully"
     },
     "network": "VISA",
     "subnetwork": "VISANET",
     "acquirer_fee_amount": 0,
     "acquirer": {
         "system_trace_audit_number": "847200"
     },
     "user": {
         "metadata": {}
     },
     "card": {
         "metadata": {}
     },
     "card_acceptor": {
         "mid": "11111",
         "mcc": "6411",
         "name": "Aegis Fleet Services",
         "street_address": "111 Main St",
         "city": "Berkeley",
         "state": "CA",
         "postal_code": "94702",
         "country_code": "USA"
     },
     "pos": {
         "partial_approval_capable": true,
         "purchase_amount_only": false,
         "is_recurring": false
     }
 }
```


## Related topics

- [Just-in-Time Funding Overview](/docs/developer-guides/just-in-time-funding-landing-page.md)
- [About Just-in-Time Funding](/docs/developer-guides/about-jit-funding.md)
- [Configuring Gateway JIT Funding](/docs/developer-guides/configuring-gateway-jit-funding.md)
- [Marqeta in Europe Responsibility Matrix](/docs/developer-guides/mq-eu-responsibility-matrix.md)
- [Building Your Managed By Marqeta Card Program](/docs/developer-guides/building-your-managed-card-program.md)
