/// <summary>
        /// Handles the tokenizer postback.
        /// </summary>
        private void HandleTokenizerPostback()
        {
            Rock.Financial.HostedGatewayPaymentControlTokenEventArgs hostedGatewayPaymentControlTokenEventArgs = new Financial.HostedGatewayPaymentControlTokenEventArgs();

            var tokenResponse = PaymentInfoTokenRaw.FromJsonOrNull <TokenizerResponse>();

            if (tokenResponse?.IsSuccessStatus() != true)
            {
                hostedGatewayPaymentControlTokenEventArgs.IsValid = false;

                if (tokenResponse.HasValidationError())
                {
                    hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = FriendlyMessageHelper.GetFriendlyMessage(tokenResponse.ValidationMessage);
                }
                else
                {
                    hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = FriendlyMessageHelper.GetFriendlyMessage(tokenResponse?.ErrorMessage ?? "null response from GetHostedPaymentInfoToken");
                }
            }
            else
            {
                hostedGatewayPaymentControlTokenEventArgs.IsValid      = true;
                hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = null;
            }

            hostedGatewayPaymentControlTokenEventArgs.Token = _hfPaymentInfoToken.Value;

            TokenReceived?.Invoke(this, hostedGatewayPaymentControlTokenEventArgs);
        }
Esempio n. 2
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (this.Page.IsPostBack)
            {
                string[] eventArgs = (this.Page.Request.Form["__EVENTARGUMENT"] ?? string.Empty).Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                if (eventArgs.Length >= 2)
                {
                    // gatewayTokenizer will pass back '{this.ID}=TokenizerPostback' in a postback. If so, we know this is a postback from that
                    if (eventArgs[0] == this.ID && eventArgs[1] == "TokenizerPostback")
                    {
                        Rock.Financial.HostedGatewayPaymentControlTokenEventArgs hostedGatewayPaymentControlTokenEventArgs = new Financial.HostedGatewayPaymentControlTokenEventArgs();

                        var tokenResponse = PaymentInfoTokenRaw.FromJsonOrNull <TokenizerResponse>();

                        if (tokenResponse?.IsSuccessStatus() != true)
                        {
                            hostedGatewayPaymentControlTokenEventArgs.IsValid = false;

                            if (tokenResponse.HasValidationError())
                            {
                                hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = FriendlyMessageHelper.GetFriendlyMessage(tokenResponse.ValidationMessage);
                            }
                            else
                            {
                                hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = FriendlyMessageHelper.GetFriendlyMessage(tokenResponse?.ErrorMessage ?? "null response from GetHostedPaymentInfoToken");
                            }
                        }
                        else
                        {
                            hostedGatewayPaymentControlTokenEventArgs.IsValid      = true;
                            hostedGatewayPaymentControlTokenEventArgs.ErrorMessage = null;
                        }

                        hostedGatewayPaymentControlTokenEventArgs.Token = _hfPaymentInfoToken.Value;

                        TokenReceived?.Invoke(this, hostedGatewayPaymentControlTokenEventArgs);
                    }
                }
            }
        }