# prefix: SRF
Feature: Refunding a sale order invoice
A supplier gives money back to a customer from an invoice, or straight after recording a return. Clipp records the
refund; it never sends money back through a card or bank processor.

Background:
Given a supplier user with full invoice access
And an invoice that went out to a customer

Rule: A refund is only offered when the customer has paid

    Scenario Outline: SRF-001 Issue Refund is offered on a partly or fully paid invoice
      Given the invoice is <status>
      When the supplier opens Manage Payments
      Then Issue Refund is available

      Examples:
        | status         |
        | partially paid |
        | fully paid     |

    Scenario: SRF-002 Issue Refund is not offered on an unpaid invoice
      Given the customer has paid nothing on the invoice
      When the supplier opens Manage Payments
      Then Issue Refund is not available
      And the supplier is told it only applies to orders with partial or full payment

    Scenario: SRF-003 a cancelled invoice accepts no refund
      Given the invoice was cancelled after being fully paid
      When the supplier opens Manage Payments
      Then the supplier sees the records only
      And Issue Refund is not available

Rule: The refund amount starts at what the customer is owed back

    Scenario: SRF-004 a full refund gives back the overpaid excess
      Given the customer paid more than the invoice total
      When the supplier opens Issue Refund
      Then Issue Full Refund is chosen and shows only the overpaid excess

    Scenario: SRF-005 a full refund gives back what the customer paid when nothing is overpaid
      Given the customer paid less than or exactly the invoice total
      When the supplier opens Issue Refund
      Then Issue Full Refund is chosen and shows the amount the customer paid

    Scenario: SRF-006 a custom amount cannot exceed what the customer paid
      When the supplier chooses Custom Amount and enters more than the customer paid
      Then the supplier is told it is more than the customer paid
      And nothing is refunded

Rule: The customer is told only when the supplier chooses

    Scenario: SRF-007 the customer is not notified unless the supplier opts in
      When the supplier issues a refund without ticking Notify customer
      Then the customer is not notified
      But when the supplier ticks Notify customer the customer is notified

    Scenario: SRF-008 retrying after a failure never refunds twice
      Given a refund failed and the supplier tries again
      When the supplier confirms the refund again
      Then the retry is recognised as the same refund
      And the customer is refunded once

Rule: A return on a paid invoice leads to a refund

    Scenario: SRF-009 recording a return on a fully paid invoice offers Issue a Refund
      Given the invoice is fully paid
      When the supplier records a return
      And chooses Issue a Refund
      Then the invoice opens on Issue Refund
      And closing it and reopening Manage Payments starts on Add Payment

    Scenario: SRF-010 recording a return on a partly paid invoice offers View Invoice
      Given the invoice is partially paid
      When the supplier records a return
      Then the supplier can view the invoice
      And is not offered Issue a Refund

    Scenario: SRF-011 a refund link to an invoice that cannot be refunded opens normally
      Given the invoice is unpaid or cancelled
      When the supplier follows a refund link to the invoice
      Then Manage Payments does not open on Issue Refund

Rule: A refund is recorded as the supplier chose

    Scenario: SRF-012 the refund is recorded with the method the supplier chose
      When the supplier issues a refund and chooses Cash as the method
      Then the refund is recorded as paid in cash

    Scenario: SRF-018 a refund updates the invoice's payment status
      Given the invoice is fully paid
      When the supplier refunds part of what the customer paid
      Then the invoice is partially paid

    Scenario: SRF-019 a refund paid as store credit credits the customer and books no cash entry
      When the supplier issues a refund and chooses Store Credit as the method
      Then the amount is added to the customer's store credit with the supplier
      And nothing is booked in the supplier's accounts

    Scenario: SRF-020 a refund paid in cash is booked in the supplier's accounts
      When the supplier issues a refund and chooses Cash as the method
      Then the supplier's accounts show the money going back out

Rule: A refund is refused when it cannot be trusted

    Scenario: SRF-013 a refund cannot be issued on a cancelled invoice
      Given the invoice was cancelled
      When a refund is requested for the invoice
      Then the refund is refused
      And nothing is refunded

    Scenario: SRF-014 editing the amount after a failed refund is a new refund
      Given a refund failed and the supplier changes the amount
      When the supplier confirms the refund again
      Then it is treated as a new refund, not a retry of the first

    Scenario: SRF-015 two refunds issued at the same moment never give back more than the customer paid
      Given the customer paid $10.00
      When two refunds of $6.00 are issued at the same moment
      Then only one of them is recorded
      And the other is told what is still refundable

    Scenario: SRF-016 a retry key that belongs to a different invoice is refused
      Given a retry key was already used for a refund on another invoice
      When the supplier issues a refund with that same key
      Then the refund is refused
      And nothing is refunded

    Scenario: SRF-017 a refund account that does not belong to the supplier is refused
      When the supplier issues a refund to an account that is not theirs
      Then the refund is refused
      And nothing is refunded

    Scenario: SRF-022 a refund that cannot be recorded in the supplier's accounts is refused and nothing is recorded
      Given the supplier has no Sales Returns accounting category set up
      When the supplier issues a cash refund
      Then the refund is refused with a message saying it cannot be recorded in their accounts
      And no refund is recorded and the invoice's payment status is unchanged
      And the customer is not notified

Rule: Issue Refund is not offered while money is still moving

    Scenario Outline: SRF-021 Issue Refund is not available on a processing or void invoice
      Given the invoice is <status>
      When the supplier opens Manage Payments
      Then Issue Refund is not available

      Examples:
        | status     |
        | processing |
        | void       |
