php - paypal 自定义金额变量 BMUpdate?

标签 php paypal sandbox

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

<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 来更新按钮数量。我不知道如何将 BMUpdateButton API 实现到 PHP 中。我如何使用 PHP 完成此操作?有教程吗?非常感谢任何帮助。

最佳答案

这里是基础知识 lol 还需要其他功能 decode

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;
    }

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

关于php - paypal 自定义金额变量 BMUpdate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11241304/

相关文章:

php - PayPal IPN 帐户跟踪,它是如何完成的?

testing - Xcode Simulator:如何获取设置 “Screen time”?

php - 使用 ffmpeg 命令将 avi 转换为 mp4、webm 和 flv

javascript - 目标 ="_blank"不打开新选项卡

javascript - Paypal 不接受 angularjs 中的 FORM

Paypal payflow pro notifyurl

google-chrome-extension - 从内容脚本访问窗口变量

macos - 文件包的文档范围、安全范围书签

php - PHP 和 Mysql 多语言

php - Laravel map 继续