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

# Create a Preauthorized PayIn

### Body parameters

<ParamField body="Tag" type="string">
  Max. length: 255 characters

  Custom data that you can add to this object.\
  For transactions (pay-in, transfer, payout), you can use this parameter to identify corresponding information regarding the user, transaction, or payment methods on your platform.
</ParamField>

<ParamField body="AuthorId" type="string">
  The unique identifier of the user at the source of the transaction.
</ParamField>

<ParamField body="CreditedUserId" type="string">
  **Default value:** The unique identifier of the owner of the credited wallet.

  The unique identifier of the user whose wallet is credited.
</ParamField>

<ParamField body="DebitedFunds" type="object" required>
  Information about the debited funds.

  <Expandable title="properties">
    <ParamField body="Currency" type="string" required>
      **Allowed values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

      The currency of the debited funds.
    </ParamField>

    <ParamField body="Amount" type="integer" required>
      An amount of money in the smallest sub-division of the currency (e.g., EUR 12.60 would be represented as `1260` whereas JPY 12 would be represented as just `12`).
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="Fees" type="object" required>
  Information about the fees taken by the platform for this transaction (and hence transferred to the Fees Wallet).

  <Expandable title="properties">
    <ParamField body="Currency" type="string" required>
      **Allowed values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

      The currency of the fees.
    </ParamField>

    <ParamField body="Amount" type="integer" required>
      An amount of money in the smallest sub-division of the currency (e.g., EUR 12.60 would be represented as `1260` whereas JPY 12 would be represented as just `12`).
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="CreditedWalletId" type="string" required>
  The unique identifier of the credited wallet.
</ParamField>

<ParamField body="PreauthorizationId" type="string" required>
  The unique identifier of the preauthorization.
</ParamField>

### Responses

