From fd054f1d7f57b5dd4a3cdcf88e87a21aaf48c7f5 Mon Sep 17 00:00:00 2001 From: Miguel Pinto Date: Mon, 19 Aug 2024 12:34:06 +0100 Subject: [PATCH] feas: add metadata to wallet transactions --- wallet.go | 51 ++++++++++++++++++++++++------------------- wallet_transaction.go | 35 +++++++++++++++++------------ 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/wallet.go b/wallet.go index 516fb06..a851eb7 100644 --- a/wallet.go +++ b/wallet.go @@ -17,30 +17,32 @@ const ( ) type RecurringTransactionRuleInput struct { - LagoID uuid.UUID `json:"lago_id,omitempty"` - Interval string `json:"interval,omitempty"` - Method string `json:"method,omitempty"` - StartedAt *time.Time `json:"started_at,omitempty"` - TargetOngoingBalance string `json:"target_ongoing_balance,omitempty"` - ThresholdCredits string `json:"threshold_credits,omitempty"` - Trigger string `json:"trigger,omitempty"` - PaidCredits string `json:"paid_credits,omitempty"` - GrantedCredits string `json:"granted_credits,omitempty"` - InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + LagoID uuid.UUID `json:"lago_id,omitempty"` + Interval string `json:"interval,omitempty"` + Method string `json:"method,omitempty"` + StartedAt *time.Time `json:"started_at,omitempty"` + TargetOngoingBalance string `json:"target_ongoing_balance,omitempty"` + ThresholdCredits string `json:"threshold_credits,omitempty"` + Trigger string `json:"trigger,omitempty"` + PaidCredits string `json:"paid_credits,omitempty"` + GrantedCredits string `json:"granted_credits,omitempty"` + InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + TransactionMetadata []WalletTransactionMetadata `json:"transaction_metadata,omitempty"` } type RecurringTransactionRuleResponse struct { - LagoID uuid.UUID `json:"lago_id,omitempty"` - Interval string `json:"interval,omitempty"` - Method string `json:"method,omitempty"` - StartedAt *time.Time `json:"started_at,omitempty"` - TargetOngoingBalance string `json:"target_ongoing_balance,omitempty"` - ThresholdCredits string `json:"threshold_credits,omitempty"` - Trigger string `json:"trigger,omitempty"` - PaidCredits string `json:"paid_credits,omitempty"` - GrantedCredits string `json:"granted_credits,omitempty"` - CreatedAt time.Time `json:"created_at,omitempty"` - InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + LagoID uuid.UUID `json:"lago_id,omitempty"` + Interval string `json:"interval,omitempty"` + Method string `json:"method,omitempty"` + StartedAt *time.Time `json:"started_at,omitempty"` + TargetOngoingBalance string `json:"target_ongoing_balance,omitempty"` + ThresholdCredits string `json:"threshold_credits,omitempty"` + Trigger string `json:"trigger,omitempty"` + PaidCredits string `json:"paid_credits,omitempty"` + GrantedCredits string `json:"granted_credits,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` + InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + TransactionMetadata []WalletTransactionMetadata `json:"transaction_metadata,omitempty"` } type WalletRequest struct { @@ -60,6 +62,7 @@ type WalletInput struct { ExpirationAt *time.Time `json:"expiration_at,omitempty"` ExternalCustomerID string `json:"external_customer_id,omitempty"` InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + TransactionMetadata []WalletTransactionMetadata `json:"transaction_metadata,omitempty"` RecurringTransactionRules []RecurringTransactionRuleInput `json:"recurring_transaction_rules,omitempty"` } @@ -180,11 +183,15 @@ func (bmr *WalletRequest) Create(ctx context.Context, walletInput *WalletInput) } func (bmr *WalletRequest) Update(ctx context.Context, walletInput *WalletInput, walletID string) (*Wallet, *Error) { + walletParams := &WalletParams{ + WalletInput: walletInput, + } + subPath := fmt.Sprintf("%s/%s", "wallets", walletID) clientRequest := &ClientRequest{ Path: subPath, Result: &WalletResult{}, - Body: walletInput, + Body: walletParams, } result, err := bmr.client.Put(ctx, clientRequest) diff --git a/wallet_transaction.go b/wallet_transaction.go index c890cab..4ba39c8 100644 --- a/wallet_transaction.go +++ b/wallet_transaction.go @@ -50,11 +50,17 @@ type WalletTransactionParams struct { } type WalletTransactionInput struct { - WalletID string `json:"wallet_id,omitempty"` - PaidCredits string `json:"paid_credits,omitempty"` - GrantedCredits string `json:"granted_credits,omitempty"` - VoidedCredits string `json:"voided_credits,omitempty"` - InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + WalletID string `json:"wallet_id,omitempty"` + PaidCredits string `json:"paid_credits,omitempty"` + GrantedCredits string `json:"granted_credits,omitempty"` + VoidedCredits string `json:"voided_credits,omitempty"` + InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + Metadata []WalletTransactionMetadata `json:"metadata,omitempty"` +} + +type WalletTransactionMetadata struct { + Key string `json:"key"` + Value string `json:"value"` } type WalletTransactionResult struct { @@ -63,15 +69,16 @@ type WalletTransactionResult struct { } type WalletTransaction struct { - LagoID uuid.UUID `json:"lago_id,omitempty"` - LagoWalletID uuid.UUID `json:"lago_wallet_id,omitempty"` - Status WalletTransactionStatus `json:"status,omitempty"` - TransactionType TransactionType `json:"transaction_type,omitempty"` - Amount string `json:"amount,omitempty"` - CreditAmount string `json:"credit_amount,omitempty"` - InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` - CreatedAt time.Time `json:"created_at,omitempty"` - SettledAt time.Time `json:"settled_at,omitempty"` + LagoID uuid.UUID `json:"lago_id,omitempty"` + LagoWalletID uuid.UUID `json:"lago_wallet_id,omitempty"` + Status WalletTransactionStatus `json:"status,omitempty"` + TransactionType TransactionType `json:"transaction_type,omitempty"` + Amount string `json:"amount,omitempty"` + CreditAmount string `json:"credit_amount,omitempty"` + InvoiceRequiresSuccessfulPayment bool `json:"invoice_requires_successful_payment,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` + SettledAt time.Time `json:"settled_at,omitempty"` + Metadata []WalletTransactionMetadata `json:"metadata,omitempty"` } func (c *Client) WalletTransaction() *WalletTransactionRequest {