Exemple #1
0
        private CreditCardPaymentCaptured_V2 Convert(CreditCardPaymentCaptured oldEvent)
        {
            var fareObject = FareHelper.GetFareFromAmountInclTax(System.Convert.ToDouble(oldEvent.Meter), _serverSettings.ServerData.VATIsEnabled ? _serverSettings.ServerData.VATPercentage : 0);

            return(new CreditCardPaymentCaptured_V2
            {
                EventDate = oldEvent.EventDate,
                SourceId = oldEvent.SourceId,
                Version = oldEvent.Version,
                TransactionId = oldEvent.TransactionId,
                AuthorizationCode = oldEvent.AuthorizationCode,
                Amount = oldEvent.Amount,
                Tip = oldEvent.Tip,
                Provider = oldEvent.Provider,
                OrderId = oldEvent.OrderId,
                IsNoShowFee = oldEvent.IsNoShowFee,
                PromotionUsed = oldEvent.PromotionUsed,
                AmountSavedByPromotion = oldEvent.AmountSavedByPromotion,

                Meter = System.Convert.ToDecimal(fareObject.AmountExclTax),
                Tax = System.Convert.ToDecimal(fareObject.TaxAmount)
            });
        }
Exemple #2
0
        private bool SettleOverduePayment(Guid orderId, AccountDetail accountDetail, decimal amount, string companyKey, bool isFee, string kountSessionId, string customerIpAddress)
        {
            var payment = _orderPaymentDao.FindByOrderId(orderId, companyKey);
            var reAuth  = payment != null;

            var preAuthResponse = _paymentService.PreAuthorize(companyKey, orderId, accountDetail, amount, reAuth, isSettlingOverduePayment: true);

            if (preAuthResponse.IsSuccessful)
            {
                // Wait for payment to be created
                Thread.Sleep(500);

                var commitResponse = _paymentService.CommitPayment(
                    companyKey,
                    orderId,
                    accountDetail,
                    amount,
                    amount,
                    amount,
                    0,
                    preAuthResponse.TransactionId,
                    preAuthResponse.ReAuthOrderId,
                    false,
                    kountSessionId,
                    customerIpAddress);

                if (commitResponse.IsSuccessful)
                {
                    // Go fetch declined order, and send its receipt
                    var paymentDetail = _orderPaymentDao.FindByOrderId(orderId, companyKey);
                    var promotion     = _promotionDao.FindByOrderId(orderId);

                    var orderDetail = _orderDao.FindById(orderId);

                    decimal tipAmount             = 0;
                    decimal meterAmountWithoutTax = amount;
                    decimal taxAmount             = 0;

                    if (!isFee)
                    {
                        if (!orderDetail.IsManualRideLinq)
                        {
                            var pairingInfo = _orderDao.FindOrderPairingById(orderId);
                            tipAmount = FareHelper.GetTipAmountFromTotalIncludingTip(amount, pairingInfo.AutoTipPercentage ?? _serverSettings.ServerData.DefaultTipPercentage);
                            var meterAmount = amount - tipAmount;

                            var fareObject = FareHelper.GetFareFromAmountInclTax(meterAmount,
                                                                                 _serverSettings.ServerData.VATIsEnabled
                                    ? _serverSettings.ServerData.VATPercentage
                                    : 0);

                            meterAmountWithoutTax = fareObject.AmountExclTax;
                            taxAmount             = fareObject.TaxAmount;
                        }
                        else
                        {
                            var ridelinqOrderDetail = _orderDao.GetManualRideLinqById(orderId);
                            taxAmount             = Convert.ToDecimal(ridelinqOrderDetail.Tax ?? 0);
                            meterAmountWithoutTax = amount - taxAmount;
                            tipAmount             = Convert.ToDecimal(ridelinqOrderDetail.Tip);
                        }
                    }

                    _commandBus.Send(new CaptureCreditCardPayment
                    {
                        IsSettlingOverduePayment = true,
                        NewCardToken             = paymentDetail.CardToken,
                        AccountId              = accountDetail.Id,
                        PaymentId              = paymentDetail.PaymentId,
                        Provider               = _paymentService.ProviderType(companyKey, orderId),
                        TotalAmount            = amount,
                        MeterAmount            = meterAmountWithoutTax,
                        TipAmount              = tipAmount,
                        TaxAmount              = taxAmount,
                        TollAmount             = Convert.ToDecimal(orderDetail.Toll ?? 0),
                        SurchargeAmount        = Convert.ToDecimal(orderDetail.Surcharge ?? 0),
                        AuthorizationCode      = commitResponse.AuthorizationCode,
                        TransactionId          = commitResponse.TransactionId,
                        PromotionUsed          = promotion != null ? promotion.PromoId : default(Guid?),
                        AmountSavedByPromotion = promotion != null ? promotion.AmountSaved : 0,
                        FeeType = isFee ? FeeTypes.Booking : FeeTypes.None
                    });

                    _commandBus.Send(new SettleOverduePayment
                    {
                        AccountId    = accountDetail.Id,
                        OrderId      = orderId,
                        CreditCardId = accountDetail.DefaultCreditCard.GetValueOrDefault()
                    });

                    return(true);
                }

                // Payment failed, void preauth
                _paymentService.VoidPreAuthorization(companyKey, orderId);
            }

            return(false);
        }
        public InitializePayPalCheckoutResponse InitializeWebPayment(Guid accountId, Guid orderId, string baseUri, double?estimatedFare, decimal bookingFees, string clientLanguageCode)
        {
            if (!estimatedFare.HasValue)
            {
                return(new InitializePayPalCheckoutResponse
                {
                    IsSuccessful = false,
                    Message = _resources.Get("CannotCreateOrder_PrepaidNoEstimate", clientLanguageCode)
                });
            }

            var regionName     = _serverSettings.ServerData.PayPalRegionInfoOverride;
            var conversionRate = _serverSettings.ServerData.PayPalConversionRate;

            _logger.LogMessage("PayPal Conversion Rate: {0}", conversionRate);

            // Fare amount
            var fareAmount = Math.Round(Convert.ToDecimal(estimatedFare.Value) * conversionRate, 2);
            var currency   = conversionRate != 1
                ? CurrencyCodes.Main.UnitedStatesDollar
                : _resources.GetCurrencyCode();

            // Need the fare object because tip amount should be calculated on the fare excluding taxes
            var fareObject = FareHelper.GetFareFromAmountInclTax(Convert.ToDouble(fareAmount),
                                                                 _serverSettings.ServerData.VATIsEnabled
                            ? _serverSettings.ServerData.VATPercentage
                            : 0);

            // Tip amount (on fare amount excl. taxes)
            var defaultTipPercentage = _accountDao.FindById(accountId).DefaultTipPercent;
            var tipPercentage        = defaultTipPercentage ?? _serverSettings.ServerData.DefaultTipPercentage;
            var tipAmount            = FareHelper.CalculateTipAmount(fareObject.AmountInclTax, tipPercentage);

            // Booking Fees with conversion rate if necessary
            var bookingFeesAmount = Math.Round(bookingFees * conversionRate, 2);

            // Fare amount with tip and booking fee
            var totalAmount = fareAmount + tipAmount + bookingFeesAmount;

            var redirectUrl = baseUri + string.Format("/{0}/proceed", orderId);

            _logger.LogMessage("PayPal Web redirect URL: {0}", redirectUrl);

            var redirUrls = new RedirectUrls
            {
                cancel_url = redirectUrl + "?cancel=true",
                return_url = redirectUrl
            };

            // Create transaction
            var transactionList = new List <Transaction>
            {
                new Transaction
                {
                    amount = new Amount
                    {
                        currency = currency,
                        total    = totalAmount.ToString("N", CultureInfo.InvariantCulture)
                    },

                    description = string.Format(
                        _resources.Get("PayPalWebPaymentDescription", regionName.HasValue()
                            ? SupportedLanguages.en.ToString()
                            : clientLanguageCode), totalAmount),

                    item_list = new ItemList
                    {
                        items = new List <Item>
                        {
                            new Item
                            {
                                name = _resources.Get("PayPalWebFareItemDescription", regionName.HasValue()
                                        ? SupportedLanguages.en.ToString()
                                        : clientLanguageCode),
                                currency = currency,
                                price    = fareAmount.ToString("N", CultureInfo.InvariantCulture),
                                quantity = "1"
                            },
                            new Item
                            {
                                name = string.Format(_resources.Get("PayPalWebTipItemDescription", regionName.HasValue()
                                        ? SupportedLanguages.en.ToString()
                                        : clientLanguageCode), tipPercentage),
                                currency = currency,
                                price    = tipAmount.ToString("N", CultureInfo.InvariantCulture),
                                quantity = "1"
                            }
                        }
                    }
                }
            };

            if (bookingFeesAmount > 0)
            {
                transactionList.First().item_list.items.Add(new Item
                {
                    name = _resources.Get("PayPalWebBookingFeeItemDescription", regionName.HasValue()
                                        ? SupportedLanguages.en.ToString()
                                        : clientLanguageCode),
                    currency = currency,
                    price    = bookingFeesAmount.ToString("N", CultureInfo.InvariantCulture),
                    quantity = "1"
                });
            }

            // Create web experience profile
            var profile = new WebProfile
            {
                name        = Guid.NewGuid().ToString(),
                flow_config = new FlowConfig
                {
                    landing_page_type = _serverPaymentSettings.PayPalServerSettings.LandingPageType.ToString()
                }
            };

            try
            {
                var webExperienceProfile = profile.Create(GetAPIContext(GetAccessToken()));

                // Create payment
                var payment = new Payment
                {
                    intent = Intents.Sale,
                    payer  = new Payer
                    {
                        payment_method = "paypal"
                    },
                    transactions          = transactionList,
                    redirect_urls         = redirUrls,
                    experience_profile_id = webExperienceProfile.id
                };

                var createdPayment = payment.Create(GetAPIContext(GetAccessToken()));
                var links          = createdPayment.links.GetEnumerator();

                while (links.MoveNext())
                {
                    var link = links.Current;
                    if (link.rel.ToLower().Trim().Equals("approval_url"))
                    {
                        return(new InitializePayPalCheckoutResponse
                        {
                            IsSuccessful = true,
                            PaymentId = createdPayment.id,
                            PayPalCheckoutUrl = link.href       // Links that give the user the option to redirect to PayPal to approve the payment
                        });
                    }
                }

                _logger.LogMessage("Error when creating PayPal Web payment: no approval_urls found");

                // No approval_url found
                return(new InitializePayPalCheckoutResponse
                {
                    IsSuccessful = false,
                    Message = "No approval_url found"
                });
            }
            catch (Exception ex)
            {
                var exceptionMessage = ex.Message;

                var paymentException = ex as PaymentsException;
                if (paymentException != null && paymentException.Details != null)
                {
                    exceptionMessage = paymentException.Details.message;
                }

                _logger.LogMessage("Initialization of PayPal Web Store failed: {0}", exceptionMessage);

                return(new InitializePayPalCheckoutResponse
                {
                    IsSuccessful = false,
                    Message = exceptionMessage
                });
            }
        }
