//POST: Ebay/OrderApiInitiateGuestCheckoutSession/{data} public ActionResult OrderApiInitiateGuestCheckoutSession(EbayOrderApiInitiateGuestCheckoutSessionModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Invalid User" })); } AddressResultModel addressData = addressTable.SelectRecord(new SelectAddressModel() { CustomerUUID = customerResult.CustomerUUID }); CheckoutSessionResponse response = OrderAPI.InitiateGuestCheckoutSession(data.orderId, customerResult, addressData); InsertCustomerOrderModel customerOrder = new InsertCustomerOrderModel() { CustomerUUID = customerResult.CustomerUUID, CheckoutSessionID = response.checkoutSessionId, ExpirationDate = response.expirationDate, ImageURL = data.imageUrl, PurchasePrice = response.pricingSummary.total.value, Title = response.lineItems[0].title }; NonQueryResultModel orderResult = customerOrderTable.InsertRecord(customerOrder); return(Json(response)); }
public ActionResult DailyPurchase() { List <CustomerResultModel> customerList = customerTable.SelectAllRecords(); foreach (CustomerResultModel customer in customerList) { //Get customer's query prefrences QueryResultModel queryPref = queryTable.SelectRecord(new SelectQueryModel() { CustomerUUID = customer.CustomerUUID }); //Ask Ebay for items. SearchPagedCollection itemCollection = BrowseAPI.ItemSummarySearch(queryPref.CategoryID, queryPref.PriceLimit); try { //There were no items found for this query if (itemCollection.itemSummaries.Length == 0) { continue; } //Get customer's address data AddressResultModel customerAddress = addressTable.SelectRecord(new SelectAddressModel() { CustomerUUID = customer.CustomerUUID }); //Initiate order with a randomly chosen index from itemCollection's itemSummaries Random rand = new Random(); int itemIndex = rand.Next(itemCollection.itemSummaries.Length); CheckoutSessionResponse response = OrderAPI.InitiateGuestCheckoutSession(itemCollection.itemSummaries[itemIndex].itemId, customer, customerAddress); InsertCustomerOrderModel customerOrder = new InsertCustomerOrderModel() { CustomerUUID = customer.CustomerUUID, CheckoutSessionID = response.checkoutSessionId, ExpirationDate = response.expirationDate, ImageURL = itemCollection.itemSummaries[itemIndex].image.imageUrl, PurchasePrice = response.pricingSummary.total.value, Title = response.lineItems[0].title }; NonQueryResultModel orderResult = customerOrderTable.InsertRecord(customerOrder); } catch (Exception e) { } } return(Json(new { result = "Daily Purchases Complete" })); }
public ActionResult GetAddress(PreferenceGetAddressModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Invalid Customer" })); } AddressResultModel customerAddress = addressTable.SelectRecord(new SelectAddressModel() { CustomerUUID = customerResult.CustomerUUID }); return(Json(new { result = customerAddress })); }
public static CheckoutSessionResponse InitiateGuestCheckoutSession(string itemId, CustomerResultModel customerInfo, AddressResultModel addressInfo) { /* * Initiate a guest checkout session * POST https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/initiate * * { * "contactEmail" : "*****@*****.**", * "contactFirstName":"Frank", * "contactLastName":"Smith", * "shippingAddress" : { * "recipient" : "Frank Smith", * "phoneNumber" : "617 817 7449 ", * "addressLine1" : "3737 Casa Verde St", * "city" : "San Jose", * "stateOrProvince" : "CA", * "postalCode" : "95134", * "country" : "US" * }, * "lineItemInputs" : [ { * "quantity" : 1, * "itemId" : "v1|190006102824|0" * } * ] * } */ CreateGuestCheckoutSessionRequest request = new CreateGuestCheckoutSessionRequest(); request.contactEmail = "*****@*****.**"; request.contactFirstName = "Frank"; request.contactLastName = "Smith"; request.shippingAddress = new ShippingAddress(); request.shippingAddress.recipient = "Frank Smith"; request.shippingAddress.phoneNumber = "617 817 7449 "; request.shippingAddress.addressLine1 = "3737 Casa Verde St"; request.shippingAddress.city = "San Jose"; request.shippingAddress.stateOrProvince = "CA"; request.shippingAddress.postalCode = "95134"; request.shippingAddress.country = "US"; request.lineItemInputs = new LineItemInputs[] { new LineItemInputs { quantity = 1, itemId = itemId } }; string apiUrl = baseUrl + "/buy/order/v1/guest_checkout_session/initiate"; CheckoutSessionResponse response = Web.Post <CheckoutSessionResponse, CreateGuestCheckoutSessionRequest>(apiUrl, request); return(response); }