コード例 #1
0
        //-------------------------------------------------------------------------------------------
        public IGatewayResponse Bill(WeavverEntityContainer data, Sales_Orders order, Logistics_Addresses primaryAddress, Logistics_Addresses billingAddress)
        {
            string memo = "WEB PURCHASE";
               // Add the credit to the ledger.
               Accounting_LedgerItems item = new Accounting_LedgerItems();
               item.Id = Guid.NewGuid();
               item.OrganizationId = OrganizationId;
               if (order.Orderee.HasValue)
                    item.AccountId = order.Orderee.Value;
               else
                    item.AccountId = order.Id;
               item.LedgerType = LedgerType.Receivable.ToString();
               item.TransactionId = order.Id;
               item.PostAt = DateTime.UtcNow;
               item.Code = CodeType.Payment.ToString();
               item.Memo = "Payment from Card " + Number.Substring(Number.Length - 4);
               item.Amount = Math.Abs(order.Total.Value);

            //               order.BillingContactEmail

               // Submit to Authorize.Net
               var request = new AuthorizationRequest(Number, ExpirationMonth.ToString("D2") + ExpirationYear.ToString("D2"), order.Total.Value, memo, true);
               request.AddCustomer("", order.PrimaryContactNameFirst, order.PrimaryContactNameLast, primaryAddress.Line1, primaryAddress.State, primaryAddress.ZipCode);
               request.AddMerchantValue("OrderId", order.Id.ToString());
               request.AddMerchantValue("CreatedBy", order.CreatedBy.ToString());
               request.AddMerchantValue("LedgerItemId", item.Id.ToString());
               request.AddShipping("", order.BillingContactNameFirst, order.BillingContactNameLast, billingAddress.Line1, billingAddress.State, billingAddress.ZipCode);
               var gate = new Gateway(ConfigurationManager.AppSettings["authorize.net_loginid"], ConfigurationManager.AppSettings["authorize.net_transactionkey"], (ConfigurationManager.AppSettings["authorize.net_testmode"] == "true"));

               var response = gate.Send(request, memo);
               item.ExternalId = response.TransactionID;
               if (!response.Approved)
               {
                    //item.Voided = true;
                    //item.VoidedBy = Guid.Empty;
                    item.Memo += "\r\nPayment failed: Code " + response.ResponseCode + ", " + response.Message;
               }
               data.Accounting_LedgerItems.Add(item);
               return response;
        }
