django_program.registration.services.refund¶
Refund service for processing order refunds and credit applications.
Handles Stripe refund creation, store credit issuance, and credit-as-payment application. All methods are stateless and operate on model instances directly.
Classes
Stateless service for refund and credit operations. |
- class django_program.registration.services.refund.RefundService[source]¶
Bases:
objectStateless service for refund and credit operations.
Processes full and partial Stripe refunds, issues store credits, and applies existing credits as payment toward new orders.
- static create_refund(order, *, amount, reason='requested_by_customer', staff_user=None)[source]¶
Issue a full or partial refund for a Stripe-paid order.
Validates the order state, calculates the refundable balance, calls the Stripe API to create the refund, and issues a store Credit record. The order status is updated to REFUNDED or PARTIALLY_REFUNDED depending on whether the cumulative refund total covers the full order amount.
- Parameters:
order (
Order) – The order to refund. Must be PAID or PARTIALLY_REFUNDED.amount (
Decimal) – The refund amount. Must be positive and not exceed the remaining refundable balance.reason (
str) – The Stripe refund reason string (e.g."requested_by_customer","duplicate","fraudulent").staff_user (
AbstractBaseUser|None) – Optional staff user initiating the refund, recorded on the credit note for audit purposes.
- Return type:
- Returns:
The newly created Credit with AVAILABLE status.
- Raises:
ValidationError – If the order is not in a refundable state, the amount is invalid, or no Stripe payment exists on the order.
- static apply_credit_as_refund(credit, target_order)[source]¶
Apply an existing store credit as payment toward an order.
Deducts the applied amount from the credit’s remaining balance and creates a CREDIT payment on the target order. If the credit is fully consumed it transitions to APPLIED. If the order becomes fully paid it transitions to PAID and the
order_paidsignal fires.- Parameters:
- Return type:
- Returns:
The created Payment record with CREDIT method and SUCCEEDED status.
- Raises:
ValidationError – If the credit is not available, has no remaining balance, the order is not pending, or the credit and order belong to different users or conferences.