{"_id":"5632a5ec49e16d0d001224c9","version":{"_id":"5632a5e549e16d0d00122443","__v":6,"project":"55b933b3146ef121002158d3","createdAt":"2015-10-29T23:04:05.701Z","releaseDate":"2015-10-29T23:04:05.701Z","categories":["5632a5e749e16d0d00122444","5632a5e749e16d0d00122445","5632a5e749e16d0d00122446","5632a5e749e16d0d00122447","5632a5e749e16d0d00122448","5632a5e749e16d0d00122449","5632a5e749e16d0d0012244a","5632a5e749e16d0d0012244b","5632a5e749e16d0d0012244c","5632a5e749e16d0d0012244d","5632a5e749e16d0d0012244e","5632a5e749e16d0d0012244f","5632a5e749e16d0d00122450","5632b179df556c0d00cd095b","564e13053b2b4a19000cd69b","59caa9df65accc001a489c95","59cab50965accc001a489d28","59cadd464ab7b70024378e74"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.1.0","version":"1.1"},"user":"55b932ba8fd1a02b00f496c8","githubsync":"","__v":0,"category":{"_id":"5632a5e749e16d0d00122444","pages":["5632a5ec49e16d0d001224bd","5632a5ec49e16d0d001224be","5632a5ec49e16d0d001224bf","5632a5ec49e16d0d001224c0","5632a5ec49e16d0d001224c1","5632a5ec49e16d0d001224c2","5632a5ec49e16d0d001224c3","5632a5ec49e16d0d001224c4","5632a5ec49e16d0d001224c5","5632a5ec49e16d0d001224c6","5632a5ec49e16d0d001224c7","5632a5ec49e16d0d001224c8","5632a5ec49e16d0d001224c9","5632a5ec49e16d0d001224ca","5632a5ec49e16d0d001224cb","5633bab59c607719001b86a1","5633bcbac49a7c19001fd0a6","5633befcc49a7c19001fd0a9","5633c585b904a10d0032f864","5633d7547b56ae0d0025a062","5633d7e87b56ae0d0025a066","5633d85435355017003ca3c8","5633da507e9e880d00af1a28","5633daa3fa71f30d00ba74ab","5633e1f87e9e880d00af1a3f","5633e323fa71f30d00ba74b9","5633e3aa7b56ae0d0025a072","5633e4c6737ea01700ea3276"],"project":"55b933b3146ef121002158d3","version":"5632a5e549e16d0d00122443","__v":14,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-31T23:12:47.262Z","from_sync":false,"order":0,"slug":"epayment-form","title":"ePayment Form"},"project":"55b933b3146ef121002158d3","parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-08-03T18:35:53.997Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":12,"body":"This is an example of how to add a discount code to the payment form. It assumes no other changes have been made to the payment form.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\nThe strategy is to validate the discount code that the customer enters into the form. If the discount code passes validation, we subtract the amount of discount from the total amount. We use UMdiscount variable for best integration with reports and other API calls.\n\nIn this example, the base amount is $20. The discount used is “discount” with a discount of $5.00.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Add Javascript\"\n}\n[/block]\nAdd the following code to the header:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script type=\\\"text/javascript\\\">\\n<!--\\n//updateTotal function used to update UMamount if parts of the form require an update to amount.\\n//In this case, if someone enters LA for UMbillstate after they enter quantity.\\nfunction updateTotal()\\n{\\nif (document.epayform.UMamount.value > 0)\\n       {\\n       calculateTotal();\\n       }\\n}\\nfunction calculateDiscount()\\n{\\nvar discountInput = document.epayform.DiscountCode.value;\\nvar discountindividual = 5.00;\\nvar discounttotal = 0;\\nvar discountmessage = \\\"\\\";\\nif (discountInput==\\\"discount\\\")\\n       {\\n       discounttotal=discountindividual;\\n       discountmessage = \\\"discount message\\\";\\n       }\\nelse if (discountInput != \\\"\\\")\\n       {\\n       discounttotal=0;\\n       discountmessage = \\\"Not a valid discount code\\\";\\n       }\\nelse\\n       {\\n       discounttotal=0;\\n       discountmessage = \\\"\\\";\\n       }\\ndocument.epayform.UMdiscount.value  = roundCurrency(discounttotal);        \\ndocument.getElementById('discountmessage').innerHTML = discountmessage;\\ncalculateTotal();\\n}\\nfunction calculateTotal()\\n{\\n/* eBizCharge API uses UMsubtotal, UMdiscount, UMshipping, UMtax as total amounts for the order.\\n UMamount = UMsubtotal + UMshipping - UMdiscount + UMtax\\n eBizCharge does not automatically calculate UMamount for us.\\n Instead of using a simmpler calculation\\n Qty * (Base Amount - Discount) * (1 + Tax) + Shipping = Amount,\\n we'll use eBizCharge variables to better tie in with it's API.\\n*/\\n//calculate subtotal\\nvar subtotal = document.epayform.UMsubtotal.value;\\nsubtotal = roundCurrency(subtotal);\\nvar discounttotal = document.epayform.UMdiscount.value;\\nif (discounttotal != 0)\\n       {\\n       document.getElementById('discount').innerHTML = \\\"$\\\" + currencyFormatted(discounttotal);\\n       }\\nvar total = subtotal - discounttotal;\\ntotal = roundCurrency(total);\\ndocument.epayform.UMamount.value = total ;\\ndocument.getElementById('totalamount').innerHTML = \\\"$\\\" + currencyFormatted(total) ;\\n}\\n//round Currency\\nfunction roundCurrency(amount)\\n{\\nvar i = Math.abs(amount);\\ni = Math.round  (i  * 100)/100;\\nreturn i;\\n}\\n//format Currency\\nfunction currencyFormatted(amount)\\n{\\nvar i = parseFloat(amount);\\nif(isNaN(i))\\n       {\\n       i = 0.00;\\n       }\\nvar minus = '';\\nif(i < 0)\\n       {\\n       minus = '-';\\n       }\\ni = Math.abs(i);\\ni = parseInt((i + .005) * 100);\\ni = i / 100;\\ns = new String(i);\\nif(s.indexOf('.') < 0)\\n       {\\n       s += '.00';\\n       }\\nif(s.indexOf('.') == (s.length - 2))\\n       {\\n       s += '0';\\n       }\\ns = minus + s;\\nreturn s;\\n}\\n//-->\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## Add HTML\nFind\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<body link=\\\"#000080\\\" vlink=\\\"#000080\\\" alink=\\\"#000080\\\" text=\\\"#000000\\\" bgcolor=\\\"#D4D7E4\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nand replace it with\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<body link=\\\"#000080\\\" vlink=\\\"#000080\\\" alink=\\\"#000080\\\" text=\\\"#000000\\\" bgcolor=\\\"#D4D7E4\\\" onload=\\\"calculateTotal()\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nFind the part of the form with the hidden inputs. It should look like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<input type=\\\"hidden\\\" name=\\\"UMsubmit\\\" value=\\\"1\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMkey\\\" value=\\\"[UMkey]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMredirDeclined\\\" value=\\\"[UMredirDeclined]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMredirApproved\\\" value=\\\"[UMredirApproved]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMhash\\\" value=\\\"[UMhash]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMcommand\\\" value=\\\"[UMcommand]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMamount\\\" value=\\\"[UMamount]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMtax\\\" value=\\\"[UMtax]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMinvoice\\\" value=\\\"[UMinvoice]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMcustid\\\" value=\\\"[UMcustid]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMrecurring\\\" value=\\\"[UMrecurring]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMaddcustomer\\\" value=\\\"[UMaddcustomer]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMbillamount\\\" value=\\\"[UMbillamount]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMcustreceipt\\\" value=\\\"[UMcustreceipt]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMschedule\\\" value=\\\"[UMschedule]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMnumleft\\\" value=\\\"[UMnumleft]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMstart\\\" value=\\\"[UMstart]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMexpire\\\" value=\\\"[UMexpire]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMdescription\\\" value=\\\"[UMdescription]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMechofields\\\" value=\\\"[UMechofields]\\\">\\n<input type=\\\"hidden\\\" name=\\\"UMformString\\\" value=\\\"[UMformString]\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nDelete:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<input type=\\\"hidden\\\" name=\\\"UMamount\\\" value=\\\"[UMamount]\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nAdd the following code below:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<input type=\\\"hidden\\\" name=\\\"UMdiscount\\\" value=\\\"[UMdiscount]\\\">\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nFind\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<tr>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"234\\\" align=\\\"right\\\"><font size=\\\"2\\\" face=\\\"Verdana\\\">Order Amount:</font></td>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"450\\\">[UMamount]\\n       </td>\\n</tr>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nand replace it with\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<tr>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"234\\\" align=\\\"right\\\"><font size=\\\"2\\\" face=\\\"Verdana\\\">Amount:</font></td>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"450\\\"><input type=\\\"hidden\\\" name=\\\"UMsubtotal\\\" value=\\\"20.00\\\" size=10>$20.00\\n       </td>\\n</tr>\\n<tr>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"234\\\" align=\\\"right\\\"><font size=\\\"2\\\" face=\\\"Verdana\\\">Enter Discount Code: </font></td>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"450\\\"><input type=\\\"text\\\" name=\\\"DiscountCode\\\" size=11 onChange=\\\"calculateDiscount()\\\"></input> <div id=\\\"discountmessage\\\">&nbsp;</div></td>\\n</tr>\\n<tr>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"234\\\" align=\\\"right\\\"><font size=\\\"2\\\" face=\\\"Verdana\\\">Discount:</font></td>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"450\\\"><div id=\\\"discount\\\">&nbsp;</div>\\n       </td>\\n</tr>\\n<tr>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"234\\\" align=\\\"right\\\"><font size=\\\"2\\\" face=\\\"Verdana\\\">Total Charge:</font></td>\\n       <td bgcolor=\\\"#F0F0F0\\\" width=\\\"450\\\"><input type=\\\"hidden\\\" name=\\\"UMamount\\\" value=\\\"[UMamount]\\\"><div id=\\\"totalamount\\\">&nbsp;</div>\\n       </td>\\n</tr>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"discount-code","type":"basic","title":"Discount Code"}
This is an example of how to add a discount code to the payment form. It assumes no other changes have been made to the payment form. [block:api-header] { "type": "basic", "title": "Overview" } [/block] The strategy is to validate the discount code that the customer enters into the form. If the discount code passes validation, we subtract the amount of discount from the total amount. We use UMdiscount variable for best integration with reports and other API calls. In this example, the base amount is $20. The discount used is “discount” with a discount of $5.00. [block:api-header] { "type": "basic", "title": "Add Javascript" } [/block] Add the following code to the header: [block:code] { "codes": [ { "code": "<script type=\"text/javascript\">\n<!--\n//updateTotal function used to update UMamount if parts of the form require an update to amount.\n//In this case, if someone enters LA for UMbillstate after they enter quantity.\nfunction updateTotal()\n{\nif (document.epayform.UMamount.value > 0)\n {\n calculateTotal();\n }\n}\nfunction calculateDiscount()\n{\nvar discountInput = document.epayform.DiscountCode.value;\nvar discountindividual = 5.00;\nvar discounttotal = 0;\nvar discountmessage = \"\";\nif (discountInput==\"discount\")\n {\n discounttotal=discountindividual;\n discountmessage = \"discount message\";\n }\nelse if (discountInput != \"\")\n {\n discounttotal=0;\n discountmessage = \"Not a valid discount code\";\n }\nelse\n {\n discounttotal=0;\n discountmessage = \"\";\n }\ndocument.epayform.UMdiscount.value = roundCurrency(discounttotal); \ndocument.getElementById('discountmessage').innerHTML = discountmessage;\ncalculateTotal();\n}\nfunction calculateTotal()\n{\n/* eBizCharge API uses UMsubtotal, UMdiscount, UMshipping, UMtax as total amounts for the order.\n UMamount = UMsubtotal + UMshipping - UMdiscount + UMtax\n eBizCharge does not automatically calculate UMamount for us.\n Instead of using a simmpler calculation\n Qty * (Base Amount - Discount) * (1 + Tax) + Shipping = Amount,\n we'll use eBizCharge variables to better tie in with it's API.\n*/\n//calculate subtotal\nvar subtotal = document.epayform.UMsubtotal.value;\nsubtotal = roundCurrency(subtotal);\nvar discounttotal = document.epayform.UMdiscount.value;\nif (discounttotal != 0)\n {\n document.getElementById('discount').innerHTML = \"$\" + currencyFormatted(discounttotal);\n }\nvar total = subtotal - discounttotal;\ntotal = roundCurrency(total);\ndocument.epayform.UMamount.value = total ;\ndocument.getElementById('totalamount').innerHTML = \"$\" + currencyFormatted(total) ;\n}\n//round Currency\nfunction roundCurrency(amount)\n{\nvar i = Math.abs(amount);\ni = Math.round (i * 100)/100;\nreturn i;\n}\n//format Currency\nfunction currencyFormatted(amount)\n{\nvar i = parseFloat(amount);\nif(isNaN(i))\n {\n i = 0.00;\n }\nvar minus = '';\nif(i < 0)\n {\n minus = '-';\n }\ni = Math.abs(i);\ni = parseInt((i + .005) * 100);\ni = i / 100;\ns = new String(i);\nif(s.indexOf('.') < 0)\n {\n s += '.00';\n }\nif(s.indexOf('.') == (s.length - 2))\n {\n s += '0';\n }\ns = minus + s;\nreturn s;\n}\n//-->\n</script>", "language": "javascript" } ] } [/block] ## Add HTML Find [block:code] { "codes": [ { "code": "<body link=\"#000080\" vlink=\"#000080\" alink=\"#000080\" text=\"#000000\" bgcolor=\"#D4D7E4\">", "language": "html" } ] } [/block] and replace it with [block:code] { "codes": [ { "code": "<body link=\"#000080\" vlink=\"#000080\" alink=\"#000080\" text=\"#000000\" bgcolor=\"#D4D7E4\" onload=\"calculateTotal()\">", "language": "html" } ] } [/block] Find the part of the form with the hidden inputs. It should look like this: [block:code] { "codes": [ { "code": "<input type=\"hidden\" name=\"UMsubmit\" value=\"1\">\n<input type=\"hidden\" name=\"UMkey\" value=\"[UMkey]\">\n<input type=\"hidden\" name=\"UMredirDeclined\" value=\"[UMredirDeclined]\">\n<input type=\"hidden\" name=\"UMredirApproved\" value=\"[UMredirApproved]\">\n<input type=\"hidden\" name=\"UMhash\" value=\"[UMhash]\">\n<input type=\"hidden\" name=\"UMcommand\" value=\"[UMcommand]\">\n<input type=\"hidden\" name=\"UMamount\" value=\"[UMamount]\">\n<input type=\"hidden\" name=\"UMtax\" value=\"[UMtax]\">\n<input type=\"hidden\" name=\"UMinvoice\" value=\"[UMinvoice]\">\n<input type=\"hidden\" name=\"UMcustid\" value=\"[UMcustid]\">\n<input type=\"hidden\" name=\"UMrecurring\" value=\"[UMrecurring]\">\n<input type=\"hidden\" name=\"UMaddcustomer\" value=\"[UMaddcustomer]\">\n<input type=\"hidden\" name=\"UMbillamount\" value=\"[UMbillamount]\">\n<input type=\"hidden\" name=\"UMcustreceipt\" value=\"[UMcustreceipt]\">\n<input type=\"hidden\" name=\"UMschedule\" value=\"[UMschedule]\">\n<input type=\"hidden\" name=\"UMnumleft\" value=\"[UMnumleft]\">\n<input type=\"hidden\" name=\"UMstart\" value=\"[UMstart]\">\n<input type=\"hidden\" name=\"UMexpire\" value=\"[UMexpire]\">\n<input type=\"hidden\" name=\"UMdescription\" value=\"[UMdescription]\">\n<input type=\"hidden\" name=\"UMechofields\" value=\"[UMechofields]\">\n<input type=\"hidden\" name=\"UMformString\" value=\"[UMformString]\">", "language": "html" } ] } [/block] Delete: [block:code] { "codes": [ { "code": "<input type=\"hidden\" name=\"UMamount\" value=\"[UMamount]\">", "language": "html" } ] } [/block] Add the following code below: [block:code] { "codes": [ { "code": "<input type=\"hidden\" name=\"UMdiscount\" value=\"[UMdiscount]\">", "language": "html" } ] } [/block] Find [block:code] { "codes": [ { "code": "<tr>\n <td bgcolor=\"#F0F0F0\" width=\"234\" align=\"right\"><font size=\"2\" face=\"Verdana\">Order Amount:</font></td>\n <td bgcolor=\"#F0F0F0\" width=\"450\">[UMamount]\n </td>\n</tr>", "language": "html" } ] } [/block] and replace it with [block:code] { "codes": [ { "code": "<tr>\n <td bgcolor=\"#F0F0F0\" width=\"234\" align=\"right\"><font size=\"2\" face=\"Verdana\">Amount:</font></td>\n <td bgcolor=\"#F0F0F0\" width=\"450\"><input type=\"hidden\" name=\"UMsubtotal\" value=\"20.00\" size=10>$20.00\n </td>\n</tr>\n<tr>\n <td bgcolor=\"#F0F0F0\" width=\"234\" align=\"right\"><font size=\"2\" face=\"Verdana\">Enter Discount Code: </font></td>\n <td bgcolor=\"#F0F0F0\" width=\"450\"><input type=\"text\" name=\"DiscountCode\" size=11 onChange=\"calculateDiscount()\"></input> <div id=\"discountmessage\">&nbsp;</div></td>\n</tr>\n<tr>\n <td bgcolor=\"#F0F0F0\" width=\"234\" align=\"right\"><font size=\"2\" face=\"Verdana\">Discount:</font></td>\n <td bgcolor=\"#F0F0F0\" width=\"450\"><div id=\"discount\">&nbsp;</div>\n </td>\n</tr>\n<tr>\n <td bgcolor=\"#F0F0F0\" width=\"234\" align=\"right\"><font size=\"2\" face=\"Verdana\">Total Charge:</font></td>\n <td bgcolor=\"#F0F0F0\" width=\"450\"><input type=\"hidden\" name=\"UMamount\" value=\"[UMamount]\"><div id=\"totalamount\">&nbsp;</div>\n </td>\n</tr>", "language": "html" } ] } [/block]