mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Implement Balances Webhooks in Stripe to reduce polling workflows * Create webhooks on install * Remove webhook at uninstall time * Add verifyWebhook function to Stripe * Pin APIVersion in Stripe Webhook Create call * Default to root account when receiving balance.update webhook * Only make call do delete webhooks if webhooks were setup to begin with * Set up two webhook endpoints - one for connect and one for root account * Use event.Created to determine balance time in Stripe webhooks * Start recording root account ID instead of dummy 'root' value * Create unit test for Stripe create webhooks * Add tests for Stripe Translate webhook * Share logic between Stripe balance polling and webhook handle * Use supported webhooks map * Update existing stripe webhooks instead of creating new ones at app start time * Run install sequence for each connector at app start of payments api pods * Turn of balances periodically for Stripe * Add nil checks for balance.Available * Remove potentially sensitive information from error message * Add migration tool to remove FETCH BALANCES schedules from stripe
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/metrics"
|
|
"github.com/stripe/stripe-go/v80"
|
|
)
|
|
|
|
type ReverseTransferRequest struct {
|
|
IdempotencyKey string
|
|
StripeTransferID string
|
|
Account *string
|
|
Amount int64
|
|
Description string
|
|
Metadata map[string]string
|
|
}
|
|
|
|
func (c *client) ReverseTransfer(ctx context.Context, reverseTransferRequest ReverseTransferRequest) (*stripe.TransferReversal, error) {
|
|
params := &stripe.TransferReversalParams{
|
|
Params: stripe.Params{
|
|
Context: metrics.OperationContext(ctx, "reverse_transfer"),
|
|
StripeAccount: reverseTransferRequest.Account,
|
|
},
|
|
ID: stripe.String(reverseTransferRequest.StripeTransferID),
|
|
Amount: stripe.Int64(reverseTransferRequest.Amount),
|
|
Description: stripe.String(reverseTransferRequest.Description),
|
|
Metadata: reverseTransferRequest.Metadata,
|
|
}
|
|
|
|
params.AddExpand("balance_transaction")
|
|
params.AddExpand("transfer")
|
|
params.AddExpand("transfer.balance_transaction")
|
|
if reverseTransferRequest.IdempotencyKey != "" {
|
|
params.IdempotencyKey = stripe.String(reverseTransferRequest.IdempotencyKey)
|
|
}
|
|
|
|
if reverseTransferRequest.Description != "" {
|
|
params.Description = stripe.String(reverseTransferRequest.Description)
|
|
}
|
|
|
|
reversalResponse, err := c.transferReversalClient.New(params)
|
|
if err != nil {
|
|
return nil, wrapSDKErr(err)
|
|
}
|
|
|
|
return reversalResponse, nil
|
|
}
|