/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public async Task PostProcessPaymentAsync(PostProcessPaymentRequest postProcessPaymentRequest) { //choosing correct order address var orderAddress = await _addressService.GetAddressByIdAsync( (postProcessPaymentRequest.Order.PickupInStore ? postProcessPaymentRequest.Order.PickupAddressId : postProcessPaymentRequest.Order.ShippingAddressId) ?? 0); var orderShippingAddress = await _addressService.GetAddressByIdAsync((int)postProcessPaymentRequest.Order.ShippingAddressId); var myUtility = new PayuHelper(); var orderId = postProcessPaymentRequest.Order.Id; var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "PayuForm"; remotePostHelper.Url = _PayuPaymentSettings.PayUri; remotePostHelper.Add("key", _PayuPaymentSettings.MerchantId.ToString()); remotePostHelper.Add("amount", postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat)); remotePostHelper.Add("productinfo", "productinfo"); remotePostHelper.Add("Currency", (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode); remotePostHelper.Add("Order_Id", orderId.ToString()); remotePostHelper.Add("txnid", orderId.ToString()); remotePostHelper.Add("service_provider", "payu_paisa"); remotePostHelper.Add("surl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("furl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("hash", myUtility.getchecksum(_PayuPaymentSettings.MerchantId.ToString(), postProcessPaymentRequest.Order.Id.ToString(), postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat), "productinfo", orderAddress?.FirstName, orderAddress?.Email.ToString(), _PayuPaymentSettings.Key)); //Billing details remotePostHelper.Add("firstname", orderAddress?.FirstName.ToString()); remotePostHelper.Add("billing_cust_address", orderAddress?.Address1); remotePostHelper.Add("phone", orderAddress?.PhoneNumber); remotePostHelper.Add("email", orderAddress?.Email.ToString()); remotePostHelper.Add("billing_cust_city", orderAddress?.City); var billingStateProvince = (await _stateProvinceService.GetStateProvinceByAddressAsync(orderAddress))?.Abbreviation; if (billingStateProvince != null) { remotePostHelper.Add("billing_cust_state", (await _stateProvinceService.GetStateProvinceByAddressAsync(orderAddress))?.Abbreviation); } else { remotePostHelper.Add("billing_cust_state", ""); } remotePostHelper.Add("billing_zip_code", orderAddress?.ZipPostalCode); var billingCountry = (await _countryService.GetCountryByAddressAsync(orderAddress))?.TwoLetterIsoCode; if (billingCountry != null) { remotePostHelper.Add("billing_cust_country", (await _countryService.GetCountryByAddressAsync(orderAddress))?.TwoLetterIsoCode); } else { remotePostHelper.Add("billing_cust_country", ""); } //Delivery details if (postProcessPaymentRequest.Order.ShippingStatus != ShippingStatus.ShippingNotRequired) { remotePostHelper.Add("delivery_cust_name", orderShippingAddress.FirstName); remotePostHelper.Add("delivery_cust_address", orderShippingAddress.Address1); remotePostHelper.Add("delivery_cust_notes", string.Empty); remotePostHelper.Add("delivery_cust_tel", orderShippingAddress.PhoneNumber); remotePostHelper.Add("delivery_cust_city", orderShippingAddress.City); var deliveryStateProvince = await _stateProvinceService.GetStateProvinceByAddressAsync(orderShippingAddress); if (deliveryStateProvince != null) { remotePostHelper.Add("delivery_cust_state", deliveryStateProvince.Abbreviation); } else { remotePostHelper.Add("delivery_cust_state", ""); } remotePostHelper.Add("delivery_zip_code", orderShippingAddress.ZipPostalCode); var deliveryCountry = await _countryService.GetCountryByAddressAsync(orderShippingAddress); // postProcessPaymentRequest.Order.ShippingAddress.Country; if (deliveryCountry != null) { remotePostHelper.Add("delivery_cust_country", deliveryCountry.ThreeLetterIsoCode); } else { remotePostHelper.Add("delivery_cust_country", ""); } } // remotePostHelper.Add("Merchant_Param", _PayuPaymentSettings.MerchantParam); remotePostHelper.Post(); }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var myUtility = new PayuHelper(); var orderId = postProcessPaymentRequest.Order.Id; var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "PayuForm"; remotePostHelper.Url = _PayuPaymentSettings.PayUri; remotePostHelper.Add("key", _PayuPaymentSettings.MerchantId.ToString()); remotePostHelper.Add("amount", postProcessPaymentRequest.Order.TotalTransactionAmount.ToString(new CultureInfo("en-US", false).NumberFormat)); remotePostHelper.Add("productinfo", "productinfo"); remotePostHelper.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); remotePostHelper.Add("Order_Id", orderId.ToString()); remotePostHelper.Add("txnid", postProcessPaymentRequest.Order.OrderGuid.ToString()); remotePostHelper.Add("surl", _webHelper.GetStoreLocation(true) + "PaymentPayu/Return"); remotePostHelper.Add("furl", _webHelper.GetStoreLocation(true) + "PaymentPayu/Return"); remotePostHelper.Add("hash", myUtility.getchecksum(_PayuPaymentSettings.MerchantId.ToString(), postProcessPaymentRequest.Order.OrderGuid.ToString(), postProcessPaymentRequest.Order.TotalTransactionAmount.ToString(new CultureInfo("en-US", false).NumberFormat), "productinfo", postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString(), postProcessPaymentRequest.Order.BillingAddress.Email.ToString(), _PayuPaymentSettings.Key)); //Billing details remotePostHelper.Add("firstname", postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString()); remotePostHelper.Add("billing_cust_address", postProcessPaymentRequest.Order.BillingAddress.Address1); remotePostHelper.Add("phone", postProcessPaymentRequest.Order.BillingAddress.PhoneNumber); remotePostHelper.Add("email", postProcessPaymentRequest.Order.BillingAddress.Email.ToString()); remotePostHelper.Add("billing_cust_city", postProcessPaymentRequest.Order.BillingAddress.City); var billingStateProvince = postProcessPaymentRequest.Order.BillingAddress.StateProvince; if (billingStateProvince != null) { remotePostHelper.Add("billing_cust_state", billingStateProvince.Abbreviation); } else { remotePostHelper.Add("billing_cust_state", ""); } remotePostHelper.Add("billing_zip_code", postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode); var billingCountry = postProcessPaymentRequest.Order.BillingAddress.Country; if (billingCountry != null) { remotePostHelper.Add("billing_cust_country", billingCountry.ThreeLetterIsoCode); } else { remotePostHelper.Add("billing_cust_country", ""); } //Delivery details if (postProcessPaymentRequest.Order.ShippingStatus != ShippingStatus.ShippingNotRequired) { remotePostHelper.Add("delivery_cust_name", postProcessPaymentRequest.Order.ShippingAddress.FirstName); remotePostHelper.Add("delivery_cust_address", postProcessPaymentRequest.Order.ShippingAddress.Address1); remotePostHelper.Add("delivery_cust_notes", string.Empty); remotePostHelper.Add("delivery_cust_tel", postProcessPaymentRequest.Order.ShippingAddress.PhoneNumber); remotePostHelper.Add("delivery_cust_city", postProcessPaymentRequest.Order.ShippingAddress.City); var deliveryStateProvince = postProcessPaymentRequest.Order.ShippingAddress.StateProvince; if (deliveryStateProvince != null) { remotePostHelper.Add("delivery_cust_state", deliveryStateProvince.Abbreviation); } else { remotePostHelper.Add("delivery_cust_state", ""); } remotePostHelper.Add("delivery_zip_code", postProcessPaymentRequest.Order.ShippingAddress.ZipPostalCode); var deliveryCountry = postProcessPaymentRequest.Order.ShippingAddress.Country; if (deliveryCountry != null) { remotePostHelper.Add("delivery_cust_country", deliveryCountry.ThreeLetterIsoCode); } else { remotePostHelper.Add("delivery_cust_country", ""); } } // remotePostHelper.Add("Merchant_Param", _PayuPaymentSettings.MerchantParam); remotePostHelper.Post(); }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var myUtility = new PayuHelper(); var orderId= postProcessPaymentRequest.Order.Id; var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "PayuForm"; remotePostHelper.Url = _PayuPaymentSettings.PayUri; remotePostHelper.Add("key", _PayuPaymentSettings.MerchantId.ToString()); remotePostHelper.Add("amount", postProcessPaymentRequest.Order.TotalTransactionAmount.ToString(new CultureInfo("en-US", false).NumberFormat)); remotePostHelper.Add("productinfo", "productinfo"); remotePostHelper.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); remotePostHelper.Add("Order_Id", orderId.ToString()); remotePostHelper.Add("txnid", postProcessPaymentRequest.Order.OrderGuid.ToString()); remotePostHelper.Add("surl", _webHelper.GetStoreLocation(true) + "PaymentPayu/Return"); remotePostHelper.Add("furl", _webHelper.GetStoreLocation(true) + "PaymentPayu/Return"); remotePostHelper.Add("hash", myUtility.getchecksum(_PayuPaymentSettings.MerchantId.ToString(), postProcessPaymentRequest.Order.OrderGuid.ToString(), postProcessPaymentRequest.Order.TotalTransactionAmount.ToString(new CultureInfo("en-US", false).NumberFormat), "productinfo",postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString(), postProcessPaymentRequest.Order.BillingAddress.Email.ToString(),_PayuPaymentSettings.Key)); //Billing details remotePostHelper.Add("firstname", postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString()); remotePostHelper.Add("billing_cust_address", postProcessPaymentRequest.Order.BillingAddress.Address1); remotePostHelper.Add("phone", postProcessPaymentRequest.Order.BillingAddress.PhoneNumber); remotePostHelper.Add("email", postProcessPaymentRequest.Order.BillingAddress.Email.ToString()); remotePostHelper.Add("billing_cust_city", postProcessPaymentRequest.Order.BillingAddress.City); var billingStateProvince = postProcessPaymentRequest.Order.BillingAddress.StateProvince; if (billingStateProvince != null) remotePostHelper.Add("billing_cust_state", billingStateProvince.Abbreviation); else remotePostHelper.Add("billing_cust_state", ""); remotePostHelper.Add("billing_zip_code", postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode); var billingCountry = postProcessPaymentRequest.Order.BillingAddress.Country; if (billingCountry != null) remotePostHelper.Add("billing_cust_country", billingCountry.ThreeLetterIsoCode); else remotePostHelper.Add("billing_cust_country", ""); //Delivery details if (postProcessPaymentRequest.Order.ShippingStatus != ShippingStatus.ShippingNotRequired) { remotePostHelper.Add("delivery_cust_name", postProcessPaymentRequest.Order.ShippingAddress.FirstName); remotePostHelper.Add("delivery_cust_address", postProcessPaymentRequest.Order.ShippingAddress.Address1); remotePostHelper.Add("delivery_cust_notes", string.Empty); remotePostHelper.Add("delivery_cust_tel", postProcessPaymentRequest.Order.ShippingAddress.PhoneNumber); remotePostHelper.Add("delivery_cust_city", postProcessPaymentRequest.Order.ShippingAddress.City); var deliveryStateProvince = postProcessPaymentRequest.Order.ShippingAddress.StateProvince; if (deliveryStateProvince != null) remotePostHelper.Add("delivery_cust_state", deliveryStateProvince.Abbreviation); else remotePostHelper.Add("delivery_cust_state", ""); remotePostHelper.Add("delivery_zip_code", postProcessPaymentRequest.Order.ShippingAddress.ZipPostalCode); var deliveryCountry = postProcessPaymentRequest.Order.ShippingAddress.Country; if (deliveryCountry != null) remotePostHelper.Add("delivery_cust_country", deliveryCountry.ThreeLetterIsoCode); else remotePostHelper.Add("delivery_cust_country", ""); } // remotePostHelper.Add("Merchant_Param", _PayuPaymentSettings.MerchantParam); remotePostHelper.Post(); }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var myUtility = new PayuHelper(); var orderId = postProcessPaymentRequest.Order.Id; var billingAddress = _addressService.GetAddressById(postProcessPaymentRequest.Order.BillingAddressId); var countryName = string.Empty; var stateName = string.Empty; if (billingAddress != null) { var country = _countryService.GetCountryById((int)billingAddress.CountryId); if (country != null) { countryName = country.ThreeLetterIsoCode; } if (billingAddress.StateProvinceId != null) { var state = _stateProvinceService.GetStateProvinceById((int)billingAddress.StateProvinceId); if (state != null) { stateName = state.Abbreviation; } } } var threeletter = string.Empty; var abbreviation = string.Empty; var shippingaddress = _addressService.GetAddressById((int)postProcessPaymentRequest.Order.ShippingAddressId); if (shippingaddress != null) { var country = _countryService.GetCountryById((int)shippingaddress.CountryId); if (country != null) { threeletter = country.ThreeLetterIsoCode; } if (shippingaddress.StateProvinceId != null) { var state = _stateProvinceService.GetStateProvinceById((int)shippingaddress.StateProvinceId); if (state != null) { abbreviation = state.Abbreviation; } } } var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "PayuForm"; remotePostHelper.Url = _PayuPaymentSettings.PayUri; remotePostHelper.Add("key", _PayuPaymentSettings.MerchantId.ToString()); remotePostHelper.Add("amount", postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat)); remotePostHelper.Add("productinfo", "productinfo"); remotePostHelper.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); remotePostHelper.Add("Order_Id", orderId.ToString()); remotePostHelper.Add("txnid", orderId.ToString()); remotePostHelper.Add("service_provider", "payu_paisa"); remotePostHelper.Add("surl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("furl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("hash", myUtility.getchecksum(_PayuPaymentSettings.MerchantId.ToString(), postProcessPaymentRequest.Order.Id.ToString(), postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat), "productinfo", billingAddress?.FirstName.ToString(), billingAddress?.Email.ToString(), _PayuPaymentSettings.Key)); //Billing details remotePostHelper.Add("firstname", billingAddress?.FirstName.ToString()); remotePostHelper.Add("billing_cust_address", billingAddress?.Address1); remotePostHelper.Add("phone", billingAddress?.PhoneNumber); remotePostHelper.Add("email", billingAddress?.Email.ToString()); remotePostHelper.Add("billing_cust_city", billingAddress?.City); remotePostHelper.Add("billing_cust_state", stateName); remotePostHelper.Add("billing_zip_code", billingAddress?.ZipPostalCode); remotePostHelper.Add("billing_cust_country", countryName); //Delivery details if (postProcessPaymentRequest.Order.ShippingStatus != ShippingStatus.ShippingNotRequired) { remotePostHelper.Add("delivery_cust_name", shippingaddress.FirstName); remotePostHelper.Add("delivery_cust_address", shippingaddress.Address1); remotePostHelper.Add("delivery_cust_notes", string.Empty); remotePostHelper.Add("delivery_cust_tel", shippingaddress.PhoneNumber); remotePostHelper.Add("delivery_cust_city", shippingaddress.City); remotePostHelper.Add("delivery_cust_state", abbreviation); remotePostHelper.Add("delivery_zip_code", shippingaddress?.ZipPostalCode); remotePostHelper.Add("delivery_cust_country", threeletter); } // remotePostHelper.Add("Merchant_Param", _PayuPaymentSettings.MerchantParam); remotePostHelper.Post(); }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var myUtility = new PayuHelper(); var orderId = postProcessPaymentRequest.Order.Id; var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "PayuForm"; remotePostHelper.Url = _payuPaymentSettings.PayUri; remotePostHelper.Add("key", _payuPaymentSettings.MerchantId.ToString()); remotePostHelper.Add("amount", postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat)); remotePostHelper.Add("productinfo", "productinfo"); remotePostHelper.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); remotePostHelper.Add("Order_Id", orderId.ToString()); var txnId = _payuPaymentSettings.PayUri.Contains("test.payu.in") ? Guid.NewGuid().ToString() : orderId.ToString(); remotePostHelper.Add("txnid", txnId); //remotePostHelper.Add("service_provider", "payu_paisa"); remotePostHelper.Add("surl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("furl", _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayu/Return"); remotePostHelper.Add("hash", myUtility.getchecksum(_payuPaymentSettings.MerchantId.ToString(), txnId, postProcessPaymentRequest.Order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat), "productinfo", postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString(), postProcessPaymentRequest.Order.BillingAddress.Email.ToString(), _payuPaymentSettings.Key)); //Billing details remotePostHelper.Add("firstname", postProcessPaymentRequest.Order.BillingAddress.FirstName.ToString()); remotePostHelper.Add("billing_cust_address", postProcessPaymentRequest.Order.BillingAddress.Address1); remotePostHelper.Add("phone", postProcessPaymentRequest.Order.BillingAddress.PhoneNumber); remotePostHelper.Add("email", postProcessPaymentRequest.Order.BillingAddress.Email.ToString()); remotePostHelper.Add("billing_cust_city", postProcessPaymentRequest.Order.BillingAddress.City); var billingStateProvince = postProcessPaymentRequest.Order.BillingAddress.StateProvince; if (billingStateProvince != null) { remotePostHelper.Add("billing_cust_state", billingStateProvince.Abbreviation); } else { remotePostHelper.Add("billing_cust_state", ""); } remotePostHelper.Add("billing_zip_code", postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode); var billingCountry = postProcessPaymentRequest.Order.BillingAddress.Country; if (billingCountry != null) { remotePostHelper.Add("billing_cust_country", billingCountry.ThreeLetterIsoCode); } else { remotePostHelper.Add("billing_cust_country", ""); } //Delivery details if (postProcessPaymentRequest.Order.ShippingStatus != ShippingStatus.ShippingNotRequired) { remotePostHelper.Add("delivery_cust_name", postProcessPaymentRequest.Order.ShippingAddress.FirstName); remotePostHelper.Add("delivery_cust_address", postProcessPaymentRequest.Order.ShippingAddress.Address1); remotePostHelper.Add("delivery_cust_notes", string.Empty); remotePostHelper.Add("delivery_cust_tel", postProcessPaymentRequest.Order.ShippingAddress.PhoneNumber); remotePostHelper.Add("delivery_cust_city", postProcessPaymentRequest.Order.ShippingAddress.City); var deliveryStateProvince = postProcessPaymentRequest.Order.ShippingAddress.StateProvince; if (deliveryStateProvince != null) { remotePostHelper.Add("delivery_cust_state", deliveryStateProvince.Abbreviation); } else { remotePostHelper.Add("delivery_cust_state", ""); } remotePostHelper.Add("delivery_zip_code", postProcessPaymentRequest.Order.ShippingAddress.ZipPostalCode); var deliveryCountry = postProcessPaymentRequest.Order.ShippingAddress.Country; if (deliveryCountry != null) { remotePostHelper.Add("delivery_cust_country", deliveryCountry.ThreeLetterIsoCode); } else { remotePostHelper.Add("delivery_cust_country", ""); } } // remotePostHelper.Add("Merchant_Param", _PayuPaymentSettings.MerchantParam); try { remotePostHelper.Post(); } catch (Exception ex) { //Send email SendPaymentFailedStoreOwnerNotification SendEmail(ex.ToString(), postProcessPaymentRequest); throw new Exception(ex.Message); } }