Criar assinatura - Assinaturas - Mercado Pago Developers
Criar assinatura

POST

/preapproval
Uma assinatura é a união entre um plano e um cliente. Sua característica principal é ter um meio de pagamento configurado que servirá como base para criar faturas. Também é possível criar assinaturas sem plano.
Parâmetros de requisição
auto_recurring
object
Localização: bodyConfiguração de recorrência. É obrigatório apenas para assinaturas sem plano associado.
back_url

OBRIGATÓRIO

string
Localização: bodyURL de retorno de sucesso. Use esta configuração para redirecionar o cliente para seu site após o checkout. É obrigatório apenas para assinaturas sem plano associado.
card_token_id
string
Localização: bodyUnique card token identifier
external_reference
string
Localização: bodyReferência para sincronizar com seu sistema. Este é um campo de texto livre que ajudará na integração com as entidades. Este campo é obrigatório apenas para assinaturas sem plano associado.
Parâmetros de resposta
id
string
Localização: bodyIdentificador único de assinatura
version
number
Localização: bodyQuantas vezes a assinatura foi modificada
application_id
number
Localização: bodyID único que identifica sua aplicação/integração. Uma das chaves do par que compõe as credenciais que identifica uma aplicação/integração na sua conta.
collector_id
number
Localização: bodyID único que identifica seu usuário como vendedor. Este ID corresponde ao seu User ID em nosso ecossistema.
Solicitação
curl
curl -X POST \
    'https://api.mercadopago.com/preapproval' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
  "preapproval_plan_id": "2c938084726fca480172750000000000",
  "reason": "Yoga classes",
  "external_reference": "YG-1234",
  "payer_email": "test_user@testuser.com",
  "card_token_id": "e3ed6f098462036dd2cbabe314b9de2a",
  "auto_recurring": {
    "frequency": 1,
    "frequency_type": "months",
    "start_date": "2020-06-02T13:07:14.260Z",
    "end_date": "2022-07-20T15:59:52.581Z",
    "transaction_amount": 10,
    "currency_id": "ARS"
  },
  "back_url": "https://www.mercadopago.com.ar",
  "status": "authorized"
}'
Resposta
json
{
  "id": "2c938084726fca480172750000000000",
  "version": 0,
  "application_id": 1234567812345678,
  "collector_id": 100200300,
  "preapproval_plan_id": "2c938084726fca480172750000000000",
  "reason": "Yoga classes.",
  "external_reference": 23546246234,
  "back_url": "https://www.mercadopago.com.ar",
  "init_point": "https://www.mercadopago.com.ar/subscriptions/checkout?preapproval_id=2c938084726fca480172750000000000",
  "auto_recurring": {
    "frequency": 1,
    "frequency_type": "months",
    "start_date": "2020-06-02T13:07:14.260Z",
    "end_date": "2022-07-20T15:59:52.581Z",
    "currency_id": "ARS",
    "transaction_amount": 10,
    "free_trial": {
      "frequency": 1,
      "frequency_type": "months"
    }
  },
  "payer_id": 123123123,
  "card_id": 123123123,
  "payment_method_id": 123123123,
  "next_payment_date": "2022-01-01T11:12:25.892-04:00",
  "date_created": "2022-01-01T11:12:25.892-04:00",
  "last_modified": "2022-01-01T11:12:25.892-04:00",
  "status": "pending"
}
Erros
400bad_request
400Subscriptions are not available for this country yet
400The payment method account money is not available in your country
400Collector and Application cannot be from different countries
400Field card_token_id is required
400Field payer_email is required
400Invalid value for payer_email, must be a valid email address
400Invalid value for transaction amount, must be a positive number
400Invalid value for transaction amount, only two decimals are allowed
400Invalid value for auto_recurring.currency_id
400Invalid value for auto_recurring.end_date, the date must be after today
400Invalid value for auto_recurring.frequency, must be a positive integer
400Invalid value for auto_recurring.frequency_type, valid ones are days, months
400Invalid value for auto_recurring.start_date, the date must be after today
400Invalid format in auto_recurring.start_date or auto_recurring.end_date
400Invalid value for back_url, must be a valid URL
400Field reason has more than 255 characters
400Field reason has unsupported characters
400Field auto_recurring.frequency is required
400Field auto_recurring.frequency_type is required
400Field auto_recurring.transaction_amount is required
400Field auto_recurring.currency_id is required
400Field auto_recurring.end_date must be after auto_recurring.start_date
400Field external_reference has more than 255 characters
400Field external_reference has unsupported characters
400Already exists a preapproval for user <payer_email> and application <application_id>
400Payer and collector cannot be the same user
400Both payer and collector must be real or test users
400This preapproval cannot be created. The seller does not accept account_money
400This preapproval cannot be created only with payment method account_money
400Cannot operate between different countries
400Cannot create preapproval pending, the feature with account money is disabled for your country.
400Cannot pay an amount lower than min
400Cannot pay an amount greater than max
400You cannot create a preapproval with payment_method in status pending
400You cannot create a new preapproval from a cancelled or inactive template
400The transaction_amount must be the same as preapproval_plan
400Card token was used, please generate new
400Card token was generated without cvv validation
400Invalid request data
401bad_request
401CC_VAL_433 Credit card validation has failed
401Verification of collectors personal data is in process, come back later
401Unauthorized access to resource
401This app cannot create subscriptions without a plan
403bad_request
403The collector does not meet the personal data verification requirements
403The caller is not authorized to access this resource
403Unauthorized seller for this feature AM_VAL_01
500bad_request
500Internal server error