Ir a contenido
Crea una cuenta
o
Inicia sesión
Logotipo de Stripe Docs
/
Pregúntale a la IA
Crear una cuenta
Iniciar sesión
Empieza ahora
Pagos
Automatización contable
Plataformas y marketplaces
Gestión del dinero
Herramientas para desarrolladores
Empieza ahora
Pagos
Automatización contable
Empieza ahora
Pagos
Automatización contable
Plataformas y marketplaces
Gestión del dinero
Resumen
Billing
    Resumen
    Acerca de las API de facturación
    Suscripciones
      Cómo funcionan las suscripciones
      Inicio rápido
      Casos de uso
      Desarrolla tu integración
      Funcionalidades de la suscripción
        Facturas de suscripciones
        Calendarios de suscripciones
        Precios de suscripciones
        Modelos de tarifas recurrentes
        Inserta un cuadro de tarifas
        Iniciar suscripciones
        Determinar cantidades
        Establecer ciclos de facturación
        Suscripciones con fechas pasadas
        Suscríbete a varios elementos
        Configura períodos de prueba
        Aplica cupones
        Migrar suscripciones a Stripe
        Cómo se calculan los prorrateos de crédito
        Pagos de suscripciones
        Métodos de pago de suscripciones
          Débito directo ACH
          Amazon Pay
          Débito directo Bacs en el Reino Unido
          Transferencia bancaria
          Débito directo BECS en Australia
          Cash App Pay
          PayPal
            PayPal en Checkout
          Revolut Pay
          Tarjetas coreanas
          Kakao Pay
          Naver Pay
          Débito preautorizado en Canadá
          Débito directo SEPA en la UE
          iDEAL con débito directo SEPA
          Bancontact con débito directo SEPA
          Sofort con débito directo SEPA
        Integra con el procesamiento de pagos de terceros
        Métodos de cobro
        Comparte un enlace para actualizar los datos de pago
        Autenticación reforzada de clientes (SCA)
        Administración de suscripciones
        Modificar suscripciones
        Gestionar actualizaciones pendientes
      Análisis
    Invoicing
    Cobro por consumo
    Connect y Billing
    Tax y Billing
    Presupuestos
    Recuperación de ingresos
    Automatizaciones
    Scripts
    Reconocimiento de ingresos
    Gestión de clientes
    Derechos
    Prueba tu integración
Impuesto
Elaboración de informes
Datos
Constitución de una startup
InicioAutomatización contableBillingSubscriptionsSubscription featuresSubscription payment methods

Nota

Esta página aún no está disponible en este idioma. Estamos trabajando intensamente para que nuestra documentación esté disponible en más idiomas. Ofreceremos la traducción en cuanto esté disponible.

Set up a subscription with PayPal

Learn how to create and charge for a subscription with PayPal.

Copiar página

Precaución

To start accepting PayPal subscriptions on Stripe, PayPal recurring payments must be enabled in the Dashboard.

Use this guide to set up a subscription using PayPal as a payment method.

Create a product and price
Dashboard

Products represent the item or service you’re selling. Prices define how much and how frequently you charge for a product. This includes how much the product costs, what currency you accept, and whether it’s a one-time or recurring charge. If you only have a few products and prices, create and manage them in the Dashboard.

This guide uses a stock photo service as an example and charges customers a 15 EUR monthly subscription. To model this:

  1. Navigate to the Add a product page.
  2. Enter a Name for the product.
  3. Enter 15 for the price.
  4. Select EUR as the currency.
  5. Click Save product.

After you create the product and the price, record the price ID so you can use it in subsequent steps. The pricing page displays the ID and it looks similar to this: price_G0FvDp6vZvdwRZ.

Create or retrieve a Customer before setup
Server-side

To reuse a PayPal payment method for future payments, attach it to a Customer.

Create a Customer object when a customer creates an account on your business. Associating the ID of the Customer object with your own internal representation of a customer lets you retrieve and use the stored payment method details later. If the customer hasn’t created an account, you can still create a Customer object now and associate it with your internal representation of the customer’s account later.

Command Line
cURL
curl -X POST https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Create a SetupIntent
Server-side

A SetupIntent is an object that represents your intent and tracks the steps to set up your customer’s payment method for future payments.

Create a SetupIntent on your server with payment_method_types set to paypal and specify the Customer’s id.

Command Line
cURL
curl https://api.stripe.com/v1/setup_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=
{{CUSTOMER_ID}}
\ -d "payment_method_types[]"=paypal \ -d "payment_method_data[type]"=paypal

The SetupIntent object contains a client_secret, a unique key that you need to pass to Stripe on the client side to redirect your buyer to PayPal and authorize the mandate.

