【问题标题】:paypal custom amount variable BMUpdate?贝宝自定义金额变量BMUpdate?
【发布时间】:2012-06-29 18:37:38
【问题描述】:

这是为我的沙盒“立即购买”按钮生成的代码。我添加了另一个隐藏输入 amount,它将包含一个变量,其中包含要发送到贝宝的总金额(我的网站上没有设定价格)。

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" id="paypal-container-2" method="post">
            <input type="hidden" name="cmd" value="_s-xclick">
            <input type="hidden" name="hosted_button_id" value="EJWG97W7YUN4G">
            <input type="hidden" name="amount" value="<?php echo $total; ?>" />
            <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
            <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
            </form>

通过阅读类似的问题 can't POST item price in paypal sandbox ,这种方式使隐藏的输入 amount 对用户开放?答案是使用 BMUpdateButton API 来更新按钮数量。我不知道如何在 PHP 中实现 BMUpdateButton API。我如何用 PHP 完成这个?有教程吗?非常感谢任何帮助。

【问题讨论】:

    标签: php paypal sandbox


    【解决方案1】:

    以这种方式将付款金额作为输入(即使作为隐藏字段)是不安全的,并且可能导致黑客支付 0.1 英镑购买一件本应花费 +100 英镑的物品...并全额收到货物!

    我防止这种情况的方法是将您的“立即购买”付款按钮发布到处理页面。当用户同意购买商品时,应计算总数并将其存储在链接到唯一标识符的数据库中。处理页面将使用标识符从数据库中提取总金额并使用该值进行支付。验证付款数据(例如 business_email 和金额)后,用户将被重定向到 PayPal 以完成付款 - 支付未触及的金额。

    我希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      这里是基础,还需要其他功能解码

      function updateItemPP($buttoncode, $amount, $item_name)
      
      {
      
      $API_USERNAME ="yourname";
      
      $API_PASSWORD = "yourpassY";
      
      $API_SIGNATURE = "yoursig";
      
      $API_ENDPOINT = 'https://api-3t.paypal.com/nvp';
      
      $VERSION = '60.0';
      
      
      
      $ch=curl_init();
      
      
      
      curl_setopt($ch, CURLOPT_URL,$API_ENDPOINT);
      
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
      
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      
      curl_setopt($ch, CURLOPT_POST, 1);
      
      $nvpreq="USER=".urlencode($API_USERNAME)."&PWD=".urlencode($API_PASSWORD)."&SIGNATURE=".urlencode($API_SIGNATURE)."&VERSION=".urlencode($VERSION)."&METHOD=BMCreateButton&HOSTEDBUTTONID=".urlencode($buttoncode)."&BUTTONTYPE=BUYNOW&L_BUTTONVAR1=amount=".urlencode($amount)."&L_BUTTONVAR2=item_name=".urlencode($item_name);
      
      echo "here is the request string:\n".$nvpreq;
      
      curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
      
      $response = curl_exec($ch);
      
      $response = urldecode($response);
      
      echo "this is update response".$response;
      
      $nvpResArray=$this->deformat($response);
      
      $ack = ($nvpResArray["ACK"]);
      
      $HostedButtonID=($nvpResArray["HOSTED_BUTTON_ID"]);
      
      if ($ack=="FAILOR")
      
      return "failor";
      
      else 
      
      return $HostedButtonID;
      
      }
      

      这个函数不是我写的,是其他用户写的

      static function deformat( $str )
          {
              $result = array();
      
              while ( strlen( $str ) ) {
                  // postion of key
      
                  $keyPos = strpos( $str, '=' );
      
                  // position of value
                  $valPos = strpos( $str, '&' ) ? strpos( $str, '&' ): strlen( $str );
      
                  /*getting the Key and Value values and storing in a Associative Array*/
                  $key = substr( $str, 0, $keyPos );
                  $val = substr( $str, $keyPos + 1, $valPos - $keyPos - 1 );
      
                  //decoding the respose
                  $result[ strtoupper( urldecode( $key ) ) ] = urldecode( $val );
                  $str = substr( $str, $valPos + 1, strlen( $str ) );
                  //echo  substr( $str, $valPos + 1, strlen( $str ) );
              }
      
      
              return $result;
          }
      

      这应该会有所帮助,但它也会返回一个新的按钮代码,因此请务必将其包含在页面上的按钮调用中

      【讨论】:

        猜你喜欢
        • 2020-01-06
        • 2014-03-08
        • 2011-09-28
        • 1970-01-01
        • 2019-06-08
        • 2011-09-15
        • 2018-10-18
        • 2013-05-07
        • 2010-12-22
        相关资源
        最近更新 更多