VictorAvelar / mollie-api-go

Golang wrapper for Mollie's REST API with full resource coverage.
https://www.mollie.com/developers/libraries/golang
MIT License
63 stars 37 forks source link

client.Balances.GetPrimaryTransactionsList() Eventually Throws Error #251

Closed MarcoWel closed 7 months ago

MarcoWel commented 1 year ago

Describe the bug The following code throws an error after about 4000 balance items:

fromId := ""
for {
      opts := mollie.BalanceTransactionsListOptions{From: fromId, Limit: 250}
      _, items, err := client.Balances.GetPrimaryTransactionsList(context.Background(), &opts)
      if err != nil {
          log.Fatalf("Failed to retrieve balances: %v", err)
      }
      if fromId = GetNextId(items.Links); fromId == "" {
        break
      }
}

Error: Failed to retrieve balances: json: cannot unmarshal array into Go struct field BalanceTransaction._embedded.balance_transactions.context of type mollie.ContextValues exit status 1

Additional context https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/balances.go

type (
    // TransactionType specifies the reason for the movement.
    TransactionType string
    // ContextValue represents a relevant value in the system
    // associated with a BalanceTransaction.
    ContextValue string
)

// ...

// ContextValues is a map of TransactionType to ContextValue.
type ContextValues map[TransactionType]ContextValue

Narrowed down the response causing the issue. First item looks good, second item is causing the error with "context": []:

{
  "resource": "balance_transactions",
  "id": "baltr_xxxxxxxxxx",
  "type": "payment",
  "resultAmount": {
      "value": "103.27",
      "currency": "EUR"
  },
  "initialAmount": {
      "value": "104.80",
      "currency": "EUR"
  },
  "deductions": {
      "value": "-1.53",
      "currency": "EUR"
  },
  "createdAt": "2022-12-23T00:00:00+00:00",
  "context": {
      "paymentId": "tr_xxxxxxxx"
  }
},
{
  "resource": "balance_transactions",
  "id": "baltr_xxxxxxxxxx",
  "type": "balance-correction",
  "resultAmount": {
      "value": "-74.74",
      "currency": "EUR"
  },
  "initialAmount": {
      "value": "-74.74",
      "currency": "EUR"
  },
  "createdAt": "2022-12-23T00:00:00+00:00",
  "context": []
},
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically closed because it has not had any activity after being labeled as staled.

VictorAvelar commented 7 months ago

This one will be closed as soon as #328 is merged, I found a different approach which covers more edge cases than the original proposed solution.

Thanks for raising this issue and sorry if it took a while to be resolved.