Skip to content

Commit

Permalink
Merge pull request #198 from getlago/add-top-up-metadata
Browse files Browse the repository at this point in the history
feat(wallet): add metadata to wallet transaction
  • Loading branch information
brunomiguelpinto authored Aug 19, 2024
2 parents ef816f9 + fd054f1 commit eccb0ce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
51 changes: 29 additions & 22 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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)
Expand Down
35 changes: 21 additions & 14 deletions wallet_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit eccb0ce

Please sign in to comment.