【问题标题】:How to pass the user enter amount value to the paypal如何将用户输入的金额值传递给贝宝
【发布时间】:2012-09-25 04:15:36
【问题描述】:

您好,我在用 php 编写的网站有问题。我正在尝试让 Paypal 接受用户输入的金额。但在重定向到 paypal 时它不接受,金额为空白。这可能吗?

这是我的表格

        <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 found\n";
}
if (!file_exists($MY_CERT_FILE)) {
    echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
}
if (!file_exists($PAYPAL_CERT_FILE)) {
    echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
}

$data = "";
foreach ($hash as $key => $value) {
    if ($value != "") {
        //echo "Adding to blob: $key=$value\n";
        $data .= "$key=$value\n";
    }
}

$openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
                    "-outform der -nodetach -binary <<_EOF_\n$data\n_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";
}
     }
   ?>   

【问题讨论】:

    标签: php paypal paypal-ipn paypal-sandbox


    【解决方案1】:

    您只需跳过amount 字段或其在表单中的值。

    <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="me@mybusiness.com">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="Teddy Bear">
    <input type="hidden" name="amount" value="">
    <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
    

    这将要求您的用户输入金额!

    【讨论】:

    • 当我在“金额”字段中输入一个值时,它会转移到贝宝屏幕,但金额字段为空白。
    • 如果有人从客户端更改金额怎么办?如果是这样,我们应该在哪里验证金额是否等于预定义的金额?
    • paypal 将在您的 IPN URL 中向您发送付款通知以及支付的金额。然后您可以验证该金额是否已全部或部分支付。
    猜你喜欢
    • 2021-04-06
    • 2012-09-08
    • 2017-11-28
    • 2019-09-07
    • 2015-02-21
    • 2020-04-04
    • 2018-02-08
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多