Используйте PayPal как платежный провайдер
Medusa Paypal Payment is a basic integration of payment provider for Paypal.
Warning
1...2"@rsc-labs/medusa-paypal-payment": "0.0.1" // or other available version3...
and execute install, e.g. .
1...2 plugins: [3 {4 resolve: "@rsc-labs/medusa-paypal-payment",5 options: {6 oAuthClientId: <oauth-client-id>,7 oAuthClientSecret: <oauth-client-secret>,8 environment: <env-definition>,9 },10 }11 ],12 modules: [13 {14 resolve: "@medusajs/medusa/payment",15 options: {16 providers: [17 {18 resolve: "@rsc-labs/medusa-paypal-payment/providers/paypal-payment",19 id: "paypal-payment",20 options: {21 oAuthClientId: <oauth-client-id>,22 oAuthClientSecret: <oauth-client-secret>,23 environment: <env-definition>,24 },25 }26 ]27 },28 },29...
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:
1import { OnApproveActions, OnApproveData } from "@paypal/paypal-js"2import { PayPalButtons, usePayPalScriptReducer } from "@paypal/react-paypal-js"3...4const PayPalPaymentButton = ({5 cart,6 notReady,7 "data-testid": dataTestId,8}: {9 cart: HttpTypes.StoreCart10 notReady: boolean11 "data-testid"?: string12}) => {13 const [submitting, setSubmitting] = useState(false)14 const [errorMessage, setErrorMessage] = useState<string | null>(null)1516 const onPaymentCompleted = async () => {17 await placeOrder()18 .catch((err) => {19 setErrorMessage(err.message)20 })21 .finally(() => {22 setSubmitting(false)23 })24 }2526 const session = cart.payment_collection?.payment_sessions?.find(27 (s) => s.status === "pending"28 )2930 const handlePayment = async (31 _data: OnApproveData,32 actions: OnApproveActions33 ) => {34 actions?.order35 ?.authorize()36 .then((authorization) => {37 if (authorization.status !== "COMPLETED") {38 setErrorMessage(`An error occurred, status: ${authorization.status}`)39 return40 }41 onPaymentCompleted()42 })43 .catch((error) => {44 setErrorMessage(`An unknown error occurred, please try again.`)45 setSubmitting(false)46 })47 }4849 const [{ isPending, isResolved }] = usePayPalScriptReducer()5051 if (isPending) {52 return <Spinner />53 }5455 if (isResolved) {56 return (57 <>58 <PayPalButtons59 style={{ layout: "horizontal" }}60 createOrder={async () => {61 return session?.data.paypalOrderId as string;62 }}63 onApprove={handlePayment}64 disabled={notReady || submitting || isPending}65 data-testid={dataTestId}66 />67 <ErrorMessage68 error={errorMessage}69 data-testid="paypal-payment-error-message"70 />71 </>72 )73 }74}75...7677// Please remember that above PaypalButton needs to be a child of PaypalScriptProvider7879return (<PayPalScriptProvider80 options={{81 "client-id": process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID || "test",82 currency: cart?.currency_code.toUpperCase(),83 intent: "authorize",84 components: "buttons",85 }}86 >87 {children}88 </PayPalScriptProvider>89)
- you can retrieve it from your Paypal Developer Dashboard.
MIT
© 2025 RSC https://rsoftcon.com/