Exemple #4
0
        private CommitPreauthorizedPaymentResponse CommitPayment(decimal totalFeeAmount, decimal bookingFees, Guid orderId, FeeTypes feeType, string companyKey = null)
        {
            var orderDetail = _orderDao.FindById(orderId);

            if (orderDetail == null)
            {
                throw new Exception("Order not found");
            }

            if (orderDetail.IBSOrderId == null)
            {
                throw new Exception("Order has no IBSOrderId");
            }

            var account = _accountDao.FindById(orderDetail.AccountId);

            var paymentDetail = _paymentDao.FindByOrderId(orderId, companyKey);

            if (paymentDetail == null)
            {
                throw new Exception("Payment not found");
            }

            var paymentProviderServiceResponse = new CommitPreauthorizedPaymentResponse
            {
                TransactionId = paymentDetail.TransactionId
            };

            try
            {
                var message = string.Empty;

                if (paymentDetail.IsCompleted)
                {
                    message = "Order already paid or payment currently processing";
                }
                else
                {
                    if (totalFeeAmount > 0)
                    {
                        // Fees are collected by the local company
                        paymentProviderServiceResponse = _paymentService.CommitPayment(null, orderId, account, paymentDetail.PreAuthorizedAmount, totalFeeAmount, totalFeeAmount, 0, paymentDetail.TransactionId);
                        message = paymentProviderServiceResponse.Message;
                    }
                    else
                    {
                        // void preauth if it exists
                        _paymentService.VoidPreAuthorization(null, orderId);

                        paymentProviderServiceResponse.IsSuccessful = true;
                    }
                }

                if (paymentProviderServiceResponse.IsSuccessful)
                {
                    // Payment completed

                    var fareObject = FareHelper.GetFareFromAmountInclTax(Convert.ToDouble(totalFeeAmount), _serverSettings.ServerData.VATIsEnabled ? _serverSettings.ServerData.VATPercentage : 0);

                    _commandBus.Send(new CaptureCreditCardPayment
                    {
                        AccountId         = account.Id,
                        PaymentId         = paymentDetail.PaymentId,
                        Provider          = _paymentService.ProviderType(companyKey, orderDetail.Id),
                        TotalAmount       = totalFeeAmount,
                        MeterAmount       = Convert.ToDecimal(fareObject.AmountExclTax),
                        TipAmount         = Convert.ToDecimal(0),
                        TaxAmount         = Convert.ToDecimal(fareObject.TaxAmount),
                        AuthorizationCode = paymentProviderServiceResponse.AuthorizationCode,
                        TransactionId     = paymentProviderServiceResponse.TransactionId,
                        FeeType           = feeType,
                        BookingFees       = bookingFees
                    });
                }
                else
                {
                    // Void PreAuth because commit failed
                    _paymentService.VoidPreAuthorization(null, orderId);

                    // Payment error
                    _commandBus.Send(new LogCreditCardError
                    {
                        PaymentId = paymentDetail.PaymentId,
                        Reason    = message
                    });

                    if (paymentProviderServiceResponse.IsDeclined)
                    {
                        _commandBus.Send(new ReactToPaymentFailure
                        {
                            AccountId       = account.Id,
                            OrderId         = orderId,
                            IBSOrderId      = orderDetail.IBSOrderId,
                            CreditCardId    = account.DefaultCreditCard.GetValueOrDefault(),
                            OverdueAmount   = totalFeeAmount,
                            TransactionId   = paymentProviderServiceResponse.TransactionId,
                            TransactionDate = paymentProviderServiceResponse.TransactionDate,
                            FeeType         = feeType
                        });
                    }
                }

                return(new CommitPreauthorizedPaymentResponse
                {
                    AuthorizationCode = paymentProviderServiceResponse.AuthorizationCode,
                    TransactionId = paymentProviderServiceResponse.TransactionId,
                    IsSuccessful = paymentProviderServiceResponse.IsSuccessful,
                    Message = paymentProviderServiceResponse.IsSuccessful ? "Success" : message
                });
            }
            catch (Exception e)
            {
                _logger.LogMessage("Error during fee payment " + e);
                _logger.LogError(e);

                return(new CommitPreauthorizedPaymentResponse
                {
                    IsSuccessful = false,
                    TransactionId = paymentProviderServiceResponse.TransactionId,
                    Message = e.Message
                });
            }
        }
