You want the net expense of the surcharge minus the rewards to be no more than the interest that you would pay otherwise.
1 + (S - R)/100 <= (1 + t*D/100)^p
t is the compounding period for the rate
D expressed as a fraction of the overall period for
D. So if
D is an annual rate (not the APR, the simple rate), it would be expressed as something like
1/365 if compounded daily. That is the number of years in the compounding period. If a monthly rate or weekly compounding, that would change.
p is the number of such time periods in the grace period. So if the grace period were one month, this might be
Other variables are as used in the question, all expressed as percentages (which is why I'm dividing by 100). The
D rate should be the simple rate, like 6% not the APR of 6.24% or whatever.
Note that I'm saying
<=. When equal, there is no financial advantage or disadvantage. You could choose either method for the same cost. Now, one method may be more annoying to implement, in which case you might add a fee for it on one side or the other of the equation. Or simply change the less than or equal to be just less than.
I may be missing something that you should consider but I don't know. The problem is generic enough that pertinent details might be hidden. But hopefully this at least gives you a framework under which to consider it.