|
8 | 8 | Dim idx, itemCount, total |
9 | 9 | Dim aryItemName, aryItemPrice, aryItemQty |
10 | 10 | Dim accessToken, clientToken |
11 | | - Dim debug: debug = False |
12 | 11 |
|
13 | 12 | itemCount = 0 |
14 | 13 | total = 0 |
15 | 14 |
|
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. |
17 | 16 |
|
18 | 17 | If InStr(1, Request.Form("ItemName"), ",") > 0 Then |
19 | 18 | aryItemName = Split(Request.Form("ItemName"), ",") |
|
29 | 28 | |
30 | 29 | clientToken = paypal.GetClientToken(accessToken)("client_token") |
31 | 30 |
|
32 | | - If debug = True Then |
| 31 | + If PaypalDebug = True Then |
33 | 32 | Response.Write "Access Token: " & accessToken & "<br />" |
34 | 33 | Response.Write "Client Token: " & clientToken & "<br />" |
35 | 34 | End If |
|
46 | 45 |
|
47 | 46 | <link rel="stylesheet" href="Content/styles.css?v=1.0"> |
48 | 47 |
|
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> |
50 | 49 | <!-- |
51 | 50 | Developer Notes: |
52 | 51 | 1) Turn off debug before moving to prod. |
|
145 | 144 | }); |
146 | 145 | }, |
147 | 146 | 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. |
148 | 151 | 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" |
150 | 184 | }); |
151 | 185 | }, |
152 | 186 | onCancel: function (data, actions) { |
153 | | - return actions.redirect(); |
| 187 | + console.log(data); |
| 188 | + console.log(actions); |
| 189 | + return actions.redirect("<%= GetSiteRootUrl %>/cancel.asp"); |
154 | 190 | }, |
155 | 191 | onError: function (err) { |
156 | | - // Show an error page here, when an error occurs |
| 192 | + window.location.href = `/error.asp?e=${err.toString()}`; |
157 | 193 | } |
158 | 194 | }).render("#paypal-button-container"); |
159 | 195 | </script> |
|
0 commit comments