Exemple #5
0
        internal BasePaymentResponse CapturePaymentForPrepaidOrder(
            string companyKey,
            Guid orderId,
            AccountDetail account,
            decimal appEstimateWithTip,
            int tipPercentage,
            decimal bookingFees,
            string cvv)
        {
            // Note: No promotion on web
            var tipAmount   = FareHelper.GetTipAmountFromTotalIncludingTip(appEstimateWithTip, tipPercentage);
            var totalAmount = appEstimateWithTip + bookingFees;
            var meterAmount = appEstimateWithTip - tipAmount;

            var preAuthResponse = _paymentService.PreAuthorize(companyKey, orderId, account, totalAmount, isForPrepaid: true, cvv: cvv);

            if (preAuthResponse.IsSuccessful)
            {
                // Wait for payment to be created
                Thread.Sleep(500);

                var commitResponse = _paymentService.CommitPayment(
                    companyKey,
                    orderId,
                    account,
                    totalAmount,
                    totalAmount,
                    meterAmount,
                    tipAmount,
                    preAuthResponse.TransactionId,
                    preAuthResponse.ReAuthOrderId,
                    isForPrepaid: true);

                if (commitResponse.IsSuccessful)
                {
                    var paymentDetail = _orderPaymentDao.FindByOrderId(orderId, companyKey);

                    var fareObject = FareHelper.GetFareFromAmountInclTax(meterAmount,
                                                                         _serverSettings.ServerData.VATIsEnabled
                            ? _serverSettings.ServerData.VATPercentage
                            : 0);

                    _commandBus.Send(new CaptureCreditCardPayment
                    {
                        AccountId         = account.Id,
                        PaymentId         = paymentDetail.PaymentId,
                        Provider          = _paymentService.ProviderType(companyKey, orderId),
                        TotalAmount       = totalAmount,
                        MeterAmount       = fareObject.AmountExclTax,
                        TipAmount         = tipAmount,
                        TaxAmount         = fareObject.TaxAmount,
                        AuthorizationCode = commitResponse.AuthorizationCode,
                        TransactionId     = commitResponse.TransactionId,
                        IsForPrepaidOrder = true,
                        BookingFees       = bookingFees
                    });
                }
                else
                {
                    // Payment failed, void preauth
                    _paymentService.VoidPreAuthorization(companyKey, orderId, true);

                    return(new BasePaymentResponse
                    {
                        IsSuccessful = false,
                        Message = commitResponse.Message
                    });
                }
            }
            else
            {
                return(new BasePaymentResponse
                {
                    IsSuccessful = false,
                    Message = preAuthResponse.Message
                });
            }

            return(new BasePaymentResponse {
                IsSuccessful = true
            });
        }
