Esempio n. 1
0
        private void SetupImageMark(PayPalConfiguration payPalConfiguration, string palParameter)
        {
            ImageMark.Attributes.Add("onclick", "javascript:var top= (screen.availHeight - 500)/2; var left=(screen.availWidth - 400)/2;window.open('https://www.paypal.com/se/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside','PayPalHelp', 'height=500, width=400, top=' +top +',left=' + left)");
            ImageMark.Style.Add(System.Web.UI.HtmlTextWriterStyle.Cursor, "pointer");

            if (payPalConfiguration.SandBox != "1")
            {
                // LIVE PayPal payment
                if (string.IsNullOrEmpty(palParameter))
                {
                    //Default image
                    ImageMark.ImageUrl = "https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark";
                }
                else
                {
                    ImageMark.ImageUrl = string.Format("https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark&pal={0}&locale={1}", palParameter, SiteContext.Current.LanguageName);
                }
            }
            else
            {
                // SANBOX PayPal payment
                if (string.IsNullOrEmpty(palParameter))
                {
                    //Default image
                    ImageMark.ImageUrl = "https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark";
                }
                else
                {
                    ImageMark.ImageUrl = string.Format("https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark&pal={0}&locale={1}", palParameter, SiteContext.Current.LanguageName);
                }
            }
        }
        /// <summary>
        /// Setup the PayPal API caller service, use the profile setting with pre-configured parameters.
        /// </summary>
        /// <param name="payPalConfiguration">The PayPal payment configuration.</param>
        public static PayPalAPIInterfaceServiceService GetPayPalAPICallerServices(PayPalConfiguration payPalConfiguration)
        {
            var configMap = new Dictionary <string, string>();

            configMap.Add("mode", payPalConfiguration.SandBox == "1" ? "sandbox" : "live");

            // Signature Credential
            configMap.Add("account1.apiUsername", payPalConfiguration.User);
            configMap.Add("account1.apiPassword", payPalConfiguration.Password);
            configMap.Add("account1.apiSignature", payPalConfiguration.APISignature);

            return(new PayPalAPIInterfaceServiceService(configMap));
        }
        public ActionResult Index()
        {
            if (PageEditing.PageIsInEditMode)
            {
                return(new EmptyResult());
            }

            var currentCart = _orderRepository.LoadCart <ICart>(PrincipalInfo.CurrentPrincipal.GetContactId(), Cart.DefaultName);

            if (!currentCart.Forms.Any() || !currentCart.GetFirstForm().Payments.Any())
            {
                throw new PaymentException(PaymentException.ErrorType.ProviderError, "", Utilities.Translate("GenericError"));
            }

            var paymentConfiguration = new PayPalConfiguration();
            var payment = currentCart.Forms.SelectMany(f => f.Payments).FirstOrDefault(c => c.PaymentMethodId.Equals(paymentConfiguration.PaymentMethodId));

            if (payment == null)
            {
                throw new PaymentException(PaymentException.ErrorType.ProviderError, "", Utilities.Translate("PaymentNotSpecified"));
            }

            var orderNumber = payment.Properties[PayPalPaymentGateway.PayPalOrderNumberPropertyName] as string;

            if (string.IsNullOrEmpty(orderNumber))
            {
                throw new PaymentException(PaymentException.ErrorType.ProviderError, "", Utilities.Translate("PaymentNotSpecified"));
            }

            // Redirect customer to receipt page
            var cancelUrl = Utilities.GetUrlFromStartPageReferenceProperty("CheckoutPage"); // get link to Checkout page

            cancelUrl = UriUtil.AddQueryString(cancelUrl, "success", "false");
            cancelUrl = UriUtil.AddQueryString(cancelUrl, "paymentmethod", "paypal");

            var gateway     = new PayPalPaymentGateway();
            var redirectUrl = cancelUrl;

            if (string.Equals(Request.QueryString["accept"], "true") && Utilities.GetAcceptUrlHashValue(orderNumber) == Request.QueryString["hash"])
            {
                var acceptUrl = Utilities.GetUrlFromStartPageReferenceProperty("PayPalPaymentLandingPage");
                redirectUrl = gateway.ProcessSuccessfulTransaction(currentCart, payment, acceptUrl, cancelUrl);
            }
            else if (string.Equals(Request.QueryString["accept"], "false") && Utilities.GetCancelUrlHashValue(orderNumber) == Request.QueryString["hash"])
            {
                TempData["Message"] = Utilities.Translate("CancelMessage");
                redirectUrl         = gateway.ProcessUnsuccessfulTransaction(cancelUrl, Utilities.Translate("CancelMessage"));
            }

            return(Redirect(redirectUrl));
        }
