PayPal Gutscheincode einfügen (Javascript)

07/21/2013 14:43 Sorrow91#1
Hallo,

ich habe auf meiner Seite den PayPal "Buy now" Button eingefügt.

Nun wollte ich noch ein Gutscheincodefeld hinzufügen, ich habe schon gegoogled, dort fand ich schon etwas ansatzweise brauchbares, aber leider komme ich nicht weiter.

Hier mein aktueller Code:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
 font-family: Arial;
 font-size: 12px;
 color:#FFFFFF;
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-position: left top;
	background-color: #02071b;
}
a img {
border: none;
}
</style>
<script type="text/javascript" src="scripts/discount.js"></script>
<script language="JavaScript" src="scripts/overlib.js" type="text/javascript"></script>
<title>PayPal</title>
</head>
<body>
<br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="[Only registered and activated users can see links. Click Here To Register...]">
<input type="hidden" name="lc" value="DE">
<input type="hidden" name="item_name" value="Referral Service 2.0">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="basedes" value="Referral Service 2.0">
<input type="hidden" name="bn" value="PP-BuyNowBF:paypal button.png:NonHostedGuest">
<table align="center">
<tr align="center">
<td align="center">
<input type="hidden" name="on0" value="Quantity">
<b>Quantity</b>
</td>
</tr>
<tr align="center">
<td align="center">
<select name="os0">
        <option value="10 Referrals">10 Referrals &euro;5,00 EUR</option>
        <option value="25 Referrals">25 Referrals &euro;10,00 EUR</option>
        <option value="50 Referrals">50 Referrals &euro;20,00 EUR</option>
        <option value="25 Referrals">75 Referrals &euro;30,00 EUR</option>
        <option value="100 Referrals">100 Referrals &euro;40,00 EUR</option>
        <option value="150 Referrals">150 Referrals &euro;50,00 EUR</option>
</select> 
</td>
</tr>
<tr align="center">
<td align="center">
<input type="hidden" name="on1" value="Referral-Link"><font size="2px"><br />
<b>Referral-Link</b></font>
</td>
</tr>
<tr align="center">
<td align="center"><input type="text" name="os1" maxlength="200">
</td>
</tr>
<tr align="center">
<td align="center">
<input type="hidden" name="on2" value="Emailadress/Skype"><font size="2px"><br />
<b>Email Adress or Skypename</b></font>
</td>
</tr>
<tr align="center">
<td align="center">
<input type="text" name="os2" maxlength="200">
</td>
</tr>
<tr align="center">
<td align="center">
<input type="hidden" name="on3" value="Friend"><font size="2px"><br />
<b>Friend advertising</b></font>&nbsp;<img src="Pictures/Information-icon.png" style="cursor:help" border="0" width="15" height="15" onmouseover="return overlib('If you buy 75 or more Referrals and you where recruided by a friend, typing here his name and he gets 10 Referrals for free!');" 
onmouseout="return nd();" />
</td>
</tr>
<tr align="center">
<td align="center">
<input type="text" name="os3" maxlength="200">
</td>
</tr>
<<tr align="center">
<td align="center">
<font size="2px"><br /><b>Couponcode</b></font>
</td>
</tr>
<tr align="center">
<td align="center">
<input type="text" size="20"  name="coupcode"; />
<br />
<input type="button" value="Check code" onclick="coupval =this.form.coupcode.value;  ChkCoup();" />
</td>
</tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="option_select0" value="10 Referrals">
<input type="hidden" name="option_amount0" value="5.00">
<input type="hidden" name="option_select1" value="25 Referrals">
<input type="hidden" name="option_amount1" value="10.00">
<input type="hidden" name="option_select2" value="50 Referrals">
<input type="hidden" name="option_amount2" value="20.00">
<input type="hidden" name="option_select3" value="75 Referrals">
<input type="hidden" name="option_amount3" value="30.00">
<input type="hidden" name="option_select4" value="100 Referrals">
<input type="hidden" name="option_amount4" value="40.00">
<input type="hidden" name="option_select5" value="150 Referrals">
<input type="hidden" name="option_amount5" value="50.00">
<input type="hidden" name="option_index" value="0">
<br>
<center>
<input onclick="self.close(); CalculateOrder(this.form)" name="submit" type="image" src="Pictures/paypal button.png" alt="PayPal" border="0" formtarget="_blank">
</center>
</form>
</body>
</html>
Und hier die discount.js Datei

