gocardless / gocardless-pro-python

GoCardless Pro Python Client
MIT License
37 stars 26 forks source link

Mandate Number is None for all payments returned by client.payout_items.list #15

Closed alfie-bae closed 1 year ago

alfie-bae commented 6 years ago

Hello,

I'm experiencing an issue where the payments returned by client.payout_items.list().records have none type for their links.mandate attribute. This is happening for all payments in all payouts within our account.

For example, a payment that I'm expecting to have a mandate of 'MD0008J11AXXXX' is None.

I can get the mandate by querying each payment using its ID. However we can have > 1000 payments per day and we'd quickly reach our api limit.

Please can you tell me if this is a known issue. If not, can you advise on what I'm doing wrong.

Thanks in advance,

Code


from datetime import datetime, timedelta 
import pandas as pd 
import numpy as np 
import gocardless_pro
import logging 

class GoCardless(object):

  def __init__(self, token, env):

    self.client = gocardless_pro.Client(access_token=token,
                                        environment=env)

  def get_payments(self, payout_id):    

    response = self.client.payout_items.list(params={'payout':payout_id, 'limit':999999})

    payments = []
    if response.api_response.status_code in [200, 204]:

      for payment in response.records:
        payment =  {"amount":payment.amount,
                    "payment_type":payment.type,
                    "mandate_number":payment.links.mandate}
        payments.append(payment)
      payments = pd.DataFrame(payments)

    else:
      logging.error("Request payments from payout {} failed. \
                     see status code {} for more details".\
                     format(payout_id, response.api_response.status_code))

    return payments 

nickcampbell18 commented 6 years ago

Thank you for the report! This is not intended behaviour of the Payout Items API - I will take a look and get back to you.

nickcampbell18 commented 6 years ago

Hi @alfie-bae, I'm going to talk to our team so we can figure out what to do. links.mandate is inconsistently returned by the API - refunds return a mandate ID, but normal payment entries do not. Not sure if this was a design decision on purpose, but it might be possible to easily return the mandate ID as well.

we'd quickly reach our api limit.

Our rate limit is 1000 requests per minute, are you still hitting that ceiling? We do give some guidance for handling that in a reasonable way here: https://developer.gocardless.com/api-reference/#making-requests-rate-limiting

alfie-bae commented 6 years ago

Hi @nickcampbell18

Thanks for getting back to me.

We've designed our collector to look up new payouts, then use gocardless_pro.payout items to get the payments and refunds for each new payout.

client.payout_items still returns the payments associated with a payout. I think the only way I can get the mandate for each of these payments otherwise would be to query them one by one using client.payment.get(payment id). Can you confirm if this is correct?

If we do have to query payments individually to get the mandate, as we usually have between 1500-2000 payments in a payout, we'd need to code in a batching strategy to avoid hitting that limit. This probably won't scale as we'll be collecting > 10,000 payments by next year.

I'd prefer to avoid this complexity and just get the mandate number when I query all the payments associated with a payout. Also, I can't imagine you'd want us hammering your API with 2000 requests every morning.

Alternatively, I see that the client also has the method client.payments.list(). Could you expand the query functionality to take payout id and have that return all payments associated with a payout id with MD number?

Looking forward to hearing from you,

Alfie

alfie-bae commented 6 years ago

Hello @nickcampbell18,

Are you any closer to a fix/resolution on this issue?

All the best,

Alfie

nickcampbell18 commented 6 years ago

HI @alfie-bae, apologies for the slow response. We've looked at our API and we aren't going to make any changes at this time. links.mandate isn't inconsistently returned, it's only for lump sum refunds at the moment, so I think it's currently "correct" by some definition.

I think the only way I can get the mandate for each of these payments otherwise would be to query them one by one using client.payment.get(payment id). Can you confirm if this is correct?

Yes this is correct I'm afraid. Is there a reason why your integration isn't storing (or can't store) payment IDs when the payments are created?