//DTO public OrderTransactionDTO ToDto() { OrderTransactionDTO dto = new OrderTransactionDTO(); dto.Action = (OrderTransactionActionDTO)((int)this.Action); dto.Amount = this.Amount; dto.CheckNumber = this.CheckNumber; dto.CompanyAccountNumber = this.CompanyAccountNumber; dto.CreditCard = new OrderTransactionCardDataDTO(); dto.CreditCard.CardHolderName = this.CreditCard.CardHolderName; dto.CreditCard.CardIsEncrypted = false; dto.CreditCard.CardNumber = this.CreditCard.CardNumber; dto.CreditCard.ExpirationMonth = this.CreditCard.ExpirationMonth; dto.CreditCard.ExpirationYear = this.CreditCard.ExpirationYear; dto.CreditCard.SecurityCode = this.CreditCard.SecurityCode; dto.GiftCardNumber = this.GiftCardNumber; dto.Id = this.Id; dto.LinkedToTransaction = this.LinkedToTransaction; dto.Messages = this.Messages; dto.OrderId = this.OrderId; dto.OrderNumber = this.OrderNumber; dto.PurchaseOrderNumber = this.PurchaseOrderNumber; dto.RefNum1 = this.RefNum1; dto.RefNum2 = this.RefNum2; dto.StoreId = this.StoreId; dto.Success = this.Success; dto.TimeStampUtc = this.TimeStampUtc; dto.Voided = this.Voided; return(dto); }
/// <summary> /// Allows the REST API to create or update a transaction. /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the transaction ID (bvin) and that this is an update, otherwise it assumes to /// create a new transaction. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the OrderTransacionDTO object</param> /// <returns>CategoryDTO - Serialized (JSON) version of the transaction</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); var response = new ApiResponse <OrderTransactionDTO>(); OrderTransactionDTO postedItem = null; try { postedItem = Json.ObjectFromJson <OrderTransactionDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new OrderTransaction(); item.FromDto(postedItem); var existing = HccApp.OrderServices.Transactions.Find(item.Id); if (existing == null || item.Id == Guid.Empty) { item.StoreId = HccApp.CurrentStore.Id; item.Id = Guid.NewGuid(); HccApp.OrderServices.Transactions.Create(item); } else { item.StoreId = HccApp.CurrentStore.Id; HccApp.OrderServices.Transactions.Update(item); } var resultItem = HccApp.OrderServices.Transactions.Find(item.Id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = Json.ObjectToJson(response); return(data); }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string bvin = FirstParameter(parameters); ApiResponse <OrderTransactionDTO> response = new ApiResponse <OrderTransactionDTO>(); OrderTransactionDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson <OrderTransactionDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(MerchantTribe.Web.Json.ObjectToJson(response)); } OrderTransaction item = new OrderTransaction(); item.FromDto(postedItem); OrderTransaction existing = MTApp.OrderServices.Transactions.Find(item.Id); if (existing == null || item.IdAsString == "00000000-0000-0000-0000-000000000000") { item.StoreId = MTApp.CurrentStore.Id; item.Id = System.Guid.NewGuid(); MTApp.OrderServices.Transactions.Create(item); } else { item.StoreId = MTApp.CurrentStore.Id; MTApp.OrderServices.Transactions.Update(item); } OrderTransaction resultItem = MTApp.OrderServices.Transactions.Find(item.Id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = MerchantTribe.Web.Json.ObjectToJson(response); return(data); }
/// <summary> /// Allows you to populate the current transaction object using a OrderTransactionDTO instance /// </summary> /// <param name="dto">An instance of the transaction from the REST API</param> public void FromDto(OrderTransactionDTO dto) { if (dto == null) { return; } Action = (ActionType)(int)dto.Action; Amount = dto.Amount; CheckNumber = dto.CheckNumber ?? string.Empty; CompanyAccountNumber = dto.CompanyAccountNumber ?? string.Empty; if (dto.CreditCard != null) { if (dto.CreditCard.CardIsEncrypted == false) { CreditCard.CardNumber = dto.CreditCard.CardNumber ?? string.Empty; } CreditCard.CardHolderName = dto.CreditCard.CardHolderName ?? string.Empty; CreditCard.ExpirationMonth = dto.CreditCard.ExpirationMonth; CreditCard.ExpirationYear = dto.CreditCard.ExpirationYear; } if (dto.GiftCard != null) { GiftCard.LineItemId = dto.GiftCard.LineItemId; GiftCard.CardNumber = dto.GiftCard.CardNumber; GiftCard.Amount = dto.GiftCard.Amount; GiftCard.RecipientName = dto.GiftCard.RecipientName; GiftCard.RecipientEmail = dto.GiftCard.RecipientEmail; GiftCard.ExpirationDate = dto.GiftCard.ExpirationDate; } Id = dto.Id; LinkedToTransaction = dto.LinkedToTransaction ?? string.Empty; Messages = dto.Messages ?? string.Empty; OrderId = dto.OrderId ?? string.Empty; OrderNumber = dto.OrderNumber ?? string.Empty; PurchaseOrderNumber = dto.PurchaseOrderNumber ?? string.Empty; RefNum1 = dto.RefNum1 ?? string.Empty; RefNum2 = dto.RefNum2 ?? string.Empty; StoreId = dto.StoreId; Success = dto.Success; TimeStampUtc = dto.TimeStampUtc; Voided = dto.Voided; }
/// <summary> /// Allows you to convert the current transaction object to the DTO equivalent for use with the REST API /// </summary> /// <returns>A new instance of OrderTransactionDTO</returns> public OrderTransactionDTO ToDto() { var dto = new OrderTransactionDTO(); dto.Action = (OrderTransactionActionDTO)(int)Action; dto.Amount = Amount; dto.CheckNumber = CheckNumber; dto.CompanyAccountNumber = CompanyAccountNumber; dto.CreditCard = new OrderTransactionCardDataDTO { CardHolderName = CreditCard.CardHolderName, CardIsEncrypted = false, CardNumber = CreditCard.CardNumber, ExpirationMonth = CreditCard.ExpirationMonth, ExpirationYear = CreditCard.ExpirationYear }; dto.GiftCard.LineItemId = GiftCard.LineItemId; dto.GiftCard.CardNumber = GiftCard.CardNumber; dto.GiftCard.Amount = GiftCard.Amount; dto.GiftCard.RecipientName = GiftCard.RecipientName; dto.GiftCard.RecipientEmail = GiftCard.RecipientEmail; dto.GiftCard.ExpirationDate = GiftCard.ExpirationDate; dto.Id = Id; dto.LinkedToTransaction = LinkedToTransaction; dto.Messages = Messages; dto.OrderId = OrderId; dto.OrderNumber = OrderNumber; dto.PurchaseOrderNumber = PurchaseOrderNumber; dto.RefNum1 = RefNum1; dto.RefNum2 = RefNum2; dto.StoreId = StoreId; dto.Success = Success; dto.TimeStampUtc = TimeStampUtc; dto.Voided = Voided; return(dto); }
public void FromDto(OrderTransactionDTO dto) { if (dto == null) { return; } this.Action = (ActionType)((int)dto.Action); this.Amount = dto.Amount; this.CheckNumber = dto.CheckNumber ?? string.Empty; this.CompanyAccountNumber = dto.CompanyAccountNumber ?? string.Empty; if (dto.CreditCard != null) { if (dto.CreditCard.CardIsEncrypted == false) { this.CreditCard.CardNumber = dto.CreditCard.CardNumber ?? string.Empty; } this.CreditCard.CardHolderName = dto.CreditCard.CardHolderName ?? string.Empty; this.CreditCard.ExpirationMonth = dto.CreditCard.ExpirationMonth; this.CreditCard.ExpirationYear = dto.CreditCard.ExpirationYear; this.CreditCard.SecurityCode = dto.CreditCard.SecurityCode ?? string.Empty; } this.GiftCardNumber = dto.GiftCardNumber ?? string.Empty; this.Id = dto.Id; this.LinkedToTransaction = dto.LinkedToTransaction ?? string.Empty; this.Messages = dto.Messages ?? string.Empty; this.OrderId = dto.OrderId ?? string.Empty; this.OrderNumber = dto.OrderNumber ?? string.Empty; this.PurchaseOrderNumber = dto.PurchaseOrderNumber ?? string.Empty; this.RefNum1 = dto.RefNum1 ?? string.Empty; this.RefNum2 = dto.RefNum2 ?? string.Empty; this.StoreId = dto.StoreId; this.Success = dto.Success; this.TimeStampUtc = dto.TimeStampUtc; this.Voided = dto.Voided; }
public void Order_CreateUpdateDeleteTransaction() { //Create API Proxy var proxy = CreateApiProxy(); //Create Order. var order = new OrderDTO { StoreId = 1, Items = new List <LineItemDTO> { new LineItemDTO { StoreId = 1, ProductId = "fcb5f832-0f72-4722-bfd9-ec099051fc00" }, new LineItemDTO { StoreId = 1, ProductId = "d6895ee4-8118-4e51-905b-fc8edad5d711" } } }; var createResponse = proxy.OrdersCreate(order); CheckErrors(createResponse); //Create Order Transaction var orderTransaction = new OrderTransactionDTO { Action = OrderTransactionActionDTO.CashReceived, Amount = 50, Messages = "test transaction", OrderId = createResponse.Content.Bvin, OrderNumber = createResponse.Content.OrderNumber, StoreId = 1, TimeStampUtc = DateTime.UtcNow }; var createTransactionResponse = proxy.OrderTransactionsCreate(orderTransaction); CheckErrors(createTransactionResponse); Assert.IsFalse(string.IsNullOrEmpty(createTransactionResponse.Content.Id.ToString())); //Update Transaction createTransactionResponse.Content.Messages = createTransactionResponse.Content.Messages + "updated"; var updateTransactionResponse = proxy.OrderTransactionsUpdate(createTransactionResponse.Content); CheckErrors(updateTransactionResponse); Assert.AreEqual(createTransactionResponse.Content.Messages, updateTransactionResponse.Content.Messages); //Delete Transaction by Transaction unique identifier. var deleteTransactionResponse = proxy.OrderTransactionsDelete(updateTransactionResponse.Content.Id); CheckErrors(deleteTransactionResponse); Assert.IsTrue(deleteTransactionResponse.Content); //Delete Order var orderBvin = createResponse.Content.Bvin; var deleteResponse = proxy.OrdersDelete(orderBvin); CheckErrors(deleteResponse); Assert.IsTrue(deleteResponse.Content); }