/// <summary> /// Send transaction to server /// </summary> /// <param name="card">The card information</param> /// <param name="command">The definition of the request is for payment or refund</param> /// <param name="amount">The amount of transaction</param> /// <param name="date">Date time transaction processed</param> /// <param name="transactionContent">Note of transaction</param> /// <param name="_version">Version of API, default 1.0.1</param> /// <returns>The transaction response information</returns> public static async Task <ProcessTransactionResponse> ProcessTransaction(Card card, COMMAND command, int amount, DateTime date, string transactionContent, string _version = "1.0.1") { TransactionInfo info = new TransactionInfo { command = command == COMMAND.PAY ? "pay" : "refund", cardCode = card.CardCode, owner = card.Owners, cvvCode = card.CVV, dateExpired = card.DateExpired, transactionContent = transactionContent, amount = amount, createdAt = Utilities.ConvertDateToString(date) }; ProcessTransactionRequest body = new ProcessTransactionRequest() { version = _version, transaction = info, appCode = card.AppCode, hashCode = Utilities.MD5Hash(JsonConvert.SerializeObject(new { secretKey = card.SecurityKey, transaction = info })) }; string result = await Utilities.GetWebContent(Config.API_INFO.BASE_URL + Config.API_INFO.PROCESS_URL, HttpMethod.Patch, JsonConvert.SerializeObject(body)); ProcessTransactionResponse response = JsonConvert.DeserializeObject <ProcessTransactionResponse>(result); return(response); }
public LacesResponse ProcessTransaction(ProcessTransactionRequest request) { LacesResponse response = new LacesResponse(); try { if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN]) { LacesDataModel.User.User buyer = new LacesDataModel.User.User(request.BuyerId); LacesDataModel.User.User seller = new LacesDataModel.User.User(request.SellerId); LacesDataModel.Product.Product product = new LacesDataModel.Product.Product(request.ProductId); Transaction trans = new Transaction(); trans.Amount = request.Amount; trans.BuyerId = buyer.UserId; trans.ProductId = product.ProductId; trans.ReferenceNumber = request.ReferenceNumber; trans.SellerId = seller.UserId; trans.CreatedDate = DateTime.Now; if (trans.Add()) { product.ProductStatusId = (int)ProductStatusOptions.Sold; product.Update(); response.Success = true; response.Message = "Transaction data saved succesfully."; } else { response.Success = false; response.Message = "An error occurred when communicating with the database."; } } else { response.Success = false; response.Message = "Invalid security token."; } } catch (Exception ex) { response = new LacesResponse(); response.Success = false; if (ex.Message.Contains("find user") || ex.Message.Contains("find product")) { response.Message = ex.Message; } else { response.Message = "An unexpected error has occurred; please verify the format of your request."; } } return(response); }
/// <summary> /// Send transaction to server /// </summary> /// <param name="card">The card information</param> /// <param name="amount">The amount of transaction</param> /// <param name="date">Date time transaction processed</param> /// <param name="transactionContent">Note of transaction</param> /// <param name="_version">Version of API, default 1.0.1</param> /// <returns>The transaction response information</returns> /// <exception cref="PaymentException"></exception> public async Task <InterbankResponse> Pay(Card card, int amount, DateTime date, string transactionContent, string _version = "1.0.1") { TransactionInfo info = new TransactionCardInfo ( "pay", card.CardCode, card.Owners, card.CVV, card.DateExpired, transactionContent, amount, Utilities.ConvertDateToString(date) ); ProcessTransactionRequest body = new ProcessTransactionRequest ( _version, info, card.AppCode, Utilities.MD5Hash(JsonConvert.SerializeObject(new { secretKey = card.SecurityKey, transaction = info })) ); string result = await boundary.SendRequest(BASE_URL + PROCESS_URL, HttpMethod.Patch, JsonConvert.SerializeObject(body)); return(MakeResponse(result)); }