Paypal payment provider for Medusa
Medusa Paypal Payment is a basic integration of payment provider for Paypal.
Warning
..."@nackamoto/medusa-paypal-payment": "0.0.2" // or other available version...
and execute install, e.g. .
...plugins: [{resolve: "@nackamoto/medusa-paypal-payment",options: {oAuthClientId: <oauth-client-id>,oAuthClientSecret: <oauth-client-secret>,environment: <env-definition>,},}],modules: [{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "@nackamoto/medusa-paypal-payment/providers/paypal-payment",id: "paypal-payment",options: {oAuthClientId: <oauth-client-id>,oAuthClientSecret: <oauth-client-secret>,environment: <env-definition>,},}]},},...
The Paypal Provider gives ability to:
Plugin uses 3 required parameters:
After above configuration, you can then add the payment provider to your reqion.
We recommend using package on your storefront as it simplifies the implementation a lot. Here is the example of using Paypal as payment:
import { OnApproveActions, OnApproveData } from "@paypal/paypal-js"import { PayPalButtons, usePayPalScriptReducer } from "@paypal/react-paypal-js"...const PayPalPaymentButton = ({cart,notReady,"data-testid": dataTestId,}: {cart: HttpTypes.StoreCartnotReady: boolean"data-testid"?: string}) => {const [submitting, setSubmitting] = useState(false)const [errorMessage, setErrorMessage] = useState<string | null>(null)const onPaymentCompleted = async () => {await placeOrder().catch((err) => {setErrorMessage(err.message)}).finally(() => {setSubmitting(false)})}const session = cart.payment_collection?.payment_sessions?.find((s) => s.status === "pending")const handlePayment = async (_data: OnApproveData,actions: OnApproveActions) => {actions?.order?.authorize().then((authorization) => {if (authorization.status !== "COMPLETED") {setErrorMessage(`An error occurred, status: ${authorization.status}`)return}onPaymentCompleted()}).catch((error) => {setErrorMessage(`An unknown error occurred, please try again.`)setSubmitting(false)})}const [{ isPending, isResolved }] = usePayPalScriptReducer()if (isPending) {return <Spinner />}if (isResolved) {return (<><PayPalButtonsstyle={{ layout: "horizontal" }}createOrder={async () => {return session?.data.paypalOrderId as string;}}onApprove={handlePayment}disabled={notReady || submitting || isPending}data-testid={dataTestId}/><ErrorMessageerror={errorMessage}data-testid="paypal-payment-error-message"/></>)}}...// Please remember that above PaypalButton needs to be a child of PaypalScriptProviderreturn (<PayPalScriptProvideroptions={{"client-id": process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID || "test",currency: cart?.currency_code.toUpperCase(),intent: "authorize",components: "buttons",}}>{children}</PayPalScriptProvider>)
- you can retrieve it from your Paypal Developer Dashboard.
MIT
© 2025 RSC https://rsoftcon.com/