Ejemplo n.º 1
0
        public async Task Consume(ConsumeContext <GetBillingAddressRequest> context)
        {
            var request = context.Message;

            var order = await repo.GetMostRecentOrderByCustomer(request.CustomerId);

            BillingAddressDTO billingAddressDTO = null;

            if (order != null)
            {
                billingAddressDTO = mapper.Map <BillingAddressDTO>(order.BillingAddress);
            }

            GetBillingAddressResponse response;

            if (billingAddressDTO == null)
            {
                response = new GetBillingAddressResponse(true, ResponseAction.NotFound);
            }
            else
            {
                response = new GetBillingAddressResponse(true, ResponseAction.Found, billingAddressDTO);
            }


            await context.RespondAsync(response);
        }
Ejemplo n.º 2
0
 public static Address AddresToken2PaypalAddress(this BillingAddressDTO token)
 {
     return(new Address
     {
         country_code = token.CountryCode.TrimString()
         , city = token.City.TrimString()
         , postal_code = token.PostalCode.TrimString()
         , line1 = token.Street1.TrimString()
         , line2 = string.IsNullOrEmpty(token.Street2) ? token.Street1.TrimString() : token.Street2.TrimString()
         , state = string.IsNullOrEmpty(token.StateCode) ? null : token.StateCode.TrimString()
     });
 }
Ejemplo n.º 3
0
        private Domain.Order BuildOrder(Customer customer, BillingAddressDTO baDTO, IEnumerable <ProductDTO> productDTOs)
        {
            var taxRate = taxService.GetTaxRate(baDTO.StateAbbreviation);

            Domain.Order order = Domain.Order.Create(customer,
                                                     baDTO.Address1, baDTO.Address2, baDTO.Country, baDTO.Phone, baDTO.StateAbbreviation, baDTO.ZipCode,
                                                     taxRate);

            foreach (var product in productDTOs)
            {
                order.AddProduct(product.Id, product.Name, product.Price.Amount);
            }
            return(order);
        }
Ejemplo n.º 4
0
 public static void UpdateAddressEntity(this USER_Addresses entity, BillingAddressDTO dto)
 {
     entity.CountryId  = dto.CountryId;
     entity.StateId    = dto.StateId;
     entity.CityName   = dto.City.TrimString();
     entity.PostalCode = dto.PostalCode.TrimString();
     entity.Street1    = dto.Street1.TrimString();
     entity.Street2    = dto.Street2.TrimString();
     entity.FirstName  = dto.BillingFirstName.TrimString();
     entity.LastName   = dto.BillingLastName.TrimString();
     entity.IsActive   = dto.IsActive;
     entity.IsDefault  = dto.IsDefault;
     entity.UpdateDate = DateTime.Now;
     entity.UpdatedBy  = DtoExtensions.CurrentUserId;
 }
Ejemplo n.º 5
0
        public async Task <BillingAddressDTO> GetDefaultBilling(Guid customerId)
        {
            BillingAddressDTO billing = null;

            await client.Get <GetBillingAddressResponse>(routingConfig.URL,
                                                         routingConfig.GetBillingAddress, customerId,
                                                         success : (response) => { billing = response.BillingAddress; },
                                                         error : (error) =>
            {
                if (error.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    //no problem
                }
            },
                                                         headerAccept : HeaderAccept.Json);

            return(billing);
        }
Ejemplo n.º 6
0
        public async Task <GetBillingAddressResponse> GetMostRecentBillingAddress(GetBillingAddressRequest request)
        {
            var order = await repo.GetMostRecentOrderByCustomer(request.CustomerId);

            BillingAddressDTO billingAddressDTO = null;

            if (order != null)
            {
                billingAddressDTO = mapper.Map <BillingAddressDTO>(order.BillingAddress);
            }

            if (billingAddressDTO == null)
            {
                return(new GetBillingAddressResponse(true, ResponseAction.NotFound));
            }

            return(new GetBillingAddressResponse(true, ResponseAction.Found, billingAddressDTO));
        }
