From e99d1a5db63306427375754859ea84f7b1598a7d Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Thu, 9 Feb 2023 10:40:57 +0100
Subject: [PATCH] refunds are working now

---
 pass/app/payment_processor/Paypal.js | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/pass/app/payment_processor/Paypal.js b/pass/app/payment_processor/Paypal.js
index 106839e..aa9c852 100644
--- a/pass/app/payment_processor/Paypal.js
+++ b/pass/app/payment_processor/Paypal.js
@@ -298,7 +298,10 @@ class Paypal extends PaymentProcessor {
                     Authorization: `Bearer ${access_token}`,
                   },
                   body: JSON.stringify({
-                    amount: amount_to_refund,
+                    amount: {
+                      value: amount_to_refund,
+                      currency_code: "EUR",
+                    },
                   }),
                 })
               );
@@ -312,6 +315,22 @@ class Paypal extends PaymentProcessor {
                     Authorization: `Bearer ${access_token}`,
                   },
                 })
+                  .then((response) => {
+                    if (response.code !== 201) {
+                      console.debug(response);
+                      throw "Error issuing refund.";
+                    } else {
+                      return response.json();
+                    }
+                  })
+                  .then((response_json) => {
+                    if (response_json.status !== "COMPLETED") {
+                      console.debug(response_json);
+                      throw "Error issuing refund.";
+                    } else {
+                      return true;
+                    }
+                  })
               );
             }
           }
-- 
GitLab