0

我希望在此 Paypal 按钮上添加折扣代码,但不知道如何去做。任何人都可以提供帮助或建议如何,我只需要它,以便客户可以输入代码并获得 10% 的价格折扣

下面是按钮的代码

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Please click on the link to pay</p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?php echo C_OUR_EMAIL; ?>" />
<input type="hidden" name="first_name" value="<?php echo   strfordisp($ofirstname); ?>" />
<input type="hidden" name="last_name" value="<?php echo strfordisp($olastname); ?>" />
<input type="hidden" name="address1" value="<?php echo strfordisp($theorder["oaddress"]); ?>" />
<input type="hidden" name="address2" value="<?php echo strfordisp($theorder["oaddress2"]); ?>" />
<input type="hidden" name="address3" value="<?php echo strfordisp($theorder["oaddress3"]); ?>" />
<input type="hidden" name="city" value="<?php echo strfordisp($theorder["otown"]); ?>">
<input type="hidden" name="zip" value="<?php echo strfordisp($theorder["opostcode"]); ?>" />
<?php $orderdets = mysql_query("select * from c4d_orderitems where orderid='" . $_SESSION["db_order"] . "' and confirm");
$iloop = 1;
while ($orderrow = mysql_fetch_array($orderdets))
{
$itemdesc = $orderrow["itemtypedesc"];
$itemdesc .= " to " . $orderrow["dpostcode"];
$itemprice = $orderrow["cost"] + $orderrow["surcharge"] +     $orderrow["insurancecost"];
?>
<input type='hidden' name="item_name_<?php echo $iloop; ?>" value='<?php   echo strfordisp($itemdesc); ?>' />
<input type='hidden' name="item_number_<?php echo $iloop; ?>" value='<?php echo $orderrow["itemtype"]; ?>' />
<input type='hidden' name="amount_<?php echo $iloop; ?>" value='<?php
  // pctrends
  if ((strtoupper($ofirstname)=="PCTRENDSTEST") ||   (strtoupper($olastname)=="PCTRENDSTEST") || (substr($_SERVER['REMOTE_ADDR'],0,11)=="82.152.55.1"))
echo("0.01");
else echo $itemprice;
?>' />
<input type='hidden' name="quantity_<?php echo $iloop; ?>" value='1' />

<?
    $iloop++;
}
?>
<input type="hidden" name="return" value="<?php echo C_SITE_ROOT; ?>stage7.php" />
<input type="hidden" name="cancel-return" value="<?php echo C_SITE_ROOT; ?>order-cancel.php" />
<input type="hidden" name="notify_url" value="<?php echo C_SITE_ROOT; ?>paypal.php" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="invoice" value="<?php echo $_SESSION["db_order"]; ?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="no-shipping" value="1" />
<input type="hidden" name="button_subtype" value="products" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input type="hidden" name="country" value="GB" />
<p class='fmenu'><input type="image" src="https://www.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.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
</form>
4

1 回答 1

0

在发送付款通知之前,您必须检查折扣代码的有效性(带有AJAX)并进行适当的计算以将折扣应用于amount变量(带有JavaScript) 。

用户在变量中写入折扣代码,您可以在其中存储您想要的任何内容以用于您自己的跟踪目的。custom

// Check here on keypress with JS and AJAX for discount code validity
<input type="text" name="custom" value="" />

如果折扣代码得到验证,则将折扣应用于amount变量。像这样的东西:

//  Javascript and jQuery
if(verified == true) {
    var discounted = $("[name='amount']").val() - ($("[name='amount']").val()/100)*10);
    $("[name='amount']").val(discounted);
}
else {
    alert("Discount code not found");
}

然后,当您发送付款并从贝宝(IPN 响应)获取信息时,如下处理:

$discountCode = $_POST["custom"];
// ... Discount-code validity check ...
$discountedAmount = $originalAmount - (($originalAmount/100)*10);
// And then check if the paid amount corresponds to the due amount
if($discountedAmount == $_POST["amount"])
于 2015-07-20T11:02:56.880 回答