-
Notifications
You must be signed in to change notification settings - Fork 79
Adding/Removing items to refunds #425
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
Conversation
| end | ||
|
|
||
| def remove_item(product_id) | ||
| raise ProductNotFoundError unless @refund_items.quantity(product_id).positive? |
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.
I wonder if this error could have more meaningful business name. Something like RefundHaveNotBeenRequestedForThisProduct
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.
Good idea, I changed the name 👍
| def call(event) | ||
| refund_id = event.data.fetch(:refund_id) | ||
| product_id = event.data.fetch(:product_id) | ||
| item = find(refund_id, product_id) |
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.
Is this event handler idempotent?
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.
Hmm, it isn't, but most, if not all, of our event handlers aren't idempotent 🤔 I'm not sure if I know how to make it idempotent, maybe you have some ideas?
| refund.add_item(command.product_id) | ||
| refund.add_item( | ||
| command.product_id, | ||
| available_quantity_to_refund(command.order_id, command.product_id) |
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.
I think that the available quantity to refund information should be passed to Refund once it is requested. We don't want this value to be changed.
I see it that way:
- Order has been paid
- Someone wants to refund part of it or whole
- Refund is created, it knows what products (or how many this case*) were there in the order
- It allows refunding those products or not
-
- Perhaps it should know which products were in the order initially, not only quantity of them?
- Are we talking about refunding items or product? Method names of refund imply items, but projection's method indicates product.
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.
Thanks for the suggestion! I'm not sure if I understand what you mean.
You propose that when creating a Refund, we should pass in all the quantities per product (e.g., { product_1_id: 13, product_2_id: 3 }), and store this information within the Refund aggregate. This would allow us to validate refund operations against the original available quantities without needing to query the projection each time.
Is that what you mean?
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.
Yes
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.
Done :)
1c6fc12 to
b55e4a5
Compare
fb29492 to
ad9e65d
Compare
|
|
||
| AddItemToRefund.new.call(item_added_to_refund(refund_id, order_id, product_id)) | ||
|
|
||
| assert_equal(Refunds::RefundItem.count, 1) |
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.
Parameters are reversed. First. parameter is "expected", the other one is actual value.
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.
Fixed, thank you! :)
| assert_equal(1, refund_item.quantity) | ||
| assert_equal(50, refund_item.price) | ||
|
|
||
| assert_equal(Refunds::Refund.count, 1) |
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.
Same here (reversed parameters)
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.
Fixed, thank you!
|
|
||
| RemoveItemFromRefund.new.call(item_removed_from_refund(refund_id, order_id, product_id)) | ||
|
|
||
| assert_equal(Refunds::RefundItem.count, 1) |
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.
Same here (reversed parameters)
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.
Fixed, thank you!
| assert_equal(1, refund_item.quantity) | ||
| assert_equal(30, refund_item.price) | ||
|
|
||
| assert_equal(Refunds::Refund.count, 1) |
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.
Same here (reversed parameters)
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.
Fixed
|
|
||
| assert_equal(Refunds::Refund.count, 1) | ||
| refund = Refunds::Refund.find_by(uid: refund_id) | ||
| assert_equal(refund.status, "Draft") |
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.
Same here (reversed parameters)
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.
Fixed
❌ Deploy Preview for ecommerce-events failed.
|
Issue: #154
This is the second step to allow order refunds. First step is here: #424.
Nagranie.z.ekranu.2025-01-7.o.10.07.34.mov