2015-07-20 82 views
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> 

回答

0

您必須檢查折扣代碼有效期(與AJAX),並進行適當的計算,以將折扣應用於amount變量(與JavaScript之前發送付款通知。

用戶編寫折扣代碼確定custom variable您可以在其中存儲任何您想要用於自己的跟蹤目的。

// 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"); 
} 

然後,當你發送付款,並讓來自PayPal的信息(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"]) 
+0

好感謝,我會嘗試了這一點 –

+1

我希望我很有幫助和清楚,讓我知道它是否適合你 –

+0

是否可以添加一個提交按鈕? –

相關問題