/// <summary> /// To Call Payment Create Api... /// </summary> /// <param name="request"></param> /// <param name="success"></param> /// <param name="failed"></param> /// <returns></returns> public async Task <PaymentCreateResponseModel> PaymentCreateApi(PaymentCreateRequestModel request, Action <object> success, Action <object> failed) { PaymentCreateResponseModel resmodel = new PaymentCreateResponseModel(); try { var url = string.Format("{0}/api/appconnect/PaymentCreate", WebServiceDetails.BaseUri); string randomGuid = Guid.NewGuid().ToString(); var dic = new Dictionary <string, string>(); //dic.Add("Content-Type", "Application/json"); dic.Add("randomguid", randomGuid); dic.Add("hash", randomGuid + WebServiceDetails.AppKey + request.usertoken + Helpers.Constants.LoginUserSecret + request.loannumber + request.loanschedulenumber); var result = _apiProvider.Post <PaymentCreateResponseModel, PaymentCreateRequestModel>(url, request, dic); var response = result.Result; PaymentCreateResponseModel objres = null; dynamic obj = ""; PaymentCreateResponseModel reg = new PaymentCreateResponseModel(); if (response.IsSuccessful != false) { objres = JsonConvert.DeserializeObject <PaymentCreateResponseModel>(response.RawResult); success.Invoke(objres); } else { UserDialogs.Instance.HideLoading(); failed.Invoke(obj); } } catch (Exception exception) { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert("Something went wrong please try again.", "", "OK"); } return(resmodel); }
public int CreatePayment(int orderId) { var order = _orderService.GetOrderById(orderId); if (order == null) { throw new ArgumentNullException("Order"); } var nopBillingAddress = _addressService.GetAddressById(order.BillingAddressId); var amount = Math.Round(order.OrderTotal, 2); var shopTransactionId = order.OrderGuid.ToString(); var buyerName = String.Format( "{0} {1}", nopBillingAddress?.FirstName, nopBillingAddress?.LastName ); var endpoint = _gestpayPayByLinkPaymentSettings.UseSandbox ? "https://sandbox.gestpay.net/api/v1/payment/create/" : "https://ecomms2s.sella.it/api/v1/payment/create/"; OrderDetails orderDetails = new OrderDetails(); CustomInfo customInfo = new CustomInfo(); Dictionary <string, string> myDict = new Dictionary <string, string>(); myDict.Add("OrderNumber", order.CustomOrderNumber); customInfo.customInfo = myDict; PaymentCreateRequestModel model = new PaymentCreateRequestModel(); model.shopLogin = _gestpayPayByLinkPaymentSettings.ShopOperatorCode; model.currency = "EUR"; model.amount = amount.ToString("0.00", CultureInfo.InvariantCulture); model.shopTransactionID = shopTransactionId; model.buyerName = buyerName; model.buyerEmail = nopBillingAddress?.Email; model.languageId = _gestpayPayByLinkPaymentSettings.LanguageCode.ToString(); model.customInfo = customInfo; model.orderDetails = orderDetails; PaymentChannel paymentChannel = new PaymentChannel(); paymentChannel.channelType = new List <string> { "EMAIL" }; model.paymentChannel = paymentChannel; var responseStr = string.Empty; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint); request.ContentType = "application/json"; request.Headers.Add("Authorization", "apikey " + _gestpayPayByLinkPaymentSettings.ApiKey); request.Method = "POST"; var json = JsonConvert.SerializeObject(model); using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); responseStr = reader.ReadToEnd(); reader.Close(); dataStream.Close(); PaymentCreateResponseModel paymentResponse = JsonConvert.DeserializeObject <PaymentCreateResponseModel>(responseStr); return(Convert.ToInt32(paymentResponse.error.code)); } } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { responseStr = reader.ReadToEnd(); } PaymentCreateResponseModel paymentResponse = JsonConvert.DeserializeObject <PaymentCreateResponseModel>(responseStr); _logger.Error("Gestpay Pay Link Error = " + paymentResponse.error.code + " " + paymentResponse.error.description, ex); return(-1); } }