Esempio n. 4
0
        public PayPalPaymentMethod(IOrderGroupFactory orderGroupFactory)
        {
            _orderGroupFactory = orderGroupFactory;
            _paymentMethodDto  = PayPalConfiguration.GetPayPalPaymentMethod();
            _paymentMethod     = _paymentMethodDto?.PaymentMethod?.FirstOrDefault();

            if (_paymentMethod == null)
            {
                return;
            }

            PaymentMethodId = _paymentMethod.PaymentMethodId;
            SystemKeyword   = _paymentMethod.SystemKeyword;
            Name            = _paymentMethod.Name;
            Description     = _paymentMethod.Description;
        }
        public PayPalPaymentGateway(
            IFeatureSwitch featureSwitch,
            IInventoryProcessor inventoryProcessor,
            IOrderNumberGenerator orderNumberGenerator,
            IOrderRepository orderRepository,
            IOrderGroupCalculator orderGroupCalculator,
            PayPalAPIHelper paypalAPIHelper)
        {
            _featureSwitch        = featureSwitch;
            _inventoryProcessor   = inventoryProcessor;
            _orderNumberGenerator = orderNumberGenerator;
            _orderRepository      = orderRepository;
            _orderGroupCalculator = orderGroupCalculator;
            _payPalAPIHelper      = paypalAPIHelper;

            _paymentMethodConfiguration = new PayPalConfiguration(Settings);
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (_payPalConfiguration == null)
            {
                _payPalConfiguration = new PayPalConfiguration();
            }

            var pal = _payPalConfiguration.PAL;

            if (string.IsNullOrEmpty(pal))
            {
                pal = ViewState["PAL"] as string;
            }

            if (string.IsNullOrEmpty(pal))
            {
                //Obtain the PAL code using API
                var caller = PayPalAPIHelper.GetPayPalAPICallerServices(_payPalConfiguration);
                if (caller != null)
                {
                    var palResponse = caller.GetPalDetails(new GetPalDetailsReq()
                    {
                        GetPalDetailsRequest = new GetPalDetailsRequestType()
                    });
                    if (palResponse.Ack == AckCodeType.SUCCESSWITHWARNING || palResponse.Ack == AckCodeType.SUCCESS)
                    {
                        pal = palResponse.Pal;
                        ViewState["PAL"] = pal;
                    }
                }
            }

            SetupImageMark(_payPalConfiguration, pal);

            Message.Text = Utilities.Translate("PayPalText");

            if (string.Equals(Request["accept"], "false") && !string.IsNullOrEmpty(Request.QueryString["hash"]))
            {
                ErrorManager.GenerateError(Utilities.Translate("CancelMessage"));
                return;
            }
        }
        public SetExpressCheckoutRequestDetailsType CreateExpressCheckoutReqDetailsType(IPayment payment, PayPalConfiguration payPalConfiguration)
        {
            var setExpressChkOutReqDetails = new SetExpressCheckoutRequestDetailsType
            {
                BillingAddress = AddressHandling.ToAddressType(payment.BillingAddress),
                BuyerEmail     = payment.BillingAddress.Email
            };

            TransactionType transactionType;

            if (Enum.TryParse(payment.TransactionType, out transactionType))
            {
                if (transactionType == TransactionType.Authorization)
                {
                    setExpressChkOutReqDetails.PaymentAction = PaymentActionCodeType.AUTHORIZATION;
                }
                else if (transactionType == TransactionType.Sale)
                {
                    setExpressChkOutReqDetails.PaymentAction = PaymentActionCodeType.SALE;
                }
            }

            if (payPalConfiguration.AllowChangeAddress != "1")
            {
                setExpressChkOutReqDetails.AddressOverride = "1";
            }

            if (payPalConfiguration.AllowGuest == "1")
            {
                setExpressChkOutReqDetails.SolutionType = SolutionTypeType.SOLE;
                setExpressChkOutReqDetails.LandingPage  = LandingPageType.BILLING;
            }

            return(setExpressChkOutReqDetails);
        }
        /// <summary>
        /// Processes the payment.
        /// </summary>
        /// <param name="orderGroup">The order group.</param>
        /// <param name="payment">The payment.</param>
        public PaymentProcessingResult ProcessPayment(IOrderGroup orderGroup, IPayment payment)
        {
            if (HttpContext.Current == null)
            {
                return(PaymentProcessingResult.CreateSuccessfulResult(Utilities.Translate("ProcessPaymentNullHttpContext")));
            }

            if (payment == null)
            {
                return(PaymentProcessingResult.CreateUnsuccessfulResult(Utilities.Translate("PaymentNotSpecified")));
            }

            var orderForm = orderGroup.Forms.FirstOrDefault(f => f.Payments.Contains(payment));

            if (orderForm == null)
            {
                return(PaymentProcessingResult.CreateUnsuccessfulResult(Utilities.Translate("PaymentNotAssociatedOrderForm")));
            }

            _paymentMethodConfiguration = new PayPalConfiguration(Settings);

            if (string.IsNullOrEmpty(payment.TransactionType) && !string.IsNullOrEmpty(_paymentMethodConfiguration.PaymentAction))
            {
                payment.TransactionType = _paymentMethodConfiguration.PaymentAction;
            }

            PaymentProcessingResult paymentProcessingResult;
            var cart = orderGroup as ICart;

            // the order which is created by Commerce Manager
            if (cart == null && orderGroup is IPurchaseOrder)
            {
                if (payment.TransactionType == TransactionType.Capture.ToString())
                {
                    paymentProcessingResult = ProcessPaymentCapture(orderGroup, payment);

                    return(paymentProcessingResult);
                }

                // When "Refund" shipment in Commerce Manager, this method will be invoked with the TransactionType is Credit
                if (payment.TransactionType == TransactionType.Credit.ToString())
                {
                    paymentProcessingResult = ProcessPaymentRefund(orderGroup, payment);

                    return(paymentProcessingResult);
                }

                // right now we do not support processing the order which is created by Commerce Manager
                paymentProcessingResult = PaymentProcessingResult.CreateUnsuccessfulResult("The current payment method does not support order type.");

                return(paymentProcessingResult); // raise exception
            }

            if (cart != null && cart.OrderStatus == OrderStatus.Completed)
            {
                // return true because this shopping cart has been paid already on PayPal
                // when program flow redirects back from PayPal to PayPal.aspx file, call ProcessSuccessfulTransaction, run WorkFlow
                paymentProcessingResult = PaymentProcessingResult.CreateSuccessfulResult(Utilities.Translate("ProcessPaymentStatusCompleted"));

                return(paymentProcessingResult);
            }

            // CHECKOUT
            paymentProcessingResult = ProcessPaymentCheckout(cart, payment);

            return(paymentProcessingResult);
        }
 private PaymentMethodDto.PaymentMethodParameterRow GetParameterByName(string name)
 {
     return(PayPalConfiguration.GetParameterByName(_paymentMethodDto, name));
 }