When I test in the paypal sandbox with smart buttons with generated code from paypal, the purchase is successfully executed. BUT when I redirect to a successful purchase page, the asp .net engine in debug, crashes and then does not execute the server code (like sending successful purchase email to the customer, saving the paypal transaction id in the database, etc).
I tested with window.location, window.location.href, window.location.replace, etc … the page redirects but does not execute the code behind it. Maybe it executes 1 or 2 lines of code and then stops immediately, other times it gets the error that localhost rejects the connection.
By Example, this code not crash (debug and code behind of paypalok.aspx runs ok)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication8.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" onclick="redirect()" />
</div>
</form>
<script>
function redirect() {
window.location.href = 'paypalok.aspx';
}
</script>
</body>
</html>
You can try it yourself and you will see how the asp .net debug stops unexpectedly after the redirection to ‘paypalok.aspx’.
by Example, this code crash:…
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paypal3.aspx.cs"
Inherits="WebApplication7.paypal3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
</div>
</form>
<script src="https://www.paypal.com/sdk/js?client-id=sb&enable-funding=venmo¤cy=USD"
data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{ "amount": { "currency_code": "USD", "value": 0.81 } }]
});
},
onApprove: function (data, actions) {
window.location.replace ('paypalok.aspx');
},
onError: function (err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
</body>
</html>
I would appreciate any help