“Refund operation failed. Error message: (91506) Cannot refund a transaction unless it is settled.”
Refunding a partial amount could fail if the transaction is not settled at the gateway.
If you are trying to process a full refund for an unsettled amount, the whole transaction will be canceled/voided(the amount would be returned to the customer eventually after some time). However, a partial refund cannot be initiated unless the amount is settled i.e. unless the gateway submits them to the bank for settlement.
In such cases, we suggest you retry the partial refund after 24 hours to ensure the payment is settled. You could also check the transaction details in your payment gateway account which contains the settlement status.
Related articles and documentation: