WooOrderRefund class
WooCommerce Order Refund Model
Represents a refund for a WooCommerce order, containing all refund details, line items, and financial information. This model is used to manage order refunds and track refund history in your WooCommerce store.
Refund Structure
A WooCommerce order refund consists of several key components:
- Refund Information: ID, creation date, amount, and reason
- Financial Data: Refund amount, taxes, and payment processing
- Line Items: Specific products and quantities being refunded
- Tax Information: Tax lines and calculations for the refund
- Shipping: Shipping costs and taxes being refunded
- Fees: Additional fees and their refund amounts
- Metadata: Custom refund metadata and notes
Refund Process
Refunds can be processed in different ways:
- API Refund: Uses payment gateway API to process refund
- Manual Refund: Manual refund without gateway processing
- Partial Refund: Refund specific line items or amounts
- Full Refund: Complete refund of the entire order
Key Features
- Refund Information: ID, date, amount, reason, and processing details
- Financial Data: Refund totals, taxes, and payment processing
- Line Items: Products and quantities being refunded
- Tax Information: Tax calculations and refund amounts
- Shipping: Shipping costs and taxes being refunded
- Fees: Additional fees and their refund amounts
- Metadata: Custom refund metadata and administrative notes
Usage Examples
Creating a New Refund
final refund = WooOrderRefund(
amount: '25.00',
reason: 'Customer requested refund',
lineItems: [
WooLineItem(
id: 1,
quantity: 1,
total: 25.00,
),
],
apiRefund: true,
apiRestock: true,
);
Working with Refund Data
// Check refund amount
print('Refund amount: \$${refund.amount}');
// Check if refund was processed via API
if (refund.apiRefund == true) {
print('Refund processed via payment gateway');
}
// Access refund line items
for (final item in refund.lineItems ?? []) {
print('Refunded item: ${item.name}, Qty: ${item.quantity}');
}
// Check refund date
if (refund.dateCreated != null) {
print('Refund created on: ${refund.dateCreated}');
}
Refund Processing
// Create a full refund
final fullRefund = WooOrderRefund(
amount: order.total.toString(),
reason: 'Full order refund',
apiRefund: true,
apiRestock: true,
);
// Create a partial refund
final partialRefund = WooOrderRefund(
amount: '15.00',
reason: 'Partial refund for damaged item',
lineItems: [
WooLineItem(
id: 1,
quantity: 1,
total: 15.00,
),
],
apiRefund: false,
apiRestock: true,
);
JSON Serialization
The class supports full JSON serialization for API communication:
// Convert to JSON for API requests
final json = refund.toJson();
// Create from JSON response
final refund = WooOrderRefund.fromJson(jsonData);
- Implementers
Constructors
-
WooOrderRefund({int? id, DateTime? dateCreated, DateTime? dateCreatedGmt, String? amount, String? reason, int? refundedBy, bool? refundedPayment, List<
WooMetaData> ? metaData, List<WooLineItem> ? lineItems, List<WooTaxLine> ? taxLines, List<WooShippingLine> ? shippingLines, List<WooOrderFeeLine> ? feeLines, bool? apiRefund, bool? apiRestock}) - Creates a new WooOrderRefund instance
- WooOrderRefund.fake()
-
Creates a fake WooOrderRefund instance for testing purposes
factory
-
WooOrderRefund.fromJson(Map<
String, dynamic> json) - Creates a WooOrderRefund instance from JSON data
Properties
- amount ↔ String?
-
Total refund amount
getter/setter pair
- apiRefund ↔ bool?
-
Whether to use payment gateway API for refund
getter/setter pair
- apiRestock ↔ bool?
-
Whether to restock refunded items
getter/setter pair
- dateCreated ↔ DateTime?
-
Date and time when the refund was created (local time)
getter/setter pair
- dateCreatedGmt ↔ DateTime?
-
Date and time when the refund was created (GMT)
getter/setter pair
-
feeLines
↔ List<
WooOrderFeeLine> ? -
Fee lines for the refund
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setteroverride
- id ↔ int?
-
Unique identifier for the refund
getter/setter pair
-
lineItems
↔ List<
WooLineItem> ? -
Line items being refunded
getter/setter pair
-
metaData
↔ List<
WooMetaData> ? -
Custom refund metadata
getter/setter pair
- reason ↔ String?
-
Reason for the refund
getter/setter pair
- refundedBy ↔ int?
-
User ID of the user who created the refund
getter/setter pair
- refundedPayment ↔ bool?
-
Whether the payment was refunded via the API
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shippingLines
↔ List<
WooShippingLine> ? -
Shipping lines for the refund
getter/setter pair
-
taxLines
↔ List<
WooTaxLine> ? -
Tax lines for the refund
getter/setter pair
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts the WooOrderRefund instance to JSON format
-
toString(
) → String -
Returns a string representation of the WooOrderRefund instance
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override