Skip to content

Commit 46806d8

Browse files
committed
Release 1.0.0.0
1 parent fe0d81e commit 46806d8

File tree

9 files changed

+208
-14
lines changed

9 files changed

+208
-14
lines changed

Paypal.Express.UI/Paypal.Express.UI.vbproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<Content Include="cart.asp" />
9797
<Content Include="Content\styles.css" />
9898
<Content Include="default.asp" />
99+
<Content Include="cancel.asp" />
100+
<Content Include="thanks.html" />
101+
<Content Include="error.asp" />
99102
<Content Include="inc\adovbs.inc" />
100103
<Content Include="inc\common.asp" />
101104
<Content Include="inc\constants.asp" />
@@ -107,6 +110,7 @@
107110
<Content Include="Scripts\jquery-3.6.0.min.js" />
108111
<Content Include="Scripts\jquery-3.6.0.slim.js" />
109112
<Content Include="Scripts\jquery-3.6.0.slim.min.js" />
113+
<Content Include="success.asp" />
110114
<Content Include="web.config" />
111115
<None Include="web.Debug.config">
112116
<DependentUpon>web.config</DependentUpon>

Paypal.Express.UI/cancel.asp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%@ language="vbscript" %>
2+
<% Option Explicit %>
3+
<!--#include file="inc/adovbs.inc"-->
4+
<!--#include file="inc/constants.asp"-->
5+
<!--#include file="inc/common.asp"-->
6+
<!--#include file="inc/PaypalObject.class.asp"-->
7+
<!doctype html>
8+
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
13+
<title>My Cart ~ Paypal Express Example Implementation</title>
14+
<meta name="description" content="A Paypal express example implementation with JavaScript and Classic ASP">
15+
<meta name="author" content="coderPro.net">
16+
17+
<link rel="stylesheet" href="Content/styles.css?v=1.0">
18+
</head>
19+
20+
<body>
21+
<section id="container">
22+
<h1>Order Cancellation</h1>
23+
</section>
24+
25+
<script src="Scripts/jquery-3.6.0.js"></script>
26+
<script src="Scripts/scripts.js"></script>
27+
</body>
28+
</html>

Paypal.Express.UI/cart.asp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
Dim idx, itemCount, total
99
Dim aryItemName, aryItemPrice, aryItemQty
1010
Dim accessToken, clientToken
11-
Dim debug: debug = False
1211
1312
itemCount = 0
1413
total = 0
1514
16-
SetLCID("en-gb") 'Manually set the locale. *NB: If locale is not available on the server it WILL explode.
15+
SetLCID(Locale) 'Manually set the locale. *NB: If locale is not available on the server it WILL explode.
1716
1817
If InStr(1, Request.Form("ItemName"), ",") > 0 Then
1918
aryItemName = Split(Request.Form("ItemName"), ",")
@@ -29,7 +28,7 @@
2928
3029
clientToken = paypal.GetClientToken(accessToken)("client_token")
3130
32-
If debug = True Then
31+
If PaypalDebug = True Then
3332
Response.Write "Access Token: " & accessToken & "<br />"
3433
Response.Write "Client Token: " & clientToken & "<br />"
3534
End If
@@ -46,7 +45,7 @@
4645

4746
<link rel="stylesheet" href="Content/styles.css?v=1.0">
4847

49-
<script src="https://www.paypal.com/sdk/js?debug=true&intent=capture&components=buttons&integration-date=2021-05-09&client-id=<%= PayPalApiClientId %>" data-client-token="<%= clientToken %>"></script>
48+
<script src="https://www.paypal.com/sdk/js?debug=<%= LCase(PaypalDebug) %>&intent=capture&components=buttons&integration-date=2021-05-09&client-id=<%= PayPalApiClientId %>" data-client-token="<%= clientToken %>"></script>
5049
<!--
5150
Developer Notes:
5251
1) Turn off debug before moving to prod.
@@ -145,15 +144,52 @@
145144
});
146145
},
147146
onApprove: function (data, actions) {
147+
// When a payment is successful:
148+
// Post data to an ASP to capture the information.
149+
// Send the user to a basic thank you page.
150+
// NB: This is done for better security. Obviously not infoulable, but better than how most people simply add vars to the querystring for the user to potentially modify them.
148151
return actions.order.capture().then(function (details) {
149-
window.location.href = '/success.html';
152+
let orderId, orderDate, intent, status;
153+
let payerId, payerEmail;
154+
let items = "", quantities = "";
155+
156+
orderId = details.id;
157+
orderDate = details.create_time;
158+
intent = details.intent;
159+
status = details.status;
160+
161+
payerId = details.payer.payer_id;
162+
payerEmail = details.payer.email_address;
163+
164+
$(details.purchase_units[0].items).each(function(i, item) {
165+
items = items + item.name + ",";
166+
quantities = quantities + item.quantity + ","
167+
});
168+
169+
items = items.substring(0, items.length - 1);
170+
quantities = quantities.substring(0, items.length - 1);
171+
172+
$.post("<%= GetSiteRootUrl %>/success.asp", {
173+
orderId: orderId,
174+
orderDate: orderDate,
175+
intent: intent,
176+
status: status,
177+
payerId: payerId,
178+
payerEmail: payerEmail,
179+
items: items,
180+
quantities
181+
});
182+
183+
window.location.href = "<%= GetSiteRootUrl %> & /thanks.html"
150184
});
151185
},
152186
onCancel: function (data, actions) {
153-
return actions.redirect();
187+
console.log(data);
188+
console.log(actions);
189+
return actions.redirect("<%= GetSiteRootUrl %>/cancel.asp");
154190
},
155191
onError: function (err) {
156-
// Show an error page here, when an error occurs
192+
window.location.href = `/error.asp?e=${err.toString()}`;
157193
}
158194
}).render("#paypal-button-container");
159195
</script>

