Repository: liberapay/liberapay.com

Issue:
Setting up payment method not working
I'm making a liberapay profile:
  https://liberapay.com/yaxu/

Someone tried setting up a donation but got this error message:
`deposit — error message: 400 {"Message":"One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.","Type":"param_error","Id":"4e4ef7ed-e306-4631-a611-52a3994d9e48#1514997880","Date":1514997881.0,"errors":{"MandateId":"This mandate only supports GBP payments"}}`

I have my a/c set up to accept donations from all currencies, and they were paying from a GBP a/c.


Discussion:
We don't support GBP yet (#833), and unfortunately euro direct debits only work inside the eurozone (your donor should have seen a message telling them that) (#853).
Thanks for the explanation. I don't think they had that message, actually one received an email implying that the payment was successfully set up
Emails about direct debits are sent by our payment processors, we have no control over them. In fact we can't even see them.

Resolving patch:
diff --git a/liberapay/billing/transactions.py b/liberapay/billing/transactions.py
--- a/liberapay/billing/transactions.py
+++ b/liberapay/billing/transactions.py
@@ -42,6 +42,9 @@ def repr_error(o):
 
 def repr_exception(e):
     if isinstance(e, APIError):
+        if isinstance(e.content, dict) and e.content.get('errors'):
+            errors = ' | '.join('%s (%s)' % (v, k) for k, v in e.content['errors'].items())
+            return '%s | Error ID: %s' % (errors, e.content['Id'])
         return '%s %s' % (e.code, e.args[0])
     else:
         return repr(e)
diff --git a/liberapay/constants.py b/liberapay/constants.py
--- a/liberapay/constants.py
+++ b/liberapay/constants.py
@@ -207,6 +207,10 @@ def with_vat(self):
     'USD': Money('95.00', 'USD'),  # fee ≈ 3.27%
 }
 PAYIN_CARD_MAX = {k: Money('2500.00', k) for k in ('EUR', 'USD')}
+PAYIN_DIRECT_DEBIT_COUNTRIES = {
+    # https://support.gocardless.com/hc/en-gb/articles/115005758445
+    'EUR': EUROZONE | set("MC SM".split()),
+}
 PAYIN_DIRECT_DEBIT_MIN_EUR_GBP = Decimal('15.00')  # fee ≈ 3.78%
 PAYIN_DIRECT_DEBIT_MIN = {
     'EUR': Money(PAYIN_DIRECT_DEBIT_MIN_EUR_GBP, 'EUR'),


Test patch:
diff --git a/tests/py/fixtures/TestDirectDebit.yml b/tests/py/fixtures/TestDirectDebit.yml
--- a/tests/py/fixtures/TestDirectDebit.yml
+++ b/tests/py/fixtures/TestDirectDebit.yml
@@ -134,4 +134,25 @@ interactions:
       expires: ['-1']
       pragma: [no-cache]
     status: {code: 200, message: OK}
+- request:
+    body: null
+    headers: {}
+    method: GET
+    uri: https://api.sandbox.mangopay.com/v2.01/liberapay-dev/users/20717495/bankaccounts/20717497
+  response:
+    body:
+      string: !!binary |
+        H4sIAAAAAAAAA0xPy26DQBD7FeTzHmZ5pnsjVFGpaIog/QBUpoAEu9WyNEJR/r0ifSg3e2yP5Qte
+        z5pt2raW5xnqgl9YDJolFGoz8blnyxD3kg+ll3EUyAa3QuHUs7dBz3x4xdD1DgIVd4PRf8bSzK4Z
+        M9MyFJKISEIgM4t2dntwqHAVyPfp8UZk6BOFkiRRRBERyeCF/JhiCOzzDAplXZ8OVVkWeQGBt5lt
+        3kLBp0Qm4UME8bPs2Exb4ZOZ2HrPzQqB0/q5nW5dAvepZFOb7n+b5cYNRj82jqFkuIvjMNgFiUD6
+        7oYvhnJ24es3AAAA//8DABxNIjxEAQAA
+    headers:
+      cache-control: [no-cache]
+      cf-ray: [3d85f4e1aeb51571-CDG]
+      content-encoding: [gzip]
+      content-type: [application/json; charset=utf-8]
+      expires: ['-1']
+      pragma: [no-cache]
+    status: {code: 200, message: OK}
 version: 1
diff --git a/tests/py/test_payio.py b/tests/py/test_payio.py
--- a/tests/py/test_payio.py
+++ b/tests/py/test_payio.py
@@ -163,7 +163,7 @@ def add_redirect_url_to_payin(payin):
     def test_charge_bad_card(self):
         self.janet_route.set_attributes(address='-1')
         exchange = charge(self.db, self.janet_route, D('10.00'), 'http://localhost/')
-        assert '"CardId":"The value -1 is not valid"' in exchange.note
+        assert exchange.note.startswith('The value -1 is not valid (CardId) | Error ID: ')
 
     def test_charge_no_card(self):
         with self.assertRaises(AssertionError):