コード例 #2
0
        public ActionResult Authorize() {
            HttpContext ctx = System.Web.HttpContext.Current;
            Customer customer = new Customer();
            Settings settings = ViewBag.settings;
            // Retrieve Customer from Sessions/Cookie
            customer.GetFromStorage(ctx);
            if (!customer.Cart.Validate()) {
                return RedirectToAction("Index", "Cart");
            }

            if (customer.Cart.GetPaymentID() > 0) {
                UDF.ExpireCart(ctx, customer.ID);
                return RedirectToAction("Index", "Cart");
            }

            customer.BindAddresses();

            decimal amount = customer.Cart.getTotal();
            string cardnum = Request.Form["cardnumber"];
            string month = Request.Form["expiremonth"];
            string year = Request.Form["expireyear"];
            string cvv = Request.Form["cvv"];
            string first = Request.Form["first"];
            string last = Request.Form["last"];

            //step 1 - create the request
            IGatewayRequest request = new AuthorizationRequest(cardnum, month + year, amount, "Transaction");

            //These are optional calls to the API
            request.AddCardCode(cvv);

            //Customer info - this is used for Fraud Detection
            request.AddCustomer(customer.ID.ToString(), first, last, customer.Cart.Billing.street1 + ((customer.Cart.Billing.street2 != "") ? " " + customer.Cart.Billing.street2 : ""), customer.Cart.Billing.State1.abbr, customer.Cart.Billing.postal_code);

            //order number
            //request.AddInvoice("invoiceNumber");

            //Custom values that will be returned with the response
            //request.AddMerchantValue("merchantValue", "value");

            //Shipping Address
            request.AddShipping(customer.ID.ToString(), customer.Cart.Shipping.first, customer.Cart.Shipping.last, customer.Cart.Shipping.street1 + ((customer.Cart.Shipping.street2 != "") ? " " + customer.Cart.Shipping.street2 : ""), customer.Cart.Shipping.State1.abbr, customer.Cart.Shipping.postal_code);


            //step 2 - create the gateway, sending in your credentials and setting the Mode to Test (boolean flag)
            //which is true by default
            //this login and key are the shared dev account - you should get your own if you 
            //want to do more testing
            bool testmode = false;
            if (settings.Get("AuthorizeNetTestMode").Trim() == "true") {
                testmode = true;
            }

            Gateway gate = new Gateway(settings.Get("AuthorizeNetLoginKey"), settings.Get("AuthorizeNetTransactionKey"), testmode);
            customer.Cart.SetStatus((int)OrderStatuses.PaymentPending);

            //step 3 - make some money
            IGatewayResponse response = gate.Send(request);
            if (response.Approved) {
                customer.Cart.AddPayment("credit card", response.AuthorizationCode, "Complete");
                customer.Cart.SetStatus((int)OrderStatuses.PaymentComplete);
                customer.Cart.SendConfirmation(ctx);
                customer.Cart.SendInternalOrderEmail(ctx);
                int cartid = customer.Cart.ID;
                
                Cart new_cart = new Cart().Save();
                new_cart.UpdateCart(ctx, customer.ID);
                DateTime cookexp = Request.Cookies["hdcart"].Expires;
                HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
                cook.Expires = cookexp;
                Response.Cookies.Add(cook);

                customer.Cart = new_cart;
                customer.Cart.BindAddresses();

                return RedirectToAction("Complete", new { id = cartid });
            } else {
                customer.Cart.SetStatus((int)OrderStatuses.PaymentDeclined);
                return RedirectToAction("Index", new { message = response.Message });
            }
        }
コード例 #3
0
        public TransactionResponse PayWithCreditCard(int peopleId, decimal amt, string cardnumber, string expires, string description, int tranid, string cardcode, string email, string first, string last, string addr, string addr2, string city, string state, string country, string zip, string phone)
        {
            var request = new AuthorizationRequest(cardnumber, expires, amt, description, includeCapture: true);

            request.AddCustomer(peopleId.ToString(), first, last, addr, state, zip);
            request.City = city; // hopefully will be resolved with https://github.com/AuthorizeNet/sdk-dotnet/pull/41
            request.Country = country;
            request.CardCode = cardcode;
            request.Phone = phone;
            request.Email = email;
            request.InvoiceNum = tranid.ToString();

            var response = Gateway.Send(request);

            return new TransactionResponse
            {
                Approved = response.Approved,
                AuthCode = response.AuthorizationCode,
                Message = response.Message,
                TransactionId = response.TransactionID
            };
        }
