//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 void CheckoutSessionResponseTest() { string json = "{\"checkoutSessionId\":\"7efe55c3-38c7-4a1b-944d-aded27032b9a\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://localhost/cv2v2/CheckoutReview.php\",\"checkoutResultReturnUrl\":\"https://localhost/cv2v2/CheckoutResult.php\",\"amazonPayRedirectUrl\":\"https://apay-us.amazon.com/checkout/processing?amazonCheckoutSessionId=7efe55c3-38c7-4a1b-944d-aded27032b9a\"},\"productType\":\"PayAndShip\",\"paymentDetails\":{\"paymentIntent\":\"Authorize\",\"canHandlePendingAuthorization\":false,\"chargeAmount\":{\"amount\":\"1.40\",\"currencyCode\":\"USD\"},\"totalOrderAmount\":null,\"softDescriptor\":null,\"presentmentCurrency\":\"USD\",\"allowOvercharge\":null,\"extendExpiration\":null},\"chargePermissionType\":\"OneTime\",\"recurringMetadata\":null,\"merchantMetadata\":{\"merchantReferenceId\":\"2020-0001\",\"merchantStoreName\":\"Your Store Name Goes Here\",\"noteToBuyer\":\"Order #12345-67890\",\"customInformation\":\"custom information can go here\"},\"supplementaryData\":null,\"buyer\":{\"name\":\"Sandbox Guillot\",\"email\":\"[email protected]\",\"buyerId\":\"amzn1.account.AFBDVVLYITS5Q7CJV7UJVFAMU2PA\"},\"billingAddress\":{\"name\":\"Christopher C. Conn\",\"addressLine1\":\"4996 Rockford Mountain Lane\",\"addressLine2\":null,\"addressLine3\":null,\"city\":\"Appleton\",\"county\":null,\"district\":null,\"stateOrRegion\":\"WI\",\"postalCode\":\"54911\",\"countryCode\":\"US\",\"phoneNumber\":null},\"paymentPreferences\":[{\"paymentDescriptor\":\"Your selected Amazon payment method\"}],\"statusDetails\":{\"state\":\"Open\",\"reasonCode\":null,\"reasonDescription\":null,\"lastUpdatedTimestamp\":\"20201023T211923Z\"},\"shippingAddress\":{\"name\":\"Susie Smith\",\"addressLine1\":\"10 Ditka Ave\",\"addressLine2\":\"Suite 2500\",\"addressLine3\":null,\"city\":\"Chicago\",\"county\":null,\"district\":null,\"stateOrRegion\":\"IL\",\"postalCode\":\"60602\",\"countryCode\":\"US\",\"phoneNumber\":\"800-000-0000\"},\"platformId\":null,\"chargePermissionId\":null,\"chargeId\":null,\"constraints\":[],\"creationTimestamp\":\"20201023T211909Z\",\"expirationTimestamp\":\"20201024T211909Z\",\"storeId\":\"amzn1.application-oa2-client.d9da4374abb24732a174be549d99eb7a\",\"providerMetadata\":{\"providerReferenceId\":null},\"releaseEnvironment\":\"Sandbox\",\"deliverySpecifications\":null}"; var dateConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyyMMddTHHmmssZ" }; CheckoutSessionResponse r = new CheckoutSessionResponse(); r = JsonConvert.DeserializeObject <CheckoutSessionResponse>(json, dateConverter); Assert.AreEqual("Christopher C. Conn", r.BillingAddress.Name); Assert.AreEqual("4996 Rockford Mountain Lane", r.BillingAddress.AddressLine1); Assert.IsNull(r.BillingAddress.AddressLine2); Assert.IsNull(r.BillingAddress.AddressLine3); Assert.AreEqual("Appleton", r.BillingAddress.City); Assert.IsNull(r.BillingAddress.County); Assert.IsNull(r.BillingAddress.District); Assert.AreEqual("WI", r.BillingAddress.StateOrRegion); Assert.AreEqual("54911", r.BillingAddress.PostalCode); Assert.AreEqual("US", r.BillingAddress.CountryCode); Assert.IsNull(r.BillingAddress.PhoneNumber); Assert.AreEqual("Susie Smith", r.ShippingAddress.Name); Assert.AreEqual("10 Ditka Ave", r.ShippingAddress.AddressLine1); Assert.AreEqual("Suite 2500", r.ShippingAddress.AddressLine2); Assert.IsNull(r.ShippingAddress.AddressLine3); Assert.AreEqual("Chicago", r.ShippingAddress.City); Assert.IsNull(r.ShippingAddress.County); Assert.IsNull(r.ShippingAddress.District); Assert.AreEqual("IL", r.ShippingAddress.StateOrRegion); Assert.AreEqual("60602", r.ShippingAddress.PostalCode); Assert.AreEqual("US", r.ShippingAddress.CountryCode); Assert.AreEqual("800-000-0000", r.ShippingAddress.PhoneNumber); }
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 void CompleteCheckoutSessionCanBeMocked() { var checkoutSessionResponse = new CheckoutSessionResponse(); this.mockWebStoreClient.Setup(mwsc => mwsc.CompleteCheckoutSession(It.IsAny <string>(), It.IsAny <CompleteCheckoutSessionRequest>(), It.IsAny <Dictionary <string, string> >())).Returns(checkoutSessionResponse); var result = this.mockWebStoreClient.Object.CompleteCheckoutSession("SessionId", new CompleteCheckoutSessionRequest(10, Types.Currency.USD), new Dictionary <string, string>()); Assert.That(result, Is.EqualTo(checkoutSessionResponse)); this.mockWebStoreClient.Verify(mwsc => mwsc.CompleteCheckoutSession(It.IsAny <string>(), It.IsAny <CompleteCheckoutSessionRequest>(), It.IsAny <Dictionary <string, string> >()), Times.Once); }
public void CreateCheckOutSessionCanBeMocked() { var checkoutSessionResponse = new CheckoutSessionResponse(); this.mockWebStoreClient.Setup(mwsc => mwsc.CreateCheckoutSession(It.IsAny <CreateCheckoutSessionRequest>(), It.IsAny <Dictionary <string, string> >())).Returns(checkoutSessionResponse); var result = this.mockWebStoreClient.Object.CreateCheckoutSession(new CreateCheckoutSessionRequest("www.amazon.com", "1"), new Dictionary <string, string>()); Assert.That(result, Is.EqualTo(checkoutSessionResponse)); this.mockWebStoreClient.Verify(mwsc => mwsc.CreateCheckoutSession(It.IsAny <CreateCheckoutSessionRequest>(), It.IsAny <Dictionary <string, string> >()), Times.Once); }
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); }