I'm not sure if this will help, but here's what I did. My backend is C#, but I'm using Accept.js and opaqueData in the front-end so Credit Cards numbers don't touch my server.
In my web site (asp.net MVC). If the transaction is settled, you need to do a refund and specify the refund amount. If it's not settled, you do a void. As a side note, it works the same for ACH too: Void and Debit.
Here's some of my c# code with my comment. I think it will help you:
/*
When issuing a credit card refund, the request must include either a full card number and expiration,
or previous transID and last 4 digits of the card number. If you don't have the last 4 digits,
you can use getTransactionDetails to get the payment object needed to issue a refund.
*/
var creditCard = new creditCardType
{
cardNumber = CCLast4Digits,
expirationDate = "XXXX"
};
Hope that helps!