Paypal.Express.UI/default.asp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!--#include file="inc/constants.asp"-->
66
<!--#include file="inc/common.asp"-->
77
<%
8-
SetLCID("en-gb") 'Manually set the locale. *NB: Make sure the server supports it.
8+
SetLCID(Locale) 'Manually set the locale. *NB: Make sure the server supports it.
99
%>
1010
<!doctype html>
1111

Paypal.Express.UI/error.asp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<%@ language="vbscript" %>
2+
<% Option Explicit %>
3+
<!--#include file="inc/adovbs.inc"-->
4+
<!--#include file="inc/constants.asp"-->
5+
<!--#include file="inc/common.asp"-->
6+
<!--#include file="inc/PaypalObject.class.asp"-->
7+
<!doctype html>
8+
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
13+
<title>My Cart ~ Paypal Express Example Implementation</title>
14+
<meta name="description" content="A Paypal express example implementation with JavaScript and Classic ASP">
15+
<meta name="author" content="coderPro.net">
16+
17+
<link rel="stylesheet" href="Content/styles.css?v=1.0">
18+
</head>
19+
20+
<body>
21+
<section id="container">
22+
<h1>Error</h1>
23+
<h2><%= Request.QueryString("e") %></h2>
24+
25+
</section>
26+
27+
<script src="Scripts/jquery-3.6.0.js"></script>
28+
<script src="Scripts/scripts.js"></script>
29+
</body>
30+
</html>

Paypal.Express.UI/inc/common.asp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,57 @@
267267
End Select
268268
269269
Response.LCID = strLCID
270+
270271
End Sub
272+
273+
Public Function GetSiteRootUrl()
274+
Dim siteRootUrl, protocol, hostname, port
271275
272-
Function Base64Encode(sText)
276+
If Request.ServerVariables("HTTPS") = "off" then
277+
protocol = "http"
278+
Else
279+
protocol = "https"
280+
End if
281+
282+
siteRootUrl = protocol & Server.HTMLEncode("://")
283+
284+
hostname = Request.ServerVariables("HTTP_HOST")
285+
siteRootUrl = siteRootUrl & hostname
286+
287+
port = Request.ServerVariables("SERVER_PORT")
288+
289+
If port <> 80 and port <> 443 then
290+
siteRootUrl = siteRootUrl & ":" & port
291+
End If
292+
293+
getSiteRootUrl = siteRootUrl
294+
End Function
295+
296+
Private Function Base64Encode(sText)
273297
Dim oXML, oNode
298+
274299
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
275300
Set oNode = oXML.CreateElement("base64")
301+
276302
oNode.dataType = "bin.base64"
277303
oNode.nodeTypedValue = Stream_StringToBinary(sText)
278304
Base64Encode = oNode.text
305+
279306
Set oNode = Nothing
280307
Set oXML = Nothing
281308
End Function
282309
283-
Function Base64Decode(ByVal sText)
310+
Private Function Base64Decode(ByVal sText)
284311
Dim oXML, oNode
312+
285313
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
286314
Set oNode = oXML.CreateElement("base64")
315+
287316
oNode.dataType = "bin.base64"
288317
oNode.text = sText
318+
289319
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
320+
290321
Set oNode = Nothing
291322
Set oXML = Nothing
292323
End Function
@@ -306,9 +337,12 @@
306337
BinaryStream.Position = 0
307338
BinaryStream.Type = adTypeBinary
308339
BinaryStream.Position = 0
340+
309341
Stream_StringToBinary = BinaryStream.Read
342+
310343
Set BinaryStream = Nothing
311344
End Function
345+
312346
Private Function Stream_BinaryToString(Binary)
313347
Const adTypeText = 2
314348
Const adTypeBinary = 1
@@ -323,7 +357,9 @@
323357
BinaryStream.Position = 0
324358
BinaryStream.Type = adTypeText
325359
BinaryStream.CharSet = "us-ascii"
360+
326361
Stream_BinaryToString = BinaryStream.ReadText
362+
327363
Set BinaryStream = Nothing
328364
End Function
329365
%>

