/// <summary> /// Initialize a payment request from an <see cref="OrderGroup"/> instance. Adds order number, amount, timestamp, buyer information etc. /// </summary> /// <param name="payment">The <see cref="VerifonePaymentRequest"/> instance to initialize</param> /// <param name="orderGroup"><see cref="OrderGroup"/></param> public virtual void InitializePaymentRequest(VerifonePaymentRequest payment, IOrderGroup orderGroup) { IOrderAddress billingAddress = FindBillingAddress(payment, orderGroup); IOrderAddress shipmentAddress = FindShippingAddress(payment, orderGroup); payment.OrderTimestamp = orderGroup.Created.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); payment.MerchantAgreementCode = GetMerchantAgreementCode(payment); payment.PaymentLocale = GetPaymentLocale(ContentLanguage.PreferredCulture); payment.OrderNumber = orderGroup.OrderLink.OrderGroupId.ToString(CultureInfo.InvariantCulture.NumberFormat); payment.OrderCurrencyCode = IsProduction(payment) ? Iso4217Lookup.LookupByCode(CurrentMarket.DefaultCurrency.CurrencyCode).Number.ToString() : "978"; var totals = OrderGroupCalculator.GetOrderGroupTotals(orderGroup); payment.OrderGrossAmount = totals.Total.ToVerifoneAmountString(); var netAmount = orderGroup.PricesIncludeTax ? totals.Total : totals.Total - totals.TaxTotal; payment.OrderNetAmount = netAmount.ToVerifoneAmountString(); payment.OrderVatAmount = totals.TaxTotal.ToVerifoneAmountString(); payment.BuyerFirstName = billingAddress?.FirstName; payment.BuyerLastName = billingAddress?.LastName; payment.OrderVatPercentage = "0"; payment.PaymentMethodCode = ""; payment.SavedPaymentMethodId = ""; payment.RecurringPayment = "0"; payment.DeferredPayment = "0"; payment.SavePaymentMethod = "0"; payment.SkipConfirmationPage = "0"; string phoneNumber = billingAddress?.DaytimePhoneNumber ?? billingAddress?.EveningPhoneNumber; if (string.IsNullOrWhiteSpace(phoneNumber) == false) { payment.BuyerPhoneNumber = phoneNumber; } payment.BuyerEmailAddress = billingAddress?.Email ?? orderGroup.Name ?? string.Empty; if (payment.BuyerEmailAddress.IndexOf('@') < 0) { payment.BuyerEmailAddress = null; } payment.DeliveryAddressLineOne = shipmentAddress?.Line1; if (shipmentAddress != null && string.IsNullOrWhiteSpace(shipmentAddress.Line2) == false) { payment.DeliveryAddressLineTwo = shipmentAddress.Line2; } payment.DeliveryAddressPostalCode = shipmentAddress?.PostalCode; payment.DeliveryAddressCity = shipmentAddress?.City; payment.DeliveryAddressCountryCode = "246"; ApplyPaymentMethodConfiguration(payment); }
public virtual string GetPaymentUrl(VerifonePaymentRequest payment) { PaymentMethodDto paymentMethodDto = GetPaymentMethodDto(payment); return(paymentMethodDto != null ? paymentMethodDto.GetPaymentUrl() : null); }
protected virtual string GetMerchantAgreementCode(VerifonePaymentRequest payment) { var paymentMethodDto = GetPaymentMethodDto(payment); return(paymentMethodDto != null ? paymentMethodDto.GetMerchantAgreementCode() : "demo-agreement-code"); }
protected virtual string GetConfigurationValue(VerifonePaymentRequest payment, string parameterName, string defaultValue = null) { PaymentMethodDto paymentMethodDto = GetPaymentMethodDto(payment); return(paymentMethodDto != null ? paymentMethodDto.GetParameter(parameterName, defaultValue) : defaultValue); }
protected virtual PaymentMethodDto GetPaymentMethodDto(VerifonePaymentRequest payment) { if (payment.PaymentMethodId != Guid.Empty) { PaymentMethodDto paymentMethodDto = PaymentManager.GetPaymentMethod(payment.PaymentMethodId); return(paymentMethodDto); } return(null); }
public void StringShorter_ByOneCharacter() { var request = new VerifonePaymentRequest(); var value = "1234567890123456789"; request.BuyerFirstName = value; request.BuyerFirstName.Should().BeEquivalentTo(value); request.BuyerFirstName.Length.Should().Be(value.Length); }
public void StringExactlyMaxLength() { var request = new VerifonePaymentRequest(); var value = "123456789012345678901234567890"; request.BuyerFirstName = value; request.BuyerFirstName.Should().BeEquivalentTo(value); request.BuyerFirstName.Length.Should().Be(value.Length); }
/// <summary> /// Applies payment method parameters based on an initialized <see cref="VerifonePaymentRequest"/> with a valid PaymentMethodId property value. /// </summary> /// <param name="payment"><see cref="VerifonePaymentRequest"/> instance.</param> protected virtual void ApplyPaymentMethodConfiguration(VerifonePaymentRequest payment) { payment.InterfaceVersion = "3"; payment.ShortCancelUrl = GetConfigurationValue(payment, VerifoneConstants.Configuration.CancelUrl, "/error").ToExternalUrl(); payment.ShortErrorUrl = GetConfigurationValue(payment, VerifoneConstants.Configuration.ErrorUrl, "/error").ToExternalUrl(); payment.ShortExpiredUrl = GetConfigurationValue(payment, VerifoneConstants.Configuration.ExpiredUrl, "/error").ToExternalUrl(); payment.ShortRejectedUrl = GetConfigurationValue(payment, VerifoneConstants.Configuration.RejectedUrl, "/error").ToExternalUrl(); payment.ShortSuccessUrl = GetConfigurationValue(payment, VerifoneConstants.Configuration.SuccessUrl, "/success").ToExternalUrl(); payment.Software = GetConfigurationValue(payment, VerifoneConstants.Configuration.WebShopName, "My web shop"); payment.SoftwareVersion = "1.0.0"; }
public void StringTooLong_ByOneCharacte() { var request = new VerifonePaymentRequest(); var value = "1234567890123456789012345678901"; var expected = "123456789012345678901234567890"; request.BuyerFirstName = value; request.BuyerFirstName.Should().BeEquivalentTo(expected); request.BuyerFirstName.Length.Should().Be(VerifoneConstants.ParameterMaxLength.BuyerFirstName); }
protected virtual IOrderAddress FindShippingAddress(VerifonePaymentRequest payment, IOrderGroup orderGroup) { IOrderForm orderForm = FindCorrectOrderForm(payment.PaymentMethodId, orderGroup.Forms); IShipment shipment = orderForm.Shipments.FirstOrDefault(); if (shipment?.ShippingAddress != null) { return(shipment.ShippingAddress); } return(FindBillingAddress(payment, orderGroup)); }
//protected virtual string ExtractFirstName(string customerName) //{ // if (string.IsNullOrWhiteSpace(customerName)) // { // return null; // } // var lastSpaceIndex = customerName.LastIndexOf(" ", StringComparison.InvariantCultureIgnoreCase); // var length = customerName.Length - lastSpaceIndex; // return customerName.Substring(0, length); //} //protected virtual string ExtractLastName(string customerName) //{ // if (string.IsNullOrWhiteSpace(customerName)) // { // return null; // } // var lastSpaceIndex = customerName.LastIndexOf(" ", StringComparison.InvariantCultureIgnoreCase); // return customerName.Substring(lastSpaceIndex + 1); //} protected virtual OrderAddress FindBillingAddress(VerifonePaymentRequest payment, OrderGroup orderGroup) { OrderForm orderForm = FindCorrectOrderForm(payment.PaymentMethodId, orderGroup.OrderForms); OrderAddress billingAddress = orderGroup.OrderAddresses.FirstOrDefault(x => x.Name == orderForm.BillingAddressId); if (billingAddress == null) { billingAddress = orderGroup.OrderAddresses.FirstOrDefault(); } return(billingAddress); }
protected virtual IOrderAddress FindBillingAddress(VerifonePaymentRequest payment, IOrderGroup orderGroup) { IOrderForm orderForm = FindCorrectOrderForm(payment.PaymentMethodId, orderGroup.Forms); IPayment orderPayment = orderForm.Payments.FirstOrDefault(x => x.PaymentMethodId == payment.PaymentMethodId); IOrderAddress billingAddress = orderPayment?.BillingAddress; if (billingAddress == null) { billingAddress = orderGroup.Forms.SelectMany(x => x.Payments) .FirstOrDefault(x => x.BillingAddress != null)?.BillingAddress; } return(billingAddress); }
/// <summary> /// Initialize a payment request from an <see cref="OrderGroup"/> instance. Adds order number, amount, timestamp, buyer information etc. /// </summary> /// <param name="payment">The <see cref="VerifonePaymentRequest"/> instance to initialize</param> /// <param name="orderGroup"><see cref="OrderGroup"/></param> public virtual void InitializePaymentRequest(VerifonePaymentRequest payment, OrderGroup orderGroup) { OrderAddress orderAddress = orderGroup.OrderAddresses.First(); payment.OrderTimestamp = orderGroup.Created.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); payment.MerchantAgreementCode = this.GetMerchantAgreementCode(payment); payment.PaymentLocale = this.GetPaymentLocale(ContentLanguage.PreferredCulture); payment.OrderNumber = orderGroup.OrderGroupId.ToString(CultureInfo.InvariantCulture.NumberFormat); payment.OrderCurrencyCode = this.IsProduction(payment) ? Iso4217Lookup.LookupByCode(CurrentMarket.DefaultCurrency.CurrencyCode).Number.ToString() : "978"; payment.OrderGrossAmount = orderGroup.Total.ToVerifoneAmountString(); payment.OrderNetAmount = (orderGroup.Total - orderGroup.TaxTotal).ToVerifoneAmountString(); payment.OrderVatAmount = orderGroup.TaxTotal.ToVerifoneAmountString(); payment.BuyerFirstName = orderAddress.FirstName; payment.BuyerLastName = orderAddress.LastName; payment.OrderVatPercentage = "0"; payment.PaymentMethodCode = ""; payment.SavedPaymentMethodId = ""; payment.StyleCode = ""; payment.RecurringPayment = "0"; payment.DeferredPayment = "0"; payment.SavePaymentMethod = "0"; payment.SkipConfirmationPage = "0"; string phoneNumber = orderAddress.DaytimePhoneNumber ?? orderAddress.EveningPhoneNumber; if (string.IsNullOrWhiteSpace(phoneNumber) == false) { payment.BuyerPhoneNumber = phoneNumber; } payment.BuyerEmailAddress = orderAddress.Email; payment.DeliveryAddressLineOne = orderAddress.Line1; if (string.IsNullOrWhiteSpace(orderAddress.Line2) == false) { payment.DeliveryAddressLineTwo = orderAddress.Line2; } payment.DeliveryAddressPostalCode = orderAddress.PostalCode; payment.DeliveryAddressCity = orderAddress.City; payment.DeliveryAddressCountryCode = "246"; ApplyPaymentMethodConfiguration(payment); }
protected virtual OrderAddress FindShippingAddress(VerifonePaymentRequest payment, OrderGroup orderGroup) { OrderForm orderForm = FindCorrectOrderForm(payment.PaymentMethodId, orderGroup.OrderForms); Shipment shipment = orderForm.Shipments.FirstOrDefault(); if (shipment != null) { OrderAddress shipmentAddress = orderGroup.OrderAddresses.FirstOrDefault(x => x.Name == shipment.ShippingAddressId); if (shipmentAddress != null) { return(shipmentAddress); } } return(FindBillingAddress(payment, orderGroup)); }
public virtual string GetPaymentUrl(VerifonePaymentRequest payment) { PaymentMethodDto paymentMethodDto = GetPaymentMethodDto(payment); if (paymentMethodDto == null) { return(null); } var isProduction = paymentMethodDto.IsVerifoneProduction(); if (isProduction) { return(Task.Run(() => GetOnlinePaymentNodeUrl(paymentMethodDto)).Result); } return(paymentMethodDto.GetPaymentTestUrl()); }
public virtual ActionResult Index(VerifonePaymentRequest response) { return(View()); }
public static string GetPaymentUrl(this VerifonePaymentRequest payment) { var paymentService = ServiceLocator.Current.GetInstance <IVerifonePaymentService>(); return(paymentService.GetPaymentUrl(payment)); }
public static void Initialize(this VerifonePaymentRequest request, OrderGroup orderGroup) { var paymentService = ServiceLocator.Current.GetInstance <IVerifonePaymentService>(); paymentService.InitializePaymentRequest(request, orderGroup); }
protected virtual bool IsProduction(VerifonePaymentRequest payment) { PaymentMethodDto paymentMethodDto = GetPaymentMethodDto(payment); return(paymentMethodDto.GetParameter(VerifoneConstants.Configuration.IsProduction, "0") == "1"); }