Используйте PayPal как платежный провайдер
The Alphabite PayPal Plugin integrates PayPal payment processing into your Medusa store. It handles various payment flows, including capturing payments, managing refunds, and ensuring robust error handling.
Pick the plugin version that matches your Medusa backend version:
| Medusa Version | Plugin Version | Install Command |
|---|---|---|
Before installing, verify your Medusa version:
npm list @medusajs/medusaThen install the matching plugin version:
1# Medusa >= 2.13.* (latest)2npm install @alphabite/medusa-paypal3
4# Medusa < 2.13.* (pinned)5npm install @alphabite/medusa-paypal@0.2.5⚠️ Use the same plugin version across local, staging, and production to avoid runtime errors.
The Alphabite PayPal Plugin integrates PayPal payment processing into your Medusa store. It handles various payment flows, including capturing payments, managing refunds, and ensuring robust error handling.
For complete documentation, visit our PayPal Plugin Documentation.
This guide walks you through installing and configuring the Alphabite PayPal Plugin in your Medusa backend.
Install the package via npm:
npm install @alphabite/medusa-paypalAdd the plugin to your or :
1{2 plugins: [3 {4 resolve: "@alphabite/medusa-paypal",5 options: {6 clientId: process.env.PAYPAL_CLIENT_ID,7 clientSecret: process.env.PAYPAL_CLIENT_SECRET,8 isSandbox: process.env.PAYPAL_IS_SANDBOX === "true",9 webhookId: process.env.PAYPAL_WEBHOOK_ID,10 includeShippingData: false,11 includeCustomerData: false,12 },13 },14 ],15 modules:[16 {17 resolve: "@medusajs/medusa/payment",18 options: {19 providers: [20 {21 resolve: "./src/modules/paypal",22 id: "paypal",23 options: {24 clientId: process.env.PAYPAL_CLIENT_ID,25 clientSecret: process.env.PAYPAL_CLIENT_SECRET,26 isSandbox: process.env.PAYPAL_SANDBOX === "true",27 webhookId: process.env.PAYPAL_WEBHOOK_ID,28 includeShippingData: false,29 includeCustomerData: false,30 },31 },32 ],33 },34 },35 ]36};The following options can be passed to the PayPal plugin in your or file:
| Option | Type | Default | Description |
|---|---|---|---|
| Required. Your PayPal API client ID. | |||
| Required. Your PayPal API client secret. | |||
| Whether to use the PayPal Sandbox environment for testing. | |||
| Optional. Your PayPal webhook ID. If provided, enables confirmation of payment captures. | |||
| Optional. If , shipping data from the storefront order will be added to the PayPal order. | |||
| Optional. If , customer data from the storefront order will be added to the PayPal order. |
👉 Configuration Guide 👉 Join our Discord Community for faster support
This guide explains how to integrate the PayPal payment flow into your Next.js storefront using .
Install the official PayPal React SDK:
npm install @paypal/react-paypal-jsEnsure your public PayPal Client ID is available in your environment variables:
NEXT_PUBLIC_PAYPAL_CLIENT_ID=your_paypal_client_idThe integration involves wrapping your payment form with and .
Here is a simplified structure of how to implement the PayPal payment component, based on :
1import {2 PayPalCardFieldsForm,3 PayPalCardFieldsProvider,4 PayPalScriptProvider,5 usePayPalCardFields,6} from "@paypal/react-paypal-js";7import { useState, useEffect } from "react";8// Import your internal hooks/utilities (e.g., sdk, usePlaceOrder)9
10export const PayPalPayment = ({ cart, onPaymentCompleted }) => {11 const [clientToken, setClientToken] = useState(null);12
13 // 1. Fetch Client Token from your backend14 useEffect(() => {15 const fetchClientToken = async () => {16 const response = await sdk.client.fetch("/store/paypal/client-token", {17 method: "POST",18 });19 setClientToken(response.clientToken);20 };21 fetchClientToken();22 }, []);23
24 // 2. Define Callbacks25 const createOrder = async () => {26 // Logic to initiate payment session and return order_id27 // e.g., sdk.store.payment.initiatePaymentSession(cart, { provider_id: "pp_paypal_paypal" })28 return order_id;29 };30
31 const onApprove = async (data) => {32 // Logic to finalize order after PayPal approval33 await placeOrder();34 onPaymentCompleted();35 };36
37 if (!clientToken) return <div>Loading...</div>;38
39 return (40 <PayPalScriptProvider41 options={{42 clientId: process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID,43 components: "card-fields",44 currency: "EUR",45 intent: "capture",46 dataClientToken: clientToken,47 }}48 >49 <PayPalCardFieldsProvider50 createOrder={createOrder}51 onApprove={onApprove}52 style={{53 input: {54 "font-size": "14px",55 "font-family": "Inter, sans-serif",56 color: "#111827",57 },58 }}59 >60 <PayPalCardFieldsForm />61 <SubmitButton />62 </PayPalCardFieldsProvider>63 </PayPalScriptProvider>64 );65};66
67const SubmitButton = () => {68 const { cardFieldsForm } = usePayPalCardFields();69
70 const handleClick = async () => {71 if (cardFieldsForm) {72 await cardFieldsForm.submit();73 }74 };75
76 return <button onClick={handleClick}>Pay Now</button>;77};