title | date | area | tags | |||
---|---|---|---|---|---|---|
Refund handling |
2021-10-13 |
checkout |
|
Shopware offers no way of unified refund handling. This results in every payment extension either implementing it themselves or not at all.
We want to implement the following structure to offer a unified refund handling for all extension types.
A payment extension will need to persist its actual captures to use the refund handling. Those captures are bound to a specific OrderTransaction
. The capture has an amount, allows saving an external reference.
A capture is directly associated with a transaction.
This relation is n order_transaction_capture
s to 1 order_transaction
.
Type | Field name | References |
---|---|---|
BINARY(16) | id | |
BINARY(16) | transaction_id | order_transaction.id |
BINARY(16) | state_id | state_machine_state.id |
VARCHAR(255) NULL | external_reference | |
LONGTEXT | amount | |
LONGTEXT NULL | custom_fields |
Type | Property name |
---|---|
string | id |
string | transactionId |
string | stateId |
string/null | externalReference |
float | totalAmount |
CalculatedPrice | amount |
array/null | customFields |
OrderTransactionEntity/null | transaction |
StateMachineStateEntity/null | stateMachineState |
OrderTransactionRefundCollection/null | refunds |
A refund is directly associated with a capture.
This relation is n order_transaction_capture_refund
s to 1 order_transaction_capture
.
Type | Field name | References |
---|---|---|
BINARY(16) | id | |
BINARY(16) | capture_id | order_transaction_capture.id |
BINARY(16) | state_id | state_machine_state.id |
VARCHAR(255) NULL | reason | |
LONGTEXT | amount | |
LONGTEXT NULL | custom_fields | |
VARCHAR(255) NULL | external_reference |
Type | Property name |
---|---|
string | id |
string | captureId |
string | stateId |
string/null | externalReference |
string/null | reason |
float | totalAmount |
CalculatedPrice | amount |
array/null | customFields |
StateMachineStateEntity/null | stateMachineState |
OrderTransactionCaptureEntity/null | transactionCapture |
OrderTransactionCaptureRefundPositionCollection/null | positions |
Refund positions are optional and only there if a refund is position-specific.
They relate n order_transaction_capture_refund_position
s to 1 order_transaction_capture_refund
.
Type | Field name | References |
---|---|---|
BINARY(16) | id | |
BINARY(16) | refund_id | order_transaction_capture_refund.id |
BINARY(16) | line_item_id | order_line_item.id |
INT(11) | quantity | |
VARCHAR(255) NULL | reason | |
LONGTEXT | refund_amount | |
LONGTEXT NULL | custom_fields |
Type | Property name |
---|---|
string | id |
string | refundId |
string | lineItemId |
string/null | reason |
int | quantity |
float | refundPrice |
CalculatedPrice | refundAmount |
array/null | customFields |
OrderLineItemEntity/null | lineItem |
OrderTransactionCaptureRefundEntity/null | orderTransactionCaptureRefund |
- Add
refundHandlingEnabled
computed field if payment method handler implementsRefundHandlerInterface
- Add OneToManyAssociation OrderTransactionCaptureCollection captures
- Add OneToManyAssociation OrderTransactionCaptureRefundPositionCollection|null refundPositions
Add 2 new state machines for OrderTransactionCapture and OrderTransactionCaptureRefund.
We want to add the following states to a new order_transaction_capture.state
state machine:
- pending
- completed
- failed
We want to add the following states to a new order_transaction_capture_refund.state
state machine:
- open
- in_progress
- cancelled
- failed
- completed
Add an interface as outlined below:
public function refund(string $orderRefundId, Context $context): void;
The PaymentRefundProcessor gets triggered via a corresponding Admin-API action and contains the method processRefund
as outlined below:
public function processRefund(string $refundId, Context $context): Response;
The whole refund handling should be available for apps and plugins. The following changes are required to allow apps to handle refunds.
Add refundUrl
to the manifest PaymentMethod
. Also change the xsd accordingly.
Add an AppRefundHandler
, which assembles payloads and talks to the app refund endpoint.
Captures are written over the Admin-API endpoint.