• Сообщество
  • Блог
Документация
Плагины и интеграцииВсе расширения для Medusa от сообществаЭкспертыПодберите специалиста для разработки и развития вашего проекта на Medusa
КейсыПосмотрите примеры Medusa в продакшене и успешные внедрения
Меч Moscow
Комплексная e-commerce платформа на Medusa для московского fashion-бренда

Меч Moscow · Fashion

Gorgo снижает затраты на адаптацию Medusa к локальным рынкам.

Мы разрабатываем плагины интеграции, осуществляем поддержку и развиваем сообщество разработчиков на Medusa в Telegram.

  • Ресурсы Medusa
  • Плагины и интеграции
  • Эксперты
  • Кейсы
  • Medusa Чат в Telegram
  • Medusa Новости в Telegram
  • Документация Gorgo
  • Связаться с нами
  • TelegramGitHub
Плагины
PayPal logo

PayPal

Используйте PayPal как платежный провайдер

npm install @rsc-labs/medusa-paypal-payment
Категория
Платежи
Создано
RSC Labs
Версия
0.0.2
Последнее обновление
1 год назад
Ежемесячные загрузки
Загрузка данных
Звезды на Github
6
npmNPMGitHubGithub

Medusa Paypal Payment

What is it?

Medusa Paypal Payment is a basic integration of payment provider for Paypal.

Installation

  1. Install plugin by adding to your :

Warning

1...
2"@rsc-labs/medusa-paypal-payment": "0.0.1" // or other available version
3...

and execute install, e.g. .

  1. Add plugin to your (Note - please notice that you need to add it to payment plugin):
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...

Overview

The Paypal Provider gives ability to:

  • make a payment using Paypal
  • cancel payment
  • refund payment
  • track payments in Paypal

Configuration

Plugin uses 3 required parameters:

  • - required parameter which you can find in your Paypal Developer Dashboard
  • - required parameter which you can find in your Paypal Developer Dashboard
  • - set to or . You can use it to test with your environment.

After above configuration, you can then add the payment provider to your reqion.

Storefront

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.StoreCart
10 notReady: boolean
11 "data-testid"?: string
12}) => {
13 const [submitting, setSubmitting] = useState(false)
14 const [errorMessage, setErrorMessage] = useState<string | null>(null)
15
16 const onPaymentCompleted = async () => {
17 await placeOrder()
18 .catch((err) => {
19 setErrorMessage(err.message)
20 })
21 .finally(() => {
22 setSubmitting(false)
23 })
24 }
25
26 const session = cart.payment_collection?.payment_sessions?.find(
27 (s) => s.status === "pending"
28 )
29
30 const handlePayment = async (
31 _data: OnApproveData,
32 actions: OnApproveActions
33 ) => {
34 actions?.order
35 ?.authorize()
36 .then((authorization) => {
37 if (authorization.status !== "COMPLETED") {
38 setErrorMessage(`An error occurred, status: ${authorization.status}`)
39 return
40 }
41 onPaymentCompleted()
42 })
43 .catch((error) => {
44 setErrorMessage(`An unknown error occurred, please try again.`)
45 setSubmitting(false)
46 })
47 }
48
49 const [{ isPending, isResolved }] = usePayPalScriptReducer()
50
51 if (isPending) {
52 return <Spinner />
53 }
54
55 if (isResolved) {
56 return (
57 <>
58 <PayPalButtons
59 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 <ErrorMessage
68 error={errorMessage}
69 data-testid="paypal-payment-error-message"
70 />
71 </>
72 )
73 }
74}
75...
76
77// Please remember that above PaypalButton needs to be a child of PaypalScriptProvider
78
79return (<PayPalScriptProvider
80 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.

Notes

  1. Intent has been chosen to in - it means that firstly payment is authorized, then it can be capture via Admin UI. Plugin (not yet) support automatic capturing.
  2. requires to be a parent. It is not problem when making a payment, but when you would like to redirect the user you need be careful. The best option is to put as high as possible in components' tree.
  3. - is created by the plugin and put it in the . However, there are more information put in by the plugin, so you can log them into console and see how you can use it in your storefront.

License

MIT


© 2025 RSC https://rsoftcon.com/

Еще в этой категории

Посмотреть все
Платежи
Braintree logo

Braintree

От Lambda Curry

Поддержка платежей и 3D Secure через Braintree

Загрузка данных
GitHubnpm
Платежи
Pay. logo

Pay.

От Webbers

Принимайте кредитные карты, цифровые платежи и купи сейчас — плати потом

Загрузка данных
GitHubnpm
Платежи
Mollie logo

Mollie

От Variable Vic

Легко принимайте мультивалютные платежи через Mollie

Загрузка данных
GitHubnpm

Еще от этого автора

Посмотреть все
Платежи
Square logo

Square

От RSC Labs

Принимайте платежи через Square

Загрузка данных
GitHubnpm