Help with some Javascript PayPal related.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smack dat
    So Fucking Banned
    • Jul 2016
    • 4613

    #1

    Tech Help with some Javascript PayPal related.

    I accept PayPal on my website and I would like to provide a coupon code for certain persons. As I understand it PayPal don't offer this directly through their website but it is possible.

    I found this website https://www.paypal-knowledge.com/inf...1512&actp=LIST

    Which says you can add the following code into the custom field (on PayPal)
    Code:
    <script type="text/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;
    }
    //-->
    </script>
    It then say you would add the following code to your website
    Code:
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
    return ReadForm (this);">
    <input type="hidden" name="cmd" value="_cart" />
    <input type="hidden" name="add" value="1" />
    <input type="hidden" name="business" value="your_email_goes_here@your_site.com" />
    <input type="hidden" name="item_name" value="2nd Item" />
    <input type="hidden" name="amount" value="20.00" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="baseamt" value="20.00" />
    <input type="hidden" name="basedes" value="2nd Item @20.00" />
    
    Enter Coupon code [coup1] &gt;
    <input type = "text"
    size = "10"
    name = "coupcode"; />
    
    <input type="button" value="Check It"
    onclick="coupval = this.form.coupcode.value;
    ChkCoup();" />
    
    Input quantity &gt;
    <input type="text" name="quantity" value="1" size="4" />
    
    <input type="image" src="addcart.gif" name="submit" alt="cart add" />
    </form>
    I haven't tried this but just need a simple "Pay Now" button that offers people the chance to input a code into a text field for a discount to be applied.
    I tried the code in an online HTM viewer and it looked naff.

    Anyone tell me if this is at all suitable for 2017 or can give me a better suggestion / code.
    Last edited by Smack dat; 07-14-2017, 02:16 PM. Reason: Changed from business to Tech for moar VIEWS!!!!!!!!!!!!
Working...