public ActionResult paypalCheckout(long id) { var order = repository.GetOrder(id); if (order == null) { Syslog.Write("Unable to find order:" + id); return(Json("Invalid invoice".ToJsonFail())); } // can't accept partially paid invoices at the moment if (order.totalPaid != 0) { return(Json("Unable to use Paypal for partially paid invoices".ToJsonFail())); } // check if there is already an incomplete payment var existingPaymentEntry = order.payments.SingleOrDefault(x => x.orderid == order.id && x.method == PaymentMethodType.Paypal.ToString()); if (existingPaymentEntry != null) { // just in case if (string.IsNullOrEmpty(existingPaymentEntry.redirectUrl)) { return(SendJsonErrorResponse(new NotSupportedException("redirecturl NULL:" + existingPaymentEntry.id))); } return(Json(existingPaymentEntry.redirectUrl.ToJsonOKData())); } var sd = order.user1.organisation1.MASTERsubdomain; var invoice = new Transaction(order, repository, sessionid.Value); var pworker = new PaypalWorker(Utility.GenerateUniqueCode(), invoice, repository, sd.GetPaypalID(), invoice.GetCurrency().id, accountHostname.ToDomainUrl(invoice.GetOrderLink())); try { var redirecturl = pworker.GetPaymentUrl(); return(Json(redirecturl.ToJsonOKData())); } catch (Exception ex) { return(SendJsonErrorResponse(ex)); } }
public ActionResult DomainOrder(bool id_theft, string plans, string domain_name, string domain_ext) { // check that domain extension is supported if (!SupportedTLD.Extensions.Contains(domain_ext)) { throw new NotImplementedException(); } // get buyer var buyer = repository.GetUserById(sessionid.Value, subdomainid.Value); // check that user has all relevant fields filled up if (string.IsNullOrEmpty(buyer.firstName) || string.IsNullOrEmpty(buyer.lastName) || string.IsNullOrEmpty(buyer.organisation1.name) || string.IsNullOrEmpty(buyer.organisation1.address) || !buyer.organisation1.city.HasValue || string.IsNullOrEmpty(buyer.organisation1.state) || string.IsNullOrEmpty(buyer.organisation1.postcode) || !buyer.organisation1.country.HasValue || string.IsNullOrEmpty(buyer.organisation1.phone) || string.IsNullOrEmpty(buyer.email)) { return(Json("Please ensure that your personal & organisation details are complete".ToJsonFail())); } // get clear pixels domain var clearpixeldomain = repository.GetSubDomains().Single(x => x.name == "clearpixels"); var transaction = new Transaction(clearpixeldomain, buyer, TransactionType.INVOICE, repository, sessionid.Value); var ordernumber = repository.GetNewOrderNumber(clearpixeldomain.id, TransactionType.INVOICE); transaction.CreateTransaction(ordernumber, DateTime.UtcNow, "", CurrencyHelper.GetCurrencies().Single(x => x.code == "USD").id); transaction.UpdateOrderStatus(OrderStatus.SENT); // define id_theft order item var idtheft_variant = repository.GetProductVariant("id_theft", clearpixeldomain.id, null); var idtheft_orderitem = new orderItem() { description = idtheft_variant.product.title, variantid = idtheft_variant.id, unitPrice = idtheft_variant.product.sellingPrice, tax = idtheft_variant.product.tax }; int numberOfYears; product_variant variant; switch (plans) { case "one_year": variant = repository.GetProductVariant("one_year", clearpixeldomain.id, null); if (variant == null) { throw new NotImplementedException(); } numberOfYears = 1; break; case "two_year": variant = repository.GetProductVariant("two_year", clearpixeldomain.id, null); if (variant == null) { throw new NotImplementedException(); } numberOfYears = 2; break; case "five_year": variant = repository.GetProductVariant("five_year", clearpixeldomain.id, null); if (variant == null) { throw new NotImplementedException(); } numberOfYears = 5; break; case "ten_year": variant = repository.GetProductVariant("ten_year", clearpixeldomain.id, null); if (variant == null) { throw new NotImplementedException(); } numberOfYears = 10; break; default: throw new NotImplementedException(); } var orderitem = new orderItem() { description = string.Format("{0}{1} {2}", domain_name, domain_ext, variant.product.title), variantid = variant.id, unitPrice = variant.product.sellingPrice, tax = variant.product.tax, quantity = numberOfYears }; transaction.AddOrderItem(orderitem, null); if (id_theft) { idtheft_orderitem.quantity = numberOfYears; transaction.AddOrderItem(idtheft_orderitem, null); } // update order total transaction.UpdateTotal(); transaction.SaveNewTransaction(); // send email to seller Syslog.Write(string.Format("{0}{1} bought by subdomainid {2}", domain_name, domain_ext, subdomainid.Value)); // handle payment var uniqueid = string.Format("{0}{1}", domain_name, domain_ext); var pworker = new PaypalWorker(uniqueid, transaction, repository, clearpixeldomain.GetPaypalID(), transaction.GetCurrency().id, accountHostname.ToDomainUrl("/dashboard/account/DomainProcess?d=" + uniqueid)); var redirecturl = pworker.GetPaymentUrl(); return(Json(redirecturl.ToJsonOKData())); }
// json is true when checkout is done from an iframe, eg. facebook page public ActionResult create(CheckoutStatus status, string shippingmethod, string paymentmethod, bool isJson = false) { Debug.Assert(!cart.orderid.HasValue); var shop_owner = cart.MASTERsubdomain.organisation.users.First(); var currency = cart.MASTERsubdomain.currency.ToCurrency(); var buyer = cart.user; var transaction = new Transaction(cart.MASTERsubdomain, buyer, TransactionType.INVOICE, repository, sessionid.Value); transaction.CreateTransaction( repository.GetNewOrderNumber(subdomainid.Value, TransactionType.INVOICE), DateTime.UtcNow, cart.MASTERsubdomain.paymentTerms, currency.id); // mark as sent transaction.UpdateOrderStatus(OrderStatus.SENT); var shoppingcart = new ShoppingCart(currency.code) { shippingMethod = shippingmethod }; foreach (var item in cart.cartitems) { var checkOutItem = item.product_variant.ToCheckoutItem(item.quantity, sessionid); var orderItem = new orderItem { description = item.product_variant.ToProductFullTitle(), variantid = item.product_variant.id, unitPrice = item.product_variant.product.ToUserPrice(cart.userid.Value), tax = item.product_variant.product.tax, quantity = item.quantity }; transaction.AddOrderItem(orderItem, item.product_variant.product.products_digitals); // update inventory transaction.UpdateInventoryItem(orderItem, item.quantity); shoppingcart.items.Add(checkOutItem); } if (!cart.isDigitalOrder()) { shoppingcart.CalculateShippingCost(cart.cartitems.Select(x => x.product_variant).AsQueryable(), cart.MASTERsubdomain, buyer); if (cart.cartitems.Select(x => x.product_variant.product.shippingProfile).UseShipwire()) { transaction.UpdateShippingMethod(shoppingcart.shipwireShippingName, shoppingcart.shippingMethod); } else { transaction.UpdateShippingMethod(shoppingcart.shippingMethod); } } transaction.UpdateTotal(cart.coupon); transaction.SaveNewTransaction(); ////////////////////// SAVE INVOICE repository.AddActivity(buyer.id, new ActivityMessage(transaction.GetID(), shop_owner.id, ActivityMessageType.INVOICE_NEW, new HtmlLink(transaction.GetOrderNumber(), transaction.GetID()).ToTransactionString(TransactionType.INVOICE)), subdomainid.Value); // add checkout note as a comment if (!string.IsNullOrEmpty(cart.note)) { transaction.AddComment(cart.note, cart.userid.Value); } // add comment if shipping method not specified if (!transaction.HasShippingMethod() && !cart.isDigitalOrder()) { transaction.AddComment(OrderComment.SHIPPING_WAIT_FOR_COST); } // set cart as processed cart.orderid = transaction.GetID(); // save payment method if (!string.IsNullOrEmpty(paymentmethod)) { switch (paymentmethod) { case "paypal": cart.paymentMethod = PaymentMethodType.Paypal.ToString(); break; default: cart.paymentMethod = PaymentMethodType.Custom.ToString(); cart.paymentCustomId = long.Parse(paymentmethod); break; } } repository.Save(); // send emails // send mail to buyer var buyerEmailContent = new OrderReceipt() { viewloc = cart.MASTERsubdomain.ToHostName().ToDomainUrl(transaction.GetOrderLink()), shopname = cart.MASTERsubdomain.storeName, date = transaction.GetOrderDate().ToShortDateString(), shippingAddress = transaction.GetShippingAddress().ToHtmlString(), billingAddress = transaction.GetBillingAddress().ToHtmlString(), subtotal = string.Format("{0}{1}", currency.symbol, transaction.GetSubTotal().ToString("n" + currency.decimalCount)), shippingcost = string.Format("{0}{1}", currency.symbol, transaction.GetShippingCost().ToString("n" + currency.decimalCount)), discount = string.Format("{0}{1}", currency.symbol, transaction.GetDiscount().ToString("n" + currency.decimalCount)), totalcost = string.Format("{0}{1}{2}", currency.code, currency.symbol, transaction.GetTotal().ToString("n" + currency.decimalCount)), orderitems = transaction .GetOrderItems() .Select(x => string.Format("{0} x {1}{2} {3}", x.quantity, currency.symbol, x.unitPrice.Value.ToString("n" + currency.decimalCount), x.description)) }; // send mail to seller var sellerEmailContent = new NewOrderEmailContent { viewloc = cart.MASTERsubdomain.ToHostName().ToDomainUrl(transaction.GetOrderLink()), sender = buyer.organisation1.name }; string buyer_subject; string seller_subject; switch (status) { case CheckoutStatus.SHIPPING_FAIL: buyer_subject = string.Format("[{0}]Invoice #{1}", cart.MASTERsubdomain.name, transaction.GetOrderNumber()); seller_subject = string.Format("[{0}]New Invoice #{1} : ACTION REQUIRED", cart.MASTERsubdomain.name, transaction.GetOrderNumber()); buyerEmailContent.message = "Thank you for placing an order with us. Unfortunately, we are not able to provide a shipping cost at this moment. We will contact you once we have the shipping costs. You can check the status of your order by following the link below:"; sellerEmailContent.message = "A customer has placed an order on your online store. However, the shipping cost could not be calculated. You will need to manually update the invoice with the shipping cost. To update the invoice, follow the link below:"; break; case CheckoutStatus.SHIPPING_NONE: case CheckoutStatus.SHIPPING_OK: buyer_subject = string.Format("[{0}]Invoice #{1} confirmed", cart.MASTERsubdomain.name, transaction.GetOrderNumber()); seller_subject = string.Format("[{0}]New Invoice #{1}", cart.MASTERsubdomain.name, transaction.GetOrderNumber()); if (cart.isDigitalOrder()) { buyerEmailContent.message = "Download links will be provided once payment is confirmed"; } sellerEmailContent.message = "A customer has placed an order on your online store. To view the invoice, follow the link below:"; break; default: throw new ArgumentOutOfRangeException("status"); } this.SendEmail(EmailViewType.INVOICEORDER_NEW, sellerEmailContent, seller_subject, shop_owner.GetEmailAddress(), shop_owner.ToFullName(), buyer); this.SendEmail(EmailViewType.ORDER_RECEIPT, buyerEmailContent, buyer_subject, buyer.GetEmailAddress(), buyer.ToFullName(), shop_owner); // handle payment string redirecturl = ""; if (!string.IsNullOrEmpty(paymentmethod)) { switch (paymentmethod) { case "paypal": string returnUrl; if (isJson) { returnUrl = string.Format("{0}/checkout/order/{1}/close", GeneralConstants.HTTP_SECURE, cart.id); } else { returnUrl = string.Format("{0}/checkout/order/{1}", GeneralConstants.HTTP_SECURE, cart.id); } var pworker = new PaypalWorker(cart.id.ToString(), transaction, repository, cart.MASTERsubdomain.GetPaypalID(), transaction.GetCurrency().id, returnUrl); try { redirecturl = pworker.GetPaymentUrl(); } catch (Exception ex) { Syslog.Write(ex); return(RedirectToAction("Index", "Error")); } break; default: break; } } if (!string.IsNullOrEmpty(redirecturl)) { return(Redirect(redirecturl)); } if (isJson) { return(View("close")); } return(RedirectToAction("Index")); }
public ActionResult SSLOrder(string plans_ssl) { // get buyer var buyer = repository.GetUserById(sessionid.Value, subdomainid.Value); // check that user has all relevant fields filled up if (string.IsNullOrEmpty(buyer.firstName) || string.IsNullOrEmpty(buyer.lastName) || string.IsNullOrEmpty(buyer.organisation1.name) || string.IsNullOrEmpty(buyer.organisation1.address) || !buyer.organisation1.city.HasValue || string.IsNullOrEmpty(buyer.organisation1.state) || string.IsNullOrEmpty(buyer.organisation1.postcode) || !buyer.organisation1.country.HasValue || string.IsNullOrEmpty(buyer.organisation1.phone) || string.IsNullOrEmpty(buyer.email)) { return(Json("Please ensure that your personal & organisation details are complete".ToJsonFail())); } // get clear pixels domain var clearpixeldomain = repository.GetSubDomains().Single(x => x.name == "clearpixels"); var transaction = new Transaction(clearpixeldomain, buyer, TransactionType.INVOICE, repository, sessionid.Value); var ordernumber = repository.GetNewOrderNumber(clearpixeldomain.id, TransactionType.INVOICE); transaction.CreateTransaction(ordernumber, DateTime.UtcNow, "", CurrencyHelper.GetCurrencies().Where(x => x.code == "USD").Single().id); transaction.UpdateOrderStatus(OrderStatus.SENT); var variant = repository.GetProductVariant(plans_ssl, clearpixeldomain.id, null); var orderitem = new orderItem() { description = variant.product.title, variantid = variant.id, unitPrice = variant.product.sellingPrice, tax = variant.product.tax, quantity = 1 }; transaction.AddOrderItem(orderitem, null); // update order total transaction.UpdateTotal(); transaction.SaveNewTransaction(); // send email to seller Syslog.Write(string.Format("{0} bought by subdomainid {1}", plans_ssl, subdomainid.Value)); // handle payment var uniqueid = string.Format("{0}:{1}", accountSubdomainName, plans_ssl); var pworker = new PaypalWorker(uniqueid, transaction, repository, clearpixeldomain.GetPaypalID(), transaction.GetCurrency().id, accountHostname.ToDomainUrl("/dashboard/account/SSLProcess?d=" + plans_ssl)); var redirecturl = pworker.GetPaymentUrl(); return(Json(redirecturl.ToJsonOKData())); }