<AccordionGroup>
  <Accordion title="200 - Successful capture">
    <ResponseField name="Id" type="string">
      Max length: 128 characters (see [data formats](/api-reference/overview/data-formats) for details)

      The unique identifier of the object.
    </ResponseField>

    <ResponseField name="Tag" type="string">
      Max. length: 255 characters

      Custom data that you can add to this object.
    </ResponseField>

    <ResponseField name="CreationDate" type="Unix timestamp">
      The date and time at which the object was created.
    </ResponseField>

    <ResponseField name="ResultCode" type="string">
      The code indicating the result of the operation. This information is mostly used to <a href="/errors/codes">handle errors</a> or for filtering purposes.
    </ResponseField>

    <ResponseField name="ResultMessage" type="string">
      The explanation of the result code.
    </ResponseField>

    <ResponseField name="AuthorId" type="string">
      The unique identifier of the user at the source of the transaction.
    </ResponseField>

    <ResponseField name="CreditedUserId" type="string">
      **Default value:** The unique identifier of the owner of the credited wallet.

      The unique identifier of the user whose wallet is credited.
    </ResponseField>

    <ResponseField name="DebitedFunds" type="object">
      Information about the debited funds.

      <Expandable title="properties">
        <ResponseField name="Currency" type="string">
          **Returned values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

          The currency of the debited funds.
        </ResponseField>

        <ResponseField name="Amount" type="integer">
          An amount of money in the smallest sub-division of the currency (e.g., EUR 12.60 would be represented as `1260` whereas JPY 12 would be represented as just `12`).
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="CreditedFunds" type="object">
      Information about the credited funds (`CreditedFunds` = `DebitedFunds` - `Fees`).

      <Expandable title="properties">
        <ResponseField name="Currency" type="string">
          **Returned values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

          The currency of the credited funds.
        </ResponseField>

        <ResponseField name="Amount" type="integer">
          An amount of money in the smallest sub-division of the currency (e.g., EUR 12.60 would be represented as `1260` whereas JPY 12 would be represented as just `12`).
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="Fees" type="object">
      Information about the fees taken by the platform for this transaction (and hence transferred to the Fees Wallet).

      <Expandable title="properties">
        <ResponseField name="Currency" type="string">
          **Returned values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

          The currency of the fees.
        </ResponseField>

        <ResponseField name="Amount" type="integer">
          An amount of money in the smallest sub-division of the currency (e.g., EUR 12.60 would be represented as `1260` whereas JPY 12 would be represented as just `12`).
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="Status" type="string">
      **Returned values:** `CREATED`, `SUCCEEDED`, `FAILED`

      The status of the transaction.
    </ResponseField>

    <ResponseField name="ExecutionDate" type="Unix timestamp">
      The date and time at which the status changed to `SUCCEEDED`, indicating that the transaction occurred. The statuses `CREATED` and `FAILED` return an `ExecutionDate` of `null`.
    </ResponseField>

    <ResponseField name="Type" type="string">
      **Returned values:** `PAYIN`, `TRANSFER`, `CONVERSION`, `PAYOUT`

      The type of the transaction.
    </ResponseField>

    <ResponseField name="Nature" type="string">
      **Returned values:** `REGULAR`, `REPUDIATION`, `REFUND`, `SETTLEMENT`

      The nature of the transaction, providing more information about the context in which the transaction occurred:

      * `REGULAR` – Relative to most of the transactions (pay-ins, payouts, and transfers) in a usual workflow.
      * `REPUDIATION` – Automatic withdrawal of funds from the platform’s repudiation wallet as part of the dispute process (when the user has requested a chargeback).
      * `REFUND` – Reimbursement of a transaction to the user (pay-in refund), to a wallet (transfer refund), or of a payout (payout refund, only initiated by Mangopay).
      * `SETTLEMENT` – Transfer made to the repudiation wallet by the platform to settle a lost dispute.
    </ResponseField>

    <ResponseField name="CreditedWalletId" type="string">
      The unique identifier of the credited wallet.
    </ResponseField>

    <ResponseField name="DebitedWalletId" type="string">
      The unique identifier of the debited wallet.

      In the case of a pay-in, this value is always `null` since there is no debited wallet.
    </ResponseField>

    <ResponseField name="PaymentType" type="string">
      **Returned values:** `CARD`, `DIRECT_DEBIT`, `PREAUTHORIZED`, `BANK_WIRE`

      The type of pay-in.
    </ResponseField>

    <ResponseField name="ExecutionType" type="string">
      **Returned values:** `WEB`, `DIRECT`, `EXTERNAL_INSTRUCTION`

      The type of execution for the pay-in.
    </ResponseField>

    <ResponseField name="PreauthorizationId" type="string">
      The unique identifier of the preauthorization.
    </ResponseField>

    <ResponseField name="AuthenticationResult" type="object | null" defaultOpen>
      Information about the authentication result, based on the request made by Mangopay and the decision of the issuer regarding the type of authentication to be enforced (if applicable).

      <Expandable title="properties">
        <ResponseField name="AuthenticationType" type="string | null">
          Response values: `CHALLENGE`, `FRICTIONLESS`, `DIRECT_AUTHORIZATION`

          The type of authentication:

          * `CHALLENGE` – The issuer requested SCA to be enforced (for example, using 3DS).
          * `FRICTIONLESS` – The transaction was exempted from SCA because an exemption was granted by the issuer.
          * `DIRECT_AUTHORIZATION` – The transaction was sent to the issuer for authorization without any frictionless or challenge (for example, if SCA doesn't apply).

          A `null` value typically indicates that authentication was not requested (for example, because the request failed before being sent) or a decision was not received.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Accordion>
</AccordionGroup>

<AccordionGroup>
  <Accordion title="400 - Failed: Preauthorization Status must be SUCCEEDED">
    ```json theme={null}
    {
       "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
       "Type": "param_error",
       "Id": "b6a5ae0d-7dc9-479a-86bd-55b0d40dccec#1669116785",
       "Date": 1669116786,
       "errors": {
           "Status": "The PreAuthorization Status value has to be up to SUCCEEDED"
       }
    }  
    ```
  </Accordion>

  <Accordion title="400 - Failed: Preauthorization PaymentStatus must be WAITING">
    ```json theme={null}
    {
        "Message": "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.",
        "Type": "param_error",
        "Id": "2a6b5503-551b-4a66-a7f4-3ae4d6efc91f",
        "Date": 1716385561.0,
        "errors": {
            "PaymentStatus": "The PreAuthorization PaymentStatus value has to be WAITING"
        }
    }
    ```
  </Accordion>
</AccordionGroup>

<ResponseExample>
  ```json 200 - Successful capture   theme={null}
  {
      "Id": "wt_8da11453-4231-4628-85c8-f8f8674b4ab8",
      "Tag": null,
      "CreationDate": 1771580679,
      "ResultCode": "000000",
      "ResultMessage": "Success",
      "AuthorId": "user_m_01KHRMAQT1ZPVBWK2KYM6S0N7M",
      "CreditedUserId": "user_m_01KH8RY4CGEYM6B5TA6JGKSYDJ",
      "DebitedFunds": {
          "Currency": "EUR",
          "Amount": 10000
      },
      "CreditedFunds": {
          "Currency": "EUR",
          "Amount": 9000
      },
      "Fees": {
          "Currency": "EUR",
          "Amount": 1000
      },
      "Status": "SUCCEEDED",
      "ExecutionDate": 1771580680,
      "Type": "PAYIN",
      "Nature": "REGULAR",
      "CreditedWalletId": "wlt_m_01KH8RY6BKXD2ZT7F76XH2TS7Z",
      "DebitedWalletId": null,
      "PaymentType": "PREAUTHORIZED",
      "ExecutionType": "DIRECT",
      "PreauthorizationId": "preauth_wt_064022a9-3640-4ed1-a4bd-3488426428fa",
      "AuthenticationResult": {
          "AuthenticationType": "CHALLENGE"
      }
  }
  ```

  ```json 200 - Failed: Amount greater than remaining funds   theme={null}
  {
      "Id": "5ca9a5a3-8db0-4184-9322-acf521a4e210",
      "Tag": "capture attempt",
      "CreationDate": 1669115134,
      "ResultCode": "001505",
      "ResultMessage": "The PayIn DebitedFunds can't be higher than the PreAuthorization remaining amount",
      "AuthorId": "user_m_01HQK25M6KVHKDV0S36JY9NRKR",
      "CreditedUserId": "user_m_01HQK25M6KVHKDV0S36JY9NRKR",
      "DebitedFunds": {
          "Currency": "EUR",
          "Amount": 700
      },
      "CreditedFunds": {
          "Currency": "EUR",
          "Amount": 700
      },
      "Fees": {
          "Currency": "EUR",
          "Amount": 0
      },
      "Status": "FAILED",
      "ExecutionDate": null,
      "Type": "PAYIN",
      "Nature": "REGULAR",
      "CreditedWalletId": "wlt_m_01HT2J9Q2M6GMFW4Z7GYBAFJ4T",
      "DebitedWalletId": null,
      "PaymentType": "PREAUTHORIZED",
      "ExecutionType": "DIRECT",
      "PreauthorizationId": "preauth_m_01HYG88W1QWJNNBGJJG0KQGX42",
      "AuthenticationResult": {
          "AuthenticationType": "CHALLENGE"
      }
  }
  ```
</ResponseExample>

<RequestExample>
  ```json REST   theme={null}
  {
      "CreditedWalletId": "204089031",
      "DebitedFunds": {
          "Currency": "EUR",
          "Amount": 2000
      },
      "Fees": {
          "Currency": "EUR",
          "Amount": 200
      },
      "PreauthorizationId": "preauth_m_01HYG88W1QWJNNBGJJG0KQGX42"
  }  
  ```

  ```php PHP  theme={null}
  <?php 

  require_once 'vendor/autoload.php';

  use MangoPay\MangoPayApi;
  use MangoPay\Libraries\ResponseException as MGPResponseException;
  use MangoPay\Libraries\Exception as MGPException;

  $api = new MangoPayApi();

  $api->Config->ClientId = 'your-client-id';
  $api->Config->ClientPassword = 'your-api-key';
  $api->Config->TemporaryFolder = 'tmp/';

  try {
      $userId = 'user_m_01HQK25M6KVHKDV0S36JY9NRKR';
      $cardId = 'card_m_01J420XC7KAW655XPP12SC28HS';
      $walletId = 'wlt_m_01HQT6422EER2N7FPRXWTSDCSV';
      $preauthId = 'preauth_m_01JH3CJ75WGC9FMST9RH7SKBSC';

      $preauthPayIn = new \MangoPay\PayIn();
      $preauthPayIn->AuthorId = $userId;
      $preauthPayIn->CreditedWalletId = $walletId;

      $preauthPayIn->DebitedFunds = new Money();
      $preauthPayIn->DebitedFunds->Amount = 1000;
      $preauthPayIn->DebitedFunds->Currency = 'EUR';

      $preauthPayIn->Fees = new Money();
      $preauthPayIn->Fees->Amount = 0;
      $preauthPayIn->Fees->Currency = 'EUR';

      $preauthPayIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsPreAuthorized();
      $preauthPayIn->PaymentDetails->PreauthorizationId = $preauthId;

      $preauthPayIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect();
      $preauthPayIn->ExecutionDetails->SecureModeReturnURL = 'http://example.com';
      $preauthPayIn->ExecutionDetails->Culture = 'FR';

      $createPayIn = $api->PayIns->Create($preauthPayIn);

      print_r($createPayIn);
  } catch(MGPResponseException $e) {
      print_r($e);
  } catch(MGPException $e) {
      print_r($e);
  }
  ```

  ```javascript NodeJS   theme={null}
  const mangopayInstance = require('mangopay4-nodejs-sdk')
  const mangopay = new mangopayInstance({
      clientId: 'your-client-id',
      clientApiKey: 'your-api-key',
  })

  let myPreauthorizedPayIn = {
    PaymentType: 'PREAUTHORIZED',
    ExecutionType: 'DIRECT',
    AuthorId: '192822811',
    Tag: 'Created with Mangopay Node.js SDK',
    CreditedUserId: '192822811',
    DebitedFunds: {
      Currency: 'EUR',
      Amount: 1000,
    },
    Fees: {
      Currency: 'EUR',
      Amount: 100,
    },
    CreditedWalletId: '192822814',
    PreauthorizationId: '192823192',
  }

  const createPreauthorizedPayin = async (payin) => {
    return await mangopay.PayIns.create(payin)
      .then((response) => {
        console.info(response)
        return response
      })
      .catch((err) => {
        console.log(err)
        return false
      })
  }

  createPreauthorizedPayin(myPreauthorizedPayIn)  
  ```

  ```ruby Ruby   theme={null}
  require 'mangopay'

  MangoPay.configure do |client|
      client.preproduction = true
      client.client_id = 'your-client-id'
      client.client_apiKey = 'your-api-key'
      client.log_file = File.join(Dir.pwd, 'mangopay.log')
  end

  def createPreauthorizedPayIn(payInObject)
      begin
          response = MangoPay::PayIn::PreAuthorized::Direct.create(payInObject)
          puts response
          return response
      rescue MangoPay::ResponseError => error
          puts "Failed to create preauthorized payin: #{error.message}"
          puts "Error details: #{error.details}"
          return false
      end
  end

  myPreauthorizedPayIn = {
      AuthorId: '192822811',
      Tag: 'Created with Mangopay Ruby SDK',
      CreditedUserId: '192822811',
      DebitedFunds: {
        Currency: 'EUR',
        Amount: 900,
      },
      Fees: {
        Currency: 'EUR',
        Amount: 100,
      },
      CreditedWalletId: '192822814',
      PreauthorizationId: '195059241'
    }

  createPreauthorizedPayIn(myPreauthorizedPayIn)  
  ```

  ```java Java  theme={null}
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.mangopay.MangoPayApi;
  import com.mangopay.core.Money;
  import com.mangopay.core.enumerations.CurrencyIso;
  import com.mangopay.entities.PayIn;
  import com.mangopay.entities.subentities.PayInExecutionDetailsDirect;
  import com.mangopay.entities.subentities.PayInPaymentDetailsPreAuthorized;

  public class CreatePreauthPayIn {
          public static void main(String[] args) throws Exception {
          MangoPayApi mangopay = new MangoPayApi();
          mangopay.getConfig().setClientId("your-client-id");
          mangopay.getConfig().setClientPassword("your-api-key");
          
          var preauthId = "preauth_m_01J218VW84JAKDZS516PPTQWFW";
          var userId = "user_m_01HT2NFK7Z2BRQNGNHMY30VVTT";
          var walletId = "wlt_m_01HWAR863HPA3FAVEXA9J6JSYD";

          PayIn payIn = new PayIn();
          payIn.setCreditedWalletId(walletId);
          payIn.setAuthorId(userId);
          payIn.setTag("Created using the Mangopay Java SDK");

          payIn.setDebitedFunds(new Money());
          payIn.getDebitedFunds().setAmount(100);
          payIn.getDebitedFunds().setCurrency(CurrencyIso.EUR);

          payIn.setFees(new Money());
          payIn.getFees().setAmount(0);
          payIn.getFees().setCurrency(CurrencyIso.EUR);

          payIn.setPaymentDetails(new PayInPaymentDetailsPreAuthorized());
          ((PayInPaymentDetailsPreAuthorized) payIn.getPaymentDetails()).setPreauthorizationId(preauthId);

          payIn.setExecutionDetails(new PayInExecutionDetailsDirect());
          ((PayInExecutionDetailsDirect) payIn.getExecutionDetails()).setSecureModeReturnUrl("http://example.com");

          PayIn createPayIn = mangopay.getPayInApi().create(payIn);
      
          Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create();
          String prettyJson = prettyPrint.toJson(createPayIn);

          System.out.println(prettyJson);
      }
  }
  ```

  ```python Python   theme={null}
  from pprint import pprint
  import mangopay

  mangopay.client_id='your-client-id'
  mangopay.apikey='your-api-key'

  from mangopay.api import APIRequest
  handler = APIRequest(sandbox=True)

  from mangopay.resources import NaturalUser, PreAuthorizedPayIn
  from mangopay.utils import Money

  natural_user = NaturalUser.get('213753890')

  preauthorization_payin = PreAuthorizedPayIn(
      author_id = natural_user.id,
      debited_funds =  Money(amount=1000, currency='GBP'),
      fees = Money(amount=0, currency='GBP'),
      credited_wallet_id = '213754077',
      preauthorization_id = '213944840',
      tag='Created using the Mangopay Python SDK'
  )

  create_preauthorization_payin = preauthorization_payin.save()
  pprint(create_preauthorization_payin)
    
  ```

  ```csharp .NET  theme={null}
  using MangoPay.SDK;
  using MangoPay.SDK.Core.Enumerations;
  using MangoPay.SDK.Entities;
  using MangoPay.SDK.Entities.POST;
  using Newtonsoft.Json;

  class Program
  {
      static async Task Main(string[] args)
      {
          MangoPayApi api = new MangoPayApi();

          api.Config.ClientId = "your-client-id";
          api.Config.ClientPassword = "your-api-key";

          var userId = "user_m_01J2TZ261WZNDM0ZDRWGDYA4GN";
          var walletId = "wlt_m_01J30991BXBB7VF28PBS82EWD3";
          var preauthorizationId = "preauth_m_01J30NHM7E0TQ9W5NRQ964W7WF";

          var preauthorizedPayIn = new PayInPreauthorizedDirectPostDTO (
              userId,
              new Money { Amount = 1000, Currency = CurrencyIso.EUR },
              new Money { Amount = 0, Currency = CurrencyIso.EUR },
              walletId, preauthorizationId)
              {
                  SecureModeReturnURL = "http://www.mangopay.com/please-ignore"
              };

          var createPreauthorizedPayIn = await api.PayIns.CreatePreauthorizedDirectAsync(preauthorizedPayIn);

          string prettyPrint = JsonConvert.SerializeObject(createPreauthorizedPayIn, Formatting.Indented);
          Console.WriteLine(prettyPrint);
      }
  }
  ```
</RequestExample>
