private PaymentProfileMessage GetPaymentProfile(int storeScope, PayPalPlusBrasilPaymentSettings settings) { var paymentProfileMessage = new PaymentProfileMessage(); paymentProfileMessage.Name = settings.ProfileName + " - " + storeScope.ToString(); paymentProfileMessage.Presentation.BrandName = settings.ProfileBrandName + " - " + storeScope.ToString(); paymentProfileMessage.Presentation.LocaleCode = settings.ProfileLocaleCode; paymentProfileMessage.InputFields.NoShipping = 0; paymentProfileMessage.InputFields.AddressOverride = 1; return(paymentProfileMessage); }
private void VerifyProfileExperience(PayPalPlusBrasilPaymentSettings settings, TokenResponse tokenResponse) { if (string.IsNullOrWhiteSpace(settings.IdProfileExperience)) { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var paymentProfileMessage = GetPaymentProfile(storeScope, settings); using (var experience = new PaymentExperience(settings.UseSandbox)) { var experienceResponse = experience.CreateAsync(paymentProfileMessage, tokenResponse.AcessToken).ConfigureAwait(false).GetAwaiter().GetResult(); settings.IdProfileExperience = experienceResponse.Id; _settingService.SaveSettingOverridablePerStore(settings, x => x.IdProfileExperience, true, storeScope, false); //now clear settings cache _settingService.ClearCache(); } } }
private PaymentMessage GetPaymentoMessage(PayPalPlusBrasilPaymentSettings payPalPlusBrasilPaymentSettings, Customer customer) { var cart = _workContext.CurrentCustomer.ShoppingCartItems. Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(_storeContext.CurrentStore.Id) .ToList(); List <AppliedGiftCard> appliedGiftCards; List <Discount> orderAppliedDiscounts; decimal orderDiscountAmount; int redeemedRewardPoints; decimal redeemedRewardPointsAmount; var orderTotal = _orderTotalCalculationService.GetShoppingCartTotal(cart, out orderDiscountAmount, out orderAppliedDiscounts, out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount); decimal tax; List <Discount> shippingTotalDiscounts; var orderShippingTotalInclTax = _orderTotalCalculationService.GetShoppingCartShippingTotal(cart, true, out tax, out shippingTotalDiscounts); decimal orderSubTotalDiscountAmount; List <Discount> orderSubTotalAppliedDiscounts; decimal subTotalWithoutDiscountBase; decimal subTotalWithDiscountBase; _orderTotalCalculationService.GetShoppingCartSubTotal(cart, true, out orderSubTotalDiscountAmount, out orderSubTotalAppliedDiscounts, out subTotalWithoutDiscountBase, out subTotalWithDiscountBase); var paymentMessage = new PaymentMessage(); paymentMessage.Intent = "sale"; paymentMessage.Payer.PaymentMethod = "paypal"; paymentMessage.ExperienceProfileId = payPalPlusBrasilPaymentSettings.IdProfileExperience; var transactionList = new List <Models.Message.Request.Transaction>(); var itemTransaction = new Models.Message.Request.Transaction(); itemTransaction.Amount.Currency = "BRL"; itemTransaction.Amount.Total = orderTotal.Value.ToString("N", new CultureInfo("en-US")); itemTransaction.Amount.Details.Shipping = orderShippingTotalInclTax.Value.ToString("N", new CultureInfo("en-US")); itemTransaction.Amount.Details.Subtotal = subTotalWithoutDiscountBase.ToString("N", new CultureInfo("en-US")); itemTransaction.Amount.Details.Discount = (orderDiscountAmount + orderSubTotalDiscountAmount).ToString("N", new CultureInfo("en-US")); itemTransaction.Description = "This is the payment transaction description"; itemTransaction.PaymentOptions.AllowedPaymentMethod = "IMMEDIATE_PAY"; itemTransaction.InvoiceNumber = string.Empty; var number = string.Empty; var complement = string.Empty; new AddressHelper(_addressAttributeParser, _workContext).GetCustomNumberAndComplement(customer.ShippingAddress.CustomAttributes, out number, out complement); itemTransaction.ItemList.ShippingAddress.RecipientName = AddressHelper.GetFullName(customer.ShippingAddress); itemTransaction.ItemList.ShippingAddress.Line1 = customer.ShippingAddress.Address1; itemTransaction.ItemList.ShippingAddress.Line2 = complement; itemTransaction.ItemList.ShippingAddress.City = customer.ShippingAddress.City; itemTransaction.ItemList.ShippingAddress.CountryCode = customer.ShippingAddress.Country.TwoLetterIsoCode; itemTransaction.ItemList.ShippingAddress.PostalCode = customer.ShippingAddress.ZipPostalCode; itemTransaction.ItemList.ShippingAddress.State = customer.ShippingAddress.StateProvince.Name; itemTransaction.ItemList.ShippingAddress.Phone = AddressHelper.FormatarCelular(customer.ShippingAddress.PhoneNumber); var itemList = new List <Models.Message.Request.Item>(); foreach (var itemCart in cart) { var item = new Models.Message.Request.Item(); item.Name = itemCart.Product.Name; item.Description = itemCart.Product.ShortDescription; item.Quantity = itemCart.Quantity; List <Discount> scDiscounts; decimal discountAmount; var scUnitPrice = _priceCalculationService.GetUnitPrice(itemCart, true, out discountAmount, out scDiscounts); item.Price = decimal.Round(scUnitPrice, 2).ToString("N2", new CultureInfo("en-US")); item.Sku = itemCart.Product.Sku; item.Currency = "BRL"; itemList.Add(item); } itemTransaction.ItemList.Items = itemList.ToArray(); transactionList.Add(itemTransaction); paymentMessage.Transactions = transactionList.ToArray(); string returnUrl = _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayPalPlusBrasil/IPNHandler"; string cancelReturnUrl = _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayPalPlusBrasil/IPNHandler"; paymentMessage.RedirectUrls.ReturnUrl = new Uri(returnUrl); paymentMessage.RedirectUrls.CancelUrl = new Uri(cancelReturnUrl); return(paymentMessage); }