Пример #1
0
        public void _001_TestApiAuthorization()
        {
            try
            {
                var Service = new ChargeService();

                var Option1 = new AuthLineitemOption();
                Option1.optName      = "Test Option 1";
                Option1.optValue     = "Large";
                Option1.optSurcharge = (decimal)1.00;

                var Options = new List <AuthLineitemOption>();
                Options.Add(Option1);

                var LineItem1 = new AuthLineitem();
                LineItem1.name     = "test item";
                LineItem1.price    = (decimal)10.00;
                LineItem1.quantity = 1;
                LineItem1.options  = Options;

                var Lineitems = new List <AuthLineitem>();
                Lineitems.Add(LineItem1);

                var Billing = new AuthBillingAddress();
                Billing.addrLine1   = "123 test st";
                Billing.city        = "Columbus";
                Billing.zipCode     = "43123";
                Billing.state       = "OH";
                Billing.country     = "USA";
                Billing.name        = "Testing Tester";
                Billing.email       = "*****@*****.**";
                Billing.phoneNumber = "5555555555";

                var Shipping = new AuthShippingAddress();
                Shipping.addrLine1 = "123 test st";
                Shipping.city      = "Columbus";
                Shipping.state     = "OH";
                Shipping.country   = "USA";
                Shipping.name      = "Testing Tester";


                var Sale = new ChargeAuthorizeServiceOptions();
                Sale.lineItems       = Lineitems;
                Sale.currency        = "USD";
                Sale.merchantOrderId = "123";
                Sale.billingAddr     = Billing;
                Sale.shippingAddr    = Shipping;
                Sale.token           = token;

                var Charge = new ChargeService();

                var result = Charge.Authorize(Sale);
                Assert.IsInstanceOf <Authorization>(result);
            }
            catch (TwoCheckoutException e)
            {
                Assert.IsInstanceOf <TwoCheckoutException>(e);
            }
        }
Пример #2
0
        public ActionResult PaywithCreditCard(UserModel objCard)
        {
            TwoCheckoutConfig.SellerID    = "901325328";
            TwoCheckoutConfig.PrivateKey  = "F94D20FF-0DA7-4177-BD6E-B3140DD59326";
            TwoCheckoutConfig.Sandbox     = true; // Set Mode to use your 2Checkout sandbox account
            TwoCheckoutConfig.ApiUsername = "******";
            TwoCheckoutConfig.ApiPassword = "******";
            TwoCheckoutConfig.Demo        = true;
            TwoCheckoutConfig.SecretWord  = "Yzc4NzIwZDUtODg0MC00N2YwLTk3MGMtNjk2ZGFhZjVkNGUx";
            TwoCheckoutConfig.SandboxUrl  = "https://sandbox.2checkout.com/checkout/api/1/" + TwoCheckoutConfig.SellerID + "/rs/authService";
            //TwoCheckoutConfig.BaseUrl = "https://www.2checkout.com/checkout/api/1/" + TwoCheckoutConfig.SellerID + "/rs/authService";
            var subscriptionDetails = new DataAccess.Subscription();

            try
            {
                #region Payment Sample Code

                //var LineItemOptions = new AuthLineitemOption();
                //LineItemOptions.optName = "Sample Option";
                //LineItemOptions.optSurcharge = (decimal)1.00;
                //LineItemOptions.optValue = "1";

                //var LineItemOptionsList = new List<AuthLineitemOption>();
                //LineItemOptionsList.Add(LineItemOptions);

                var Items = new AuthLineitem();
                Items.name = objCard.PlanName;
                //Items.options = LineItemOptionsList;
                Items.price      = Convert.ToDecimal(objCard.Amount);
                Items.productId  = "123";
                Items.quantity   = 1;
                Items.type       = "product";
                Items.recurrence = "N";
                Items.tangible   = "N";

                var ItemsList = new List <AuthLineitem>();
                ItemsList.Add(Items);

                var user = this._userRepository.Find(x => x.UserId == UserId).FirstOrDefault();

                var Shipping = new AuthShippingAddress();

                var Billing = new AuthBillingAddress();
                Billing.addrLine2   = user.Address;
                Billing.addrLine1   = user.Address;
                Billing.city        = user.Address;
                Billing.zipCode     = user.PinCode;
                Billing.state       = Enum.GetName(typeof(Core.States), user.State);
                Billing.country     = Enum.GetName(typeof(Core.States), user.State);
                Billing.name        = user.FirstName + " " + user.LastName;
                Billing.email       = user.Email;
                Billing.phoneNumber = user.MobileNumber;



                #endregion End of Region


                var Auth = new ChargeAuthorizeServiceOptions();
                Auth.currency        = "USD";
                Auth.merchantOrderId = "456";
                Auth.token           = objCard.token;
                Auth.total           = (decimal)Convert.ToDecimal(objCard.Amount);
                Auth.billingAddr     = Billing;
                Auth.lineItems       = ItemsList;
                //Auth.shippingAddr = Shipping;


                var Charge = new ChargeService();
                var result = Charge.Authorize(Auth);

                subscriptionDetails.Status          = result.responseCode == "APPROVED" ? true : false;
                subscriptionDetails.ReferenceNumber = result.orderNumber.ToString();
                SubscriptionStatus(objCard, subscriptionDetails);
                TempData["IsSucess"] = true;
            }
            catch (TwoCheckoutException e)
            {
                subscriptionDetails.Status = false;
                SubscriptionStatus(objCard, subscriptionDetails);
                TempData["IsSucess"] = false;
            }

            return(RedirectToAction("CardDetails", "Account"));
        }