Coupon Code for Paypal Express Checkout

I am using Paypal Express Checkout on my website. But I want to put a coupon (discount). This will reduce if the code is correct. (Like GoDaddy.com system)

Do you have any idea where to start?

(I do not use the framework of e-commerce)

+8
paypal express-checkout
source share
3 answers

One approach is to have a shopping cart on your site where the user can enter a promotional code. After they have entered their promo codes and are ready to start the registration process, this is when you redirect them to an express order (where you send Paypal the final amount of your order, etc.).

According to this post on the Paypal forum, they donโ€™t have the opportunity to transfer discount data to the checkout process: https://www.x.com/thread/39681 (โ€œWith express verification, all discount calculations must be performed on your websiteโ€ .)

How to calculate before sending paypal prices
1) Add a SEPARATE form for a 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, refresh the page accordingly with the new prices (for example, rebuild your selection menu with the new prices). PHP example:

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

If you do not have access to the server, you should do it using JavaScript, I think (i.e. your promo code and price are hardcoded on the page)

To initiate express server-side validation
Download the PHP NVP SDK and examples from the Paypal 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"); } ?> 
+4
source share

I know this is an old thread, but I would like to put my experience here for others looking for the same, and maybe this does not apply then, but it applies now, at least in the sandbox, that I have not tested it in real transaction

When you add the items 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 add another element

L_PAYMENTREQUEST_0_QTY1 = 1

L_PAYMENTREQUEST_0_AMT1 = 1.00

L_PAYMENTREQUEST_0_NAME1 = name of my item 1

L_PAYMENTREQUEST_0_NUMBER1 = myitem1id

Now add a 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 add the subtotals and totals

PAYMENTREQUEST_0_AMT = 1.50

AMT = 1.50

What I think Paypal does is announcements for all amounts of items so that it does something like

1.00 + 1.00-0.50 = 1.50

Then compares it with your amounts

if they match, it means that the client sees this as an additional element, but obviously with a minus sign, this is the image below from the paypal sandbox express check transaction

Paypal express checkout transaction with coupon code

+9
source share

Here is the method I use to create discount coupons for PayPal buttons:

Use this code for your button:

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

Create a Javascript file and copy and paste this code into it:

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

Save the file as discount.js or whatever you want it to be called and uploaded to your server. Then call the script by placing this line in the <head> of your site:

 <script type="text/javascript" src="http://yourwebsite.com/discount.js"></script> 

You can read the blog post I wrote on this topic at http://icode4you.net/how-to-create-a-coupon-discount-for-paypal-buttons for more information on how to indicate your discount passwords and discount amounts that apply when the correct password is entered, as well as how to pack Javascript to make your passwords more secure.

+3
source share

All Articles