Redirect your customer
Client-side

When a customer attempts to set up their PayPal account for future payments, we recommend you use Stripe.js to confirm the SetupIntent. Stripe.js is our foundational JavaScript library for building payment flows. It will automatically handle complexities like the redirect described below, and enables you to easily extend your integration to other payment methods in the future.

Include the Stripe.js script on your checkout page by adding it to the head of your HTML file.

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>

Create an instance of Stripe.js with the following JavaScript on your checkout page.

// Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
, {} );

To confirm the setup on the client side, pass the client secret of the SetupIntent object that you created in Step 3.

The client secret is different from your API keys that authenticate Stripe API requests. It should still be handled carefully because it can complete the charge. Do not log it, embed it in URLs, or expose it to anyone but the customer.

Confirm PayPal Setup

To authorize you to use their PayPal account for future payments, your customer will be redirected to a PayPal billing agreement page, which they will need to approve before being redirected back to your website. Use stripe.confirmPayPalSetup to handle the redirect away from your page and to complete the setup. Add a return_url to this function to indicate where Stripe should redirect the user to after they approve the billing agreement on PayPal’s website.

client.js
// Redirects away from the client const {error} = await stripe.confirmPayPalSetup( '{{SETUP_INTENT_CLIENT_SECRET}}', { return_url: 'https://example.com/setup/complete', mandate_data: { customer_acceptance: { type: 'online', online: { infer_from_client: true } } }, } ); if (error) { // Inform the customer that there was an error. }

You can find the Payment Method payer ID and Billing Agreement ID on the resulting Mandate under the payment_method_details property. You can also find the buyer’s email and payer ID in the paypal property on the PaymentMethod.

FieldValue
payer_emailThe email address of the payer on their PayPal account.
payer_idA unique ID of the payer’s PayPal account.
billing_agreement_idThe PayPal Billing Agreement ID (BAID). This is an ID generated by PayPal which represents the mandate between the business and the customer.

Monitor webhooks
Server-side

Use a method such as webhooks to confirm the billing agreement was authorized successfully by your customer, instead of relying on your customer to return to the payment status page. When a customer successfully authorizes the billing agreement, the SetupIntent emits the setup_intent.succeeded webhook event. If a customer doesn’t successfully authorize the billing agreement, the SetupIntent will emit the setup_intent.setup_failed webhook event and returns to a status of requires_payment_method. When a customer revokes the billing agreement from their PayPal account, the mandate.updated is emitted.

Create the subscription
Server-side

Create a subscription with the price and customer:

Command Line
cURL
curl https://api.stripe.com/v1/subscriptions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=cus_Gk0uVzT2M4xOKD \ -d default_payment_method=pm_1F0c9v2eZvKYlo2CJDeTrB4n \ -d "items[0][price]"=price_F52b2UdntfQsfR \ -d "expand[0]"="latest_invoice.confirmation_secret" \ -d off_session=true

Creating subscriptions automatically charges customers because the default payment method is set. After a successful payment, the status in the Stripe Dashboard changes to Active. The price you created earlier determines subsequent billings.

Manage subscription status
Client-side

If the initial payment succeeds, the state of the subscription is active and no further action is needed. When payments fail, the status is changed to the Subscription status configured in your automatic collection settings. Notify the customer on failure and charge them with a different payment method.

Update a subscription
Server-side

When you update a subscription, you need to specify off_session=true. Otherwise, any new payment requires a user redirection to PayPal for confirmation. For example, if you want to change the quantity of an item included in the subscription you can use:

Command Line
cURL
curl https://api.stripe.com/v1/subscriptions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=cus_Gk0uVzT2M4xOKD \ -d default_payment_method=pm_1F0c9v2eZvKYlo2CJDeTrB4n \ -d "items[0][price]"=price_F52b2UdntfQsfR \ -d "items[0][quantity]"=2 \ -d off_session=true

Test the integration

Test your PayPal integration with your test API keys by viewing the redirect page. You can test the successful payment case by authenticating the payment on the redirect page. The PaymentIntent will transition from requires_action to succeeded.

To test the case where the user fails to authenticate, use your test API keys and view the redirect page. On the redirect page, click Fail test payment. The PaymentIntent will transition from requires_action to requires_payment_method.

OpcionalSetting the billing cycle

OpcionalSubscription trials

OpcionalRemove a saved PayPal account

¿Te fue útil esta página?
SíNo
¿Necesitas ayuda? Ponte en contacto con soporte.
Únete a nuestro programa de acceso anticipado.
Echa un vistazo a nuestro registro de cambios.
¿Tienes alguna pregunta? Contacto.
¿LLM? Lee llms.txt.
Con tecnología de Markdoc