Coupon Code For Paypal Express Checkout
Asked Answered
K

2

9

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)

Kashmir answered 27/2, 2011 at 15:49 Comment(0)
S
4

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

?>
Sfumato answered 27/2, 2011 at 15:55 Comment(9)
Can you elaborate on what you mean by "migrate"?Sfumato
(Answer EDITED) ok, i can calculate this discounts on my site and then send this price to paypal . But how can i integrate this ? Paypal's BUY NOW button code isn't dynamic . This is an example : jsfiddle.net/teknoblogo/bPR8QKashmir
I updated my answer to explain how you could do this. Hope that helps!Sfumato
Thank you but you misunderstood me :) I can calculate new (discounted) price . There isn't problem in here. But i don't know how can i send to paypal new price.Kashmir
Ah, gotcha. In the past, I've done this via server side, using Paypal's API. I'll add some more details to my postSfumato
I'm waiting thank you. Recently, i'm using this method : jsfiddle.net/teknoblogo/bPR8QKashmir
Okay, updated sample.. you'll have to clean up the code a bit, and customize to what you're doing, but hopefully you get the ideaSfumato
thank you dolan. Lastly, can you say which files must be included to page for Paypal API ?Kashmir
I couldn't find the library I used, so instead updated my post to have a sample from Paypal's site, with instructions on where to download. Good luckSfumato
E
9

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

Eniwetok answered 14/2, 2013 at 12:2 Comment(0)
S
4

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

?>
Sfumato answered 27/2, 2011 at 15:55 Comment(9)
Can you elaborate on what you mean by "migrate"?Sfumato
(Answer EDITED) ok, i can calculate this discounts on my site and then send this price to paypal . But how can i integrate this ? Paypal's BUY NOW button code isn't dynamic . This is an example : jsfiddle.net/teknoblogo/bPR8QKashmir
I updated my answer to explain how you could do this. Hope that helps!Sfumato
Thank you but you misunderstood me :) I can calculate new (discounted) price . There isn't problem in here. But i don't know how can i send to paypal new price.Kashmir
Ah, gotcha. In the past, I've done this via server side, using Paypal's API. I'll add some more details to my postSfumato
I'm waiting thank you. Recently, i'm using this method : jsfiddle.net/teknoblogo/bPR8QKashmir
Okay, updated sample.. you'll have to clean up the code a bit, and customize to what you're doing, but hopefully you get the ideaSfumato
thank you dolan. Lastly, can you say which files must be included to page for Paypal API ?Kashmir
I couldn't find the library I used, so instead updated my post to have a sample from Paypal's site, with instructions on where to download. Good luckSfumato

© 2022 - 2024 — McMap. All rights reserved.