コード例 #4
0
        public ActionResult Index(Donation donation)
        {
            var request = new AuthorizationRequest(donation.CardNumber, donation.ExpMonth + donation.ExpYear, donation.Amount,
                "Sponsor an AFSer");

            request.AddCustomer("", donation.FirstName, donation.LastName, donation.Address, donation.State,
                                donation.Zip);

            request.City = donation.City;
            request.Email = donation.Email;

            using (var context = new AFSAdminContext())
            {
                var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                request.ShipToFirstName = widget.FirstName;
                request.ShipToLastName = widget.LastName;
            }

            //step 2 - create the gateway, sending in your credentials
            //var gate = new Gateway("6zz6m5N4Et", "9V9wUv6Yd92t27t5", true);
            var gate = new Gateway("7f5SDz7huZ", "8A44F37ee89KqBDz", false);

            //step 3 - make some money
            var response = gate.Send(request);

            if (response.Approved)
            {
                donation.TransactionId = response.TransactionID;
                using (var context = new AFSAdminContext())
                {
                    var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                    donation.DonationId = Guid.NewGuid();
                    donation.StudentWidget = widget;
                    donation.DateOfTransaction = DateTime.Now;
                    donation.StudentWidget.AmountRaised += donation.Amount;
                    context.Donations.Add(donation);
                    context.SaveChanges();

                }

                using (var svc = new WebserviceFundAFSerSoapClient())
                {
                    XElement rsp = svc.AFSWidgetPaymentDetails("afserwidget", "globalwidgerasfer2012"
                                                                    , donation.StudentWidget.ServiceId.ToString()
                                                                    , donation.StudentWidget.StudentWidgetId.ToString()
                                                                    , donation.TransactionId
                                                                    , donation.DonationId.ToString()
                                                                    , donation.FirstName
                                                                    , donation.LastName
                                                                    , donation.Address
                                                                    , donation.City
                                                                    , donation.State
                                                                    , donation.Zip
                                                                    , donation.Email
                                                                    , donation.Amount.ToString()
                                                                    , donation.Message);
                    TempData["WSResponse"] = rsp;
                }

                TempData["Email"] = donation.Email;
                TempData["Name"] = donation.StudentWidget.FirstName;
                TempData["Amount"] = donation.Amount;
                return RedirectToAction("Reciept");
            }

            using (var context = new AFSAdminContext())
            {
                var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                donation.StudentWidget = widget;
                ViewBag.WidgetName = widget.FirstName;
            }
            ViewBag.ErrorMsg = "Error code: " + response.ResponseCode + " Message: " + response.Message;
            return View(donation);
        }
コード例 #5
0
        public ActionResult Authorize(int id = 0)
        {
            Customer c = new Customer { ID = id };
            c.Get();
            Cart currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();
            Settings settings = ViewBag.settings;

            decimal amount = currentCart.getTotal();
            string cardnum = Request.Form["cardnumber"];
            string month = Request.Form["expiremonth"];
            string year = Request.Form["expireyear"];
            string cvv = Request.Form["cvv"];
            string first = Request.Form["first"];
            string last = Request.Form["last"];

            //step 1 - create the request
            IGatewayRequest request = new AuthorizationRequest(cardnum, month + year, amount, "Transaction");

            //These are optional calls to the API
            request.AddCardCode(cvv);

            //Customer info - this is used for Fraud Detection
            request.AddCustomer(c.ID.ToString(), first, last, currentCart.Billing.street1 + ((currentCart.Billing.street2 != "") ? " " + currentCart.Billing.street2 : ""), currentCart.Billing.State1.abbr, currentCart.Billing.postal_code);

            //order number
            //request.AddInvoice("invoiceNumber");

            //Custom values that will be returned with the response
            //request.AddMerchantValue("merchantValue", "value");

            //Shipping Address
            request.AddShipping(c.ID.ToString(), currentCart.Shipping.first, currentCart.Shipping.last, currentCart.Shipping.street1 + ((currentCart.Shipping.street2 != "") ? " " + currentCart.Shipping.street2 : ""), currentCart.Shipping.State1.abbr, currentCart.Shipping.postal_code);

            //step 2 - create the gateway, sending in your credentials and setting the Mode to Test (boolean flag)
            //which is true by default
            //this login and key are the shared dev account - you should get your own if you
            //want to do more testing
            bool testmode = false;
            if (settings.Get("AuthorizeNetTestMode").Trim() == "true") {
                testmode = true;
            }

            Gateway gate = new Gateway(settings.Get("AuthorizeNetLoginKey"), settings.Get("AuthorizeNetTransactionKey"), testmode);

            //step 3 - make some money
            IGatewayResponse response = gate.Send(request);
            if (response.Approved) {
                currentCart.AddPayment("credit card", response.AuthorizationCode,"Complete");
                currentCart.SendConfirmation();
                int cartid = currentCart.ID;
                return RedirectToAction("Step6", new { id = cartid });
            } else {
                TempData["message"] = response.Message;
                return RedirectToAction("Step5", new { id = c.ID });
            }
        }