mollie-api-go
mollie-api-go copied to clipboard
client.Balances.GetPrimaryTransactionsList() Eventually Throws Error
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": []
},