public void Execute(IList <string> args) { var appSettings = _apiSettingsFactory(); if (!string.IsNullOrEmpty(appSettings.AccessKey)) { _outputWriter.WriteError("An access-key is already specified in your settings."); return; } var inviteCode = args.FirstOrDefault(); if (string.IsNullOrEmpty(inviteCode)) { _outputWriter.WriteError("'invite-code' is required"); return; } var result = _cmdCoffeeApi.Join(inviteCode).Result; _outputWriter.WriteLine("\nInvite code accepted!"); _outputWriter.WriteLine($"\n{result.legal}"); _outputWriter.WriteLine($"{result.termsOfUse}"); _outputWriter.WriteLine($"{result.privacyPolicy}"); var answer = _outputWriter.AskYesNo("Ok?"); if (!answer) { _outputWriter.AwaitAnyKey("Okay. When you change your mind, we're here for you"); return; } _outputWriter.WriteLine("\nGreat. Let's update your app-settings.json file"); _outputWriter.WriteLine($"You can find it here: {appSettings.SettingsFile}"); _outputWriter.AwaitAnyKey(); _outputWriter.WriteLine("Under 'Configuration' add this:"); _outputWriter.WriteLine($"\"AccessKey\": \"{result.accessKey}\""); _outputWriter.AwaitAnyKey(); _outputWriter.WriteLine("Update your \"ShippingAddress\"."); _outputWriter.AwaitAnyKey(); _outputWriter.WriteLine("Save the file."); _outputWriter.AwaitAnyKey(); _outputWriter.WriteLine("You're good to go! Restart to use new settings."); }
public void Execute(IList <string> args) { try { var productCode = args.First(); if (string.IsNullOrEmpty(productCode)) { _writer.WriteError("product-code required"); return; } var promoCode = args.Count() > 1 ? args[1] : string.Empty; if (_appSettings.ShippingAddress == null) { _writer.WriteError("shipping address required"); return; } var result = _cmdCoffeeApi.PostOrder(productCode, _appSettings.ShippingAddress, promoCode).Result; var order = result.orderDetails; _writer.WriteLine(_outputGenerator.GeneratePairs(new Dictionary <string, object> { { "product", order.productName }, { "sub-total", order.subTotal }, { "discount", order.discount }, { "total", order.total } }, "Please confirm order details")); _writer.WriteLine( $"{_outputGenerator.GeneratePairs((IEnumerable<KeyValuePair<string, JToken>>) order.shippingAddress, "shipping address")}"); if (!_writer.AskYesNo("Is this correct?")) { _writer.WriteLine( "If your address is not correct, please update your address in app-settings.json and try again."); return; } _writer.WriteLine($"\nCheck out our return policy: {result.returnPolicy}"); if (!_writer.AskYesNo("Does that work for you?")) { _writer.AwaitAnyKey( $"Bummer. Feel free to shoot us an email to {_appSettings.ContactEmail} to share your concerns."); return; } _writer.WriteLine($"\nWe'll get started on your order as soon as we receive payment."); _writer.WriteLine($"Payment will be accepted until {result.paymentExpiration}"); _writer.AwaitAnyKey("Press enter to see payment methods"); var paymentOptions = new List <dynamic>(); paymentOptions.AddRange(result.paymentOptions as IEnumerable <dynamic>); var paypalAddress = $"{_appSettings.PayPalAddress}{order.total}USD"; paymentOptions.Add(new { Name = "PayPal.Me", Value = new { amount = order.total, address = paypalAddress } }); _writer.WriteLine(_outputGenerator.GenerateTable(paymentOptions, new [] { "Type", "Amount", "Address" }, o => o.Name, o => o.Value.amount, o => o.Value.address)); _writer.WriteLine($"Make sure you include your order key ({order.orderKey}) in the payment note."); _writer.AwaitAnyKey(); } catch (Exception ex) { _writer.WriteError(ex); } }