Ejemplo n.º 7
0
        public ActionResult SavePayoutSettings(UserPayoutSettingsDTO token, BillingAddressDTO address)
        {
            string error;


            switch (token.PayoutType)
            {
            case BillingEnums.ePayoutTypes.PAYPAL:
                if (String.IsNullOrEmpty(token.Email))
                {
                    return(ErrorResponse("email required"));
                }
                break;

            case BillingEnums.ePayoutTypes.CHEQUE:
                if (address == null)
                {
                    return(ErrorResponse("address required"));
                }
                token.BillingAddress = address;
                break;

            default:
                return(ErrorResponse("Unknown payout type"));
            }

            int?addressId;

            token.UserId = CurrentUserId;
            var isUpdated = _userAccountServices.SavePayoutSetting(token, out addressId, out error);

            if (isUpdated)
            {
                token.UpdateUserClaims();
            }

            return(Json(new JsonResponseToken
            {
                success = isUpdated
                , error = error
                , result = new { addressId }
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
 public static USER_Addresses AddressDto2UserAddressEntity(this BillingAddressDTO dto)
 {
     return(new USER_Addresses
     {
         UserId = dto.UserId
         , CountryId = dto.CountryId
         , StateId = dto.StateId
         , CityName = dto.City.TrimString()
         , PostalCode = dto.PostalCode.TrimString()
         , Street1 = dto.Street1.TrimString()
         , Street2 = dto.Street2.TrimString()
         , FirstName = dto.BillingFirstName.TrimString()
         , LastName = dto.BillingLastName.TrimString()
         , IsActive = true
         , IsDefault = dto.IsDefault
         , AddOn = DateTime.Now
         , CreatedBy = DtoExtensions.CurrentUserId
     });
 }
Ejemplo n.º 9
0
        private bool IsAddressValid(ref BillingAddressDTO address, out string error)
        {
            error = string.Empty;

            if (address == null)
            {
                error = "address required";
                return(false);
            }

            if (address.CountryId == null)
            {
                error = "Country required";
                return(false);
            }

            if (address.CountryId != null && Constants.COUNTRIES_WITH_STATES.Contains((int)address.CountryId) && address.StateId == null)
            {
                error = "State required";
                return(false);
            }

            if (String.IsNullOrEmpty(address.PostalCode))
            {
                error = "Postal code required";
                return(false);
            }

            if (String.IsNullOrEmpty(address.City))
            {
                error = "City required";
                return(false);
            }

            if (String.IsNullOrEmpty(address.Street1))
            {
                error = "Street required";
                return(false);
            }

            if (String.IsNullOrEmpty(address.BillingFirstName))
            {
                error = "Billing FirstName required";
                return(false);
            }

            if (String.IsNullOrEmpty(address.BillingLastName))
            {
                error = "Billing LastName required";
                return(false);
            }
            var cid     = address.CountryId;
            var country = _geoServices.ActiveCountries().FirstOrDefault(x => x.CountryId == cid);

            if (country != null)
            {
                address.CountryCode = country.A2;
            }
            else
            {
                error = "country not found";
                return(false);
            }

            if (address.StateId != null)
            {
                var sid   = address.StateId;
                var state = _geoServices.GetStates((short)cid).FirstOrDefault(x => x.StateId == sid);
                if (state != null)
                {
                    address.StateCode = state.StateCode;
                }
            }

            address.UserId = CurrentUserId;

            return(true);
        }
Ejemplo n.º 10
0
        public ActionResult ExecuteItemPurchase(ItemPurchaseDataToken token, BillingAddressDTO address, eActionKinds actionKind, string referral)
        {
            string error;
            var    orderNo = -1;
            var    user    = this.CurrentUser();

            if (user == null)
            {
                return(Redirect2PaymentError("authentication issue. please re-login again"));
            }

            try
            {
                if (token.IsFree)
                {
                    if (String.IsNullOrWhiteSpace(token.CouponCode))
                    {
                        return(Redirect2PaymentError("coupon code required"));
                    }

                    token.PaymentMethod = BillingEnums.ePaymentMethods.Charge_Free;

                    var completed = _billingServices.CompleteFreeCouponRequest(token, user.UserId, out orderNo, out error);

                    if (!completed)
                    {
                        return(Redirect2PaymentError(error));
                    }

                    SavePurchaseCompleteEvent(token);

                    return(ReturnPurchaseSuccess(token.PriceToken.PriceLineID, orderNo, token.TrackingID, referral));
                }


                var priceToken = _billingServices.GetPriceLineToken(token.PriceToken.PriceLineID, out error);

                if (priceToken == null)
                {
                    return(Redirect2PaymentError(error));
                }


                token.BuySubscription = priceToken.PriceType == BillingEnums.ePricingTypes.SUBSCRIPTION;

                #region private variables
                //int? storeId = null;
                //if (!String.IsNullOrEmpty(token.TrackingID))
                //{
                //    storeId = _webStorePortalServices.ValidateTrackingId(token.TrackingID);
                //}

                string approval_url;
                bool   paymentExecuted;
                var    paymentInstrumentId = Guid.Empty;
                var    CANCEL_PAYMENT_URL  = _BaseUrl + "CancelPayment".GenerateCheckoutUrl(token.PriceToken.PriceLineID, null, token.TrackingID, referral);
                #endregion

                #region handle billing address

                int?addressId = null;
                if (token.PaymentMethod == BillingEnums.ePaymentMethods.Credit_Card)
                {
                    var billingAddressDto = address;

                    if (!IsAddressValid(ref billingAddressDto, out error))
                    {
                        return(Redirect2PaymentError(error));
                    }

                    token.BillingAddress = billingAddressDto;

                    var addressSaved = _userAccountServices.SaveUserBillingAddress(ref billingAddressDto, out error);

                    if (!addressSaved)
                    {
                        return(Redirect2PaymentError(error));
                    }

                    addressId = billingAddressDto.AddressId;
                }

                #endregion

                #region payment method validation

                //in case of subscription with credit card save payment instrument option should be always true
                //we don't create on the moment recurring paypal payments with credit card = > payment method switched to Saved_Instrument
                if (token.BuySubscription && token.PaymentMethod == BillingEnums.ePaymentMethods.Credit_Card)
                {
                    token.SavePaymentInstrument = true;
                }

                switch (token.PaymentMethod)
                {
                case BillingEnums.ePaymentMethods.Paypal:
                    //if (token.SavePaymentInstrument) return Redirect2PaymentError("saving paypal agreement currently not supported");
                    break;

                case BillingEnums.ePaymentMethods.Credit_Card:
                    if (token.CreditCard == null)
                    {
                        return(Redirect2PaymentError("credit card required"));
                    }

                    if (addressId == null)
                    {
                        return(Redirect2PaymentError("Address required"));
                    }

                    if (token.SavePaymentInstrument)
                    {
                        //create card token
                        var card = token.CoursePurchaseDataToken2CreditCardDto(this.CurrentUser());

                        //save cc to paypal
                        var cardSaved = _paypalServices.SaveCreditCard2Paypal(card, CurrentUserId, out paymentInstrumentId, out error);

                        if (!cardSaved)
                        {
                            return(Redirect2PaymentError(error));
                        }
                    }
                    Session["RecurringCc"] = token.CreditCard;

                    if (token.BuySubscription)
                    {
                        token.PaymentMethod = BillingEnums.ePaymentMethods.Saved_Instrument;
                    }

                    break;

                case BillingEnums.ePaymentMethods.Saved_Instrument:
                    paymentInstrumentId = token.PaymentInstrumentId ?? Guid.Empty;
                    if (paymentInstrumentId.Equals(Guid.Empty))
                    {
                        return(Redirect2PaymentError("Select credit card"));
                    }
                    break;
                }
                #endregion

                switch (priceToken.PriceType)
                {
                case BillingEnums.ePricingTypes.ONE_TIME:
                case BillingEnums.ePricingTypes.RENTAL:
                    PaypalCreditCardPaymentDTO ccToken;
                    switch (token.PaymentMethod)
                    {
                    case BillingEnums.ePaymentMethods.Paypal:
                        #region

                        var SUCCESS_PAYMENT_URL = _BaseUrl + "OnPaymentComplete".GenerateCheckoutUrl(token.PriceToken.PriceLineID, null, token.TrackingID, referral);        //Url.Action("OnPaymentComplete", "Payment", new { area = "Widget",referral });

                        var data = token.ItemPurchaseDataToken2PayPalCreatePaymentDto(SUCCESS_PAYMENT_URL, CANCEL_PAYMENT_URL, addressId, null);

                        paymentExecuted = _paypalServices.CreatePaypalAccountPayment(data, out approval_url, out error);

                        if (paymentExecuted && !String.IsNullOrEmpty(approval_url))
                        {
                            return(Redirect(approval_url));
                        }

                        return(Redirect2PaymentError(error ?? "unexpected error"));

                        #endregion
                    case BillingEnums.ePaymentMethods.Credit_Card:
                        #region
                        Guid requestId;

                        if (token.SavePaymentInstrument)
                        {
                            //create cc payment token
                            ccToken = token.CoursePurchaseDataToken2PayPalDirectCcPaymentDto(this.CurrentUser(), addressId, null);

                            ccToken.paymentInstrumentId = paymentInstrumentId;

                            //execute payment and complete purchase process
                            paymentExecuted = _paypalServices.ExecuteSavedCreditCardPayment(ccToken, CurrentUserId, paymentInstrumentId, out requestId, out error) && _billingServices.CompletePaymentRequest(requestId, out orderNo, out error);
                        }
                        else
                        {
                            //create cc payment token
                            ccToken = token.CoursePurchaseDataToken2PayPalDirectCcPaymentDto(this.CurrentUser(), addressId, null);

                            //execute payment and complete purchase process
                            paymentExecuted = _paypalServices.ExecuteDirectCreditCardPayment(ccToken, out requestId, out error) && _billingServices.CompletePaymentRequest(requestId, out orderNo, out error);
                        }

                        if (paymentExecuted)
                        {
                            SavePurchaseCompleteEvent(token);
                        }

                        //return paymentExecuted ? (storeId != null ? View("ThankYouStore",new PaypalCompleteRequestToken{IsSuccess = true,RedirectUrl = itemPageUrl}) : View("ThankYou")) : Redirect2PaymentError(error);
                        return(paymentExecuted ? ReturnPurchaseSuccess(token.PriceToken.PriceLineID, orderNo, token.TrackingID, referral) : Redirect2PaymentError(error));

                        #endregion
                    case BillingEnums.ePaymentMethods.Saved_Instrument:
                        #region
                        //create cc payment token
                        ccToken = token.CoursePurchaseDataToken2PayPalDirectCcPaymentDto(this.CurrentUser(), addressId, null);

                        ccToken.paymentInstrumentId = token.PaymentInstrumentId;

                        //execute payment and complete purchase process
                        paymentExecuted = _paypalServices.ExecuteSavedCreditCardPayment(ccToken, CurrentUserId, paymentInstrumentId, out requestId, out error) && _billingServices.CompletePaymentRequest(requestId, out orderNo, out error);

                        if (paymentExecuted)
                        {
                            SavePurchaseCompleteEvent(token);
                        }

                        // return paymentExecuted ? (storeId != null ? View("ThankYouStore", new PaypalCompleteRequestToken { IsSuccess = true, RedirectUrl = itemPageUrl }) : View("ThankYou")) : Redirect2PaymentError(error);
                        return(paymentExecuted ? ReturnPurchaseSuccess(token.PriceToken.PriceLineID, orderNo, token.TrackingID, referral) : Redirect2PaymentError(error));

                        #endregion
                    }
                    break;

                case BillingEnums.ePricingTypes.SUBSCRIPTION:
                    switch (token.PaymentMethod)
                    {
                    case BillingEnums.ePaymentMethods.Paypal:
                        #region
                        //create paypal agreement
                        //create request token
                        var requestId   = Guid.NewGuid();
                        var success_url = _BaseUrl + "OnSubscriptionComplete".GenerateCheckoutUrl(token.PriceToken.PriceLineID, null, token.TrackingID, referral);         //Utils.GetKeyValue("baseUrl") + Url.Action("OnSubscriptionComplete", null, new { id = requestId, referral  });

                        var data = token.CoursePurchaseDataToken2PayPalAgreementDto(user.FullName, user.Email, success_url, CANCEL_PAYMENT_URL, addressId, paymentInstrumentId, token.PaymentMethod, priceToken);


                        //create payment agreement
                        paymentExecuted = _paypalServices.CreateRecurringPaymentAgreement(data, requestId, out approval_url, out error);

                        //redirect to paypal approval page
                        return(paymentExecuted && !String.IsNullOrEmpty(approval_url) ? Redirect(approval_url) : Redirect2PaymentError(error ?? "unexpected error"));

                        #endregion
                    //currently(2014-2-11) this option disabled
                    //case BillingEnums.ePaymentMethods.Credit_Card:
                    //    #region
                    //    requestId = Guid.NewGuid();
                    //    RecurringPaymentExecutionResultToken result;
                    //    var dto = token.CoursePurchaseDataToken2PaypalPaymentRequestDto(requestId, CurrentUserId, addressId);
                    //    var executed = _paypalServices.ExecuteCourseSubscriptionCcRecurringPayment(dto, CurrentUserId, requestId, token.CreditCard, out result, out error) && _billingServices.CompleteSubscriptionRequest(result, out error);

                    //    var responseToken = new PaypalCompleteRequestToken
                    //    {
                    //        IsSuccess    = executed
                    //        ,Message     = error
                    //        ,RedirectUrl = executed ? Utils.GetKeyValue("baseUrl") + Url.Action("ThankYou", null, new { requestId }) : string.Empty
                    //    };

                    //    return executed ? View("ThankYou", responseToken) : Redirect2PaymentError(error ?? "unexpected error");
                    //    #endregion
                    case BillingEnums.ePaymentMethods.Saved_Instrument:
                        #region
                        var subscriptionToken = token.CoursePurchaseDataToken2SubscriptionWithSavedCardDto(CurrentUserId, paymentInstrumentId, addressId);
                        //TODO check case , when initial amount == 0;
                        subscriptionToken.amount = subscriptionToken.InitialAmount > 0 ? subscriptionToken.InitialAmount : (decimal)0.01;

                        paymentExecuted = _paypalServices.ExecuteSubscriptionPaymentWithStoredCreditCard(subscriptionToken, out requestId, out error);

                        if (!paymentExecuted)
                        {
                            return(Redirect2PaymentError(error));
                        }

                        var subscriptionCreated = _billingServices.CreateSubscriptionWithSavedCard(subscriptionToken, requestId, out orderNo, out error);

                        if (!subscriptionCreated)
                        {
                            return(Redirect2PaymentError(error ?? "unexpected error"));
                        }

                        SavePurchaseCompleteEvent(token);

                        return(ReturnPurchaseSuccess(token.PriceToken.PriceLineID, orderNo, token.TrackingID, referral));

                        #endregion
                    }
                    break;
                }

                CheckoutBase.IsValid           = false;
                CheckoutBase.Message           = "Unexpected result. Please contact support team";
                CheckoutBase.PurchaseDataToken = token;
                return(View("Index", CheckoutBase));
                // return View("Payment/_PurchaseItem", token);
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);

                return(Redirect2PaymentError(error));
            }
        }
Ejemplo n.º 11
0
        public async Task <OrderDTO> CreateOrder(Customer.DTO.CustomerDTO customer, ShoppingCartDTO cart, BillingAddressDTO billing)
        {
            var request = new CreateOrderRequest();

            request.Customer       = mapper.Map <OrderCustomerDTO>(customer);
            request.BillingAddress = billing;
            request.Products       = mapper.Map <IEnumerable <ProductDTO> >(cart.Products);

            var response = await client.Post <CreateOrderRequest, CreateOrderResponse>(
                routingConfig.URL,
                routingConfig.CreateOrder, request, HeaderAccept.Json);

            return(response.Order);
        }