Alphabite's Medusa Paypal Plugin
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-paypal
Add the plugin to your or :
{plugins: [{resolve: "@alphabite/medusa-paypal",options: {clientId: process.env.PAYPAL_CLIENT_ID,clientSecret: process.env.PAYPAL_CLIENT_SECRET,isSandbox: process.env.PAYPAL_IS_SANDBOX === "true",webhookId: process.env.PAYPAL_WEBHOOK_ID,includeShippingData: false,includeCustomerData: false,},},],modules:[{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "./src/modules/paypal",id: "paypal",options: {clientId: process.env.PAYPAL_CLIENT_ID,clientSecret: process.env.PAYPAL_CLIENT_SECRET,isSandbox: process.env.PAYPAL_SANDBOX === "true",webhookId: process.env.PAYPAL_WEBHOOK_ID,includeShippingData: false,includeCustomerData: false,},},],},},]};
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
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-paypal
Add the plugin to your or :
{plugins: [{resolve: "@alphabite/medusa-paypal",options: {clientId: process.env.PAYPAL_CLIENT_ID,clientSecret: process.env.PAYPAL_CLIENT_SECRET,isSandbox: process.env.PAYPAL_IS_SANDBOX === "true",webhookId: process.env.PAYPAL_WEBHOOK_ID,includeShippingData: false,includeCustomerData: false,},},],modules:[{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "./src/modules/paypal",id: "paypal",options: {clientId: process.env.PAYPAL_CLIENT_ID,clientSecret: process.env.PAYPAL_CLIENT_SECRET,isSandbox: process.env.PAYPAL_SANDBOX === "true",webhookId: process.env.PAYPAL_WEBHOOK_ID,includeShippingData: false,includeCustomerData: false,},},],},},]};
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-js
Ensure your public PayPal Client ID is available in your environment variables:
NEXT_PUBLIC_PAYPAL_CLIENT_ID=your_paypal_client_id
The integration involves wrapping your payment form with and .
Here is a simplified structure of how to implement the PayPal payment component, based on :
import {PayPalCardFieldsForm,PayPalCardFieldsProvider,PayPalScriptProvider,usePayPalCardFields,} from "@paypal/react-paypal-js";import { useState, useEffect } from "react";// Import your internal hooks/utilities (e.g., sdk, usePlaceOrder)export const PayPalPayment = ({ cart, onPaymentCompleted }) => {const [clientToken, setClientToken] = useState(null);// 1. Fetch Client Token from your backenduseEffect(() => {const fetchClientToken = async () => {const response = await sdk.client.fetch("/store/paypal/client-token", {method: "POST",});setClientToken(response.clientToken);};fetchClientToken();}, []);// 2. Define Callbacksconst createOrder = async () => {// Logic to initiate payment session and return order_id// e.g., sdk.store.payment.initiatePaymentSession(cart, { provider_id: "pp_paypal_paypal" })return order_id;};const onApprove = async (data) => {// Logic to finalize order after PayPal approvalawait placeOrder();onPaymentCompleted();};if (!clientToken) return <div>Loading...</div>;return (<PayPalScriptProvideroptions={{clientId: process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID,components: "card-fields",currency: "EUR",intent: "capture",dataClientToken: clientToken,}}><PayPalCardFieldsProvidercreateOrder={createOrder}onApprove={onApprove}style={{input: {"font-size": "14px","font-family": "Inter, sans-serif",color: "#111827",},}}><PayPalCardFieldsForm /><SubmitButton /></PayPalCardFieldsProvider></PayPalScriptProvider>);};const SubmitButton = () => {const { cardFieldsForm } = usePayPalCardFields();const handleClick = async () => {if (cardFieldsForm) {await cardFieldsForm.submit();}};return <button onClick={handleClick}>Pay Now</button>;};