Skip to content

Commit

Permalink
fix: support for stripe pay-in status (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Zawila <113581282+darkmatterpool@users.noreply.github.com>
  • Loading branch information
darkmatterpool authored Nov 23, 2022
1 parent e41feb7 commit a68bb1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
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

0 comments on commit a68bb1b

Please sign in to comment.