Paypal.Express.UI/inc/constants.asp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<%
2-
Const PayPalApiClientId = "AeX0M6nc67b-XbNootr5EvKfZcbyCBIoxbsJ4IMLyNDdIscOmfFMIQywKQ9ey1aNo0fdiVdMRmuez2cn"
3-
Const PayPalApiSecret = "EKiJpIV8cZkyvcATidMCC4dHLTMSeFE2h3eg9_alhh8KPevdNhAxbGGmUkj6icQE_f7tI5JKLDmlg5Wz"
2+
Const PayPalApiClientId = "XXXXXX"
3+
Const PayPalApiSecret = "XXXXXX"
4+
45
' The below is VERY important. It is a **base64 encoded** copy of PaypalApiClientId:PayPalApiSecret (the : is necessary).
5-
Const PayPalEncodedAuth = "QWVYME02bmM2N2ItWGJOb290cjVFdktmWmNieUNCSW94YnNKNElNTHlORGRJc2NPbWZGTUlReXdLUTlleTFhTm8wZmRpVmRNUm11ZXoyY246RUtpSnBJVjhjWmt5dmNBVGlkTUNDNGRITFRNU2VGRTJoM2VnOV9hbGhoOEtQZXZkTmhBeGJHR21Va2o2aWNRRV9mN3RJNUpLTERtbGc1V3o="
6+
Const PayPalEncodedAuth = "XXXXXX"
67
Const PaypalApiEndPoint = "https://api.sandbox.paypal.com/v1/"
78
8-
Const SslClientCertFriendlyName = "LOCAL_MACHINE\My\ServerXMLHTTP" 'The path and friendly name. Either obtained from your host or from Start => "Manage Computer Certificates" => Personal (could possibly be elsewhere)
9+
'The path and friendly name of the CLIENT (or client/server) ssl cert. Either obtained from your host or from Start => "Manage Computer Certificates" => Personal (could possibly be elsewhere)
10+
Const SslClientCertFriendlyName = "LOCAL_MACHINE\My\ServerXMLHTTP"
11+
Const Locale = "en-us"
12+
Const PaypalDebug = False
913
%>

Paypal.Express.UI/success.asp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%@ language="vbscript" %>
2+
<% Option Explicit %>
3+
<!--#include file="inc/adovbs.inc"-->
4+
<!--#include file="inc/constants.asp"-->
5+
<!--#include file="inc/common.asp"-->
6+
<!--#include file="inc/PaypalObject.class.asp"-->
7+
<%
8+
Dim orderId, orderDate, intent, status, payerId, payerEmail
9+
Dim items, quantities
10+
11+
orderId = Request.Form("orderId")
12+
orderDate = Request.Form("orderDate")
13+
intent = Request.Form("intent")
14+
status = Request.Form("status")
15+
payerId = Request.Form("payerId")
16+
payerEmail = Request.Form("payerEmail")
17+
18+
items = Split(Request.Form("items"), ",")
19+
quantities = Split(Request.Form("quantitites"), ",")
20+
21+
'Pseudo code:
22+
' INSERT INTO tblOrders(orderId, orderDate, status, payerId, payerEmail) VALUES(?, ?, ?, ?, ?)
23+
' FOR i = LBound(items) To UBound(items)
24+
' INSERT INTO tblOrderLine(orderId, item, quantity) VALUE(?, ?, ?)
25+
' NEXT
26+
%>

Paypal.Express.UI/thanks.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<%@ language="vbscript" %>
2+
<% Option Explicit %>
3+
<!--#include file="inc/adovbs.inc"-->
4+
<!--#include file="inc/constants.asp"-->
5+
<!--#include file="inc/common.asp"-->
6+
<!--#include file="inc/PaypalObject.class.asp"-->
7+
<!doctype html>
8+
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
13+
<title>My Cart ~ Paypal Express Example Implementation</title>
14+
<meta name="description" content="A Paypal express example implementation with JavaScript and Classic ASP">
15+
<meta name="author" content="coderPro.net">
16+
17+
<link rel="stylesheet" href="Content/styles.css?v=1.0">
18+
</head>
19+
20+
<body>
21+
<section id="container">
22+
<h1>Thank You for Your Order!</h1>
23+
<h2><%= Request.QueryString("e") %></h2>
24+
25+
</section>
26+
27+
<script src="Scripts/jquery-3.6.0.js"></script>
28+
<script src="Scripts/scripts.js"></script>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)