private static CompletedOrderResponse CompleteOrder(string accessToken, int locationId, string qrCode, string proposedOrderUUID, int discountAppliedInCents, int taxAmountInCents, List <Item> itemsToOrder) { try { var orderProcessor = LevelUpClientFactory.Create <IManageProposedOrders>(LuIdentifier, LuEnvironment); return(orderProcessor.CompleteProposedOrder( accessToken: accessToken, locationId: locationId, qrPaymentData: qrCode, proposedOrderUuid: proposedOrderUUID, spendAmountCents: GetSpendAmountInCents(itemsToOrder), taxAmountCents: taxAmountInCents, exemptionAmountCents: GetExemptAmountInCents(itemsToOrder), appliedDiscountAmountCents: discountAppliedInCents, register: "Register 2", cashier: "Jane", identifierFromMerchant: "123456", receiptMessageHtml: "Thanks for eating at <strong>Freddy's Clamshack</strong>", items: itemsToOrder)); } catch (LevelUpApiException ex) { Console.WriteLine("There was an error completing the order! {0}{0}" + "Exception Details: {1}", Environment.NewLine, ex.Message); // Following the proposed order, you may have taken some action to register the // discount amount with your POS (step 4.) Since the complete order call failed, // you will likely need to roll-back that discount you applied to the check here. return(null); } }
/// <summary> /// Placing an order with LevelUp is a two-step process. The first step is to "propose" an order /// with the LevelUp platform. This is an api call that registers your intent to place an order, and /// allows our platform to determine if there is any available discount that may be applied to the /// check. The response from this call will tell the POS how much discount to apply, at which point /// the POS may apply the discount, recalculate the tax, and complete the order. /// </summary> private static ProposedOrderResponse ProposedOrder(string accessToken, int locationId, string qrCode, List <Item> itemsToOrder) { try { var orderProcessor = LevelUpClientFactory.Create <IManageProposedOrders>(LuIdentifier, LuEnvironment); return(orderProcessor.CreateProposedOrder( accessToken: accessToken, locationId: locationId, // The location id associated with the store in which the order was made. qrPaymentData: qrCode, // The QR code scanned from a customer's phone spendAmountCents: GetSpendAmountInCents(itemsToOrder), taxAmountCents: CalculateTaxInCents(GetSpendAmountInCents(itemsToOrder)), exemptionAmountCents: GetExemptAmountInCents(itemsToOrder), register: "Register 2", cashier: "Jane", identifierFromMerchant: "123456", // If your POS has it's own system of associating orders with an ID, put that ID here. receiptMessageHtml: "Thanks for eating at <strong>Freddy's Clamshack</strong>", // Added to the LevelUp email recipt. items: itemsToOrder)); } catch (LevelUpApiException ex) { Console.WriteLine(string.Format("There was an error placing the order! {0}{0}" + "Exception Details: {1}", Environment.NewLine, ex.Message)); return(null); } }
/// <summary> /// Gets a LevelUp module that hits sandbox endpoints. /// </summary> /// <typeparam name="T">The specific type of ILevelUpClientModule to return.</typeparam> internal static T GetSandboxedLevelUpModule <T>() where T : ILevelUpClientModule { return(LevelUpClientFactory.Create <T>( new AgentIdentifier(LevelUpTestConfiguration.Current.CompanyName, LevelUpTestConfiguration.Current.ProductName, LevelUpTestConfiguration.Current.ProductVersion, LevelUpTestConfiguration.Current.OperatingSystem), LevelUpEnvironment.Sandbox)); }
private static void RefundOrder(string accessToken, string orderId) { try { var refundProcessor = LevelUpClientFactory.Create <ICreateRefund>(LuIdentifier, LuEnvironment); refundProcessor.RefundOrder(accessToken, orderId); } catch (LevelUpApiException ex) { Console.WriteLine(string.Format("There was an error refunding the order! {0}{0}" + "Exception Details: {1}", Environment.NewLine, ex.Message)); } }
private static T GenerateMockLevelUpModuleWhereEveryHttpVerbDoesTheSameThing <T>( Func <string, string, string, string, IRestResponse> expectedResponseForAnyCall, LevelUpEnvironment targetEnvironment) where T : ILevelUpClientModule { var service = GenerateMockIRestfulService( expectedResponseForAnyCall, expectedResponseForAnyCall, (a, b, c) => expectedResponseForAnyCall(a, null, b, c), // GET and DELETE return the same specified RestResponse (a, b, c) => expectedResponseForAnyCall(a, null, b, c)); // object, they just don't provide a body. return(LevelUpClientFactory.Create <T>(new AgentIdentifier("SDK Unit Tests", "", "", ""), targetEnvironment, service.Object)); }
/// <summary> /// Performs the Authenticate(...) call to retrieve the access token that will be required for most of the /// subsequent requests you make to the LevelUp platform. /// </summary> private static string Authenticate(string merchantUserName, string merchantPassword, string apiKey) { try { IAuthenticate authenticator = LevelUpClientFactory.Create <IAuthenticate>(LuIdentifier, LuEnvironment); AccessToken tokenObj = authenticator.Authenticate(apiKey, merchantUserName, merchantPassword); return(tokenObj.Token); } catch (LevelUpApiException ex) { Console.WriteLine(string.Format("There was an error authenticating your user. Are the credentials " + "correct? {0}{0}Exception Details: {1}", Environment.NewLine, ex.Message)); return(null); } }