HTML Code:
<!--
var discnt = 0;   // no default percent discount

var coupons = new Array (  // place to put coupon codes
  "gutschein10"
);
var coupdc  = new Array (  // place to put discounts for coupon vals
  10
);
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 ("This is a valid coupon code! \n\n" + "€" + discnt +
             " discount now in effect.");
      return;
    }
  }
  alert ("'" + coupval + "'  is not a valid coupon code!");
}

function Euro (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 = Euro (amt - (amt * discnt/100.0));
    des = des + ", " + "€" + discnt + "dis, COUP = " + coupval;
  }

  obj1.amount.value = Euro (amt);
  obj1.item_name.value = des;
}
//-->
Leider berechnet er mir nicht den richtigen Wert, ich denke das liegt daran dass ich dort ein Dropdownmenü zur Auswahl drin habe.

Und er zieht den Wert nicht richitg ab.
Also sagen wir ich kaufe 100 Stück für 40€ und gebe den Gutscheincode "gutschein10" ein, somit müssten 4€ eingespart werden.
Leider gibt er mir immer €10 aus...

Ich bitte um Hilfe und danke schonmal für die Mühe

Grüße

Sorrow91
07/21/2013 14:56 MrPuschel#2
Vermutlich wird immer ein Coupon mit dem Wert 100 gewählt. Überprüf ob du deine Coupons in dem Abschnitt wo du sie definierst, richtig eingetragen hast.
07/21/2013 18:50 Sorrow91#3
Quote:
Originally Posted by MrPuschel View Post
Vermutlich wird immer ein Coupon mit dem Wert 100 gewählt. Überprüf ob du deine Coupons in dem Abschnitt wo du sie definierst, richtig eingetragen hast.
Hey, erstmal danke für die Antwort.

Leider kenne ich mich nicht so gut aus, habe mir das ganze "ergoogled"...
Meinst du du könntest mich bei Skype adden und einmal über das ganze drüber schauen? :)

Skype: Sorrow_1991
07/21/2013 20:16 tolio#4
javascript ist feindesland, da willst du nen rabatt berechnen?
07/21/2013 20:27 Sorrow91#5
Quote:
Originally Posted by tolio View Post
javascript ist feindesland, da willst du nen rabatt berechnen?
Also wenn es eine andere Möglichkeit gibt das ganze mit dem "Buy now" button von Paypal zu machen bin ich offen für alles :)
07/21/2013 22:13 MrPuschel#6
Quote:
Originally Posted by tolio View Post
javascript ist feindesland, da willst du nen rabatt berechnen?
Er ermittelt nur welcher Gutschein eingegeben wurde und gibt dem Nutzer zurück was er zu erwarten hat. Die Validierung macht PayPal.

Ich denke aber du solltest es wirklich lassen wenn du Gutscheine benutzen möchtest aber noch nicht einmal darüber nachgedacht hast wie die Gutscheine heißen und wo sie definiert sind. ;)
07/21/2013 23:00 tolio#7
naja gut wenns nur anzeige ist dann isses wayne, aber dann ist es ja auch kein problem das grad anzuzeigen
07/22/2013 00:06 Sorrow91#8
Alo er ermittelt und übergibt Paypal nur nicht die richtigen Werte, wenn mir einer von euch evlt helfen könnte oder den verbesserten Code mir hier posten könne ;)
07/25/2013 22:18 Sorrow91#9
#Push

Habe bei Paypal noch eine input Funktion namens discount_rate gefunden

Hier ist eine Beschreibung von Paypal:


Nur da ich nicht über die Kenntnisse verfüge das ganze mit dem oben angegeben Code umzusetzen, frage ich hier. :)

Kennt jemand die Lösung?

Kann mich gerne bei Skype adde: sorrow_1991