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

Support InvoiceID field in type SettlementPeriod #252

Closed MarcoWel closed 1 year ago

MarcoWel commented 1 year ago

Is your feature request related to a problem? Please describe. Settlement.InvoiceID has been deprecated and has now been moved to SettlementPeriod. This is not yet reflected by the go client.

Describe the solution you'd like Add InvoiceID string field to type SettlementPeriod.

Additional context https://docs.mollie.com/reference/v2/settlements-api/get-settlement

VictorAvelar commented 1 year ago

I can add the field but wanted to ask first, would you like to open a PR yourself?

MarcoWel commented 1 year ago

Done! When there is no invoice for a settlement yet, there is no InvoiceID field neither in (Settlement.InvoiceID nor in SettlementPeriod.InvoiceID).

In this case however, there is another (undocumented) SettlementPeriod.InvoiceReference field holding an invoice reference, so I added this field as well.

"invoiceReference": "MOL-NL-R2023.0000123456"

MarcoWel commented 1 year ago

Documentation: With the new Settlement.InvoiceID field, the proper way to get all invoice IDs for a settlement is:

invIds := []string{}
for _, yr := range settlement.Periods {
  for _, m := range yr {
    if m.InvoiceID != "" {
      invIds = append(invIds, m.InvoiceID)
    }
  }
}
invoiceID := strings.Join(invIds, "/")

Before, Settlement.InvoiceID only held the oldest invoice ID.