Pular para o conteúdo
Criar conta
ou
Entrar
O logotipo da documentação da Stripe
/
Pergunte à IA
Criar conta
Login
Comece já
Pagamentos
Automação de finanças
Plataformas e marketplaces
Gestão de valores
Ferramentas para desenvolvedores
Comece já
Pagamentos
Automação de finanças
Comece já
Pagamentos
Automação de finanças
Plataformas e marketplaces
Gestão de valores
Visão geral
Billing
    Visão geral
    Sobre as APIs do Billing
    Assinaturas
      Como funcionam as assinaturas
      Início rápido
      Casos de uso
      Crie sua integração
      Recursos de assinatura
        Faturas de assinatura
        Cronogramas de assinatura
        Preços de assinatura
        Modelos de preço recorrente
        Incorporar uma tabela de preços
        Iniciar assinaturas
        Definir quantidades
        Defina ciclos de faturamento
        Inicie assinaturas com data passada
        Inscrever-se em vários itens
        Definir períodos de avaliação
        Aplicar cupons
        Migrar assinaturas para a Stripe
        Como cobranças proporcionais de crédito são calculadas
        Pagamentos de assinaturas
        Formas de pagamento de assinaturas
          Débito automático ACH
          Amazon Pay
          Débito automático Bacs no Reino Unido
          Transferência bancária
          Débito automático BECS na Austrália
          Cash App Pay
          PayPal
            PayPal no Checkout
          Revolut Pay
          Cartões coreanos
          Kakao Pay
          Naver Pay
          Débito pré-autorizado no Canadá
          Débito automático SEPA na UE
          iDEAL com débito automático SEPA
          Bancontact com débito automático SEPA
          Sofort com débito automático SEPA
        Integrar com processamento de pagamentos externo
        Métodos de cobrança
        Compartilhe um link para atualizar dados de pagamento
        SCA (autenticação forte de cliente)
        Gerenciar assinaturas
        Modifique assinaturas
        Gerencie atualizações pendentes
      Análises
    Invoicing
    Cobrança por uso
    Connect e Billing
    Tax e Billing
    Cotações
    Recuperação de receitas
    Automações
    Scripts
    Reconhecimento de receitas
    Gerenciamento de clientes
    Direitos
    Teste sua integração
Tributos
Relatórios
Dados
Incorporação de startups
Página inicialAutomação de finançasBillingSubscriptionsSubscription featuresSubscription payment methods

Observação

Esta página ainda não está disponível no idioma desejado. Estamos trabalhando para tornar nossa documentação disponível em mais idiomas e vamos disponibilizar a tradução assim possível.

Set up a subscription with PayPal

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

Copiar página

Cuidado

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

Esta página foi útil?
SimNão
Precisa de ajuda? Fale com o suporte.
Participe do nosso programa de acesso antecipado.
Confira nosso changelog.
Dúvidas? Fale com a equipe de vendas.
LLM? Read llms.txt.
Powered by Markdoc