From 69f6cb45a8043ac47494e6508974575da5aa0fde Mon Sep 17 00:00:00 2001 From: Eric Dobbertin Date: Tue, 21 Apr 2020 14:45:28 -0500 Subject: [PATCH] refactor: move payments plugin to NPM package Signed-off-by: Eric Dobbertin --- jest.config.cjs | 1 + package-lock.json | 10 + package.json | 1 + plugins.json | 2 +- src/core-services/payments/i18n/ar.json | 35 --- src/core-services/payments/i18n/bg.json | 35 --- src/core-services/payments/i18n/cs.json | 35 --- src/core-services/payments/i18n/de.json | 35 --- src/core-services/payments/i18n/el.json | 35 --- src/core-services/payments/i18n/en.json | 39 --- src/core-services/payments/i18n/es.json | 35 --- src/core-services/payments/i18n/fr.json | 35 --- src/core-services/payments/i18n/he.json | 34 --- src/core-services/payments/i18n/hr.json | 35 --- src/core-services/payments/i18n/hu.json | 35 --- src/core-services/payments/i18n/index.js | 54 ---- src/core-services/payments/i18n/it.json | 35 --- src/core-services/payments/i18n/my.json | 35 --- src/core-services/payments/i18n/nb.json | 6 - src/core-services/payments/i18n/nl.json | 35 --- src/core-services/payments/i18n/pl.json | 35 --- src/core-services/payments/i18n/pt.json | 35 --- src/core-services/payments/i18n/ro.json | 35 --- src/core-services/payments/i18n/ru.json | 35 --- src/core-services/payments/i18n/sl.json | 35 --- src/core-services/payments/i18n/sv.json | 35 --- src/core-services/payments/i18n/tr.json | 35 --- src/core-services/payments/i18n/vi.json | 35 --- src/core-services/payments/i18n/zh.json | 35 --- src/core-services/payments/index.js | 29 -- .../approveOrderPayments.test.js.snap | 11 - .../enablePaymentMethodForShop.test.js.snap | 9 - .../mutations/approveOrderPayments.js | 69 ----- .../mutations/approveOrderPayments.test.js | 111 -------- .../mutations/captureOrderPayments.js | 105 -------- .../mutations/captureOrderPayments.test.js | 47 ---- .../mutations/enablePaymentMethodForShop.js | 51 ---- .../enablePaymentMethodForShop.test.js | 122 --------- src/core-services/payments/mutations/index.js | 9 - .../availablePaymentMethods.test.js.snap | 3 - .../__snapshots__/paymentMethods.test.js.snap | 5 - .../queries/availablePaymentMethods.js | 25 -- .../queries/availablePaymentMethods.test.js | 70 ----- .../queries/getPaymentMethodConfigByName.js | 14 - src/core-services/payments/queries/index.js | 9 - .../payments/queries/paymentMethods.js | 27 -- .../payments/queries/paymentMethods.test.js | 83 ------ src/core-services/payments/registration.js | 14 - .../Mutation/approveOrderPayments.js | 33 --- .../Mutation/captureOrderPayments.js | 33 --- .../Mutation/enablePaymentMethodForShop.js | 28 -- .../enablePaymentMethodForShop.test.js | 35 --- .../payments/resolvers/Mutation/index.js | 9 - .../payments/resolvers/Payment/index.js | 5 - .../payments/resolvers/PaymentMethod/index.js | 3 - .../Query/availablePaymentMethods.js | 17 -- .../payments/resolvers/Query/index.js | 7 - .../resolvers/Query/paymentMethods.js | 17 -- src/core-services/payments/resolvers/index.js | 11 - src/core-services/payments/schemas/index.js | 5 - .../payments/schemas/schema.graphql | 254 ------------------ src/core-services/payments/xforms/id.js | 14 - src/mockTypes.graphql | 39 +-- 63 files changed, 19 insertions(+), 2186 deletions(-) delete mode 100644 src/core-services/payments/i18n/ar.json delete mode 100644 src/core-services/payments/i18n/bg.json delete mode 100644 src/core-services/payments/i18n/cs.json delete mode 100644 src/core-services/payments/i18n/de.json delete mode 100644 src/core-services/payments/i18n/el.json delete mode 100644 src/core-services/payments/i18n/en.json delete mode 100644 src/core-services/payments/i18n/es.json delete mode 100644 src/core-services/payments/i18n/fr.json delete mode 100644 src/core-services/payments/i18n/he.json delete mode 100644 src/core-services/payments/i18n/hr.json delete mode 100644 src/core-services/payments/i18n/hu.json delete mode 100644 src/core-services/payments/i18n/index.js delete mode 100644 src/core-services/payments/i18n/it.json delete mode 100644 src/core-services/payments/i18n/my.json delete mode 100644 src/core-services/payments/i18n/nb.json delete mode 100644 src/core-services/payments/i18n/nl.json delete mode 100644 src/core-services/payments/i18n/pl.json delete mode 100644 src/core-services/payments/i18n/pt.json delete mode 100644 src/core-services/payments/i18n/ro.json delete mode 100644 src/core-services/payments/i18n/ru.json delete mode 100644 src/core-services/payments/i18n/sl.json delete mode 100644 src/core-services/payments/i18n/sv.json delete mode 100644 src/core-services/payments/i18n/tr.json delete mode 100644 src/core-services/payments/i18n/vi.json delete mode 100644 src/core-services/payments/i18n/zh.json delete mode 100644 src/core-services/payments/index.js delete mode 100644 src/core-services/payments/mutations/__snapshots__/approveOrderPayments.test.js.snap delete mode 100644 src/core-services/payments/mutations/__snapshots__/enablePaymentMethodForShop.test.js.snap delete mode 100644 src/core-services/payments/mutations/approveOrderPayments.js delete mode 100644 src/core-services/payments/mutations/approveOrderPayments.test.js delete mode 100644 src/core-services/payments/mutations/captureOrderPayments.js delete mode 100644 src/core-services/payments/mutations/captureOrderPayments.test.js delete mode 100644 src/core-services/payments/mutations/enablePaymentMethodForShop.js delete mode 100644 src/core-services/payments/mutations/enablePaymentMethodForShop.test.js delete mode 100644 src/core-services/payments/mutations/index.js delete mode 100644 src/core-services/payments/queries/__snapshots__/availablePaymentMethods.test.js.snap delete mode 100644 src/core-services/payments/queries/__snapshots__/paymentMethods.test.js.snap delete mode 100644 src/core-services/payments/queries/availablePaymentMethods.js delete mode 100644 src/core-services/payments/queries/availablePaymentMethods.test.js delete mode 100644 src/core-services/payments/queries/getPaymentMethodConfigByName.js delete mode 100644 src/core-services/payments/queries/index.js delete mode 100644 src/core-services/payments/queries/paymentMethods.js delete mode 100644 src/core-services/payments/queries/paymentMethods.test.js delete mode 100644 src/core-services/payments/registration.js delete mode 100644 src/core-services/payments/resolvers/Mutation/approveOrderPayments.js delete mode 100644 src/core-services/payments/resolvers/Mutation/captureOrderPayments.js delete mode 100644 src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.js delete mode 100644 src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.test.js delete mode 100644 src/core-services/payments/resolvers/Mutation/index.js delete mode 100644 src/core-services/payments/resolvers/Payment/index.js delete mode 100644 src/core-services/payments/resolvers/PaymentMethod/index.js delete mode 100644 src/core-services/payments/resolvers/Query/availablePaymentMethods.js delete mode 100644 src/core-services/payments/resolvers/Query/index.js delete mode 100644 src/core-services/payments/resolvers/Query/paymentMethods.js delete mode 100644 src/core-services/payments/resolvers/index.js delete mode 100644 src/core-services/payments/schemas/index.js delete mode 100644 src/core-services/payments/schemas/schema.graphql delete mode 100644 src/core-services/payments/xforms/id.js diff --git a/jest.config.cjs b/jest.config.cjs index de7b60aa78a..a0a11c6761b 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -15,6 +15,7 @@ const externalNodeModules = [ "@reactioncommerce/api-plugin-job-queue", "@reactioncommerce/api-plugin-notifications", "@reactioncommerce/api-plugin-orders", + "@reactioncommerce/api-plugin-payments", "@reactioncommerce/api-plugin-payments-stripe", "@reactioncommerce/api-plugin-settings", "@reactioncommerce/api-plugin-simple-schema", diff --git a/package-lock.json b/package-lock.json index 49b17bddba3..41a151f879d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1726,6 +1726,16 @@ } } }, + "@reactioncommerce/api-plugin-payments": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@reactioncommerce/api-plugin-payments/-/api-plugin-payments-1.0.0.tgz", + "integrity": "sha512-3wc4/oKKJsZCW7MvVvj8WCGgiaUKWJ8OTWlkG5u/pvPX83LfEwLwmrk/nOqdLoLkAo4Ipb4wQgr97cSEckOA6A==", + "requires": { + "@reactioncommerce/api-utils": "^1.9.0", + "@reactioncommerce/reaction-error": "^1.0.1", + "simpl-schema": "^1.5.7" + } + }, "@reactioncommerce/api-plugin-payments-stripe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@reactioncommerce/api-plugin-payments-stripe/-/api-plugin-payments-stripe-1.0.0.tgz", diff --git a/package.json b/package.json index 8c6427dec42..7563dbaf54b 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@reactioncommerce/api-plugin-job-queue": "~1.0.0", "@reactioncommerce/api-plugin-notifications": "~1.0.0", "@reactioncommerce/api-plugin-orders": "~1.0.0", + "@reactioncommerce/api-plugin-payments": "~1.0.0", "@reactioncommerce/api-plugin-payments-stripe": "~1.0.0", "@reactioncommerce/api-plugin-settings": "~1.0.0", "@reactioncommerce/api-plugin-shops": "~1.0.0", diff --git a/plugins.json b/plugins.json index 5edf5194b00..19e76b8dd46 100644 --- a/plugins.json +++ b/plugins.json @@ -18,7 +18,7 @@ "navigation": "@reactioncommerce/plugin-navigation", "notifications": "@reactioncommerce/api-plugin-notifications", "orders": "@reactioncommerce/api-plugin-orders", - "payments": "./src/core-services/payments/index.js", + "payments": "@reactioncommerce/api-plugin-payments", "pricing": "./src/plugins/simple-pricing/index.js", "product": "./src/core-services/product/index.js", "sMTPEmail": "./src/plugins/email-smtp/index.js", diff --git a/src/core-services/payments/i18n/ar.json b/src/core-services/payments/i18n/ar.json deleted file mode 100644 index 31a8c82831c..00000000000 --- a/src/core-services/payments/i18n/ar.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Arabic", - "i18n": "ar", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "المدفوعات", - "paymentsTitle": "المدفوعات" - }, - "dashboard": { - "paymentsLabel": "المدفوعات", - "paymentsTitle": "المدفوعات", - "paymentsDescription": "التكوين المدفوعات" - }, - "settings": { - "paymentSettingsLabel": "إعدادات الدفع" - }, - "paymentSettings": { - "paymentMethod": "مزود الافتراضي" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "إضافة الدفع لإكمال النظام", - "processingError": "كان هناك مشكلة مع الدفع الخاص بك.", - "completeYourOrder": "استكمال طلبك", - "noPaymentMethods": "يتم تكوين أي وسائل الدفع.", - "contactAdmin": "يرجى الاتصال بمسؤول المتجر.", - "configureNow": "تكوين الآن.", - "failedToPlaceOrder": "فشل لوضع النظام." - } - } - } -}] diff --git a/src/core-services/payments/i18n/bg.json b/src/core-services/payments/i18n/bg.json deleted file mode 100644 index 1dbb8a0310d..00000000000 --- a/src/core-services/payments/i18n/bg.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Bulgarian", - "i18n": "bg", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Плащания", - "paymentsTitle": "Плащания" - }, - "dashboard": { - "paymentsLabel": "Плащания", - "paymentsTitle": "Плащания", - "paymentsDescription": "конфигурация Плащания" - }, - "settings": { - "paymentSettingsLabel": "Настройки на плащане" - }, - "paymentSettings": { - "paymentMethod": "Default Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Добави плащане, за да завършите поръчка", - "processingError": "Имаше проблем с плащането.", - "completeYourOrder": "Завършете поръчката", - "noPaymentMethods": "Не са начините на плащане са конфигурирани.", - "contactAdmin": "Моля, свържете се с администратора на магазина.", - "configureNow": "Конфигуриране на предприятието.", - "failedToPlaceOrder": "Не може да се постави цел." - } - } - } -}] diff --git a/src/core-services/payments/i18n/cs.json b/src/core-services/payments/i18n/cs.json deleted file mode 100644 index 98b408c9625..00000000000 --- a/src/core-services/payments/i18n/cs.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Czech", - "i18n": "cs", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Platby", - "paymentsTitle": "Platby" - }, - "dashboard": { - "paymentsLabel": "Platby", - "paymentsTitle": "Platby", - "paymentsDescription": "konfigurace platby" - }, - "settings": { - "paymentSettingsLabel": "Platební Nastavení" - }, - "paymentSettings": { - "paymentMethod": "Výchozí Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Přidejte platby k dokončení objednávky", - "processingError": "Došlo k potížím s vaší platby.", - "completeYourOrder": "Dokončit svou objednávku", - "noPaymentMethods": "Žádné platební metody jsou konfigurovány.", - "contactAdmin": "Obraťte se na správce obchodu.", - "configureNow": "Nakofigurujte.", - "failedToPlaceOrder": "Nepodařilo se místo pořadí." - } - } - } -}] diff --git a/src/core-services/payments/i18n/de.json b/src/core-services/payments/i18n/de.json deleted file mode 100644 index 06ba9debffb..00000000000 --- a/src/core-services/payments/i18n/de.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "German", - "i18n": "de", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Zahlungen", - "paymentsTitle": "Zahlungen" - }, - "dashboard": { - "paymentsLabel": "Zahlungen", - "paymentsTitle": "Zahlungen", - "paymentsDescription": "Zahlungen Konfiguration" - }, - "settings": { - "paymentSettingsLabel": "Zahlungseinstellungen" - }, - "paymentSettings": { - "paymentMethod": "Standardanbieter" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "In Zahlungsauftrag abzuschließen", - "processingError": "Es gab ein Problem mit Ihrer Zahlung.", - "completeYourOrder": "Ergänzen Sie Ihre Bestellung", - "noPaymentMethods": "Keine Zahlungsmethoden konfiguriert sind.", - "contactAdmin": "Bitte wenden Sie sich an den Ladenverwalter.", - "configureNow": "Jetzt konfigurieren.", - "failedToPlaceOrder": "Fehlgeschlagen Auftrag zu vergeben." - } - } - } -}] diff --git a/src/core-services/payments/i18n/el.json b/src/core-services/payments/i18n/el.json deleted file mode 100644 index 8b4d7dbc737..00000000000 --- a/src/core-services/payments/i18n/el.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Greek", - "i18n": "el", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "πληρωμές", - "paymentsTitle": "πληρωμές" - }, - "dashboard": { - "paymentsLabel": "πληρωμές", - "paymentsTitle": "πληρωμές", - "paymentsDescription": "διαμόρφωση πληρωμές" - }, - "settings": { - "paymentSettingsLabel": "Ρυθμίσεις πληρωμής" - }, - "paymentSettings": { - "paymentMethod": "προεπιλογή Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Προσθέστε την πληρωμή να ολοκληρώσετε την παραγγελία", - "processingError": "Υπήρξε ένα πρόβλημα με την πληρωμή σας.", - "completeYourOrder": "Ολοκληρώστε την παραγγελία σας", - "noPaymentMethods": "Δεν μέθοδοι πληρωμής ρυθμιστεί.", - "contactAdmin": "Επικοινωνήστε με τον διαχειριστή του καταστήματος.", - "configureNow": "Διαμορφώστε τώρα.", - "failedToPlaceOrder": "Αποτυχία να δώσετε την παραγγελία." - } - } - } -}] diff --git a/src/core-services/payments/i18n/en.json b/src/core-services/payments/i18n/en.json deleted file mode 100644 index afcff2af290..00000000000 --- a/src/core-services/payments/i18n/en.json +++ /dev/null @@ -1,39 +0,0 @@ -[{ - "language": "English", - "i18n": "en", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "captureAllElevatedRiskWarning": "One or more of the payments you are attempting to capture has an elevated charge risk. Do you want to proceed?", - "captureOneElevatedRiskWarning": "The payment you are attempting to capture has an elevated charge risk. Do you want to proceed?", - "captureAllPayments": "Capture all payments", - "capturePayment": "Capture payment", - "admin": { - "shortcut": { - "paymentsLabel": "Payments", - "paymentsTitle": "Payments" - }, - "dashboard": { - "paymentsLabel": "Payments", - "paymentsTitle": "Payments", - "paymentsDescription": "Payments configuration" - }, - "settings": { - "paymentSettingsLabel": "Payment" - }, - "paymentSettings": { - "paymentMethod": "Default Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Add payment to complete order", - "processingError": "There was a problem with your payment.", - "completeYourOrder": "Complete your order", - "noPaymentMethods": "No payment methods are configured.", - "contactAdmin": "Please contact the store administrator.", - "configureNow": "Configure now.", - "failedToPlaceOrder": "Failed to place order." - } - } - } -}] diff --git a/src/core-services/payments/i18n/es.json b/src/core-services/payments/i18n/es.json deleted file mode 100644 index 3977365ddef..00000000000 --- a/src/core-services/payments/i18n/es.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Spanish", - "i18n": "es", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Pagos", - "paymentsTitle": "Pagos" - }, - "dashboard": { - "paymentsLabel": "Pagos", - "paymentsTitle": "Pagos", - "paymentsDescription": "configuración de pagos" - }, - "settings": { - "paymentSettingsLabel": "Configuración de pagos" - }, - "paymentSettings": { - "paymentMethod": "Proveedor predeterminado" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Añadir el pago a la orden completa", - "processingError": "Hubo un problema con su pago.", - "completeYourOrder": "Completar su pedido", - "noPaymentMethods": "No hay métodos de pago están configurados.", - "contactAdmin": "Póngase en contacto con el administrador de la tienda.", - "configureNow": "Configurar ahora.", - "failedToPlaceOrder": "No se pudo realizar el pedido." - } - } - } -}] diff --git a/src/core-services/payments/i18n/fr.json b/src/core-services/payments/i18n/fr.json deleted file mode 100644 index e3e7099eb19..00000000000 --- a/src/core-services/payments/i18n/fr.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "French", - "i18n": "fr", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Paiements", - "paymentsTitle": "Paiements" - }, - "dashboard": { - "paymentsLabel": "Paiements", - "paymentsTitle": "Paiements", - "paymentsDescription": "Configuration des paiements" - }, - "settings": { - "paymentSettingsLabel": "Paramètres de paiement" - }, - "paymentSettings": { - "paymentMethod": "Fournisseur par défaut" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Ajouter une méthode de paiement pour terminer la commande", - "processingError": "Un problème est survenu concernant votre paiement.", - "completeYourOrder": "Complétez votre commande", - "noPaymentMethods": "Aucun mode de paiement n'est configuré.", - "contactAdmin": "Veuillez contacter l'administrateur de la boutique.", - "configureNow": "Configurer maintenant.", - "failedToPlaceOrder": "Impossible de passer commande." - } - } - } -}] diff --git a/src/core-services/payments/i18n/he.json b/src/core-services/payments/i18n/he.json deleted file mode 100644 index 3c6203382e3..00000000000 --- a/src/core-services/payments/i18n/he.json +++ /dev/null @@ -1,34 +0,0 @@ -[{ - "language": "Hebrew", - "i18n": "he", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "תשלומים", - "paymentsTitle": "תשלומים" - }, - "dashboard": { - "paymentsLabel": "תשלומים", - "paymentsTitle": "תשלומים", - "paymentsDescription": "קביעת תצורה לתשלומים" - }, - "settings": { - "paymentSettingsLabel": "הגדרות תשלום" - }, - "paymentSettings": { - "paymentMethod": "ספק ברירת מחדל" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "הוסף תשלום כדי להשלים את ההזמנה", - "processingError": "התגלתה בעיה עם התשלום.", - "completeYourOrder": "השלם את ההזמנה שלך", - "noPaymentMethods": "לא הוגדרו שיטות תשלום.", - "configureNow": "קבע תצורה עכשיו.", - "failedToPlaceOrder": "משלוח ההזמנה נכשל." - } - } - } -}] diff --git a/src/core-services/payments/i18n/hr.json b/src/core-services/payments/i18n/hr.json deleted file mode 100644 index 3adfe0de751..00000000000 --- a/src/core-services/payments/i18n/hr.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Croatian", - "i18n": "hr", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Plaćanja", - "paymentsTitle": "Plaćanja" - }, - "dashboard": { - "paymentsLabel": "Plaćanja", - "paymentsTitle": "Plaćanja", - "paymentsDescription": "Plaćanja konfiguracija" - }, - "settings": { - "paymentSettingsLabel": "Postavke plaćanja" - }, - "paymentSettings": { - "paymentMethod": "zadana Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Dodaj plaćanje završiti narudžbu", - "processingError": "Došlo je do problema s plaćanjem.", - "completeYourOrder": "Dovršite narudžbu", - "noPaymentMethods": "Načini plaćanja su konfigurirani.", - "contactAdmin": "Obratite se administratoru trgovine.", - "configureNow": "Konfiguracija sada.", - "failedToPlaceOrder": "Nije uspjelo staviti red." - } - } - } -}] diff --git a/src/core-services/payments/i18n/hu.json b/src/core-services/payments/i18n/hu.json deleted file mode 100644 index e92d6a43fc4..00000000000 --- a/src/core-services/payments/i18n/hu.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Hungarian", - "i18n": "hu", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "kifizetések", - "paymentsTitle": "kifizetések" - }, - "dashboard": { - "paymentsLabel": "kifizetések", - "paymentsTitle": "kifizetések", - "paymentsDescription": "kifizetések konfiguráció" - }, - "settings": { - "paymentSettingsLabel": "fizetési beállítások" - }, - "paymentSettings": { - "paymentMethod": "Alapértelmezett szolgáltató" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Add fizetési megbízás teljesítéséhez", - "processingError": "Volt egy probléma a fizetést.", - "completeYourOrder": "Teljesíteni rendelését", - "noPaymentMethods": "Nem fizetési módok vannak beállítva.", - "contactAdmin": "Kérjük, forduljon a bolt rendszergazda.", - "configureNow": "Konfigurálása most.", - "failedToPlaceOrder": "Nem sikerült helyet érdekében." - } - } - } -}] diff --git a/src/core-services/payments/i18n/index.js b/src/core-services/payments/i18n/index.js deleted file mode 100644 index 9deb0a6b6e7..00000000000 --- a/src/core-services/payments/i18n/index.js +++ /dev/null @@ -1,54 +0,0 @@ -import ar from "./ar.json"; -import bg from "./bg.json"; -import de from "./de.json"; -import el from "./el.json"; -import en from "./en.json"; -import es from "./es.json"; -import fr from "./fr.json"; -import he from "./he.json"; -import hr from "./hr.json"; -import it from "./it.json"; -import my from "./my.json"; -import nb from "./nb.json"; -import nl from "./nl.json"; -import pl from "./pl.json"; -import pt from "./pt.json"; -import ro from "./ro.json"; -import ru from "./ru.json"; -import sl from "./sl.json"; -import sv from "./sv.json"; -import tr from "./tr.json"; -import vi from "./vi.json"; -import zh from "./zh.json"; - -// -// we want all the files in individual -// imports for easier handling by -// automated translation software -// -export default { - translations: [ - ...ar, - ...bg, - ...de, - ...el, - ...en, - ...es, - ...fr, - ...he, - ...hr, - ...it, - ...my, - ...nb, - ...nl, - ...pl, - ...pt, - ...ro, - ...ru, - ...sl, - ...sv, - ...tr, - ...vi, - ...zh - ] -}; diff --git a/src/core-services/payments/i18n/it.json b/src/core-services/payments/i18n/it.json deleted file mode 100644 index 4ccb1186d8c..00000000000 --- a/src/core-services/payments/i18n/it.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Italian", - "i18n": "it", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Pagamenti", - "paymentsTitle": "Pagamenti" - }, - "dashboard": { - "paymentsLabel": "Pagamenti", - "paymentsTitle": "Pagamenti", - "paymentsDescription": "configurazione Pagamenti" - }, - "settings": { - "paymentSettingsLabel": "Impostazioni di pagamento" - }, - "paymentSettings": { - "paymentMethod": "Fornitore di default" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Aggiungere il pagamento ad ordine completo", - "processingError": "C'è stato un problema con il pagamento.", - "completeYourOrder": "Completa l'ordine", - "noPaymentMethods": "No Metodi di pagamento sono configurati.", - "contactAdmin": "Contattare l'amministratore del negozio.", - "configureNow": "Configurare ora.", - "failedToPlaceOrder": "Impossibile ordinare." - } - } - } -}] diff --git a/src/core-services/payments/i18n/my.json b/src/core-services/payments/i18n/my.json deleted file mode 100644 index 94bba38ff8d..00000000000 --- a/src/core-services/payments/i18n/my.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Burmese", - "i18n": "my", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "ငွေပေးချေ", - "paymentsTitle": "ငွေပေးချေ" - }, - "dashboard": { - "paymentsLabel": "ငွေပေးချေ", - "paymentsTitle": "ငွေပေးချေ", - "paymentsDescription": "ငွေပေးချေမှုအတွက် configuration ကို" - }, - "settings": { - "paymentSettingsLabel": "ငွေပေးချေမှုရမည့်ချိန်ညှိ" - }, - "paymentSettings": { - "paymentMethod": "default ပေးသူ" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "အမိန့်ဖြည့်စွက်ရန်ငွေပေးချေမှု Add", - "processingError": "သင့်ရဲ့ငွေပေးချေမှုနှင့်အတူပြဿနာတစ်ခုရှိခဲ့သည်။", - "completeYourOrder": "သင့်ရဲ့အမိန့်တွေကိုဖြည့်", - "noPaymentMethods": "အဘယ်သူမျှမပေးချေမှုနည်းစနစ် configured ကြသည်။", - "contactAdmin": "စတိုးဆိုင်စီမံခန့်ခွဲသူကိုဆက်သွယ်ပါ။", - "configureNow": "ယခု configure ။", - "failedToPlaceOrder": "အမိန့်နေရာမရခဲ့ပါ။" - } - } - } -}] diff --git a/src/core-services/payments/i18n/nb.json b/src/core-services/payments/i18n/nb.json deleted file mode 100644 index 26c782506a4..00000000000 --- a/src/core-services/payments/i18n/nb.json +++ /dev/null @@ -1,6 +0,0 @@ -[{ - "language": "Bokmål", - "i18n": "nb", - "ns": "reaction-payments", - "translation": { } -}] diff --git a/src/core-services/payments/i18n/nl.json b/src/core-services/payments/i18n/nl.json deleted file mode 100644 index fb7f1e473cb..00000000000 --- a/src/core-services/payments/i18n/nl.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Dutch", - "i18n": "nl", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Betalingen", - "paymentsTitle": "Betalingen" - }, - "dashboard": { - "paymentsLabel": "Betalingen", - "paymentsTitle": "Betalingen", - "paymentsDescription": "betalingen configuratie" - }, - "settings": { - "paymentSettingsLabel": "betaling Instellingen" - }, - "paymentSettings": { - "paymentMethod": "Default Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "betaling toevoegen aan bestelling af te ronden", - "processingError": "Er was een probleem met uw betaling.", - "completeYourOrder": "Vul uw bestelling", - "noPaymentMethods": "Geen betaalmethodes zijn geconfigureerd.", - "contactAdmin": "Neem contact op met de winkelbeheerder.", - "configureNow": "Configureren nu.", - "failedToPlaceOrder": "Kan bestelling te plaatsen." - } - } - } -}] diff --git a/src/core-services/payments/i18n/pl.json b/src/core-services/payments/i18n/pl.json deleted file mode 100644 index 435fec7b30b..00000000000 --- a/src/core-services/payments/i18n/pl.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Polish", - "i18n": "pl", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Płatności", - "paymentsTitle": "Płatności" - }, - "dashboard": { - "paymentsLabel": "Płatności", - "paymentsTitle": "Płatności", - "paymentsDescription": "konfiguracja płatności" - }, - "settings": { - "paymentSettingsLabel": "Ustawienia płatności" - }, - "paymentSettings": { - "paymentMethod": "Domyślnie Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Dodaj do wykonania nakazu zapłaty", - "processingError": "Wystąpił problem z płatnością.", - "completeYourOrder": "Zrealizuj zamówienie", - "noPaymentMethods": "są skonfigurowane żadne metody płatności.", - "contactAdmin": "Skontaktuj się z administratorem sklepu.", - "configureNow": "Skonfiguruj teraz.", - "failedToPlaceOrder": "Nie udało się złożyć zamówienie." - } - } - } -}] diff --git a/src/core-services/payments/i18n/pt.json b/src/core-services/payments/i18n/pt.json deleted file mode 100644 index f72f5f77f55..00000000000 --- a/src/core-services/payments/i18n/pt.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Portuguese", - "i18n": "pt", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Pagamentos", - "paymentsTitle": "Pagamentos" - }, - "dashboard": { - "paymentsLabel": "Pagamentos", - "paymentsTitle": "Pagamentos", - "paymentsDescription": "configuração de pagamentos" - }, - "settings": { - "paymentSettingsLabel": "Configurações de pagamento" - }, - "paymentSettings": { - "paymentMethod": "Provedor padrão" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Adicionar pagamento para completar a fim", - "processingError": "Houve um problema com o seu pagamento.", - "completeYourOrder": "Concluir a sua encomenda", - "noPaymentMethods": "Não há métodos de pagamento são configurados.", - "contactAdmin": "Entre em contato com o administrador da loja.", - "configureNow": "Configurar agora.", - "failedToPlaceOrder": "Falha ao colocar ordem." - } - } - } -}] diff --git a/src/core-services/payments/i18n/ro.json b/src/core-services/payments/i18n/ro.json deleted file mode 100644 index e17229c9f59..00000000000 --- a/src/core-services/payments/i18n/ro.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Romanian", - "i18n": "ro", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "plăţile", - "paymentsTitle": "plăţile" - }, - "dashboard": { - "paymentsLabel": "plăţile", - "paymentsTitle": "plăţile", - "paymentsDescription": "configurarea plăților" - }, - "settings": { - "paymentSettingsLabel": "Setări de plată" - }, - "paymentSettings": { - "paymentMethod": "furnizor de implicit" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Adauga o plată pentru a finaliza comanda", - "processingError": "A apărut o problemă cu plata.", - "completeYourOrder": "Finaliza comanda", - "noPaymentMethods": "Nu există metode de plată sunt configurate.", - "contactAdmin": "Contactați administratorul magazinului.", - "configureNow": "Configurati.", - "failedToPlaceOrder": "Nu s-a plasa comanda." - } - } - } -}] diff --git a/src/core-services/payments/i18n/ru.json b/src/core-services/payments/i18n/ru.json deleted file mode 100644 index bf0db1e1214..00000000000 --- a/src/core-services/payments/i18n/ru.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Russian", - "i18n": "ru", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "платежи", - "paymentsTitle": "платежи" - }, - "dashboard": { - "paymentsLabel": "платежи", - "paymentsTitle": "платежи", - "paymentsDescription": "конфигурация платежи" - }, - "settings": { - "paymentSettingsLabel": "Настройки оплаты" - }, - "paymentSettings": { - "paymentMethod": "По умолчанию Провайдер" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Добавить платеж для завершения заказа", - "processingError": "Существовал проблема с вашей компенсацией.", - "completeYourOrder": "Заполните ваш заказ", - "noPaymentMethods": "Нет способов оплаты не настроены.", - "contactAdmin": "Обратитесь к администратору магазина.", - "configureNow": "Настроить сейчас.", - "failedToPlaceOrder": "Не удалось разместить заказ." - } - } - } -}] diff --git a/src/core-services/payments/i18n/sl.json b/src/core-services/payments/i18n/sl.json deleted file mode 100644 index 735aad12294..00000000000 --- a/src/core-services/payments/i18n/sl.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Slovenian", - "i18n": "sl", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Plačila", - "paymentsTitle": "Plačila" - }, - "dashboard": { - "paymentsLabel": "Plačila", - "paymentsTitle": "Plačila", - "paymentsDescription": "konfiguracija plačila" - }, - "settings": { - "paymentSettingsLabel": "Nastavitve plačil" - }, - "paymentSettings": { - "paymentMethod": "privzeti ponudnika" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Dodaj plačilo za izvedbo naročila", - "processingError": "Prišlo je do težav pri plačilu.", - "completeYourOrder": "Izpolnite naročilo", - "noPaymentMethods": "Brez plačila so nastavljeni.", - "contactAdmin": "Obrnite se na skrbnika trgovine.", - "configureNow": "Konfiguracija zdaj.", - "failedToPlaceOrder": "Ni, da se vrstni red." - } - } - } -}] diff --git a/src/core-services/payments/i18n/sv.json b/src/core-services/payments/i18n/sv.json deleted file mode 100644 index 6d34bc0c43c..00000000000 --- a/src/core-services/payments/i18n/sv.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Swedish", - "i18n": "sv", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "betalningar", - "paymentsTitle": "betalningar" - }, - "dashboard": { - "paymentsLabel": "betalningar", - "paymentsTitle": "betalningar", - "paymentsDescription": "betalningskonfiguration" - }, - "settings": { - "paymentSettingsLabel": "betalnings~~POS=TRUNC" - }, - "paymentSettings": { - "paymentMethod": "default Provider" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Lägg betalning för att slutföra order", - "processingError": "Det fanns ett problem med din betalning.", - "completeYourOrder": "Slutföra din beställning", - "noPaymentMethods": "Inga betalningsmetoder är konfigurerade.", - "contactAdmin": "Kontakta butikshanteraren.", - "configureNow": "Konfigurera nu.", - "failedToPlaceOrder": "Det gick inte att placera order." - } - } - } -}] diff --git a/src/core-services/payments/i18n/tr.json b/src/core-services/payments/i18n/tr.json deleted file mode 100644 index 41ae511552f..00000000000 --- a/src/core-services/payments/i18n/tr.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Turkish", - "i18n": "tr", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Ödemeler", - "paymentsTitle": "Ödemeler" - }, - "dashboard": { - "paymentsLabel": "Ödemeler", - "paymentsTitle": "Ödemeler", - "paymentsDescription": "Ödemeler yapılandırma" - }, - "settings": { - "paymentSettingsLabel": "Ödeme Ayarları" - }, - "paymentSettings": { - "paymentMethod": "varsayılan Sağlayıcı" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Siparişinizi tamamlamak için ödeme ekle", - "processingError": "Ödemeniz ile ilgili bir sorun oluştu.", - "completeYourOrder": "Siparişinizi tamamlamak", - "noPaymentMethods": "Hiçbir ödeme yöntemleri yapılandırılır.", - "contactAdmin": "Lütfen mağaza yöneticisine başvurun.", - "configureNow": "Şimdi yapılandırın.", - "failedToPlaceOrder": "sipariş için başarısız oldu." - } - } - } -}] diff --git a/src/core-services/payments/i18n/vi.json b/src/core-services/payments/i18n/vi.json deleted file mode 100644 index ed7af2eb6f8..00000000000 --- a/src/core-services/payments/i18n/vi.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Vietnamese", - "i18n": "vi", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "Thanh toán", - "paymentsTitle": "Thanh toán" - }, - "dashboard": { - "paymentsLabel": "Thanh toán", - "paymentsTitle": "Thanh toán", - "paymentsDescription": "cấu hình thanh toán" - }, - "settings": { - "paymentSettingsLabel": "Cài đặt thanh toán" - }, - "paymentSettings": { - "paymentMethod": "Nhà cung cấp mặc định" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "Thêm thanh toán để hoàn tất đơn", - "processingError": "Có một vấn đề với thanh toán của bạn.", - "completeYourOrder": "Hoàn thành đặt hàng của bạn", - "noPaymentMethods": "Không có phương thức thanh toán được cấu hình.", - "contactAdmin": "Vui lòng liên hệ với quản trị viên kho.", - "configureNow": "Cấu hình hiện nay.", - "failedToPlaceOrder": "Không thể đặt hàng." - } - } - } -}] diff --git a/src/core-services/payments/i18n/zh.json b/src/core-services/payments/i18n/zh.json deleted file mode 100644 index f79a216d914..00000000000 --- a/src/core-services/payments/i18n/zh.json +++ /dev/null @@ -1,35 +0,0 @@ -[{ - "language": "Chinese", - "i18n": "zh", - "ns": "reaction-payments", - "translation": { - "reaction-payments": { - "admin": { - "shortcut": { - "paymentsLabel": "支付", - "paymentsTitle": "支付" - }, - "dashboard": { - "paymentsLabel": "支付", - "paymentsTitle": "支付", - "paymentsDescription": "付款配置" - }, - "settings": { - "paymentSettingsLabel": "付款设置" - }, - "paymentSettings": { - "paymentMethod": "默认提供" - } - }, - "checkoutPayment": { - "addPaymentToCompleteOrder": "添加付款完成订单", - "processingError": "有您的付款有问题。", - "completeYourOrder": "完成订单", - "noPaymentMethods": "任何付款方式进行配置。", - "contactAdmin": "请联系店主管理员。", - "configureNow": "现在配置。", - "failedToPlaceOrder": "无法下订单。" - } - } - } -}] diff --git a/src/core-services/payments/index.js b/src/core-services/payments/index.js deleted file mode 100644 index 0ac42679465..00000000000 --- a/src/core-services/payments/index.js +++ /dev/null @@ -1,29 +0,0 @@ -import i18n from "./i18n/index.js"; -import mutations from "./mutations/index.js"; -import queries from "./queries/index.js"; -import { registerPluginHandlerForPayments } from "./registration.js"; -import resolvers from "./resolvers/index.js"; -import schemas from "./schemas/index.js"; - -/** - * @summary Import and call this function to add this plugin to your API. - * @param {ReactionAPI} app The ReactionAPI instance - * @returns {undefined} - */ -export default async function register(app) { - await app.registerPlugin({ - label: "Payments", - name: "reaction-payments", - version: app.context.appVersion, - i18n, - functionsByType: { - registerPluginHandler: [registerPluginHandlerForPayments] - }, - graphQL: { - resolvers, - schemas - }, - queries, - mutations - }); -} diff --git a/src/core-services/payments/mutations/__snapshots__/approveOrderPayments.test.js.snap b/src/core-services/payments/mutations/__snapshots__/approveOrderPayments.test.js.snap deleted file mode 100644 index 7e05e464662..00000000000 --- a/src/core-services/payments/mutations/__snapshots__/approveOrderPayments.test.js.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`throws if orderId isn't supplied 1`] = `"Order ID is required"`; - -exports[`throws if paymentIds isn't supplied 1`] = `"Payment ids is required"`; - -exports[`throws if permission check fails 1`] = `"Access Denied"`; - -exports[`throws if shopId isn't supplied 1`] = `"Shop ID is required"`; - -exports[`throws if the order doesn't exist 1`] = `"Order not found"`; diff --git a/src/core-services/payments/mutations/__snapshots__/enablePaymentMethodForShop.test.js.snap b/src/core-services/payments/mutations/__snapshots__/enablePaymentMethodForShop.test.js.snap deleted file mode 100644 index 5e6dea814c7..00000000000 --- a/src/core-services/payments/mutations/__snapshots__/enablePaymentMethodForShop.test.js.snap +++ /dev/null @@ -1,9 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`errors on invalid payment method 1`] = `"Requested payment method is invalid"`; - -exports[`errors on invalid shop 1`] = `"Shop not found"`; - -exports[`errors on missing arguments 1`] = `"Is enabled is required"`; - -exports[`throws if userHasPermission returns false 1`] = `"Requested payment method is invalid"`; diff --git a/src/core-services/payments/mutations/approveOrderPayments.js b/src/core-services/payments/mutations/approveOrderPayments.js deleted file mode 100644 index b1ade8561a8..00000000000 --- a/src/core-services/payments/mutations/approveOrderPayments.js +++ /dev/null @@ -1,69 +0,0 @@ -import ReactionError from "@reactioncommerce/reaction-error"; -import SimpleSchema from "simpl-schema"; - -const inputSchema = new SimpleSchema({ - orderId: String, - paymentIds: [String], - shopId: String -}); - -/** - * @method approveOrderPayments - * @summary Attempt to approve one or more authorized payments for an order - * @param {Object} context - an object containing the per-request state - * @param {Object} input - ApproveOrderPaymentsInput - * @param {String} input.orderId - The order ID - * @param {String[]} input.paymentIds - An array of one or more payment IDs to approve - * @param {String} input.shopId - The ID of the shop that owns this order - * @returns {Promise} ApproveOrderPaymentsResult - */ -export default async function approveOrderPayments(context, input = {}) { - inputSchema.validate(input); - - const { appEvents, collections, userId = null } = context; - const { Orders } = collections; - const { orderId, paymentIds, shopId } = input; - - await context.validatePermissions( - `reaction:legacy:orders:${orderId}`, - "approve:payment", - { shopId } - ); - - const order = await Orders.findOne({ _id: orderId, shopId }); - if (!order) throw new ReactionError("not-found", "Order not found"); - - if (paymentIds.length === 0) return { order }; - - const updatedPayments = order.payments; - const paymentStatusesAllowedToBeApproved = ["adjustments", "created"]; - - // Set payment.status to approved for all paymentIds provided - paymentIds.forEach((paymentId) => { - const payment = updatedPayments.find((pmt) => pmt._id === paymentId); - if (payment && paymentStatusesAllowedToBeApproved.includes(payment.status)) { - payment.status = "approved"; - } - }); - - // Update Order with new payment status - const { value: updatedOrder } = await Orders.findOneAndUpdate({ - _id: orderId - }, { - $set: { - payments: updatedPayments - } - }, { returnOriginal: false }); - - await appEvents.emit("afterOrderUpdate", { - order: updatedOrder, - updatedBy: userId - }); - - await appEvents.emit("afterOrderApprovePayment", { - approvedBy: userId, - order: updatedOrder - }); - - return { order: updatedOrder }; -} diff --git a/src/core-services/payments/mutations/approveOrderPayments.test.js b/src/core-services/payments/mutations/approveOrderPayments.test.js deleted file mode 100644 index 2a8e61945a3..00000000000 --- a/src/core-services/payments/mutations/approveOrderPayments.test.js +++ /dev/null @@ -1,111 +0,0 @@ -import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; -import ReactionError from "@reactioncommerce/reaction-error"; -import approveOrderPayments from "./approveOrderPayments.js"; - -beforeEach(() => { - jest.resetAllMocks(); -}); - -test("throws if orderId isn't supplied", async () => { - await expect(approveOrderPayments(mockContext, { - paymentIds: ["1"], - shopId: "SHOP_ID" - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("throws if paymentIds isn't supplied", async () => { - await expect(approveOrderPayments(mockContext, { - orderId: "abc", - shopId: "SHOP_ID" - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("throws if shopId isn't supplied", async () => { - await expect(approveOrderPayments(mockContext, { - orderId: "abc", - paymentIds: ["1"] - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("throws if the order doesn't exist", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - - mockContext.collections.Orders.findOne.mockReturnValueOnce(Promise.resolve(null)); - - await expect(approveOrderPayments(mockContext, { - orderId: "abc", - paymentIds: ["1"], - shopId: "SHOP_ID" - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("throws if permission check fails", async () => { - mockContext.collections.Orders.findOne.mockReturnValueOnce(Promise.resolve({ - _id: "abc", - payments: [ - { - _id: "1", - status: "created" - } - ], - shopId: "SHOP_ID" - })); - - mockContext.validatePermissions.mockImplementation(() => { - throw new ReactionError("access-denied", "Access Denied"); - }); - - - await expect(approveOrderPayments(mockContext, { - orderId: "abc", - paymentIds: ["1"], - shopId: "SHOP_ID" - })).rejects.toThrowErrorMatchingSnapshot(); - - expect(mockContext.validatePermissions).toHaveBeenCalledWith( - "reaction:legacy:orders:abc", - "approve:payment", - { shopId: "SHOP_ID" } - ); -}); - -test("updates an order status", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - - mockContext.collections.Orders.findOne.mockReturnValueOnce(Promise.resolve({ - _id: "abc", - payments: [ - { - _id: "1", - status: "created" - } - ], - shopId: "SHOP_ID" - })); - - mockContext.collections.Orders.findOneAndUpdate.mockReturnValueOnce(Promise.resolve({ - modifiedCount: 1, - value: {} - })); - - await approveOrderPayments(mockContext, { - orderId: "abc", - paymentIds: ["1"], - shopId: "SHOP_ID" - }); - - await expect(mockContext.collections.Orders.findOneAndUpdate).toHaveBeenCalledWith( - { _id: "abc" }, - { - $set: { - payments: [ - { - _id: "1", - status: "approved" - } - ] - } - }, - { returnOriginal: false } - ); -}); diff --git a/src/core-services/payments/mutations/captureOrderPayments.js b/src/core-services/payments/mutations/captureOrderPayments.js deleted file mode 100644 index ec9fef99630..00000000000 --- a/src/core-services/payments/mutations/captureOrderPayments.js +++ /dev/null @@ -1,105 +0,0 @@ -import ReactionError from "@reactioncommerce/reaction-error"; -import SimpleSchema from "simpl-schema"; - -const inputSchema = new SimpleSchema({ - orderId: String, - paymentIds: [String], - shopId: String -}); - -/** - * @method captureOrderPayments - * @summary Attempt to capture one or more authorized payments for an order - * @param {Object} context - an object containing the per-request state - * @param {Object} input - CaptureOrderPaymentsInput - * @param {String} input.orderId - The order ID - * @param {String[]} input.paymentIds - An array of one or more payment IDs to capture - * @param {String} input.shopId - The ID of the shop that owns this order - * @returns {Promise} CaptureOrderPaymentsResult - */ -export default async function captureOrderPayments(context, input = {}) { - inputSchema.validate(input); - const { appEvents, collections, userId } = context; - const { Orders } = collections; - const { orderId, paymentIds, shopId } = input; - - await context.validatePermissions(`reaction:legacy:orders:${orderId}`, "capture:payment", { shopId }); - - const order = await Orders.findOne({ _id: orderId, shopId }); - if (!order) throw new ReactionError("not-found", "Order not found"); - - // If order status is still "new", bump to "processing" - if (order.workflow.status === "new") { - await Orders.updateOne({ _id: orderId }, { - $set: { - "workflow.status": "coreOrderWorkflow/processing" - }, - $addToSet: { - "workflow.workflow": "coreOrderWorkflow/processing" - } - }); - } - - const orderPaymentsToCapture = (order.payments || []).filter((payment) => - paymentIds.includes(payment._id) && payment.mode === "authorize" && ["approved", "error"].includes(payment.status)); - - if (orderPaymentsToCapture.length === 0) return { order }; - - // TODO capture a specific amount, maybe partial, if only some groups are fulfilled - - const capturePromises = orderPaymentsToCapture.map(async (payment) => { - let result = { saved: false }; - try { - result = await context.queries.getPaymentMethodConfigByName(payment.name).functions.capturePayment(context, payment); - } catch (error) { - result.error = error; - result.errorCode = "uncaught_plugin_error"; - result.errorMessage = error.message; - } - result.paymentId = payment._id; - return result; - }); - - const captureResults = await Promise.all(capturePromises); - - const updatedPayments = order.payments; - const capturedPayments = []; - captureResults.forEach((captureResult) => { - const payment = updatedPayments.find((pmt) => pmt._id === captureResult.paymentId); - - if (captureResult.saved || captureResult.isAlreadyCaptured) { - payment.mode = "captured"; - payment.status = "completed"; - payment.metadata = { ...(payment.metadata || {}), ...(captureResult.metadata || {}) }; - capturedPayments.push(payment); - } else { - payment.status = "error"; - payment.captureErrorCode = captureResult.errorCode; - payment.captureErrorMessage = captureResult.errorMessage; - } - - payment.transactions.push(captureResult); - }); - - const { value: updatedOrder } = await Orders.findOneAndUpdate({ _id: orderId }, { - $set: { - payments: updatedPayments, - updatedAt: new Date() - } - }, { returnOriginal: false }); - - await appEvents.emit("afterOrderUpdate", { - order: updatedOrder, - updatedBy: userId - }); - - capturedPayments.forEach((payment) => { - appEvents.emit("afterOrderPaymentCapture", { - capturedBy: userId, - order: updatedOrder, - payment - }); - }); - - return { order: updatedOrder }; -} diff --git a/src/core-services/payments/mutations/captureOrderPayments.test.js b/src/core-services/payments/mutations/captureOrderPayments.test.js deleted file mode 100644 index 1a89e28e53f..00000000000 --- a/src/core-services/payments/mutations/captureOrderPayments.test.js +++ /dev/null @@ -1,47 +0,0 @@ -test("should return access denied if user does not have access", async () => { - // sandbox.stub(Reaction, "hasPermission", () => false); - // spyOnMethod("capturePayments", order.userId); - // function capturePayments() { - // return Meteor.call("orders/capturePayments", order._id); - // } - // expect(capturePayments).to.throw(ReactionError, /Access Denied/); -}); - -test("should update the order item workflow to coreOrderItemWorkflow/captured", async () => { - // sandbox.stub(Reaction, "hasPermission", () => true); - // spyOnMethod("capturePayments", order.userId); - // Meteor.call("orders/capturePayments", order._id); - // const orderItemWorkflow = Orders.findOne({ _id: order._id }).items[0].workflow; - // expect(orderItemWorkflow.status).to.equal("coreOrderItemWorkflow/captured"); -}); - -test("should update the order after the payment processor has captured the payment", async () => { - // sandbox.stub(Reaction, "hasPermission", () => true); - // spyOnMethod("capturePayments", order.userId); - // Meteor.call("orders/capturePayments", order._id, () => { - // const orderPayment = shippingObjectMethod(Orders.findOne({ _id: order._id })).payment; - // expect(orderPayment.mode).to.equal("capture"); - // expect(orderPayment.status).to.equal("completed"); - // done(); - // }); -}); - -test("should update order payment method status to error if payment processor fails", async () => { - // sandbox.stub(Reaction, "hasPermission", () => true); - // spyOnMethod("capturePayments", order.userId); - // sandbox.stub(Meteor.server.method_handlers, "example/payment/capture", function (...args) { - // check(args, [Match.Any]); - // return { - // error: "stub error", - // saved: false - // }; - // }); - - // sandbox.stub(Logger, "fatal"); // since we expect this, let's keep the output clean - // Meteor.call("orders/capturePayments", order._id, () => { - // const orderPayment = shippingObjectMethod(Orders.findOne({ _id: order._id })).payment; - // expect(orderPayment.mode).to.equal("capture"); - // expect(orderPayment.status).to.equal("error"); - // done(); - // }); -}); diff --git a/src/core-services/payments/mutations/enablePaymentMethodForShop.js b/src/core-services/payments/mutations/enablePaymentMethodForShop.js deleted file mode 100644 index e60c4bdb308..00000000000 --- a/src/core-services/payments/mutations/enablePaymentMethodForShop.js +++ /dev/null @@ -1,51 +0,0 @@ -import ReactionError from "@reactioncommerce/reaction-error"; -import SimpleSchema from "simpl-schema"; -import { paymentMethods as allPaymentMethods } from "../registration.js"; - -const paramsSchema = new SimpleSchema({ - isEnabled: Boolean, - paymentMethodName: String, - shopId: String -}); - -/** - * @method enablePaymentMethodForShop - * @summary Enables (or disables) payment method for a given shop - * @param {Object} context - an object containing the per-request state - * @param {Object} input - EnablePaymentMethodForShopInput - * @param {String} input.isEnabled - Whether to enable or disable specified payment method - * @param {String} input.paymentMethodName - The name of the payment method to enable or disable - * @param {String} input.shopId - The id of the shop to enable payment method on - * @param {String} [input.clientMutationId] - An optional string identifying the mutation call - * @returns {Promise>} Array - */ -export default async function enablePaymentMethodForShop(context, input = {}) { - paramsSchema.validate(input, { ignore: [SimpleSchema.ErrorTypes.KEY_NOT_IN_SCHEMA] }); - const { collections } = context; - const { Shops } = collections; - const { isEnabled, paymentMethodName, shopId } = input; - - await context.validatePermissions(`reaction:legacy:shops:${shopId}`, "update", { shopId }); - - if (!allPaymentMethods[paymentMethodName]) { - throw new ReactionError("not-found", "Requested payment method is invalid"); - } - - const shop = await context.queries.shopById(context, shopId); - if (!shop) throw new ReactionError("not-found", "Shop not found"); - - const methods = new Set(shop.availablePaymentMethods); - - if (isEnabled) { - methods.add(paymentMethodName); - } else { - methods.delete(paymentMethodName); - } - - await Shops.updateOne( - { _id: shop._id }, - { $set: { availablePaymentMethods: Array.from(methods) } } - ); - - return context.queries.paymentMethods(context, shopId); -} diff --git a/src/core-services/payments/mutations/enablePaymentMethodForShop.test.js b/src/core-services/payments/mutations/enablePaymentMethodForShop.test.js deleted file mode 100644 index 4697160482d..00000000000 --- a/src/core-services/payments/mutations/enablePaymentMethodForShop.test.js +++ /dev/null @@ -1,122 +0,0 @@ -import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; -import Factory from "/tests/util/factory.js"; // TODO: research how to add `factory.js` to `api-utils` (https://github.com/reactioncommerce/reaction/issues/5646) -import enablePaymentMethodForShop from "./enablePaymentMethodForShop.js"; - -jest.mock("../registration", () => ({ - paymentMethods: { - mockPaymentMethod: { - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin" - } - } -})); - -const fakeShop = Factory.Shop.makeOne(); -const mockEnablePaymentMethod = jest.fn().mockName("enablePaymentMethodForShop"); -const mockPaymentMethods = jest.fn().mockName("paymentMethods"); -const mockShopById = jest.fn().mockName("shopById"); - -beforeAll(() => { - mockContext.queries = { - paymentMethods: mockPaymentMethods, - shopById: mockShopById - }; - mockContext.mutations = { enablePaymentMethodForShop: mockEnablePaymentMethod }; -}); - -beforeEach(() => { - jest.resetAllMocks(); - mockShopById.mockClear(); - mockEnablePaymentMethod.mockClear(); - fakeShop.availablePaymentMethods = []; -}); - -test("throws if userHasPermission returns false", async () => { - mockContext.userHasPermission.mockReturnValue(false); - mockShopById.mockReturnValue(fakeShop); - - await expect(enablePaymentMethodForShop(mockContext, { - shopId: fakeShop._id, - paymentMethodName: "does not exist", - isEnabled: true - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("errors on missing arguments", async () => { - mockContext.userHasPermission.mockReturnValue(true); - mockShopById.mockReturnValue(fakeShop); - - await expect(enablePaymentMethodForShop(mockContext, {})).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("errors on invalid payment method", async () => { - mockContext.userHasPermission.mockReturnValue(true); - mockShopById.mockReturnValue(fakeShop); - - await expect(enablePaymentMethodForShop(mockContext, { - shopId: fakeShop._id, - paymentMethodName: "does not exist", - isEnabled: true - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("errors on invalid shop", async () => { - mockContext.userHasPermission.mockReturnValue(true); - mockShopById.mockReturnValue(); - - await expect(enablePaymentMethodForShop(mockContext, { - shopId: "does not exist", - paymentMethodName: "mockPaymentMethod", - isEnabled: true - })).rejects.toThrowErrorMatchingSnapshot(); -}); - -test("enables payment method for valid shop", async () => { - fakeShop.availablePaymentMethods = ["mockPaymentMethod"]; - mockContext.userHasPermission.mockReturnValue(true); - mockShopById.mockReturnValue(fakeShop); - mockPaymentMethods.mockReturnValue([{ - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin", - isEnabled: true - }]); - - await expect(enablePaymentMethodForShop(mockContext, { - shopId: fakeShop._id, - paymentMethodName: "mockPaymentMethod", - isEnabled: true - })).resolves.toEqual([{ - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin", - isEnabled: true - }]); - - expect(mockPaymentMethods).toHaveBeenCalledWith(mockContext, fakeShop._id); -}); - -test("disables payment method for valid shop", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - mockShopById.mockReturnValue(fakeShop); - mockPaymentMethods.mockReturnValue([{ - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin", - isEnabled: false - }]); - - await expect(enablePaymentMethodForShop(mockContext, { - shopId: fakeShop._id, - paymentMethodName: "mockPaymentMethod", - isEnabled: false - })).resolves.toEqual([{ - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin", - isEnabled: false - }]); - - expect(mockPaymentMethods).toHaveBeenCalledWith(mockContext, fakeShop._id); -}); diff --git a/src/core-services/payments/mutations/index.js b/src/core-services/payments/mutations/index.js deleted file mode 100644 index 957d34edce8..00000000000 --- a/src/core-services/payments/mutations/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import approveOrderPayments from "./approveOrderPayments.js"; -import captureOrderPayments from "./captureOrderPayments.js"; -import enablePaymentMethodForShop from "./enablePaymentMethodForShop.js"; - -export default { - approveOrderPayments, - captureOrderPayments, - enablePaymentMethodForShop -}; diff --git a/src/core-services/payments/queries/__snapshots__/availablePaymentMethods.test.js.snap b/src/core-services/payments/queries/__snapshots__/availablePaymentMethods.test.js.snap deleted file mode 100644 index 37d529d846b..00000000000 --- a/src/core-services/payments/queries/__snapshots__/availablePaymentMethods.test.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`throws if shop not found 1`] = `"Shop not found"`; diff --git a/src/core-services/payments/queries/__snapshots__/paymentMethods.test.js.snap b/src/core-services/payments/queries/__snapshots__/paymentMethods.test.js.snap deleted file mode 100644 index fb180366bfc..00000000000 --- a/src/core-services/payments/queries/__snapshots__/paymentMethods.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`throws if permission check fails 1`] = `"Access Denied"`; - -exports[`throws if shop not found 1`] = `"Shop not found"`; diff --git a/src/core-services/payments/queries/availablePaymentMethods.js b/src/core-services/payments/queries/availablePaymentMethods.js deleted file mode 100644 index 61c3bf2ae33..00000000000 --- a/src/core-services/payments/queries/availablePaymentMethods.js +++ /dev/null @@ -1,25 +0,0 @@ -import ReactionError from "@reactioncommerce/reaction-error"; -import { paymentMethods } from "../registration.js"; - -/** - * @name availablePaymentMethods - * @method - * @memberof Payments/NoMeteorQueries - * @summary get list of all available payment methods for a shop - * @param {Object} context - an object containing the per-request state - * @param {String} shopId - shop id for which to get payment methods - * @returns {Array} Array of PaymentMethods - */ -export default async function availablePaymentMethods(context, shopId) { - const shop = await context.queries.shopById(context, shopId); - if (!shop) throw new ReactionError("not-found", "Shop not found"); - const availableMethods = shop.availablePaymentMethods || []; - - return availableMethods - .reduce((all, name) => { - if (paymentMethods[name]) { - all.push({ ...paymentMethods[name], isEnabled: true }); - } - return all; - }, []); -} diff --git a/src/core-services/payments/queries/availablePaymentMethods.test.js b/src/core-services/payments/queries/availablePaymentMethods.test.js deleted file mode 100644 index df5953aba63..00000000000 --- a/src/core-services/payments/queries/availablePaymentMethods.test.js +++ /dev/null @@ -1,70 +0,0 @@ -import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; -import Factory from "/tests/util/factory.js"; // TODO: research how to add `factory.js` to `api-utils` (https://github.com/reactioncommerce/reaction/issues/5646) -import query from "./availablePaymentMethods.js"; - -jest.mock("../registration", () => ({ - paymentMethods: { - mockPaymentMethod: { - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin" - } - } -})); - -const fakeShop = Factory.Shop.makeOne(); -const mockShopById = jest.fn().mockName("shopById"); - -beforeAll(() => { - mockContext.queries = { - shopById: mockShopById - }; -}); - -beforeEach(() => { - jest.resetAllMocks(); - mockShopById.mockClear(); - fakeShop.availablePaymentMethods = []; -}); - -test("throws if shop not found", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - mockShopById.mockReturnValueOnce(); - - await expect(query(mockContext, "nonexistent-shop-id")).rejects.toThrowErrorMatchingSnapshot(); - expect(mockShopById).toHaveBeenCalledWith(mockContext, "nonexistent-shop-id"); -}); - -test("returns empty array when shop has no payment methods", async () => { - mockShopById.mockReturnValueOnce(fakeShop); - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - - const result = await query(mockContext, mockContext.shopId); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(result).toEqual([]); -}); - -test("returns empty array when shop has no valid payment methods", async () => { - mockShopById.mockReturnValueOnce(fakeShop); - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - fakeShop.availablePaymentMethods.push("nonexistent-payment-method"); - - const result = await query(mockContext, mockContext.shopId); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(result).toEqual([]); -}); - -test("returns available payment methods for a shop", async () => { - mockShopById.mockReturnValueOnce(fakeShop); - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - fakeShop.availablePaymentMethods.push("mockPaymentMethod"); - - const result = await query(mockContext, mockContext.shopId); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(result).toEqual([{ - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin", - isEnabled: true - }]); -}); diff --git a/src/core-services/payments/queries/getPaymentMethodConfigByName.js b/src/core-services/payments/queries/getPaymentMethodConfigByName.js deleted file mode 100644 index 7d9d66e469b..00000000000 --- a/src/core-services/payments/queries/getPaymentMethodConfigByName.js +++ /dev/null @@ -1,14 +0,0 @@ -import { paymentMethods } from "../registration.js"; - -/** - * @name getPaymentMethodConfigByName - * @param {String} name payment method name, e.g. example, stripe_card - * @returns {Object} payment method configuration - */ -export default function getPaymentMethodConfigByName(name) { - const config = paymentMethods[name]; - if (!config) { - throw new Error(`Configuration not found for ${name} payment method. Did you remove the plugin that provides this payment method?`); - } - return config; -} diff --git a/src/core-services/payments/queries/index.js b/src/core-services/payments/queries/index.js deleted file mode 100644 index 139172961b3..00000000000 --- a/src/core-services/payments/queries/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import availablePaymentMethods from "./availablePaymentMethods.js"; -import getPaymentMethodConfigByName from "./getPaymentMethodConfigByName.js"; -import paymentMethods from "./paymentMethods.js"; - -export default { - availablePaymentMethods, - getPaymentMethodConfigByName, - paymentMethods -}; diff --git a/src/core-services/payments/queries/paymentMethods.js b/src/core-services/payments/queries/paymentMethods.js deleted file mode 100644 index 329279e1ca8..00000000000 --- a/src/core-services/payments/queries/paymentMethods.js +++ /dev/null @@ -1,27 +0,0 @@ -import ReactionError from "@reactioncommerce/reaction-error"; -import { paymentMethods as allPaymentMethods } from "../registration.js"; - -/** - * @name paymentMethods - * @method - * @memberof Payments/NoMeteorQueries - * @summary get list of all registered payment methods for a shop - * @param {Object} context - an object containing the per-request state - * @param {String} shopId - shop id for which to get payment methods - * @returns {Array} Array of PaymentMethods - */ -export default async function paymentMethods(context, shopId) { - const shop = await context.queries.shopById(context, shopId); - if (!shop) throw new ReactionError("not-found", "Shop not found"); - const availablePaymentMethods = shop.availablePaymentMethods || []; - - await context.validatePermissions(`reaction:legacy:shops:${shopId}`, "read", { shopId }); - - return Object.keys(allPaymentMethods) - .map((name) => ({ - ...allPaymentMethods[name], - // Force canRefund to be set - canRefund: allPaymentMethods[name].canRefund !== false, - isEnabled: availablePaymentMethods.includes(name) - })); -} diff --git a/src/core-services/payments/queries/paymentMethods.test.js b/src/core-services/payments/queries/paymentMethods.test.js deleted file mode 100644 index cc22c5d1155..00000000000 --- a/src/core-services/payments/queries/paymentMethods.test.js +++ /dev/null @@ -1,83 +0,0 @@ -import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; -import ReactionError from "@reactioncommerce/reaction-error"; -import Factory from "/tests/util/factory.js"; // TODO: research how to add `factory.js` to `api-utils` (https://github.com/reactioncommerce/reaction/issues/5646) -import query from "./paymentMethods.js"; - -jest.mock("../registration", () => ({ - paymentMethods: { - mockPaymentMethod: { - name: "mockPaymentMethod", - displayName: "Mock!", - pluginName: "mock-plugin" - } - } -})); - -const fakeShop = Factory.Shop.makeOne(); -const mockShopById = jest.fn().mockName("shopById"); - -beforeAll(() => { - mockContext.queries = { - shopById: mockShopById - }; -}); - -beforeEach(() => { - jest.resetAllMocks(); - mockShopById.mockClear(); - fakeShop.availablePaymentMethods = []; -}); - -test("throws if permission check fails", async () => { - mockContext.validatePermissions.mockImplementation(() => { - throw new ReactionError("access-denied", "Access Denied"); - }); - mockShopById.mockReturnValueOnce(fakeShop); - - await expect(query(mockContext, mockContext.shopId)).rejects.toThrowErrorMatchingSnapshot(); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(mockContext.validatePermissions).toHaveBeenCalledWith( - `reaction:legacy:shops:${mockContext.shopId}`, - "read", - { shopId: mockContext.shopId } - ); -}); - -test("throws if shop not found", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - mockShopById.mockReturnValueOnce(); - - await expect(query(mockContext, "nonexistent-shop-id")).rejects.toThrowErrorMatchingSnapshot(); - expect(mockShopById).toHaveBeenCalledWith(mockContext, "nonexistent-shop-id"); -}); - -test("returns all payment methods for a shop", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - mockShopById.mockReturnValueOnce(fakeShop); - - const result = await query(mockContext, mockContext.shopId); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(result).toEqual([{ - canRefund: true, - displayName: "Mock!", - isEnabled: false, - name: "mockPaymentMethod", - pluginName: "mock-plugin" - }]); -}); - -test("returns payment methods with correct enabled status", async () => { - mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null)); - mockShopById.mockReturnValueOnce(fakeShop); - fakeShop.availablePaymentMethods.push("mockPaymentMethod"); - - const result = await query(mockContext, mockContext.shopId); - expect(mockShopById).toHaveBeenCalledWith(mockContext, mockContext.shopId); - expect(result).toEqual([{ - canRefund: true, - displayName: "Mock!", - isEnabled: true, - name: "mockPaymentMethod", - pluginName: "mock-plugin" - }]); -}); diff --git a/src/core-services/payments/registration.js b/src/core-services/payments/registration.js deleted file mode 100644 index e45518afb96..00000000000 --- a/src/core-services/payments/registration.js +++ /dev/null @@ -1,14 +0,0 @@ -export const paymentMethods = {}; - -/** - * @summary Will be called for every plugin - * @param {Object} options The options object that the plugin passed to registerPackage - * @returns {undefined} - */ -export function registerPluginHandlerForPayments({ name: pluginName, paymentMethods: pluginPaymentMethods }) { - if (Array.isArray(pluginPaymentMethods)) { - for (const pluginPaymentMethod of pluginPaymentMethods) { - paymentMethods[pluginPaymentMethod.name] = { ...pluginPaymentMethod, pluginName }; - } - } -} diff --git a/src/core-services/payments/resolvers/Mutation/approveOrderPayments.js b/src/core-services/payments/resolvers/Mutation/approveOrderPayments.js deleted file mode 100644 index 0376b768baa..00000000000 --- a/src/core-services/payments/resolvers/Mutation/approveOrderPayments.js +++ /dev/null @@ -1,33 +0,0 @@ -import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; - -/** - * @name Mutation/approveOrderPayments - * @method - * @memberof Payment/GraphQL - * @summary resolver for the approveOrderPayments GraphQL mutation - * @param {Object} parentResult - unused - * @param {String} args.input.orderId - The order ID - * @param {String[]} args.input.paymentIds - An array of one or more payment IDs to approve - * @param {String} args.input.shopId - The ID of the shop that owns this order - * @param {String} [args.input.clientMutationId] - An optional string identifying the mutation call - * @param {Object} context - an object containing the per-request state - * @returns {Promise} ApproveOrderPaymentsPayload - */ -export default async function approveOrderPayments(parentResult, { input }, context) { - const { clientMutationId, orderId: opaqueOrderId, paymentIds: opaquePaymentIds, shopId: opaqueShopId } = input; - - const orderId = decodeOrderOpaqueId(opaqueOrderId); - const paymentIds = opaquePaymentIds.map(decodePaymentOpaqueId); - const shopId = decodeShopOpaqueId(opaqueShopId); - - const { order } = await context.mutations.approveOrderPayments(context, { - orderId, - paymentIds, - shopId - }); - - return { - clientMutationId, - order - }; -} diff --git a/src/core-services/payments/resolvers/Mutation/captureOrderPayments.js b/src/core-services/payments/resolvers/Mutation/captureOrderPayments.js deleted file mode 100644 index a5f7dce659f..00000000000 --- a/src/core-services/payments/resolvers/Mutation/captureOrderPayments.js +++ /dev/null @@ -1,33 +0,0 @@ -import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; - -/** - * @name Mutation/captureOrderPayments - * @method - * @memberof Payment/GraphQL - * @summary resolver for the captureOrderPayments GraphQL mutation - * @param {Object} parentResult - unused - * @param {String} args.input.orderId - The order ID - * @param {String[]} args.input.paymentIds - An array of one or more payment IDs to capture - * @param {String} args.input.shopId - The ID of the shop that owns this order - * @param {String} [args.input.clientMutationId] - An optional string identifying the mutation call - * @param {Object} context - an object containing the per-request state - * @returns {Promise} CaptureOrderPaymentsPayload - */ -export default async function captureOrderPayments(parentResult, { input }, context) { - const { clientMutationId, orderId: opaqueOrderId, paymentIds: opaquePaymentIds, shopId: opaqueShopId } = input; - - const orderId = decodeOrderOpaqueId(opaqueOrderId); - const paymentIds = opaquePaymentIds.map(decodePaymentOpaqueId); - const shopId = decodeShopOpaqueId(opaqueShopId); - - const { order } = await context.mutations.captureOrderPayments(context, { - orderId, - paymentIds, - shopId - }); - - return { - clientMutationId, - order - }; -} diff --git a/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.js b/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.js deleted file mode 100644 index 9e46dbe6a34..00000000000 --- a/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.js +++ /dev/null @@ -1,28 +0,0 @@ -import { decodeShopOpaqueId } from "../../xforms/id.js"; - -/** - * @name Mutation/enablePaymentMethodForShop - * @method - * @memberof Payment/GraphQL - * @summary resolver for the enablePaymentMethodForShop GraphQL mutation - * @param {Object} parentResult - unused - * @param {Object} args.input - EnablePaymentMethodForShopInput - * @param {String} args.input.isEnabled - Whether to enable or disable specified payment method - * @param {String} args.input.paymentMethodName - The name of the payment method to enable or disable - * @param {String} args.input.shopId - The id of the shop to enable payment method on - * @param {String} [args.input.clientMutationId] - An optional string identifying the mutation call - * @param {Object} context - an object containing the per-request state - * @returns {Promise>} EnablePaymentMethodForShopPayload - */ -export default async function enablePaymentMethodForShop(parentResult, { input }, context) { - const { clientMutationId } = input; - const paymentMethods = await context.mutations.enablePaymentMethodForShop(context, { - ...input, - shopId: decodeShopOpaqueId(input.shopId) - }); - - return { - clientMutationId, - paymentMethods - }; -} diff --git a/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.test.js b/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.test.js deleted file mode 100644 index 6c1938014bf..00000000000 --- a/src/core-services/payments/resolvers/Mutation/enablePaymentMethodForShop.test.js +++ /dev/null @@ -1,35 +0,0 @@ -import enablePaymentMethodForShop from "./enablePaymentMethodForShop.js"; - -const internalShopId = "555"; -const opaqueShopId = "cmVhY3Rpb24vc2hvcDo1NTU="; - -test("correctly passes through to mutations.enablePaymentMethodForShop", async () => { - const fakeResult = { - shop: { _id: "123" } - }; - - const mockMutation = jest.fn().mockName("mutations.enablePaymentMethodForShop"); - mockMutation.mockReturnValueOnce(fakeResult); - const context = { - mutations: { - enablePaymentMethodForShop: mockMutation - } - }; - - const result = await enablePaymentMethodForShop(null, { - input: { - shopId: opaqueShopId, - clientMutationId: "clientMutationId" - } - }, context); - - expect(result).toEqual({ - paymentMethods: { ...fakeResult }, - clientMutationId: "clientMutationId" - }); - - expect(mockMutation).toHaveBeenCalledWith(context, { - shopId: internalShopId, - clientMutationId: "clientMutationId" - }); -}); diff --git a/src/core-services/payments/resolvers/Mutation/index.js b/src/core-services/payments/resolvers/Mutation/index.js deleted file mode 100644 index 957d34edce8..00000000000 --- a/src/core-services/payments/resolvers/Mutation/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import approveOrderPayments from "./approveOrderPayments.js"; -import captureOrderPayments from "./captureOrderPayments.js"; -import enablePaymentMethodForShop from "./enablePaymentMethodForShop.js"; - -export default { - approveOrderPayments, - captureOrderPayments, - enablePaymentMethodForShop -}; diff --git a/src/core-services/payments/resolvers/Payment/index.js b/src/core-services/payments/resolvers/Payment/index.js deleted file mode 100644 index 9c1ca184ac5..00000000000 --- a/src/core-services/payments/resolvers/Payment/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import { encodePaymentOpaqueId } from "../../xforms/id.js"; - -export default { - _id: (node) => encodePaymentOpaqueId(node._id) -}; diff --git a/src/core-services/payments/resolvers/PaymentMethod/index.js b/src/core-services/payments/resolvers/PaymentMethod/index.js deleted file mode 100644 index e9f268fc406..00000000000 --- a/src/core-services/payments/resolvers/PaymentMethod/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - canRefund: (node) => node.canRefund !== false -}; diff --git a/src/core-services/payments/resolvers/Query/availablePaymentMethods.js b/src/core-services/payments/resolvers/Query/availablePaymentMethods.js deleted file mode 100644 index 6b0d94948f0..00000000000 --- a/src/core-services/payments/resolvers/Query/availablePaymentMethods.js +++ /dev/null @@ -1,17 +0,0 @@ -import { decodeShopOpaqueId } from "../../xforms/id.js"; - -/** - * @name Query.availablePaymentMethods - * @method - * @memberof Payment/GraphQL - * @summary get all available payment methods for a given shop - * @param {Object} _ - unused - * @param {Object} args - an object of all arguments that were sent by the client - * @param {String} args.shopId - shop id for which to get payment methods - * @param {Object} context - an object containing the per-request state - * @returns {Promise>} Array of PaymentMethods - */ -export default async function availablePaymentMethods(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); - return context.queries.availablePaymentMethods(context, dbShopId); -} diff --git a/src/core-services/payments/resolvers/Query/index.js b/src/core-services/payments/resolvers/Query/index.js deleted file mode 100644 index 69750c7ca4e..00000000000 --- a/src/core-services/payments/resolvers/Query/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import availablePaymentMethods from "./availablePaymentMethods.js"; -import paymentMethods from "./paymentMethods.js"; - -export default { - availablePaymentMethods, - paymentMethods -}; diff --git a/src/core-services/payments/resolvers/Query/paymentMethods.js b/src/core-services/payments/resolvers/Query/paymentMethods.js deleted file mode 100644 index 4eda8220f64..00000000000 --- a/src/core-services/payments/resolvers/Query/paymentMethods.js +++ /dev/null @@ -1,17 +0,0 @@ -import { decodeShopOpaqueId } from "../../xforms/id.js"; - -/** - * @name Query.paymentMethods - * @method - * @memberof Payment/GraphQL - * @summary get all available payment methods for a given shop - * @param {Object} _ - unused - * @param {Object} args - an object of all arguments that were sent by the client - * @param {String} args.shopId - shop id for which to get payment methods - * @param {Object} context - an object containing the per-request state - * @returns {Promise>} Array of PaymentMethods - */ -export default async function paymentMethods(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); - return context.queries.paymentMethods(context, dbShopId); -} diff --git a/src/core-services/payments/resolvers/index.js b/src/core-services/payments/resolvers/index.js deleted file mode 100644 index 6fa33f2240d..00000000000 --- a/src/core-services/payments/resolvers/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import Mutation from "./Mutation/index.js"; -import Payment from "./Payment/index.js"; -import PaymentMethod from "./PaymentMethod/index.js"; -import Query from "./Query/index.js"; - -export default { - Mutation, - Payment, - PaymentMethod, - Query -}; diff --git a/src/core-services/payments/schemas/index.js b/src/core-services/payments/schemas/index.js deleted file mode 100644 index 30096f92e54..00000000000 --- a/src/core-services/payments/schemas/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import importAsString from "@reactioncommerce/api-utils/importAsString.js"; - -const schema = importAsString("./schema.graphql"); - -export default [schema]; diff --git a/src/core-services/payments/schemas/schema.graphql b/src/core-services/payments/schemas/schema.graphql deleted file mode 100644 index ddaa7cdc8b1..00000000000 --- a/src/core-services/payments/schemas/schema.graphql +++ /dev/null @@ -1,254 +0,0 @@ -extend type Query { - """ - Get a list of all payment methods available during a checkout. This may filter by auth, - active/inactive, IP/region, shop, etc. To get the full list, use the `paymentMethods` - query with proper authorization. - """ - availablePaymentMethods( - "ID of the shop for which the order will be placed" - shopId: ID! - ): [PaymentMethod]! - - "Get a full list of all payment methods" - paymentMethods( - "The shop to get payment methods for" - shopId: ID! - ): [PaymentMethod]! -} - -extend type Mutation { - "Approve one or more payments for an order" - approveOrderPayments( - "Mutation input" - input: ApproveOrderPaymentsInput! - ): ApproveOrderPaymentsPayload! - - "Capture one or more payments for an order" - captureOrderPayments( - "Mutation input" - input: CaptureOrderPaymentsInput! - ): CaptureOrderPaymentsPayload! - - "Enable a payment method for a shop" - enablePaymentMethodForShop( - "Mutation input" - input: EnablePaymentMethodForShopInput! - ): EnablePaymentMethodForShopPayload! -} - -""" -Information about a payment made -""" -type Payment implements Node { - "The Payment ID" - _id: ID! - - """ - The amount that will be applied to this payment method. If there are multiple payment methods applied to the - cart, this may be less than the cart total. - """ - amount: Money! - - "The billing address for this payment, if one was collected" - billingAddress: Address - - """ - If status is `error` due to a capture error, this code describes the error in a machine-readable way. - """ - captureErrorCode: String - - """ - If status is `error` due to a capture error, this code describes the error in a human-readable way. - """ - captureErrorMessage: String - - "For card payments, the brand of the card. Useful for showing card icons for common brands." - cardBrand: String - - "The date and time at which this payment was created" - createdAt: DateTime! - - """ - The shopper-provided data needed to complete the payment using this method. - For example, a billing address, store credit code, stored credit card ID, etc. - """ - data: PaymentData - - "Use this identifier when showing this payment in a user interface" - displayName: String! - - "Has the payment authorization been canceled?" - isAuthorizationCanceled: Boolean! - - "Has the payment been captured? If false, it is just an authorization." - isCaptured: Boolean! - - "The payment method" - method: PaymentMethod! - - "The payment mode" - mode: String - - "The payment processor" - processor: String - - "Refunds that have been applied to this payment." - refunds: [Refund] - - "Risk level of payment" - riskLevel: RiskLevel - - "The current status of this payment" - status: PaymentStatus! - - "The payment transaction ID" - transactionId: String -} - -"Valid payment statuses" -enum PaymentStatus { - "A shop operator adjusted the payment amount after the order was placed" - adjustments - - "A shop operator has approved this payment" - approved - - "A shop operator has canceled this payment before it was captured" - canceled - - "A shop operator has captured this payment" - completed - - "Upon placing an order, the status of all payments for that order begins at 'created'" - created - - "There was an error capturing the payment" - error - - "A shop operator has refunded some but not all of this payment" - partialRefund - - "A shop operator has refunded all of this payment" - refunded -} - -"Valid payment risk levels" -enum RiskLevel { - "An elevated risk level for a payment" - elevated - - "The highest risk level for a payment" - highest - - "A normal risk level for a payment" - normal -} - -# Use `extend union` to define a payment plugin's PaymentData type -"Data identifying a payment for an order" -union PaymentData = FakeData - -# Use `extend enum` to add a plugin's payment method name -"The name of a payment method, which is how payment methods are keyed" -enum PaymentMethodName { - "No payment method" - none -} - -# Use `extend union` to define a payment plugin's PaymentMethodData type -"Any extra data needed by the payment method" -union PaymentMethodData = FakeData - -"Describes a payment method" -type PaymentMethod { - "If this is `false`, the payment method does not support refunding. Use this to hide refund UI." - canRefund: Boolean! - - "Data for this method. The data format differs for each method" - data: PaymentMethodData - - "Human-readable display name" - displayName: String! - - "Whether the payment method is enabled on a given shop" - isEnabled: Boolean! - - "The payment method name. Any valid name that has been registered by a payment plugin. e.g., saved_card" - # TODO: this being a string is temporary until extend works for enums, at which point we'll use PaymentMethodName - name: String! - - "Name of the plugin that added the payment method" - pluginName: String! -} - -"Input for the `enablePaymentMethodForShop` mutation" -input EnablePaymentMethodForShopInput { - "An optional string identifying the mutation call, which will be returned in the response payload" - clientMutationId: String - - "True to enable it or false to disable it" - isEnabled: Boolean! - - "The name of the payment method to enable or disable" - paymentMethodName: String! - - "The ID of the shop for which this payment method should be enabled or disabled" - shopId: ID! -} - -"Response payload for the `enablePaymentMethodForShop` mutation" -type EnablePaymentMethodForShopPayload { - "The same string you sent with the mutation params, for matching mutation calls with their responses" - clientMutationId: String - - "The full list of payment methods for the shop" - paymentMethods: [PaymentMethod]! -} - -"Input for the `approveOrderPayments` mutation" -input ApproveOrderPaymentsInput { - "An optional string identifying the mutation call, which will be returned in the response payload" - clientMutationId: String - - "The order ID" - orderId: ID! - - "The IDs of one or more payments to approve for this order" - paymentIds: [ID]! - - "The ID of the shop that owns this order" - shopId: ID! -} - -"Response from the `approveOrderPayments` mutation" -type ApproveOrderPaymentsPayload { - "The same string you sent with the mutation params, for matching mutation calls with their responses" - clientMutationId: String - - "The updated order" - order: Order! -} - -"Input for the `captureOrderPayments` mutation" -input CaptureOrderPaymentsInput { - "An optional string identifying the mutation call, which will be returned in the response payload" - clientMutationId: String - - "The order ID" - orderId: ID! - - "The IDs of one or more payments to capture for this order" - paymentIds: [ID]! - - "The ID of the shop that owns this order" - shopId: ID! -} - -"Response from the `captureOrderPayments` mutation" -type CaptureOrderPaymentsPayload { - "The same string you sent with the mutation params, for matching mutation calls with their responses" - clientMutationId: String - - "The updated order" - order: Order! -} diff --git a/src/core-services/payments/xforms/id.js b/src/core-services/payments/xforms/id.js deleted file mode 100644 index 2bc5fc3fdd0..00000000000 --- a/src/core-services/payments/xforms/id.js +++ /dev/null @@ -1,14 +0,0 @@ -import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; - -const namespaces = { - Order: "reaction/order", - Payment: "reaction/payment", - Shop: "reaction/shop" -}; - -export const encodePaymentOpaqueId = encodeOpaqueId(namespaces.Payment); - -export const decodeOrderOpaqueId = decodeOpaqueIdForNamespace(namespaces.Order); -export const decodePaymentOpaqueId = decodeOpaqueIdForNamespace(namespaces.Payment); -export const decodeShopOpaqueId = decodeOpaqueIdForNamespace(namespaces.Shop); diff --git a/src/mockTypes.graphql b/src/mockTypes.graphql index fde078b00ae..f6846cb2030 100644 --- a/src/mockTypes.graphql +++ b/src/mockTypes.graphql @@ -58,6 +58,9 @@ input MetafieldInput { type Metafield { "Fake" fake: String + + "Fake" + fakeData: FakeData } "Do not use this" @@ -66,19 +69,6 @@ type FakeData { doNotUse: String } -"Fake" -type EmailRecord { - "Fake" - fake: String -} - -"Fake" -input EmailRecordInput { - "Fake" - fake: String -} - - "Distance units" enum DistanceUnit { "Centimeter" @@ -338,34 +328,25 @@ type lives in `api-plugin-orders` type OrderFulfillmentGroup { "A fake field to satisfy linting" fakeField: String -} -""" -A fake type to satisfy linting -type lives in `api-plugin-orders` -""" -type OrderItem { "A fake field to satisfy linting" - fakeField: String + order: Order } """ A fake type to satisfy linting type lives in `api-plugin-orders` """ -type OrderSummary { +type OrderItem { "A fake field to satisfy linting" fakeField: String - - "A fake field to satisfy linting" - paymentMethodName: PaymentMethodName } """ A fake type to satisfy linting type lives in `api-plugin-orders` """ -type Refund { +type OrderSummary { "A fake field to satisfy linting" fakeField: String } @@ -382,14 +363,6 @@ type Shop { fakeField: String } -extend type FakeData { - "Fake field to satisfy linting" - emailRecord( - "Fake field to satisfy linting" - emailRecordInput: EmailRecordInput - ): EmailRecord -} - # ======================================== # api-plugin-tags # ========================================