Exemple #6
0
        public object Post(TestEmailAdministrationRequest request)
        {
            try
            {
                switch (request.TemplateName)
                {
                case NotificationService.EmailConstant.Template.AccountConfirmation:
                    _notificationService.SendAccountConfirmationEmail(new Uri("http://www.google.com"),
                                                                      request.EmailAddress, request.Language);
                    break;

                case NotificationService.EmailConstant.Template.BookingConfirmation:
                    _notificationService.SendBookingConfirmationEmail(12345, "This is a standard note",
                                                                      _pickupAddress, _dropOffAddress,
                                                                      DateTime.Now, _bookingSettings, request.EmailAddress, request.Language, true);
                    break;

                case NotificationService.EmailConstant.Template.PasswordReset:
                    _notificationService.SendPasswordResetEmail("N3wp@s5w0rd", request.EmailAddress, request.Language);
                    break;

                case NotificationService.EmailConstant.Template.CancellationFeesReceipt:
                    _notificationService.SendCancellationFeesReceiptEmail(1234, 24.42, "1111", request.EmailAddress, request.Language);
                    break;

                case NotificationService.EmailConstant.Template.NoShowFeesReceipt:
                    _notificationService.SendNoShowFeesReceiptEmail(1234, 10.00, _pickupAddress, "1111", request.EmailAddress, request.Language);
                    break;

                case NotificationService.EmailConstant.Template.Receipt:
                    var fareObject = _serverSettings.ServerData.VATIsEnabled
                            ? FareHelper.GetFareFromAmountInclTax(45m, _serverSettings.ServerData.VATPercentage)
                            : FareHelper.GetFareFromAmountInclTax(45m, 0);
                    var toll = 3;
                    var tip  = (double)45 * ((double)15 / (double)100);
                    var amountSavedByPromo = 10;
                    var extra        = 2;
                    var surcharge    = 5;
                    var bookingFees  = 7;
                    var tipIncentive = 10;

                    var driverInfos = new DriverInfos
                    {
                        DriverId            = "7009",
                        FirstName           = "Alex",
                        LastName            = "Proteau",
                        MobilePhone         = "5551234567",
                        VehicleColor        = "Silver",
                        VehicleMake         = "DMC",
                        VehicleModel        = "Delorean",
                        VehicleRegistration = "OUTATIME",
                        VehicleType         = "Time Machine"
                    };

                    var fare = Convert.ToDouble(fareObject.AmountExclTax);
                    var tax  = Convert.ToDouble(fareObject.TaxAmount);

                    _notificationService.SendTripReceiptEmail(Guid.NewGuid(), 12345, "9007", driverInfos, fare, toll, tip, tax, extra,
                                                              surcharge, bookingFees, fare + toll + tip + tax + bookingFees + extra + tipIncentive - amountSavedByPromo,
                                                              _payment, _pickupAddress, _dropOffAddress, DateTime.Now.AddMinutes(-15), DateTime.UtcNow,
                                                              request.EmailAddress, request.Language, amountSavedByPromo, "PROMO10", new SendReceipt.CmtRideLinqReceiptFields
                    {
                        Distance               = 13,
                        DriverId               = "D1337",
                        DropOffDateTime        = DateTime.Now,
                        AccessFee              = 0.3,
                        LastFour               = "1114",
                        TripId                 = 9874,
                        RateAtTripStart        = 1,
                        RateAtTripEnd          = 4,
                        FareAtAlternateRate    = 23.45,
                        LastLatitudeOfVehicle  = 45.546571,
                        LastLongitudeOfVehicle = -73.586309,
                        Tolls = new[]
                        {
                            new TollDetail
                            {
                                TollName   = "Toll 1",
                                TollAmount = 95
                            },
                            new TollDetail
                            {
                                TollName   = "Toll 2",
                                TollAmount = 5
                            },
                            new TollDetail
                            {
                                TollName   = "Toll 3",
                                TollAmount = 30
                            },
                            new TollDetail
                            {
                                TollName   = "Toll 4",
                                TollAmount = 35
                            }
                        },
                        TipIncentive = tipIncentive
                    }, true);
                    break;

                case NotificationService.EmailConstant.Template.PromotionUnlocked:
                    _notificationService.SendPromotionUnlockedEmail("10% Off your next ride", "PROMO123", DateTime.Now.AddMonths(1), request.EmailAddress, request.Language, true);
                    break;

                case NotificationService.EmailConstant.Template.CreditCardDeactivated:
                    _notificationService.SendCreditCardDeactivatedEmail("Visa", "1234", request.EmailAddress, request.Language, true);
                    break;

                default:
                    throw new Exception("sendTestEmailErrorNoMatchingTemplate");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e);
                throw new HttpError(HttpStatusCode.InternalServerError, e.Message);
            }

            return(new HttpResult(HttpStatusCode.OK));
        }