TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
357
120.8k
Redirect to PayPal upon clicking the Submit button
Apr 27 2012 5:10 PM
Hi Vulpes
Sorry to email you direct I have posted an advert on the forum but havent had a reply and I know your be able to answer this no problems.
Ive written Submit and GetTotal methods as follows:-
public decimal GetTotal(string cartID)
{
using (DCECommerceDBEntities db = new DCECommerceDBEntities())
{
decimal cartTotal = 0;
try
{
var mycart = (from c in db.ViewCarts where c.CartID == cartID select c);
if (mycart.Count() > 0)
{
cartTotal = mycart.Sum(od => (decimal)od.Quantity * (decimal)od.UnitCost);
}
}
catch (Exception exp)
{
throw new Exception("ERROR: Unable to Calculate Order Total - " +
exp.Message.ToString(), exp);
}
return (cartTotal);
}
}
public bool SubmitOrder(string userName)
{
using (DCECommerceDBEntities db = new DCECommerceDBEntities())
{
try
{
Order newOrder = new Order();
newOrder.CustomerName = userName;
newOrder.OrderDate = DateTime.Now;
db.Orders.AddObject(newOrder);
db.SaveChanges();
int NewOrderKey = (from p in db.Orders select p.OrderID).Max();
String cartId = GetShoppingCartId();
var myCart = (from c in db.ViewCarts where c.CartID == cartId select c);
foreach (ViewCart item in myCart)
{
OrderDetail od = new OrderDetail();
od.OrderID = NewOrderKey;
od.ProductID = item.ProductID;
od.Quantity = item.Quantity;
od.UnitCost = item.UnitCost;
db.OrderDetails.AddObject(od);
var myItem = (from c in db.ShoppingCarts where c.CartID == item.CartID &&
c.ProductID == item.ProductID select c).FirstOrDefault();
if (myItem != null)
{
db.DeleteObject(myItem);
}
}
db.SaveChanges();
}
catch(Exception exp)
{
}
}
return true;
}
I basically want to implement the below so that I can pass the return values ie orderId etc to PayPal.
string redirect = "";
redirect += "https://www.paypal.com/xclick/
[email protected]
";
redirect += "&item_name=" + siteName + " Order " + orderId;
redirect += "&item_number=" + orderId;
redirect += "&amount=" + String.Format("{0:0.00} ", amount);
redirect += "¤cy=USD";
redirect += "&return=http://www." + siteName + ".com";
redirect += "&cancel_return=http://www." + siteName + ".com";
// Redirect to the payment page
Response.Redirect(redirect);
With regards to the siteName I can use a const string so thats fine and the currency is easily enough also, its mainly the Total Amount and OrderId I need help with please.
Many thanks
Steven
Reply
Answers (
23
)
Export GridView to Excel
C# web application deploy options