Square Afterpay/Clearpay Refund

I have implemented Square Afterpay/Clearpay inside my ticketing portal. And related to the place order everything is working fine. But Now when I try to refund the order Specifically from placed from the Afterpay payment option it throws api error with status code of 500. For the refund I am using this endpoint.

If I try to hit this endpoint with the order total amount then throws error of (Refund amount exceeds then the order total.) and If I try to add the lesser amount or the amount which is equal to the installment which user has paid then it Throws status code 500 error. And Surprisingly When I check with this endpoint https://developer.squareup.com/explorer/square/refunds-api/list-payment-refunds

Then for that particular order it shows pending status.

can you please guide me so I can implement in correct way and I can enable the Full payment and partial payment with Square API endpoint for the Afterpay.