下午好,我设法解决了这个问题。我已经修改了我的职能。php访问以下内容。
function mcPaySubmit(){
global $wpdb;
include(\'paygate.php\');
$last = wp_get_recent_posts(array(\'numberposts\' => \'1\', \'post_type\' => \'post\', \'post_status\' => \'pending\', \'author\' => $user_id));
$purchase_post_id = $last[\'0\'][\'ID\'];
$purchase_days = $_POST[\'dext\'];
$purchase_date = $_POST[\'mcTransactionDate\'];
$purchase_amount = $_POST[\'totalDue\'];
if($wpdb->insert(\'ac_purchases\', array(
\'purchase_post_id\' => $purchase_post_id,
\'purchase_days\' => $purchase_days,
\'purchase_date\' => $purchase_date,
\'purchase_amount\' => $purchase_amount,
\'purchase_status\' => \'pending\'
))===FALSE) {
echo "ERROR";
} else {
$reference = $wpdb -> insert_id;
$amount = str_replace(\'.\',\'\',$purchase_amount);
$checksum_source = $PAYGATE_ID."|".$reference."|".$amount."|".$CURRENCY."|".$RETURN_URL."|".$purchase_date."|".$EMAIL."|".$encryption_key;
$CHECKSUM = md5($checksum_source);
$response = array(\'AMOUNT\' => $amount, \'TRANSACTION_DATE\' => $purchase_date, \'REFERENCE\' => $reference, \'CHECKSUM\' => $CHECKSUM, \'PAYGATE_ID\' => $PAYGATE_ID, \'CURRENCY\' => $CURRENCY, \'RETURN_URL\' => $RETURN_URL, \'EMAIL\' => $EMAIL);
echo json_encode($response);
}
wp_die();
}
add_action(\'wp_ajax_mcPaySubmit\', \'mcPaySubmit\');
add_action(\'wp_ajax_nopriv_mcPaySubmit\', \'mcPaySubmit\');
我的表格:
<script>
function payCalc(){
var dext = document.getElementById("dext").value;
var sumDext = document.getElementById("sumDext").value = Math.round(24.99 * dext * 100)/100;
var totalDue = document.getElementById("totalDue").value = Math.round((sumDext + 79.99) * 100)/100;
}
</script>
<form method="POST" id="mcPayment" name="mcPayment" action="https://www.paygate.co.za/paywebv2/process.trans">
<table>
<tr>
<td colspan="3"><b>Please note that the amounts are quoted in South African Rands (ZAR)</b></td>
</tr>
<tr>
<td colspan="2"><label for="mcPublish"><b>Publish for 3 Days</b></label></td>
<td><input type="text" id="mcPublish" name="mcPublish" readonly value="79.99" /></td>
</tr>
<tr>
<td><label for="daysToExtend" /><b>Number of Days to Extend</b></label></td>
<td><input type="number" id="dext" oninput="payCalc()" name="dext" min="0" value="1" /></td>
<td><input type="text" id="sumDext" name="sumDext" readonly value="24.99" /></td>
</tr>
<tr>
<td colspan="2"><label for="totalDue"><b>Total Due<b></label>
<td><input type="text" id="totalDue" name="totalDue" readonly value="104.98" /></td>
</tr>
<tr>
<td><input type="hidden" id="mcTransactionDate" name="mcTransactionDate" value="<?=$TRANSACTION_DATE?>"></td>
<td><input type="hidden" id="my-hidden-field" name="my-hidden-field" value="this is hidden" />
</tr>
<tr>
<td><input type="hidden" name="action" value="mcPaySubmit" /></td>
<td><input type="submit" id="mcPaySubmit" name="mcPaySubmit" value="Proceed to Pay" /></td>
<td></td>
</tr>
<tr>
<td><input type="hidden" id="PAYGATE_ID" name="PAYGATE_ID" value="<?=$PAYGATE_ID?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="REFERENCE" name="REFERENCE" value="<?=$REFERENCE?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="AMOUNT" name="AMOUNT" value="<?=$AMOUNT?>") /></td>
</tr>
<tr>
<td><input type="hidden" id="CURRENCY" name="CURRENCY" value="<?=$CURRENCY?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="RETURN_URL" name="RETURN_URL" value="<?=$RETURN_URL?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="TRANSACTION_DATE" name="TRANSACTION_DATE" value="<?=$TRANSACTION_DATE?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="EMAIL" name="EMAIL" value="<?=$EMAIL?>" /></td>
</tr>
<tr>
<td><input type="hidden" id="CHECKSUM" name="CHECKSUM" value="<?=$CHECKSUM?>" /></td>
</tr>
</table>
</form>
还有这个的js。
$ = jQuery.noConflict();
$(document).ready(function() {
$(\'#mcPayment\').submit(submit_mcPayment);
});
function submit_mcPayment(){
$.ajax({
url: myAjax.ajaxurl,
type: "POST",
data: $(this).serialize(),
dataType: \'json\',
success: function mcPaymentSuccess(response) {
$(\'#AMOUNT\').val(response.AMOUNT);
$(\'#TRANSACTION_DATE\').val(response.TRANSACTION_DATE);
$(\'#REFERENCE\').val(response.REFERENCE);
$(\'#CHECKSUM\').val(response.CHECKSUM);
$(\'#PAYGATE_ID\').val(response.PAYGATE_ID);
$(\'#CURRENCY\').val(response.CURRENCY);
$(\'#RETURN_URL\').val(response.RETURN_URL);
$(\'#EMAIL\').val(response.EMAIL);
document.forms[\'mcPayment\'].submit();
}
});
return false;
}