コード例 #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
        static void Main(string[] args)
        {
            TwoCheckoutConfig.SellerID = "901288242";
            TwoCheckoutConfig.PrivateKey = "80D02EA2-4847-4AC0-9E11-77B50CDFBB97";
            TwoCheckoutConfig.Sandbox = true;   //<-- Set Mode to use your 2Checkout sandbox account
            System.Console.Write("Enter cc token:");
            var token = System.Console.ReadLine();;

            try
            {
                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 Customer = new ChargeAuthorizeServiceOptions();
                Customer.total = (decimal)1.00;
                Customer.currency = "USD";
                Customer.merchantOrderId = "123";
                Customer.billingAddr = Billing;
                Customer.token = token;
                Customer.lineItems = new List<AuthLineitem>();

                Customer.lineItems.Add(new AuthLineitem {
                    price = 1,
                    name = "Baygon",
                    productId = "5567",
                    type = "product", // TODO: this should be passed in from outside. Possible values: ‘product’, ‘shipping’, ‘tax’ or ‘coupon’
                    quantity = 1      // TODO: this should be passed in from outside. Possible values: 1-999                    
                });

                var Charge = new ChargeService();

                var result = Charge.Authorize(Customer);
                System.Console.Write("[INFO] - Charging is success. Response code: "+result.responseCode+", message: "+result.responseMsg);
            }
            catch (TwoCheckoutException e)
            {
                System.Console.Write("[ERROR] - Charing is failed. Exception: "+e.Message);
            }            
        }
コード例 #3
0
        public ActionResult Process()
        {
            TwoCheckoutConfig.SellerID = "sandbox-seller-id";
            TwoCheckoutConfig.PrivateKey = "sandbox-private-key";
            TwoCheckoutConfig.Sandbox = true;

            try
            {
                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.phone = "5555555555";

                var Customer = new ChargeAuthorizeServiceOptions();
                Customer.total = (decimal)1.00;
                Customer.currency = "USD";
                Customer.merchantOrderId = "123";
                Customer.billingAddr = Billing;
                Customer.token = Request["token"];

                var Charge = new ChargeService();

                var result = Charge.Authorize(Customer);
                ViewBag.Message = result.responseMsg;
            }
            catch (TwoCheckoutException e)
            {
                ViewBag.Message = e.Message.ToString();
            }

            return View();
        }