Skip to content

Conversation

@marlena-b
Copy link
Collaborator

Issue: #154

This is the second step to allow order refunds. First step is here: #424.

  • add/remove buttons now works, the form can be filled
  • the form cannot be submitted yet - it will be added in another PR :)
Nagranie.z.ekranu.2025-01-7.o.10.07.34.mov

end

def remove_item(product_id)
raise ProductNotFoundError unless @refund_items.quantity(product_id).positive?
Copy link
Collaborator

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

Copy link
Collaborator Author

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done :)

@marlena-b marlena-b force-pushed the add-new-refund-form branch from 1c6fc12 to b55e4a5 Compare February 3, 2025 14:11
@marlena-b marlena-b changed the base branch from add-new-refund-form to master February 3, 2025 14:42
@marlena-b marlena-b changed the base branch from master to add-new-refund-form February 3, 2025 14:45
@marlena-b marlena-b force-pushed the add-remove-items-to-refund branch from fb29492 to ad9e65d Compare February 3, 2025 14:47
@marlena-b marlena-b changed the base branch from add-new-refund-form to master February 3, 2025 14:47

AddItemToRefund.new.call(item_added_to_refund(refund_id, order_id, product_id))

assert_equal(Refunds::RefundItem.count, 1)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here (reversed parameters)

Copy link
Collaborator Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here (reversed parameters)

Copy link
Collaborator Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here (reversed parameters)

Copy link
Collaborator Author

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here (reversed parameters)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@netlify
Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for ecommerce-events failed.

Name Link
🔨 Latest commit 0074aa2
🔍 Latest deploy log https://app.netlify.com/sites/ecommerce-events/deploys/67b3096b67268800082d0cc5

@marlena-b marlena-b merged commit f8faf0a into master Feb 18, 2025
27 of 31 checks passed
@mostlyobvious mostlyobvious deleted the add-remove-items-to-refund branch July 9, 2025 19:41
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