我希望PayPal接受用户输入金额。但它在重定向到PayPal金额时不接受 blank.is 可以使用非托管加密按钮动态覆盖金额。任何人都可以帮忙吗。我很无奈
这是我的表格
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target=_blank>
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="<?PHP echo $encrypted; ?>">
<div class="paypal_list2">
<input type="hidden"><h3>Enter the amount</h3><br /> </div>
<input id="total" class="paypal_input_1" type="text" value="" name="amount">
<input class="paypal_btn" type="image"src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
这是我的PHP代码
<?php
$MY_KEY_FILE = "/home/khader/smsmobilebase/certs/private-key.pem";
$MY_CERT_FILE = "/home/khader/smsmobilebase/certs/publi-cert.pem";
$PAYPAL_CERT_FILE = "/home/khader/smsmobilebase/certs/paypal_cert_pem.txt";
$OPENSSL = "/usr/bin/openssl";
$form = array('cmd' => '_xclick','business' => 'roki_1347003608_biz@gmail.com','cert_id' => '6BPQP9KEEBCJ6','currency_code' => 'USD',
'no_shipping' => '1',
'item_name' => 'PayNow',
'cancel_return' => 'http://mobiletool.xichlomobile.com/',
'amount' => "'$amount'"
);
$encrypted = paypal_encrypt($form);
function paypal_encrypt($hash)
{
global $MY_KEY_FILE;
global $MY_CERT_FILE;
global $PAYPAL_CERT_FILE;
global $OPENSSL;
if (!file_exists($MY_KEY_FILE)) {
echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not foundn";
}
if (!file_exists($MY_CERT_FILE)) {
echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not foundn";
}
if (!file_exists($PAYPAL_CERT_FILE)) {
echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not foundn";
}
$data = "";
foreach ($hash as $key => $value) {
if ($value != "") {
//echo "Adding to blob: $key=$valuen";
$data .= "$key=$valuen";
}
}
$openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
"-outform der -nodetach -binary <<_EOF_n$datan_EOF_n) | " .
"$OPENSSL smime -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE";
exec($openssl_cmd, $output, $error);
if (!$error) {
return implode("n",$output);
print $hash;
} else {
return "ERROR: encryption failed";
}
}
?>
每次
用户更改amount
时,都可以使用 Ajax 调用来更新encrypted
字段.使用像jQuery这样的库来做到这一点很容易:
$('input[name=amount]').change( function () {
$.ajax({
url: "http://mydomain.com/encrypter.php",
type: "POST",
data: { amount: $('input[name=amount]').val() }
}).done(function ( data ) {
$('input[name=enctypted]').val(data);
});
});