Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support for stripe pay-in status #58

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/pkg/connectors/stripe/task_connected_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func ingestBatch(ctx context.Context, logger sharedlogging.Logger, ingester inge
) error {
batch := ingestion.PaymentBatch{}

for _, bt := range bts {
batchElement, handled := CreateBatchElement(bt, !tail)
for i := range bts {
batchElement, handled := CreateBatchElement(bts[i], !tail)

if !handled {
logger.Debugf("Balance transaction type not handled: %s", bt.Type)
logger.Debugf("Balance transaction type not handled: %s", bts[i].Type)

continue
}
Expand Down
41 changes: 19 additions & 22 deletions internal/pkg/connectors/stripe/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func CreateBatchElement(balanceTransaction *stripe.BalanceTransaction, forward b
return ingestion.PaymentBatchElement{}, false
}

if balanceTransaction.Source.Payout == nil {
if balanceTransaction.Source.Payout == nil && balanceTransaction.Source.Charge == nil {
return ingestion.PaymentBatchElement{}, false
}

Expand All @@ -167,10 +167,8 @@ func CreateBatchElement(balanceTransaction *stripe.BalanceTransaction, forward b
return fmt.Sprintf("%s/%d", asset, def.decimals)
}

payoutStatus := convertPayoutStatus(balanceTransaction.Source.Payout.Status)

switch balanceTransaction.Type {
case "charge":
case stripe.BalanceTransactionTypeCharge:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Charge.ID,
Type: payments.TypePayIn,
Expand All @@ -183,30 +181,29 @@ func CreateBatchElement(balanceTransaction *stripe.BalanceTransaction, forward b
Scheme: payments.Scheme(balanceTransaction.Source.Charge.PaymentMethodDetails.Card.Brand),
CreatedAt: time.Unix(balanceTransaction.Created, 0),
}
case "payout":
case stripe.BalanceTransactionTypePayout:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Payout.ID,
Type: payments.TypePayout,
}
paymentData = &payments.Data{
Status: payoutStatus,
Status: convertPayoutStatus(balanceTransaction.Source.Payout.Status),
InitialAmount: balanceTransaction.Source.Payout.Amount,
Raw: balanceTransaction,
Asset: formatAsset(balanceTransaction.Source.Payout.Currency),
Scheme: func() payments.Scheme {
switch balanceTransaction.Source.Payout.Type {
case "bank_account":
case stripe.PayoutTypeBank:
return payments.SchemeSepaCredit
case "card":
case stripe.PayoutTypeCard:
return payments.Scheme(balanceTransaction.Source.Payout.Card.Brand)
}

return payments.SchemeUnknown
}(),
CreatedAt: time.Unix(balanceTransaction.Created, 0),
}

case "transfer":
case stripe.BalanceTransactionTypeTransfer:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Transfer.ID,
Type: payments.TypePayout,
Expand All @@ -219,18 +216,18 @@ func CreateBatchElement(balanceTransaction *stripe.BalanceTransaction, forward b
Scheme: payments.SchemeOther,
CreatedAt: time.Unix(balanceTransaction.Created, 0),
}
case "refund":
case stripe.BalanceTransactionTypeRefund:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Refund.Charge.ID,
Type: payments.TypePayIn,
Type: payments.TypePayout,
}
adjustment = &payments.Adjustment{
Status: payments.StatusSucceeded,
Amount: balanceTransaction.Amount,
Date: time.Unix(balanceTransaction.Created, 0),
Raw: balanceTransaction,
}
case "payment":
case stripe.BalanceTransactionTypePayment:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Charge.ID,
Type: payments.TypePayIn,
Expand All @@ -243,53 +240,53 @@ func CreateBatchElement(balanceTransaction *stripe.BalanceTransaction, forward b
Scheme: payments.SchemeOther,
CreatedAt: time.Unix(balanceTransaction.Created, 0),
}
case "payout_cancel":
case stripe.BalanceTransactionTypePayoutCancel:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Payout.ID,
Type: payments.TypePayout,
}
adjustment = &payments.Adjustment{
Status: payoutStatus,
Status: convertPayoutStatus(balanceTransaction.Source.Payout.Status),
Amount: 0,
Date: time.Unix(balanceTransaction.Created, 0),
Raw: balanceTransaction,
Absolute: true,
}
case "payout_failure":
case stripe.BalanceTransactionTypePayoutFailure:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Payout.ID,
Type: payments.TypePayIn,
}
adjustment = &payments.Adjustment{
Status: payoutStatus,
Status: convertPayoutStatus(balanceTransaction.Source.Payout.Status),
Amount: 0,
Date: time.Unix(balanceTransaction.Created, 0),
Raw: balanceTransaction,
Absolute: true,
}
case "payment_refund":
case stripe.BalanceTransactionTypePaymentRefund:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Refund.Charge.ID,
Type: payments.TypePayIn,
Type: payments.TypePayout,
}
adjustment = &payments.Adjustment{
Status: payments.StatusSucceeded,
Amount: balanceTransaction.Amount,
Date: time.Unix(balanceTransaction.Created, 0),
Raw: balanceTransaction,
}
case "adjustment":
case stripe.BalanceTransactionTypeAdjustment:
reference = payments.Referenced{
Reference: balanceTransaction.Source.Dispute.Charge.ID,
Type: payments.TypePayIn,
Type: payments.TypePayout,
}
adjustment = &payments.Adjustment{
Status: payments.StatusCancelled,
Amount: balanceTransaction.Amount,
Date: time.Unix(balanceTransaction.Created, 0),
Raw: balanceTransaction,
}
case "stripe_fee", "network_cost":
case stripe.BalanceTransactionTypeStripeFee:
return ingestion.PaymentBatchElement{}, true
default:
return ingestion.PaymentBatchElement{}, false
Expand Down