-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
307 lines (283 loc) · 12.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="header" style="font-size: xx-large; color: black; font-family: sans-serif"><img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_37x23.jpg"> Checkout Button Options</div>
<hr>
<label>Color: </label><select name="color" id="color">
<option value="gold">Gold</option>
<option value="blue">Blue</option>
<option value="silver">Silver</option>
<option value="black">Black</option>
<option value="white">White</option>
</select>
<label> Size: </label><select name="size" id="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="responsive">Responsive</option>
</select>
<label> Shape: </label><select name="shape" id="shape">
<option value="pill">Pill</option>
<option value="rect">Rectangle</option>
</select>
<label> Label: </label><select name="label" id="label">
<option value="checkout">Checkout</option>
<option value="credit">Credit</option>
<option value="pay">Pay</option>
<option value="buynow">Buy Now</option>
<option value="paypal">PayPal</option>
</select>
<label> Tagline: </label><select name="tagline" id="tagline">
<option value="false">False</option>
<option value="true">True</option>
</select>
<br>
<label>Layout: </label><select name="layout" id="layout">
<option value="horizontal">Horizontal</option>
<option value="vertical">Vertical</option>
</select>
<label> Max Buttons: </label><select name="maxbuttons" id="maxbuttons">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label> Show Credit Card Icons: </label>
<input type="checkbox" name="fundingicons" id="fundingicons">
<br><label>Funding options: </label>
<input type="checkbox" name="credit_allowed" id="credit_allowed" checked>PayPal Credit
<input type="checkbox" name="cc_allowed" id="cc_allowed" checked>Credit Cards
<input type="checkbox" name="elv_allowed" id="elv_allowed" checked>ELV
<input type="checkbox" name="other_allowed" id="other_allowed" checked>Other APMs
<br />
<label>Locale: </label><select name="locale" id="locale">
<option value="en_US">US</option>
<option value="en_AU">AU</option>
<option value="de_DE">AT</option>
<option value="pt_BR">BR</option>
<option value="zh_CN">CN</option>
<option value="de_DE">DE</option>
<option value="es_ES">ES</option>
<option value="en_GB">GB</option>
<option value="fr_FR">FR</option>
<option value="it_IT">IT</option>
<option value="nl_NL">NL</option>
<option value="pt_PT">PT</option>
<option value="pl_PL">PL</option>
</select>
<label>Currency: </label><select name="currency" id="currency">
<option value="USD">USD</option>
<option value="CAD">CAD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
</select>
<br/><br />
<div id="paypal-button"></div>
<button type="button" onclick="renderButton()">Generate</button>
<script>
// If Credit is selected, change available Color options
function labelChanged() {
var label = document.getElementById("label").value,
colorDropdown = document.getElementById("color");
if (label == "credit") {
colorDropdown.innerHTML = '<option value="black">Black</option><option value="darkblue">Dark Blue</option>';
} else {
colorDropdown.innerHTML = '<option value="gold">Gold</option><option value="blue">Blue</option><option value="silver">Silver</option><option value="black">Black</option><option value="white">White</option>';
}
}
document.getElementById("label").addEventListener("change", labelChanged);
// Layout: Vertical has a number of limitations
function layoutChanged() {
var layout = document.getElementById("layout").value,
size = document.getElementById("size").value,
sizeBox = document.getElementById("size"),
taglineBox = document.getElementById("tagline"),
labelBox = document.getElementById("label"),
funding = document.getElementById("fundingicons");
if (layout == "vertical") {
taglineBox.disabled = true;
funding.checked = false;
funding.disabled = true;
if (size == "small")
size = "medium";
sizeBox.innerHTML = '<option value="medium">Medium</option><option value="large">Large</option><option value="responsive">Responsive</option>';
sizeBox.value = size;
} else {
taglineBox.disabled = false;
funding.disabled = false;
sizeBox.innerHTML = '<option value="small">Small</option><option value="medium">Medium</option><option value="large">Large</option><option value="responsive">Responsive</option>';
sizeBox.value = size;
}
}
document.getElementById("layout").addEventListener("change", layoutChanged);
function renderButton() {
document.getElementById("paypal-button").innerHTML="";
var color = document.getElementById("color").value,
size = document.getElementById("size").value,
shape = document.getElementById("shape").value,
label = document.getElementById("label").value,
tagline = document.getElementById("tagline").value,
layout = document.getElementById("layout").value,
maxbuttons = document.getElementById("maxbuttons").value,
currency = document.getElementById("currency").value,
locale = document.getElementById("locale").value,
credit_allowed = document.getElementById("credit_allowed").checked,
cc_allowed = document.getElementById("cc_allowed").checked,
elv_allowed = document.getElementById("elv_allowed").checked,
other_allowed = document.getElementById("other_allowed").checked,
fundingicons = document.getElementById("fundingicons").checked,
allowed_methods = [],
disallowed_methods = [],
CLIENT_ID_SANDBOX = ""; // enter your own
if (credit_allowed) {
allowed_methods.push(paypal.FUNDING.CREDIT);
} else {
disallowed_methods.push(paypal.FUNDING.CREDIT);
}
if (cc_allowed) {
allowed_methods.push(paypal.FUNDING.CARD);
} else {
disallowed_methods.push(paypal.FUNDING.CARD);
}
if (elv_allowed) {
allowed_methods.push(paypal.FUNDING.ELV);
} else {
disallowed_methods.push(paypal.FUNDING.ELV);
}
if (other_allowed) {
allowed_methods.push(paypal.FUNDING.IDEAL);
allowed_methods.push(paypal.FUNDING.GIROPAY);
allowed_methods.push(paypal.FUNDING.EPS);
allowed_methods.push(paypal.FUNDING.SOFORT);
allowed_methods.push(paypal.FUNDING.MYBANK);
allowed_methods.push(paypal.FUNDING.P24);
allowed_methods.push(paypal.FUNDING.ZIMPLER);
} else {
disallowed_methods.push(paypal.FUNDING.IDEAL);
disallowed_methods.push(paypal.FUNDING.GIROPAY);
disallowed_methods.push(paypal.FUNDING.EPS);
disallowed_methods.push(paypal.FUNDING.SOFORT);
disallowed_methods.push(paypal.FUNDING.MYBANK);
disallowed_methods.push(paypal.FUNDING.P24);
disallowed_methods.push(paypal.FUNDING.ZIMPLER);
}
if (label == "credit") {
if (color != "black" && color != "darkblue") {
alert("Black or Dark Blue are only valid PayPal Credit colors");
return;
} else
fundingicons = false;
}
if (color == "darkblue" && label != "credit") {
alert("Dark Blue is only valid for label: credit");
return;
}
// Label, tagline, and fundingicons only allowed on horizontal layout
if (layout == "vertical") {
//label = false;
tagline = false;
fundingicons = false;
// Medium is smallest size for vertical layout
if (size == "small")
size = "medium";
}
if (other_allowed && currency !== "EUR") {
alert("Currently, only EUR currency is allowed for other APMs. Please set currency to EUR and try again.");
return;
}
paypal.Button.render({
env: 'sandbox',
client: {
sandbox: CLIENT_ID_SANDBOX
},
locale: locale,
commit: true, // Show a 'Pay Now' button
style: {
color: color,
size: size,
shape: shape,
tagline: tagline,
layout: layout,
label: label,
maxbuttons: Number(maxbuttons),
fundingicons: fundingicons
},
funding: {
allowed: allowed_methods,
disallowed: disallowed_methods
},
payment: function(data, actions) {
return actions.payment.create({
payment: {
intent: "sale",
transactions: [
{
amount: {
total: '149.99',
currency: currency
}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
alert("Payment complete!");
});
},
onCancel: function(data, actions) {
/*
* Buyer cancelled the payment
*/
},
onError: function(err) {
/*
* An error occurred during the transaction
*/
}
}, '#paypal-button');
}
</script>
<br>
<br>
<br />
<br>
<h2>Limitations of PayPal Checkout</h2>
<p>Certain parameters do not work with others:</p>
<ul>
<li>Color: <b>Dark Blue</b> is only available for <b>Label: Credit</b></li>
<li>When using <b>Label: Credit</b>, only <b>Color: Dark Blue</b> or <b>Black</b> will work.</li>
<li>When using <b>Layout: Vertical</b>, cannot use <b>Size: Small</b> and does not use options of <b>Tagline</b></li>
<li><b>Funding Icons</b> only work with <b>Layout: Horizontal</b></li>
<li>Selecting <b>Funding Icons</b> will override the <b>Tagline</b></li>
<li>Venmo button will not appear unless on mobile with a device that has a Venmo cookie and OneTouch is enabled.</li>
</ul>
<h2>Alternative Payment Methods</h2>
<h3>iDEAL, Sofort, Giropay, EPS, Mybank, P24, Zimpler</h3>
<p>To get these APMs to show:</p>
<ul>
<li>commit: true</li>
<li>currency: EUR</li>
<li>layout: vertical</li>
<li>maxbuttons: >= 2 (4 recommended)</li>
<li>The APM must be added to the <i>funding -> allowed</i> array</li>
</ul>
<p>Buyer must be located in the following locations (or for testing, Locale must be set to:</p>
<ul>
<li>paypal.FUNDING.IDEAL :: NL</li>
<li>paypal.FUNDING.GIROPAY :: DE</li>
<li>paypal.FUNDING.EPS :: AT</li>
<li>paypal.FUNDING.SOFORT :: NL, DE, AT, BE, IT, ES</li>
<li>paypal.FUNDING.MYBANK :: IT</li>
<li>paypal.FUNDING.P24 :: PL</li>
<li>paypal.FUNDING.ZIMPLER :: FI</li>
<li>paypal.FUNDING.ELV :: DE, AT</li>
</ul>
<p>Additionally, for these APMs, since commit=true, you cannot change the amounts of the transactions when you execute the payment.</p>
<h3>Want the full code for this generator? Visit my <a href="https://github.com/Chaithi/PayPal-Smart-Buttons-Demo" target="_blank">GitHub</a>.</h3>
</body>