Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using com.paypal.sdk.services;
- using com.paypal.sdk.profiles;
- using com.paypal.sdk.util;
- using System.Data;
- using System.Text;
- using System.Net.Mail;
- using System.Web.Security;
- public partial class OrderConfirm : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Request.QueryString["token"].ToString() != "")
- {
- if (ECGetExpressCheckoutCode(Request.QueryString["token"].ToString()) == "Success" ||
- ECGetExpressCheckoutCode(Request.QueryString["token"].ToString()) == "SuccessWithWarning")
- {
- pnlOrderconfirm.Visible = true;
- }
- else
- {
- pnlConfirmOrderNoReciepe.Visible = true;
- }
- }
- else
- Response.Redirect("Default.aspx");
- }
- public string ECGetExpressCheckoutCode(string token)
- {
- NVPCallerServices caller = new NVPCallerServices();
- IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
- // Set up your API credentials, PayPal end point, API operation and version.
- profile.APIUsername = "";
- profile.APIPassword = "";
- profile.APISignature = "";
- profile.Environment = "live";
- caller.APIProfile = profile;
- NVPCodec encoder = new NVPCodec();
- //encoder["VERSION"] = "51.0";
- encoder["VERSION"] = "65.0";
- encoder["METHOD"] = "GetExpressCheckoutDetails";
- encoder["TOKEN"] = token; // Pass the token returned in SetExpressCheckout.
- // Execute the API operation and obtain the response.
- string pStrrequestforNvp = encoder.Encode();
- string pStresponsenvp = caller.Call(pStrrequestforNvp);
- NVPCodec decoder = new NVPCodec();
- decoder.Decode(pStresponsenvp);
- lblNamn.Text = decoder["SHIPTONAME"];
- lblAdress.Text = decoder["SHIPTOSTREET"];
- lblPostnr.Text = decoder["SHIPTOZIP"];
- lblOrt.Text = decoder["SHIPTOCITY"];
- lblTele.Text = decoder["SHIPTOPHONENUM"];
- lblEpost.Text = decoder["EMAIL"];
- if(Session["payment_amt"] != null)
- lblBelopp.Text = Session["payment_amt"].ToString();
- else
- lblBelopp.Text = decoder["PAYMENTREQUEST_0_AMT"];
- return decoder["ACK"];
- }
- public class ECDoExpressCheckout
- {
- public ECDoExpressCheckout()
- {
- }
- }
- public string ECDoExpressCheckoutCode(string token, string payerID, string amount, string paymentType, string currencyCode)
- {
- NVPCallerServices caller = new NVPCallerServices();
- IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
- // Set up your API credentials, PayPal end point, API operation and version.
- profile.APIUsername = "";
- profile.APIPassword = "";
- profile.APISignature = "";
- profile.Environment = "live";
- caller.APIProfile = profile;
- NVPCodec encoder = new NVPCodec();
- encoder["VERSION"] = "65.0";
- encoder["METHOD"] = "DoExpressCheckoutPayment";
- // Add request-specific fields to the request.
- // Pass the token returned in SetExpressCheckout.
- encoder["TOKEN"] = token;
- encoder["PAYERID"] = payerID;
- encoder["AMT"] = amount;
- encoder["PAYMENTACTION"] = paymentType;
- encoder["CURRENCYCODE"] = currencyCode;
- // Execute the API operation and obtain the response.
- string pStrrequestforNvp = encoder.Encode();
- string pStresponsenvp = caller.Call(pStrrequestforNvp);
- NVPCodec decoder = new NVPCodec();
- decoder.Decode(pStresponsenvp);
- lblUsermsg.Text += pStresponsenvp.ToString();
- return decoder["ACK"];
- }
- protected void Confirm(object sender, EventArgs e)
- {
- if (ECDoExpressCheckoutCode(Request.QueryString["token"].ToString(), Request.QueryString["PayerID"].ToString(),
- Session["payment_amt"].ToString(), "Sale", "SEK") == "Success")
- {
- try
- {
- // Skicka mail
- SendCustomerMail(lblEpost.Text);
- SendOrderMail();
- // Skicka vidare till bekräftelsesida
- Response.Redirect("Completed.aspx");
- }
- catch (Exception ex)
- {
- lblUsermsg.Text = "Ett fel uppstod: " + ex;
- }
- }
- else
- {
- pnlOrderconfirm.Visible = false;
- pnlConfirmOrderNoReciepe.Visible = false;
- }
- }
- //Skicka bekräftande mail till beställaren
- protected void SendCustomerMail(string email)
- {
- DataTable ordertable = ManageShoppingCart.getProductsFromShoppingCart();
- DataTable totaltable = ManageShoppingCart.getSumFromShoppingCart();
- StringBuilder sb = new StringBuilder();
- foreach (DataRow row in ordertable.Rows)
- {
- sb.AppendLine("<tr>");
- sb.AppendLine("<td>" + row["Name"] + "</td>");
- sb.AppendLine("<td>" + String.Format("{0:0 kr}", row["Price"]) + "</td>");
- sb.AppendLine("<td>" + row["Quantity"] + "</td>");
- sb.AppendLine("<td>" + row["AttributeOne"].ToString() + row["AttributeTwo"] + "</td>");
- sb.AppendLine("</tr>");
- }
- SmtpClient client = new SmtpClient("");
- MailMessage mail = new MailMessage();
- mail.From = new MailAddress("", "Bekräftelse på köp ");
- mail.To.Add(email);
- mail.Subject = "Din beställning";
- mail.Body =
- "<html><body><head><title>Din beställning från</title>" +
- "<style>body {font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;} h1,h2,h3 {margin-bottom:0; color:#840D16; " +
- "font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;} " +
- "p {font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;}</style>" +
- "</head>" +
- "<h2>Tack för din beställning!</h2>" +
- "<p>Detta är en bekräftelse på att din beställning är mottagen." +
- "<h3>Dina uppgifter</h3>" +
- "<p><strong>Personliga uppgifter: </strong><br>" +
- lblNamn.Text + "<br>" +
- lblAdress.Text + "<br>" + lblPostnr.Text + " " + lblOrt.Text + "</p>" +
- "<p>Telefon: " + lblTele.Text + "<br>" +
- "E-post: " + email + "</p>" +
- "<p><strong>Beställningen gjordes:</strong> " + DateTime.Now.ToShortDateString() +
- "</p><p>Betalning har skett via Paypal.</p>" +
- "<p><strong>Leverans: </strong>" +
- "75 kr </p>" +
- "<h3>Beställda varor </h3><table cellpadding='4'><tr><th>Namn</th><th>Pris</th>" +
- "<th>Antal</th><th>Attibut</th></tr>" +
- sb.ToString() +
- "</table>" +
- "<h3>Totalsumma: <span style='color:#000;'>" +
- Session["payment_amt"].ToString() +
- "</span></h3>" +
- "<p>Tack för Er beställning!Ert smycke kommer att skickas inom 10 dagar, vanligtvis 3-4 dagar. Ni får exakt besked när orden är mottagen.</p>" +
- "<p>Alla smycken levereras i fin ask med logga.</p>" +
- "<p>Svensk köplag gäller.</p>" +
- "<p><strong>Vi hoppas att du blir nöjd med varorna.</strong></p>" +
- "<p>Tack för din beställnig!</p>" +
- "</body></html>";
- mail.IsBodyHtml = true;
- try
- {
- client.Send(mail);
- }
- catch (Exception ex)
- {
- }
- }
- //Skicka mail till administratören.
- //I mailet är leverans och betalsätt hårdkodat, eftersom det just nu bara finns ett alternativ vardera.
- protected void SendOrderMail()
- {
- DataTable ordertable = ManageShoppingCart.getProductsFromShoppingCart();
- DataTable totaltable = ManageShoppingCart.getSumFromShoppingCart();
- StringBuilder sb = new StringBuilder();
- foreach (DataRow row in ordertable.Rows)
- {
- sb.AppendLine("<tr>");
- sb.AppendLine("<td>" + row["Name"] + "</td>");
- sb.AppendLine("<td>" + String.Format("{0:0 kr}", row["Price"]) + "</td>");
- sb.AppendLine("<td>" + row["Quantity"] + "</td>");
- sb.AppendLine("<td>" + row["AttributeOne"].ToString() + row["AttributeTwo"] + "</td>");
- sb.AppendLine("</tr>");
- }
- SmtpClient client = new SmtpClient("213...28");
- MailMessage mail = new MailMessage();
- mail.From = new MailAddress("order@.se", "Ny order från .se");
- mail.To.Add("info@.se");
- mail.Subject = "Order från .se";
- mail.Body =
- "<html><body><head><title>Din beställning från .se</title>" +
- "<style>body {font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;} h1,h2,h3 {margin-bottom:0; color:#840D16; font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;} " +
- "p {font-family:'Trebuchet MS',Arial,Helvetica,sans-serif;}</style>" +
- "</head>" +
- "<h2>En ny beställning har gjorts i webshoppen</h2>" +
- "<p>Ett mail har skickats till kunden.</p>" +
- "<h3>Kundens uppgifter</h3>" +
- "<p><strong>Personliga uppgifter: </strong><br>" +
- lblNamn.Text + "<br>" +
- lblAdress.Text + "<br>" + lblPostnr.Text + " " + lblOrt.Text + "</p>" +
- "<p>Telefon: " + lblTele.Text + "<br>" +
- "E-post: " + lblEpost.Text + "</p>" +
- "<p><strong>Beställningen gjordes:</strong> " + DateTime.Now.ToShortDateString() +
- "</p><p>Betalning har skett via Paypal.</p>" +
- "<p><strong>Leverans: </strong>" +
- "75 kr </p>" +
- "<h3>Beställda varor </h3><table cellpadding='4'><tr><th>Namn</th><th>Pris</th>" +
- "<th>Antal</th><th>Attibut</th></tr>" +
- sb.ToString() +
- "</table>" +
- "<h3>Totalsumma: <span style='color:#000;'>" +
- Session["payment_amt"].ToString() +
- "</span></h3>";
- mail.IsBodyHtml = true;
- try
- {
- client.Send(mail);
- }
- catch (Exception ex)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement