我在我的网站上使用Paypal Express Checkout系统。但我想放一张优惠券(折扣)代码区。如果代码为真,它将减少。 (像GoDaddy.com的推车系统一样)
您有什么想法,我应该从哪里开始?
(我没有使用任何电子商务框架)
答案 0 :(得分:9)
我知道这是一个老线程,但是想把这些我的经验放在其他人那里寻找相同的东西,也许这不适用于现在,但现在确实适用,至少在沙箱意味着我没有测试过这个真正的交易
添加您发送给PayPal的商品时,您基本上会发送此
L_PAYMENTREQUEST_0_QTY0 = 1
L_PAYMENTREQUEST_0_AMT0 = 1.00
L_PAYMENTREQUEST_0_NAME0 =我的项目0名称
L_PAYMENTREQUEST_0_NUMBER0 = myitem0id
然后我们添加另一个项目
L_PAYMENTREQUEST_0_QTY1 = 1
L_PAYMENTREQUEST_0_AMT1 = 1.00
L_PAYMENTREQUEST_0_NAME1 =我的第1项名称
L_PAYMENTREQUEST_0_NUMBER1 = myitem1id
现在我们添加优惠券
L_PAYMENTREQUEST_0_QTY2 = 1
L_PAYMENTREQUEST_0_AMT2 = -0.50
L_PAYMENTREQUEST_0_NAME2 =我的优惠券名称
L_PAYMENTREQUEST_0_NUMBER2 = mycouponcode
然后我们添加小计和总值
PAYMENTREQUEST_0_AMT = 1.50
AMT = 1.50
我认为paypal所做的是广告所有项目总计,所以它会为这个订单做点像
1.00 + 1.00-0.50 = 1.50
然后将其与总金额进行比较
如果匹配那么它就是一个去,客户认为这是一个额外的项目,但显然有减号,这张图片来自paypal沙盒快递结账交易
答案 1 :(得分:4)
一种方法是在您的网站上安装购物车,用户可以在其中输入促销代码。一旦他们输入了促销代码,并准备好开始结账流程,这就是您将它们重定向到Express Checkout(您向Paypal发送订单的最终金额等)。
根据Paypal论坛上的这篇文章,他们没有将折扣详情传递给结账流程的功能:https://www.x.com/thread/39681(“快速结账需要在您的网站上完成所有折扣计算。” )
如何在向paypal发送价格之前计算
1)为您的页面添加促销代码的单独表格:
<form method="GET">
<input type="text" name="promocode">
<input type="submit" value="Add Promo">
</form>
2)在服务器端,检查代码,使用新价格相应地更新页面(例如,使用新价格重新构建选择菜单)。 PHP示例:
<?
if(isset($_GET('promocode')) {
$prices = processPromo($_GET('promocode'));
}
else {
$prices = array(2000, 4000, 6000);
}
?>
如果您无法访问服务器,我必须使用JavaScript进行此操作(即将您的促销代码和价格硬编码到页面中)
在服务器端启动快速结帐
下载PHP NVP SDK&amp; Paypal网站上的例子:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdks
<?php
require_once 'CallerService.php';
session_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
/* Gather the information to make the final call to
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
$token =urlencode( $_SESSION['token']);
$paymentAmount =urlencode ($_SESSION['TotalAmount']);
$paymentType = urlencode($_SESSION['paymentType']);
$currCodeType = urlencode($_SESSION['currCodeType']);
$payerID = urlencode($_SESSION['payer_id']);
$serverName = urlencode($_SERVER['SERVER_NAME']);
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName ;
/* Make the call to PayPal to finalize payment
If an error occured, show the resulting errors
*/
$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
if($ack != 'SUCCESS' && $ack != 'SUCCESSWITHWARNING'){
$_SESSION['reshash']=$resArray;
$location = "APIError.php";
header("Location: $location");
}
?>
答案 2 :(得分:3)
以下是我用于为PayPal按钮创建折扣券的方法:
将此代码用于您的按钮:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal'; return ReadForm (this);">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="YOUR MERCHANT ACCOUNT ID NUMBER HERE" />
<input type="hidden" name="item_name" value="10 sessions" />
<input type="hidden" name="amount" value="773.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="baseamt" value="773.00" />
<input type="hidden" name="basedes" value="10 sessions" />
Enter Coupon code
<input type = "text" size = "10" name = "coupcode"; />
<input type="button" value="Check code" onclick="coupval =this.form.coupcode.value; ChkCoup();" /><br/><br/>
<input type="image" id="xx" disabled="disabled" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="CalculateOrder(this.form)" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
创建一个Javascript文件并将此代码复制并粘贴到其中:
<!-- var discnt = 0; // no default percent discount var coupons = new Array ( // place to put coupon codes "coup1", // 1st coupon value - comma seperated "coup2", // 2nd coupon value - add all you want "coup3" // 3rd coupon value ); var coupdc = new Array ( // place to put discounts for coupon vals 5, 10, 15 ); var coupval = "(blanket)"; // what user entered as coupon code function ChkCoup () { // check user coupon entry var i; discnt = 0; // assume the worst for (i=0; i<coupons.length; i++) { if (coupval == coupons[i]) { discnt = coupdc[i]; // remember the discount amt alert ("Valid coupon number! \n\n" + discnt + "% discount now in effect."); return; } } alert ("'" + coupval + "' is not a valid code!"); } function Dollar (val) { // force to valid dollar amount var str,pos,rnd=0; if (val < .995) rnd = 1; // for old Netscape browsers str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape pos = str.indexOf ("."); if (pos > 0) str = str.substring (rnd, pos + 3); return str; } function ReadForm (obj1) { // apply the discount var amt,des; amt = obj1.baseamt.value*1.0; // base amount des = obj1.basedes.value; // base description if (discnt > 0) { // only if discount is active amt = Dollar (amt - (amt * discnt/100.0)); des = des + ", " + discnt + "% dis, COUP = " + coupval; } obj1.amount.value = Dollar (amt); obj1.item_name.value = des; } //-->
将文件保存为discount.js或任何您想要调用的文件并将其上传到您的服务器。然后通过将此行放在&lt;中来调用脚本。头&gt;您网站的一部分:
<script type="text/javascript" src="http://yourwebsite.com/discount.js"></script>
您可以在http://icode4you.net/how-to-create-a-coupon-discount-for-paypal-buttons阅读我在此主题上撰写的博客文章,详细了解如何指定折扣密码以及输入正确密码时应用的折扣金额,以及如何打包Javascript使您的密码更安全。