I have a payment gateway that generates a script to allow for recurring payments, however it lacks a personal touch that I wish to add. The script has 3 values it works with, amount, *recurring_amount *and custom_quantity. In the initial code they supply, they only multiply the *amount *and *custom_quantity *when the page is submitted to the payment gateway, however, I needed the *recurring_amount *also to be multiplied by the custom_quantity
Thank you in advance for your assistance.
<script type="text/javascript">
function customQuantitiesPayFast (formReference) {
formReference['amount'].value = formReference['amount'].value * formReference['custom_quantity'].value;
formReference['recurring_amount'].value = formReference['recurring_amount'].value * formReference['custom_quantity'].value;
return true;
}
</script>
<script type="text/javascript">
function actionPayFastJavascript ( formReference ) {
let shippingValidOrOff = typeof shippingValid !== 'undefined' ? shippingValid : true;
let customValid = shippingValidOrOff ? customQuantitiesPayFast( formReference ) : false;
if (typeof shippingValid !== 'undefined' && !shippingValid) {
return false;
}
if (typeof customValid !== 'undefined' && !customValid) {
return false;
}
return true;
}
</script>
<form onsubmit="return actionPayFastJavascript( this );" name="PayFastPayNowForm" action="https://payment.payfast.io/eng/process" method="post" target="blank">
<table>
<tr style="height:1px">
<td><input required type="hidden" name="cmd" value="_paynow"></td>
<td><input required type="hidden" name="receiver" pattern="[0-9]" value="[censored]"></td>
<td><input type="hidden" name="return_url" value="[censored]"></td>
<td><input type="hidden" name="cancel_url" value="[censored]"></td>
<td><input type="hidden" name="notify_url" value="[censored]"></td>
<td><input required type="hidden" name="amount" value="700"></td>
</tr>
<tr>
<td><label for="custom_quantity">Quantity: </label></td>
<td><input required id="custom_quantity" type="number" name="custom_quantity" value="1"></td>
</tr>
</table>
<table>
<tr style="height:1px">
<td><input required type="hidden" name="item_name" maxlength="255" value="[censored]"></td>
<td><input required type="hidden" name="subscription_type" pattern="1"value="1"></td>
<td><input type="hidden" name="recurring_amount" value="400"></td>
<td><input required type="hidden" name="cycles" pattern="[0-9]" value="0"></td>
<td><input required type="hidden" name="frequency" pattern="[0-9]" value="3"></td>
</tr>
<tr>
<td colspan=5 align=center>
<input type="image" src="[censored]" alt="Subscribe" title="Subscribe with Payfast">
</td>
</tr>
</table>
</form>
I found another post with a similar scenario, however theirs works again when the browser is restarted, mine does not have the same effect.
Upon first edit, it works! Yay, but after a number of uses, it doesn’t. I paste a backed up version of the code that worked, but then the incorrect values are populated at the payment gateway, as if no calculations were done on either 2 calculations.