mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Move models and other shareable code to pkg/domain and add own go.mod * Update all references to use pkg/domain paths * Fix generated file * Ensure pkg/domain tests are run by just tests * Use new models path in connector templates * Copy local pkg/domain in dockerfile * Ensure pkg/domain is subject to go generate
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math/big"
|
|
"time"
|
|
)
|
|
|
|
type PaymentAdjustment struct {
|
|
// Unique ID of the payment adjustment
|
|
ID PaymentAdjustmentID `json:"id"`
|
|
|
|
// Reference of the adjustment. If we do not have a new reference for the
|
|
// adjustment, it will be the same as the payment reference.
|
|
Reference string `json:"reference"`
|
|
|
|
// Creation date of the adjustment
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
// Status of the payment adjustment
|
|
Status PaymentStatus `json:"status"`
|
|
|
|
// Optional
|
|
// Amount moved in this adjustment, using gross convention.
|
|
// Do not subtract PSP fees from this value.
|
|
Amount *big.Int `json:"amount"`
|
|
// Optional
|
|
// Asset related to amount
|
|
Asset *string `json:"asset"`
|
|
|
|
// Additional metadata
|
|
Metadata map[string]string `json:"metadata"`
|
|
// PSP response in raw
|
|
Raw json.RawMessage `json:"raw"`
|
|
}
|
|
|
|
func (p *PaymentAdjustment) IdempotencyKey() string {
|
|
return IdempotencyKey(p.ID)
|
|
}
|
|
|
|
func (c PaymentAdjustment) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(&struct {
|
|
ID string `json:"id"`
|
|
Reference string `json:"reference"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
Status PaymentStatus `json:"status"`
|
|
Amount *big.Int `json:"amount"`
|
|
Asset *string `json:"asset"`
|
|
Metadata map[string]string `json:"metadata"`
|
|
Raw json.RawMessage `json:"raw"`
|
|
}{
|
|
ID: c.ID.String(),
|
|
Reference: c.Reference,
|
|
CreatedAt: c.CreatedAt,
|
|
Status: c.Status,
|
|
Amount: c.Amount,
|
|
Asset: c.Asset,
|
|
Metadata: c.Metadata,
|
|
Raw: c.Raw,
|
|
})
|
|
}
|
|
|
|
func (c *PaymentAdjustment) UnmarshalJSON(data []byte) error {
|
|
var aux struct {
|
|
ID string `json:"id"`
|
|
Reference string `json:"reference"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
Status PaymentStatus `json:"status"`
|
|
Amount *big.Int `json:"amount"`
|
|
Asset *string `json:"asset"`
|
|
Metadata map[string]string `json:"metadata"`
|
|
Raw json.RawMessage `json:"raw"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &aux); err != nil {
|
|
return err
|
|
}
|
|
|
|
adjustmentID, err := PaymentAdjustmentIDFromString(aux.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.ID = *adjustmentID
|
|
c.Reference = aux.Reference
|
|
c.CreatedAt = aux.CreatedAt
|
|
c.Status = aux.Status
|
|
c.Amount = aux.Amount
|
|
c.Asset = aux.Asset
|
|
c.Metadata = aux.Metadata
|
|
c.Raw = aux.Raw
|
|
|
|
return nil
|
|
}
|