Accept a PayPal payment
Learn how to accept PayPal payment, a digital wallet popular with businesses in Europe.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
Stripe uses a payment object, called a PaymentIntent, to track and handle all the states of the payment until it’s completed. Create a PaymentIntent
on your server, specifying the amount to collect and the currency. If you already have an integration using the Payment Intents API, add paypal
to the list of payment method types for your PaymentIntent.
Included in the returned PaymentIntent is a client secret, which is used to securely complete the payment process instead of passing the entire PaymentIntent object. Send the client secret back to the client so you can use it in later steps.
Include a custom description
By default, the order details on the PayPal users purchase activity page displays the order amount. You can change this by providing a custom description in the description
property.
Customize the preferred locale
By default, the PayPal authorization page is localized based on variables such as the merchant’s country. You can set this to your customer’s preferred locale using the preferred_
property. The value must be a two-character lowercased language code, followed by a hyphen (-
), followed by a two-character uppercased country code. For example, the value for a French-language user in Belgium would be fr-BE
. See supported locales for more information.
Statement descriptors with PayPal
The descriptor that appears on the buyer’s bank statement is set by PayPal, and by default is PAYPAL *YOUR_
. If you set the statement_
field when creating the PaymentIntent
, its value is appended to the one set by PayPal, up to a total limit of 22 characters.
For example, if your business name in PayPal is BUSINESS
and you set statement_
to order_
, buyers see PAYPAL *BUSINESS order
on their bank account statement.
Submit the payment to StripeClient-side
When a customer clicks to pay with PayPal, use Stripe.js to submit the payment to Stripe. Stripe.js is the foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to extend your integration to other payment methods. Include the Stripe.js script on your checkout page by adding it to the head
of your HTML file.
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></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 create a payment on the client side, pass the client secret of the PaymentIntent
object that you created in Step 2. The client secret is different from your API keys that authenticate Stripe API requests. Handle this carefully because it can complete the charge. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Confirm PayPal payment
Call stripe.confirmPayPalPayment to redirect your customer to PayPal to complete the payment. You must add a return_
to specify where Stripe will redirect your customer after they complete the payment. You can also add the return_
for new PayPal payment methods, but it’s not required when using a previously set up PayPal payment method with SetupIntent or a PaymentIntent that includes setup_
.
// Redirects away from the client const {error} = await stripe.confirmPayPalPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { return_url: 'https://example.com/checkout/complete', } ); if (error) { // Inform the customer that there was an error. }
If you settle your PayPal funds with PayPal, the balance transaction linked to the payment has an amount of zero regardless of the payment amount, because the transaction represents money moved into and out of your Stripe balance. However, for PayPal, funds settle in your PayPal balance, and no money goes to your Stripe balance. The balance transaction in this case also includes fees associated with it. Learn about other important details related to the settlement preference.
Handling the redirect
The following URL query parameters are provided when Stripe redirects the customer to the return_
.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent . |
payment_ | The client secret of the PaymentIntent object. |
You may also append your own query parameters when providing the return_
. They persist throughout the redirect process. The return_
should correspond to a page on your website that provides the status of the payment. You should verify the status of the PaymentIntent
when rendering the return page. You can do so by using the retrievePaymentIntent
function from Stripe.js and passing in the payment_
.
(async () => { const url = new URL(window.location); const clientSecret = url.searchParams.get('payment_intent_client_secret'); const {paymentIntent, error} = await stripe.retrievePaymentIntent(clientSecret); if (error) { // Handle error } else if (paymentIntent && paymentIntent.status === 'succeeded') { // Handle successful payment } })();
You can find the payment owner’s name, email, payer ID, and transaction ID in the payment_method_details property.
Field | Value |
---|---|
payer_ | The email address of the payer on their PayPal account. |
payer_ | The name of the payer on their PayPal account. |
payer_ | A unique ID of the payer’s PayPal account. |
transaction_ | A unique transaction ID generated by PayPal. |
{ "charges": { "data": [ { "payment_method_details": { "paypal": { "payer_id": "H54KFE9XXVVYJ", "payer_email": "jenny@example.com", "payer_name": "Jenny Rosen", "transaction_id": "89W40396MK104212M" }, "type": "paypal" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU", "created": 1445277809, "currency": "eur", "flow": "redirect",
OptionalHandle post-payment events
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.
Receive events and run business actions 
There are a few options for receiving and running business actions.
Manually
Use the Stripe Dashboard to view all your Stripe payments, send email receipts, handle payouts, or retry failed payments.
Custom code
Build a webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.
Prebuilt apps
Handle common business events, like automation or marketing and sales, by integrating a partner application.
OptionalHandle the PayPal redirect manually
Stripe.js helps you extend your integration to other payment methods. However, you can manually redirect your customers on your server.
- Create and confirm a PaymentIntent of type
paypal
. By specifyingpayment_
, a PaymentMethod is created and immediately used with the PaymentIntent.method_ data
You must also provide the URL where your customer is redirected to after they complete their payment in the return_
field. You can provide your own query parameters in this URL. These parameters are included in the final URL upon completing the redirect flow.
- Check that the
PaymentIntent
has a status ofrequires_
and the type foraction next_
isaction redirect_
.to_ url
{ "status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", ... }
- Redirect the customer to the URL provided in the
next_
property. This code example is approximate—the redirect method might be different in your web framework.action. redirect_ to_ url. url
Your customer is redirected to the return_
when they complete the payment process. The payment_
and payment_
URL query parameters are included along with any of your own query parameters. Stripe recommends setting up a webhook endpoint to programmatically confirm the status of a payment.
OptionalAuthorize a payment and then capture later
PayPal supports separate authorization and capture. If you’ve opted for settlement to Stripe, your authorizations are valid for 10 days. Stripe automatically reauthorizes the payment to extend the authorization period by another 10 days. This results in a total of 20 days. If the reauthorization doesn’t work, Stripe makes the payment expire right after 10 days. Listen to the charge.expired webhook to know when the authorization period ends.
If you’ve opted for settlement to PayPal, your authorizations remain valid for 3 days. Stripe tries to extend the authorization period by another 3 days. For an extended guaranteed authorization period of up to 10 days, referred to as honor period on PayPal, contact PayPal support.
Tell Stripe to authorize only
To indicate that you want separate authorization and capture, set capture_method to manual
when creating the PaymentIntent. This parameter instructs Stripe to only authorize the amount on the customer’s PayPal account.
Upon authorization success, Stripe sends a payment_intent.amount_capturable_updated event. Read our Events guide to learn more.
Capture the funds
After the authorization succeeds, the PaymentIntent status transitions to requires_
. To capture the authorized funds, make a PaymentIntent capture request. The total authorized amount is captured by default—you can’t capture more than this, but you can capture less.
Optional Cancel the authorization
If you need to cancel an authorization, you can cancel the PaymentIntent.
OptionalTurn on asynchronous payment methods on PayPal
By default, Stripe only allows synchronous payment methods on PayPal. This guarantees that you receive an immediate notification for the success or the failure of each payment. If you allow asynchronous payment methods, you might encounter delayed notifications for some payments. As a result, you must rely on webhook endpoints to receive notifications about the success or failure of certain payments.
To enable asynchronous payments on PayPal, contact Stripe support.
OptionalError codes
These are the common error codes and corresponding details while integrating with PayPal. If a PayPal API request returned the error, it includes a PayPal issue code and the associated Debug ID for the request. You can use the Debug ID when contacting PayPal support to get help with your issue.
Error Code | Details |
---|---|
country_ | The specified country code in the shipping address is invalid. |
incorrect_ | The specified shipping address is invalid. This error is also thrown if the specified country additionally requires either a city or a postal code. For further information, please check the error message and contact PayPal support with the Debug ID and PayPal issue . |
payment_ | The paypal payment method is currently not available. This error might be caused by a timeout or server issue when connecting to PayPal API. |
payment_ | The transaction is declined by PayPal. This is commonly caused by the merchant’s fraud protection settings on PayPal, a compliance violation, or the payer being unable to pay with the chosen funding instrument. For further information, please check the error message and contact PayPal support with the Debug ID and PayPal issue . |
payment_ | The request timed out on PayPal. In most cases, this is a transient error and you can retry the request after a few moments. |
payment_ | The paypal payment method isn’t activated for your Stripe account. |
payment_ | The request failed on PayPal. This can occur if the merchant’s business account is locked, restricted, or closed by PayPal, or if the payer’s PayPal account is restricted. For further information, please check the error message and contact PayPal support with the Debug ID and PayPal issue . |
OptionalTest PayPal integration
To test a successful payment on your PayPal integration, use your test API keys and view the redirect page. This page shows you the options to Authorize or Fail the user authentication as test scenarios. When you select Authorize test payment, the PaymentIntent transitions from requires_
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 then transitions from requires_
to requires_
.
To simulate the most common integration and failure scenarios for PayPal payments, pass email
values that match the patterns described in Test Scenarios when you create the PaymentIntent as part of the billing details. For example, when confirming the PaymentIntent server-side, a request simulating a transaction refused by PayPal would look like:
Test scenarios
Email pattern | Scenario | Explanation |
---|---|---|
. | Merchant account restricted | Capturing or authorizing a payment fails with a payment_ error if your merchant account is restricted by PayPal. Provide an email matching this pattern at time of authorization to fail the authorization. |
. | Transaction refused | Capturing a payment fails with a payment_ error if the transaction is refused by PayPal. |
. | Payment instrument declined | Capturing a payment fails with a payment_ error if the instrument presented was either declined by the processor or bank, or it can’t be used for this payment. |
. | Manually capturing an authorized payment | Capturing an authorized payment fails with a capture_ error if the authorization has already expired. |