-
Notifications
You must be signed in to change notification settings - Fork 9
Revert "Revert "backend/feat: Stripe payout dynamic transfer top-up f… #1326
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ module Kernel.External.Payout.Interface.Stripe | |
| ( createExternalPayout, | ||
| externalPayoutOrderStatus, | ||
| createTransfer, | ||
| getBalance, | ||
| getAvailableForCurrency, | ||
| payoutStripeServiceEventWebhook, | ||
| castPayoutStatus, | ||
| unPayoutId, | ||
|
|
@@ -132,6 +134,26 @@ createTransfer config req = do | |
| mkCreateTransferResp :: Stripe.TransferObject -> CreateTransferResp | ||
| mkCreateTransferResp Stripe.TransferObject {..} = CreateTransferResp {transferId = id, transferStatus = TRANSFERRED} | ||
|
|
||
| getBalance :: | ||
| ( Metrics.CoreMetrics m, | ||
| EncFlow m r, | ||
| HasRequestId r, | ||
| MonadReader r m | ||
| ) => | ||
| StripeConfig -> | ||
| Maybe Text -> | ||
| m Stripe.BalanceResp | ||
| getBalance config mbConnectedAccountId = do | ||
| apiKey <- decrypt config.apiKey | ||
| Stripe.getBalance config.url apiKey mbConnectedAccountId | ||
|
|
||
| -- | Extract available balance for a specific currency from a Stripe BalanceResp. | ||
| -- Stripe amounts are in smallest currency unit (cents); converts to HighPrecMoney. | ||
| getAvailableForCurrency :: Currency -> Stripe.BalanceResp -> HighPrecMoney | ||
| getAvailableForCurrency currency Stripe.BalanceResp {available} = | ||
| let currencyText = T.toLower $ show currency | ||
| in sum [centsToUsd f.amount | f <- available, f.currency == currencyText] | ||
|
Comment on lines
+152
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect the cents/major-unit converters to confirm scale is currency-agnostic.
ast-grep --pattern 'centsToUsd $_ = $$$'
ast-grep --pattern 'eurToCents $_ = $$$'
ast-grep --pattern 'usdToCents $_ = $$$'
rg -nP --type=haskell -C2 '\b(centsToUsd|eurToCents|usdToCents)\b'Repository: nammayatri/shared-kernel Length of output: 12663 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find the Interface.hs referenced by the review comment
fd -e hs -a Interface.hs lib/mobility-core/src | head -n 50
# Search for the specific comparison expression
rg -n --type=haskell "fleetAvail\s*\+\s*req\.transferAmount\s*>?=\s*req\.amount" lib/mobility-core/src || true
# If not found, search for fleetAvail usage near transferAmount/amount
rg -n --type=haskell "fleetAvail" lib/mobility-core/src | head -n 50Repository: nammayatri/shared-kernel Length of output: 2691 🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="lib/mobility-core/src/Kernel/External/Payout/Interface.hs"
# Show the relevant block around the comparison
nl -ba "$FILE" | sed -n '1,140p'
# Find the request record type that contains transferAmount/amount
rg -n --type=haskell "transferAmount" lib/mobility-core/src/Kernel/External/Payout/Interface.hs
rg -n --type=haskell "data .*Transfer.*|data .*Payout.*|record.*Transfer|req\.transferAmount" lib/mobility-core/src/Kernel/External/Payout/Interface.hs
# Broader search for where req.amount / transferAmount are built for payout
rg -n --type=haskell "transferAmount\s*=\s*" lib/mobility-core/src/Kernel/External/Payout lib/mobility-core/src/Kernel/External -S
rg -n --type=haskell "req\.amount" lib/mobility-core/src/Kernel/External/Payout -SRepository: nammayatri/shared-kernel Length of output: 111 🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="lib/mobility-core/src/Kernel/External/Payout/Interface.hs"
# Line-numbered view without nl
cat -n "$FILE" | sed -n '1,120p'
# Find request/type definitions and uses
rg -n --type=haskell "transferAmount" "$FILE"
rg -n --type=haskell "req\.amount|req\.transferAmount|amount\s*=|transferAmount\s*=" lib/mobility-core/src/Kernel/External/Payout -S
rg -n --type=haskell "data .*Payout|data .*Transfer|Create.*Payout|Transfer.*Req|Payout.*Req|record .*Payout" lib/mobility-core/src/Kernel/External/Payout -SRepository: nammayatri/shared-kernel Length of output: 25372 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect payout request types
rg -n --type=haskell "data CreatePayoutOrderReq" lib/mobility-core/src/Kernel/External/Payout/Interface/Types.hs
cat -n lib/mobility-core/src/Kernel/External/Payout/Interface/Types.hs | sed -n '1,220p'
# Inspect Stripe payout conversion of req.amount/transferAmount to Stripe minor units
cat -n lib/mobility-core/src/Kernel/External/Payout/Interface/Stripe.hs | sed -n '1,220p'
# Find Currency definition and any decimal/minor-unit scaling logic
rg -n --type=haskell "data Currency|newtype Currency|type Currency" lib/mobility-core/src/Kernel | head -n 50
rg -n --type=haskell "Currency" lib/mobility-core/src/Kernel | rg -n "decim|minor|zero|scale|fraction" | head -n 50 || true
rg -n --type=haskell "zero[-_ ]?decimal|minor unit|decimal" lib/mobility-core/src/Kernel | head -n 50 || trueRepository: nammayatri/shared-kernel Length of output: 19012 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n --type=haskell "HighPrecMoney" lib/mobility-core/src/Kernel/Types/Price.hs lib/mobility-core/src/Kernel | head -n 50
rg -n --type=haskell "newtype HighPrecMoney|type HighPrecMoney" lib/mobility-core/src/Kernel | head -n 50
rg -n --type=haskell "HighPrecMoney.*cents|cents.*HighPrecMoney|minor.*HighPrecMoney" lib/mobility-core/src/Kernel | head -n 50Repository: nammayatri/shared-kernel Length of output: 6407 🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="lib/mobility-core/src/Kernel/Types/Price.hs"
# show around HighPrecMoney definition
sed -n '1,140p' "$FILE" | cat -n | sed -n '40,110p'
# show rest where cents/minor may be defined
sed -n '140,260p' "$FILE" | cat -n | head -n 160Repository: nammayatri/shared-kernel Length of output: 8353 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n --type=haskell "getAvailableForCurrency|centsToUsd|usdToCents|eurToCents" lib/mobility-core/src/Kernel/External/Payout/Interface/Stripe.hs lib/mobility-core/src/Kernel/External/Payout/Interface.hs lib/mobility-core/src/Kernel/External/Payment/Interface/Stripe.hs
rg -n --type=haskell "getAccuracy\s+INR|data Currency\s*=\s*INR\s*\|" lib/mobility-core/src/Kernel/Types/Price.hsRepository: nammayatri/shared-kernel Length of output: 4628 Fix currency minor-unit conversion in
getAvailableForCurrency :: Currency -> Stripe.BalanceResp -> HighPrecMoney
getAvailableForCurrency currency Stripe.BalanceResp {available} =
let currencyText = T.toLower $ show currency
in sum [centsToUsd f.amount | f <- available, f.currency == currencyText]
🤖 Prompt for AI Agents |
||
|
|
||
| payoutStripeServiceEventWebhook :: | ||
| ( EncFlow m r, | ||
| HasRequestId r, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't leak the merchant platform balance in a client-facing error.
InvalidRequestis surfaced to the API caller. Embedding the platform/merchant account's available balance (and exact required amount) in the message discloses internal financial state to whoever triggers the payout. Log the details internally and return a generic message.🔒 Proposed fix
🤖 Prompt for AI Agents