Skip to content

Comments

Transaction amount calculations#1416

Merged
IKarbowiak merged 8 commits intomainfrom
shopx-1721-transaction-amount-calculations
Jan 10, 2025
Merged

Transaction amount calculations#1416
IKarbowiak merged 8 commits intomainfrom
shopx-1721-transaction-amount-calculations

Conversation

@IKarbowiak
Copy link
Member

Explain transaction amount calculations

@IKarbowiak IKarbowiak self-assigned this Dec 13, 2024
@vercel
Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 11:22am

- The value can be negative.REFUND_REVERSE

#### Charge Pending Value ([`transactionItem.chargePendingAmount`](/api-reference/payments/objects/transaction-item#transactionitemchargependingamountmoney---))
- When an `CHARGE_REQUEST` event occurs and there is no `CHARGE_FAILURE` or `CHARGE_SUCCESS` event is: value increases by the `REQUEST` event's amount.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: isn't this value impacted by refund and chargeback as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, CHARGEBACK does not influence charge_pending_amount

#### 2. Pending Amounts:
- Pending amounts (`authorizePendingAmount`, `chargePendingAmount`, `refundPendingAmount`, `cancelPendingAmount`) are increased only if a `REQUEST` event exists for the corresponding PSP reference.
- If a success or failure event is also associated with the same PSP reference, the system assumes the requested amount has already been processed, and the pending amount will not be increased.
#### 3. `SUCCESS` and `FAILURE` Events:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be also good to mention that in case of the SUCCESS, the amount will be subtracted from the "previous" value?
I mean, we have a transaction with event AUTHORIZE_SUCCESS and amount 100. TR has authorizedAmount:100, chargedAmount:0. Then we receive the event CHARGE_SUCESS and amount: 100. The 100 will have an impact on authorizedAmount. TR will have: authorizedAmount:0, chargedAmount:100 (as we subtracted the amount from CHARGE_SUCCESS from authorizedAmount and added it to chargedAmount)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see that you deeply explained it below. So the question is: Do you think, that this is wort also to mention it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note about that in Calculation process part


This logic ensures that transaction amounts reflect the current state of the transaction based on its event history while accounting for both processed and pending actions.

### Calculation details
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth explicitly say, that we are talking about the events returned by APP - I mean, events that have psp_reference provided by App. For example, you could still see X_request event created by Saleor when calling the app, but it is not included in calculations until receiving at least psp_refernce from payment app 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not be clear here.
I was meaning the situation when saleor creates X_REQUEST event (like calling charge-request, or refund-request). The event's amount will not be included in calculations until receiving the SUCCESS response from the app. As this action is called asynchronously (I mean a situation when calling this action from dashboard), we can have a TR like:
TR: chargedAmount 100, refundAmount:0
Event1: amount: 100, type CHARGE_SUCCESS, pspRef:123
Event2: amount: 100, type: REFUND_REQUEST, pspRef:null

As event2 was created by Saleor, and we're proceeding the refund request right now, the transaction.chargedAmount , transaction.refundedAmount are not impacted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note about that

witoszekdev
witoszekdev previously approved these changes Jan 2, 2025
witoszekdev
witoszekdev previously approved these changes Jan 9, 2025
@IKarbowiak IKarbowiak merged commit ae94509 into main Jan 10, 2025
6 checks passed
@IKarbowiak IKarbowiak deleted the shopx-1721-transaction-amount-calculations branch January 10, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants