Paypal 快速结账优惠券代码

发布于 2024-10-19 05:24:32 字数 145 浏览 4 评论 0原文

我在我的网站上使用 Paypal Express Checkout 系统。但我想放一个优惠券(折扣)代码区域。如果代码为真,则会减少。 (就像 GoDaddy.com 的购物车系统)

您知道我应该从哪里开始吗?

(我没有使用任何电子商务框架)

I'm using Paypal Express Checkout system on my website. But I want to put a coupon (discount) code area. It will make a reduction if code is true. (Like GoDaddy.com's cart system)

Have you any idea, where should I start for this?

(I'm not using any eCommerce framework)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮是我掰弯的 2024-10-26 05:24:32

我知道这是一个旧线程,但想将我的经验放在这里,供其他人寻找相同的东西,也许这在当时不适用,但现在确实适用,至少在沙箱上,这意味着我还没有在实际交易中测试过这一点

添加发送到 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_A MT1 = 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

我认为贝宝所做的是广告所有项目总计,所以它可以做到这一点订购类似

1.00+1.00-0.50 = 1.50

然后将其与您的总金额进行比较

,如果匹配则可以,客户将其视为额外项目,但显然带有减号,下图来自 paypal 沙箱快速结帐交易

带优惠券代码的 Paypal 快速结帐交易

I know this is an old thread but wanted to put here my experience for others looking for the same thing, and maybe this did not apply then but it does apply now, at least on the sandbox meaning I have not tested this in a real transaction

When adding items that you send to paypal you basically send this

L_PAYMENTREQUEST_0_QTY0 = 1

L_PAYMENTREQUEST_0_AMT0 = 1.00

L_PAYMENTREQUEST_0_NAME0 = my item 0 name

L_PAYMENTREQUEST_0_NUMBER0 = myitem0id

Then we add another item

L_PAYMENTREQUEST_0_QTY1 = 1

L_PAYMENTREQUEST_0_AMT1 = 1.00

L_PAYMENTREQUEST_0_NAME1 = my item 1 name

L_PAYMENTREQUEST_0_NUMBER1 = myitem1id

And now we add the coupon

L_PAYMENTREQUEST_0_QTY2 = 1

L_PAYMENTREQUEST_0_AMT2 = -0.50

L_PAYMENTREQUEST_0_NAME2 = my coupon name

L_PAYMENTREQUEST_0_NUMBER2 = mycouponcode

And then we add the subtotal and total values

PAYMENTREQUEST_0_AMT = 1.50

AMT = 1.50

What I think paypal does is ads up all item totals so it would do for this order something like

1.00+1.00-0.50 = 1.50

Then compares it to your total amounts

if they match then it is a go, the customer sees this as an extra item, but obviously with the minus sign, this picture below is from a paypal sandbox express checkout transaction

Paypal express checkout transaction with coupon code

惜醉颜 2024-10-26 05:24:32

一种方法是在您的网站上设置购物车,用户可以在其中输入促销代码。一旦他们输入了促销代码并准备好开始结账流程,您就可以将他们重定向到快速结账(您可以在其中向 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 & 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");
               }

?>

One approach is to have a shopping cart on your site where the user can enter a promo code. Once they've entered their promo codes, and are ready to begin the checkout process, this is when you redirect them to the Express Checkout (where you send Paypal the final amount of your order, etc).

According to this post on Paypal forum, they do not have a feature to pass the discount details to the checkout process: https://www.x.com/thread/39681 ("With express checkout all discount calculations will need to be done on your site.")

How to calculate before sending price to paypal
1) Add a SEPARATE form for the promo code to your page:

<form method="GET">
    <input type="text" name="promocode"> 
    <input type="submit" value="Add Promo">
</form>

2) On the server side, check the code, update the page accordingly with new prices (e.g. re-build your select menu with new prices). Example with PHP:

<?
if(isset($_GET('promocode')) {
    $prices = processPromo($_GET('promocode'));
}
else {
    $prices = array(2000, 4000, 6000);
}
?>

If you don't have access to the server, you would have to do this with JavaScript I guess (i.e. have your promo-code and price hard-coded into the page)

To initiate express checkout on server side
Download PHP NVP SDK & examples from Paypal's website:
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");
               }

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文