public virtual InitializePaymentResponse InitializePayment(InitializePaymentRequest request) { Ensure.That(request, "request").IsNotNull(); var httpRequest = InitializePaymentHttpRequestFactory.Create(request); var httpResponse = Connection.Send(httpRequest); return(ResponseFactory.Create <InitializePaymentResponse>(httpResponse)); }
protected virtual InitializePaymentRequest InitInitializePaymentRequest() { var interfaceOptions = new InterfaceOptions( InterfaceId.Aero, "SWE", "https://foo.com/payments/success".ToUri(), "https://foo.com/payments/cancel".ToUri(), "https://foo.com/payments/pending".ToUri()); var r = new InitializePaymentRequest(CreateOrderResponse.OrderId, CreateOrderRequest.TotalAmount, PaymentChannelId.Web, interfaceOptions); return(CreateOrderRequest.LineItems.Any() ? r.WithLineItems(CreateOrderRequest.LineItems) : r); }
/// <summary> /// Initializes the specified payment in the cart. /// </summary> /// <param name="param">Parameters used to initialized the Payment.</param> /// <returns>The updated processed cart.</returns> public virtual Task <Overture.ServiceModel.Orders.Cart> InitializePaymentAsync(InitializePaymentParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.PaymentId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.PaymentId)), nameof(param)); } var cacheKey = BuildCartCacheKey(param.Scope, param.CartName, param.CustomerId); var request = new InitializePaymentRequest { AdditionalData = param.AdditionalData == null ? null : new PropertyBag(param.AdditionalData), CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, Options = param.Options == null ? null : new PropertyBag(param.Options), PaymentId = param.PaymentId, ScopeId = param.Scope }; return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
public override PaymentHtmlForm GenerateHtmlForm( Order order, string teaCommerceContinueUrl, string teaCommerceCancelUrl, string teaCommerceCallBackUrl, string teaCommerceCommunicationUrl, IDictionary<string, string> settings ) { order.MustNotBeNull( "order" ); settings.MustNotBeNull( "settings" ); settings.MustContainKey( "customerLanguageCode", "settings" ); settings.MustContainKey( "testMode", "settings" ); PaymentHtmlForm htmlForm = new PaymentHtmlForm(); IPaynovaClient client = GetClient( settings ); Currency currency = CurrencyService.Instance.Get( order.StoreId, order.CurrencyId ); if ( !Iso4217CurrencyCodes.ContainsKey( currency.IsoCode ) ) { throw new Exception( "You must specify an ISO 4217 currency code for the " + currency.Name + " currency" ); } try { //Create order request CreateOrderRequest createOrderRequest = new CreateOrderRequest( order.CartNumber, currency.IsoCode, order.TotalPrice.Value.WithVat ) { Customer = new Customer(), BillTo = new NameAndAddress(), ShipTo = new NameAndAddress() }; #region Customer information createOrderRequest.Customer.EmailAddress = order.PaymentInformation.Email; createOrderRequest.Customer.Name.CompanyName = createOrderRequest.BillTo.Name.CompanyName = order.Properties[ settings.ContainsKey( "companyPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "companyPropertyAlias" ] ) ? settings[ "companyPropertyAlias" ] : "company" ]; createOrderRequest.Customer.Name.Title = createOrderRequest.BillTo.Name.Title = order.Properties[ settings.ContainsKey( "titlePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "titlePropertyAlias" ] ) ? settings[ "titlePropertyAlias" ] : "title" ]; createOrderRequest.Customer.Name.FirstName = createOrderRequest.BillTo.Name.FirstName = order.PaymentInformation.FirstName; createOrderRequest.Customer.Name.MiddleNames = createOrderRequest.BillTo.Name.MiddleNames = order.Properties[ settings.ContainsKey( "middleNamesPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "middleNamesPropertyAlias" ] ) ? settings[ "middleNamesPropertyAlias" ] : "middleNames" ]; createOrderRequest.Customer.Name.LastName = createOrderRequest.BillTo.Name.LastName = order.PaymentInformation.LastName; createOrderRequest.Customer.Name.Suffix = createOrderRequest.BillTo.Name.Suffix = order.Properties[ settings.ContainsKey( "suffixPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "suffixPropertyAlias" ] ) ? settings[ "suffixPropertyAlias" ] : "suffix" ]; createOrderRequest.Customer.HomeTelephone = order.Properties[ settings.ContainsKey( "homeTelephonePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "homeTelephonePropertyAlias" ] ) ? settings[ "homeTelephonePropertyAlias" ] : "phone" ]; createOrderRequest.Customer.WorkTelephone = order.Properties[ settings.ContainsKey( "workTelephonePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "workTelephonePropertyAlias" ] ) ? settings[ "workTelephonePropertyAlias" ] : "workPhone" ]; createOrderRequest.Customer.MobileTelephone = order.Properties[ settings.ContainsKey( "mobileTelephonePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "mobileTelephonePropertyAlias" ] ) ? settings[ "mobileTelephonePropertyAlias" ] : "mobile" ]; createOrderRequest.BillTo.Address.Street1 = order.Properties[ settings.ContainsKey( "street1PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "street1PropertyAlias" ] ) ? settings[ "street1PropertyAlias" ] : "streetAddress" ]; createOrderRequest.BillTo.Address.Street2 = order.Properties[ settings.ContainsKey( "street2PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "street2PropertyAlias" ] ) ? settings[ "street2PropertyAlias" ] : "streetAddress2" ]; createOrderRequest.BillTo.Address.Street3 = order.Properties[ settings.ContainsKey( "street3PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "street3PropertyAlias" ] ) ? settings[ "street3PropertyAlias" ] : "streetAddress3" ]; createOrderRequest.BillTo.Address.Street4 = order.Properties[ settings.ContainsKey( "street4PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "street4PropertyAlias" ] ) ? settings[ "street4PropertyAlias" ] : "streetAddress4" ]; createOrderRequest.BillTo.Address.City = order.Properties[ settings.ContainsKey( "cityPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "cityPropertyAlias" ] ) ? settings[ "cityPropertyAlias" ] : "city" ]; createOrderRequest.BillTo.Address.PostalCode = order.Properties[ settings.ContainsKey( "postalCodePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "postalCodePropertyAlias" ] ) ? settings[ "postalCodePropertyAlias" ] : "zipCode" ]; if ( order.PaymentInformation.CountryRegionId != null ) { createOrderRequest.BillTo.Address.RegionCode = CountryRegionService.Instance.Get( order.StoreId, order.PaymentInformation.CountryRegionId.Value ).RegionCode; } createOrderRequest.BillTo.Address.CountryCode = CountryService.Instance.Get( order.StoreId, order.PaymentInformation.CountryId ).RegionCode; createOrderRequest.ShipTo.Name.CompanyName = order.Properties[ settings.ContainsKey( "shipping_companyPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_companyPropertyAlias" ] ) ? settings[ "shipping_companyPropertyAlias" ] : "shipping_company" ]; createOrderRequest.ShipTo.Name.Title = order.Properties[ settings.ContainsKey( "shipping_titlePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_titlePropertyAlias" ] ) ? settings[ "shipping_titlePropertyAlias" ] : "shipping_title" ]; createOrderRequest.ShipTo.Name.FirstName = order.Properties[ settings.ContainsKey( "shipping_firstNamePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_firstNamePropertyAlias" ] ) ? settings[ "shipping_firstNamePropertyAlias" ] : "shipping_firstName" ]; createOrderRequest.ShipTo.Name.MiddleNames = order.Properties[ settings.ContainsKey( "shipping_middleNamesPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_middleNamesPropertyAlias" ] ) ? settings[ "shipping_middleNamesPropertyAlias" ] : "shipping_middleNames" ]; createOrderRequest.ShipTo.Name.LastName = order.Properties[ settings.ContainsKey( "shipping_lastNamePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_lastNamePropertyAlias" ] ) ? settings[ "shipping_lastNamePropertyAlias" ] : "shipping_lastName" ]; createOrderRequest.ShipTo.Name.Suffix = order.Properties[ settings.ContainsKey( "shipping_suffixPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_suffixPropertyAlias" ] ) ? settings[ "shipping_suffixPropertyAlias" ] : "shipping_suffix" ]; createOrderRequest.ShipTo.Address.Street1 = order.Properties[ settings.ContainsKey( "shipping_street1PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_street1PropertyAlias" ] ) ? settings[ "shipping_street1PropertyAlias" ] : "shipping_streetAddress" ]; createOrderRequest.ShipTo.Address.Street2 = order.Properties[ settings.ContainsKey( "shipping_street2PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_street2PropertyAlias" ] ) ? settings[ "shipping_street2PropertyAlias" ] : "shipping_streetAddress2" ]; createOrderRequest.ShipTo.Address.Street3 = order.Properties[ settings.ContainsKey( "shipping_street3PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_street3PropertyAlias" ] ) ? settings[ "shipping_street3PropertyAlias" ] : "shipping_streetAddress3" ]; createOrderRequest.ShipTo.Address.Street4 = order.Properties[ settings.ContainsKey( "shipping_street4PropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_street4PropertyAlias" ] ) ? settings[ "shipping_street4PropertyAlias" ] : "shipping_streetAddress4" ]; createOrderRequest.ShipTo.Address.City = order.Properties[ settings.ContainsKey( "shipping_cityPropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_cityPropertyAlias" ] ) ? settings[ "shipping_cityPropertyAlias" ] : "shipping_city" ]; createOrderRequest.ShipTo.Address.PostalCode = order.Properties[ settings.ContainsKey( "shipping_postalCodePropertyAlias" ) && !string.IsNullOrEmpty( settings[ "shipping_postalCodePropertyAlias" ] ) ? settings[ "shipping_postalCodePropertyAlias" ] : "shipping_zipCode" ]; if ( order.ShipmentInformation.CountryRegionId != null ) { createOrderRequest.ShipTo.Address.RegionCode = CountryRegionService.Instance.Get( order.StoreId, order.ShipmentInformation.CountryRegionId.Value ).RegionCode; } if ( order.ShipmentInformation.CountryId != null ) { createOrderRequest.ShipTo.Address.CountryCode = CountryService.Instance.Get( order.StoreId, order.ShipmentInformation.CountryId.Value ).RegionCode; } #endregion CreateOrderResponse createOrderResponse = client.CreateOrder( createOrderRequest ); //Initialize payment request InterfaceOptions interfaceOptions = new InterfaceOptions( InterfaceId.Aero, settings[ "customerLanguageCode" ], new Uri( teaCommerceContinueUrl ), new Uri( teaCommerceCancelUrl ), new Uri( teaCommerceContinueUrl ) ); InitializePaymentRequest initializePaymentRequest = new InitializePaymentRequest( createOrderResponse.OrderId, order.TotalPrice.Value.WithVat, PaymentChannelId.Web, interfaceOptions ); if ( settings.ContainsKey( "paymentMethods" ) && !string.IsNullOrEmpty( settings[ "paymentMethods" ] ) ) { initializePaymentRequest.WithPaymentMethods( settings[ "paymentMethods" ].Split( ',' ).Select( i => PaynovaPaymentMethod.Custom( int.Parse( i ) ) ) ); } InitializePaymentResponse initializePaymentResponse = client.InitializePayment( initializePaymentRequest ); htmlForm.Action = initializePaymentResponse.Url; } catch ( Exception e ) { } return htmlForm; }
public override PaymentHtmlForm GenerateHtmlForm(Order order, string teaCommerceContinueUrl, string teaCommerceCancelUrl, string teaCommerceCallBackUrl, string teaCommerceCommunicationUrl, IDictionary <string, string> settings) { order.MustNotBeNull("order"); settings.MustNotBeNull("settings"); settings.MustContainKey("customerLanguageCode", "settings"); settings.MustContainKey("testMode", "settings"); PaymentHtmlForm htmlForm = new PaymentHtmlForm(); IPaynovaClient client = GetClient(settings); Currency currency = CurrencyService.Instance.Get(order.StoreId, order.CurrencyId); if (!Iso4217CurrencyCodes.ContainsKey(currency.IsoCode)) { throw new Exception("You must specify an ISO 4217 currency code for the " + currency.Name + " currency"); } try { //Create order request CreateOrderRequest createOrderRequest = new CreateOrderRequest(order.CartNumber, currency.IsoCode, order.TotalPrice.Value.WithVat) { Customer = new Customer(), BillTo = new NameAndAddress(), ShipTo = new NameAndAddress() }; #region Customer information createOrderRequest.Customer.EmailAddress = order.PaymentInformation.Email; createOrderRequest.Customer.Name.CompanyName = createOrderRequest.BillTo.Name.CompanyName = order.Properties[settings.ContainsKey("companyPropertyAlias") && !string.IsNullOrEmpty(settings["companyPropertyAlias"]) ? settings["companyPropertyAlias"] : "company"]; createOrderRequest.Customer.Name.Title = createOrderRequest.BillTo.Name.Title = order.Properties[settings.ContainsKey("titlePropertyAlias") && !string.IsNullOrEmpty(settings["titlePropertyAlias"]) ? settings["titlePropertyAlias"] : "title"]; createOrderRequest.Customer.Name.FirstName = createOrderRequest.BillTo.Name.FirstName = order.PaymentInformation.FirstName; createOrderRequest.Customer.Name.MiddleNames = createOrderRequest.BillTo.Name.MiddleNames = order.Properties[settings.ContainsKey("middleNamesPropertyAlias") && !string.IsNullOrEmpty(settings["middleNamesPropertyAlias"]) ? settings["middleNamesPropertyAlias"] : "middleNames"]; createOrderRequest.Customer.Name.LastName = createOrderRequest.BillTo.Name.LastName = order.PaymentInformation.LastName; createOrderRequest.Customer.Name.Suffix = createOrderRequest.BillTo.Name.Suffix = order.Properties[settings.ContainsKey("suffixPropertyAlias") && !string.IsNullOrEmpty(settings["suffixPropertyAlias"]) ? settings["suffixPropertyAlias"] : "suffix"]; createOrderRequest.Customer.HomeTelephone = order.Properties[settings.ContainsKey("homeTelephonePropertyAlias") && !string.IsNullOrEmpty(settings["homeTelephonePropertyAlias"]) ? settings["homeTelephonePropertyAlias"] : "phone"]; createOrderRequest.Customer.WorkTelephone = order.Properties[settings.ContainsKey("workTelephonePropertyAlias") && !string.IsNullOrEmpty(settings["workTelephonePropertyAlias"]) ? settings["workTelephonePropertyAlias"] : "workPhone"]; createOrderRequest.Customer.MobileTelephone = order.Properties[settings.ContainsKey("mobileTelephonePropertyAlias") && !string.IsNullOrEmpty(settings["mobileTelephonePropertyAlias"]) ? settings["mobileTelephonePropertyAlias"] : "mobile"]; createOrderRequest.BillTo.Address.Street1 = order.Properties[settings.ContainsKey("street1PropertyAlias") && !string.IsNullOrEmpty(settings["street1PropertyAlias"]) ? settings["street1PropertyAlias"] : "streetAddress"]; createOrderRequest.BillTo.Address.Street2 = order.Properties[settings.ContainsKey("street2PropertyAlias") && !string.IsNullOrEmpty(settings["street2PropertyAlias"]) ? settings["street2PropertyAlias"] : "streetAddress2"]; createOrderRequest.BillTo.Address.Street3 = order.Properties[settings.ContainsKey("street3PropertyAlias") && !string.IsNullOrEmpty(settings["street3PropertyAlias"]) ? settings["street3PropertyAlias"] : "streetAddress3"]; createOrderRequest.BillTo.Address.Street4 = order.Properties[settings.ContainsKey("street4PropertyAlias") && !string.IsNullOrEmpty(settings["street4PropertyAlias"]) ? settings["street4PropertyAlias"] : "streetAddress4"]; createOrderRequest.BillTo.Address.City = order.Properties[settings.ContainsKey("cityPropertyAlias") && !string.IsNullOrEmpty(settings["cityPropertyAlias"]) ? settings["cityPropertyAlias"] : "city"]; createOrderRequest.BillTo.Address.PostalCode = order.Properties[settings.ContainsKey("postalCodePropertyAlias") && !string.IsNullOrEmpty(settings["postalCodePropertyAlias"]) ? settings["postalCodePropertyAlias"] : "zipCode"]; if (order.PaymentInformation.CountryRegionId != null) { createOrderRequest.BillTo.Address.RegionCode = CountryRegionService.Instance.Get(order.StoreId, order.PaymentInformation.CountryRegionId.Value).RegionCode; } createOrderRequest.BillTo.Address.CountryCode = CountryService.Instance.Get(order.StoreId, order.PaymentInformation.CountryId).RegionCode; createOrderRequest.ShipTo.Name.CompanyName = order.Properties[settings.ContainsKey("shipping_companyPropertyAlias") && !string.IsNullOrEmpty(settings["shipping_companyPropertyAlias"]) ? settings["shipping_companyPropertyAlias"] : "shipping_company"]; createOrderRequest.ShipTo.Name.Title = order.Properties[settings.ContainsKey("shipping_titlePropertyAlias") && !string.IsNullOrEmpty(settings["shipping_titlePropertyAlias"]) ? settings["shipping_titlePropertyAlias"] : "shipping_title"]; createOrderRequest.ShipTo.Name.FirstName = order.Properties[settings.ContainsKey("shipping_firstNamePropertyAlias") && !string.IsNullOrEmpty(settings["shipping_firstNamePropertyAlias"]) ? settings["shipping_firstNamePropertyAlias"] : "shipping_firstName"]; createOrderRequest.ShipTo.Name.MiddleNames = order.Properties[settings.ContainsKey("shipping_middleNamesPropertyAlias") && !string.IsNullOrEmpty(settings["shipping_middleNamesPropertyAlias"]) ? settings["shipping_middleNamesPropertyAlias"] : "shipping_middleNames"]; createOrderRequest.ShipTo.Name.LastName = order.Properties[settings.ContainsKey("shipping_lastNamePropertyAlias") && !string.IsNullOrEmpty(settings["shipping_lastNamePropertyAlias"]) ? settings["shipping_lastNamePropertyAlias"] : "shipping_lastName"]; createOrderRequest.ShipTo.Name.Suffix = order.Properties[settings.ContainsKey("shipping_suffixPropertyAlias") && !string.IsNullOrEmpty(settings["shipping_suffixPropertyAlias"]) ? settings["shipping_suffixPropertyAlias"] : "shipping_suffix"]; createOrderRequest.ShipTo.Address.Street1 = order.Properties[settings.ContainsKey("shipping_street1PropertyAlias") && !string.IsNullOrEmpty(settings["shipping_street1PropertyAlias"]) ? settings["shipping_street1PropertyAlias"] : "shipping_streetAddress"]; createOrderRequest.ShipTo.Address.Street2 = order.Properties[settings.ContainsKey("shipping_street2PropertyAlias") && !string.IsNullOrEmpty(settings["shipping_street2PropertyAlias"]) ? settings["shipping_street2PropertyAlias"] : "shipping_streetAddress2"]; createOrderRequest.ShipTo.Address.Street3 = order.Properties[settings.ContainsKey("shipping_street3PropertyAlias") && !string.IsNullOrEmpty(settings["shipping_street3PropertyAlias"]) ? settings["shipping_street3PropertyAlias"] : "shipping_streetAddress3"]; createOrderRequest.ShipTo.Address.Street4 = order.Properties[settings.ContainsKey("shipping_street4PropertyAlias") && !string.IsNullOrEmpty(settings["shipping_street4PropertyAlias"]) ? settings["shipping_street4PropertyAlias"] : "shipping_streetAddress4"]; createOrderRequest.ShipTo.Address.City = order.Properties[settings.ContainsKey("shipping_cityPropertyAlias") && !string.IsNullOrEmpty(settings["shipping_cityPropertyAlias"]) ? settings["shipping_cityPropertyAlias"] : "shipping_city"]; createOrderRequest.ShipTo.Address.PostalCode = order.Properties[settings.ContainsKey("shipping_postalCodePropertyAlias") && !string.IsNullOrEmpty(settings["shipping_postalCodePropertyAlias"]) ? settings["shipping_postalCodePropertyAlias"] : "shipping_zipCode"]; if (order.ShipmentInformation.CountryRegionId != null) { createOrderRequest.ShipTo.Address.RegionCode = CountryRegionService.Instance.Get(order.StoreId, order.ShipmentInformation.CountryRegionId.Value).RegionCode; } if (order.ShipmentInformation.CountryId != null) { createOrderRequest.ShipTo.Address.CountryCode = CountryService.Instance.Get(order.StoreId, order.ShipmentInformation.CountryId.Value).RegionCode; } #endregion CreateOrderResponse createOrderResponse = client.CreateOrder(createOrderRequest); //Initialize payment request InterfaceOptions interfaceOptions = new InterfaceOptions(InterfaceId.Aero, settings["customerLanguageCode"], new Uri(teaCommerceContinueUrl), new Uri(teaCommerceCancelUrl), new Uri(teaCommerceContinueUrl)); InitializePaymentRequest initializePaymentRequest = new InitializePaymentRequest(createOrderResponse.OrderId, order.TotalPrice.Value.WithVat, PaymentChannelId.Web, interfaceOptions); if (settings.ContainsKey("paymentMethods") && !string.IsNullOrEmpty(settings["paymentMethods"])) { initializePaymentRequest.WithPaymentMethods(settings["paymentMethods"].Split(',').Select(i => PaynovaPaymentMethod.Custom(int.Parse(i)))); } InitializePaymentResponse initializePaymentResponse = client.InitializePayment(initializePaymentRequest); htmlForm.Action = initializePaymentResponse.Url; } catch (Exception e) { } return(htmlForm); }
internal static InitializePaymentRequest AddExtraLineItemWithoutUpdatingTotalAmount(this InitializePaymentRequest request) { return(request.AddLineItem(CreateExtraLineItem())); }