/// <summary>
        /// The SubscribeToEvent method subscribes to an event
        /// </summary>
        /// <param name="subscription">The subscription parameter</param>
        /// <returns>The AuthNet.PoC.EventModel.Entities.Subscription type object</returns>        
        public Subscription SubscribeToEvent(Subscription subscription)
        {
            int subscriberId = subscription.SubscriberID;
            int eventTypeId = subscription.EventType.ID;
            string description = string.Empty;
            string notificationType = Convert.ToString(subscription.NotificationEndpoint.NotificationType);
            int subscriptionId = 0;

            List<DbParameter> parameters = new List<DbParameter>();
            parameters.Add(new IntParameter(Constants.Parameters.SubscriberId, subscriberId));
            parameters.Add(new IntParameter(Constants.Parameters.EventTypeId, eventTypeId));
            parameters.Add(new StringParameter(Constants.Parameters.Description, description));
            parameters.Add(new StringParameter(Constants.Parameters.NotificationType, notificationType));

            using (IDataReader reader = ExecuteStoredProcReader(Constants.StoredProcedures.GetSubscribers, parameters))
            {
                while (reader.Read())
                {
                    subscriptionId = int.Parse(reader[0].ToString());
                }
            }

            List<DbParameter> innerParameters = new List<DbParameter>();
            if (notificationType.Equals("Email"))
            {
                EmailNotificationSetting emailAddress = (EmailNotificationSetting)subscription.NotificationEndpoint;
                string email = emailAddress.EmailAddress;
                innerParameters.Add(new IntParameter("subscriptionId", subscriptionId));
                innerParameters.Add(new StringParameter("email", email));
                this.ExecuteStoredProcNonQuery("CreateEmailNotificationSetting", innerParameters);
            }
            else if (notificationType.Equals("SMS"))
            {
                SmsNotificationSetting phoneNumber = (SmsNotificationSetting)subscription.NotificationEndpoint;
                string phone = phoneNumber.PhoneNumber;
                innerParameters.Add(new IntParameter("subscriptionId", subscriptionId));
                innerParameters.Add(new StringParameter("phone", phone));
                this.ExecuteStoredProcNonQuery("CreateSmsNotificationSetting", innerParameters);
            }
            else if (notificationType.Equals("Webhook"))
            {
                WebhookNotificationSetting webhook = (WebhookNotificationSetting)subscription.NotificationEndpoint;
                string webUrl = webhook.Url;
                innerParameters.Add(new IntParameter("subscriptionId", subscriptionId));
                innerParameters.Add(new StringParameter("Url", webUrl));
                this.ExecuteStoredProcNonQuery("CreateWebhookNotificationSetting", innerParameters);
            }

            return subscription;
        }
Пример #2
0
        /// <summary>
        /// The PostWebhookNotification method
        /// </summary>
        /// <param name="subscription">The subscription parameter</param>
        /// <param name="notificationTemplate">The notificationTemplate parameter</param>
        /// <returns>The boolean type object</returns>        
        public static bool PostWebhookNotification(Subscription subscription, NotificationTemplate notificationTemplate)
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            string templateName = notificationTemplate.TemplateName.Replace('.', '_');
            string nrsEndPoint = "https://sl73cnsaapq001.visa.com:8443/notification/v1/notification-templates/ipn/json/webhook";
            var request = (HttpWebRequest)WebRequest.Create(nrsEndPoint);
            request.Method = "POST";
            string postData = "{     \"url\"  : \"https://sl73cnsaapq001.rrqa.visa.com:8443/MerchantEndPoint/Merchant\",     \"owner\": \"ANet\",     \"encryptedHashKey\" :\"{CBC}sus4W1+eVANo6fd1gLbhJUEB/kabXGnHxarYcAOrj50=\",    \"encryptionKey\" :\"PII05192015\",     \"data\" : {   \"requestId\": \"4387909360535000001540\",   \"merchantId\": \"ANet\",   \"gatewayName\": \"alipay\",   \"transactionReferenceNumber\": \"008899775512345\",   \"notificationDate\": \"2015-07-29 13:08:32\",   \"paymentStatus\": \"COMPLETEDA\",   \"transactionType\": \"" + templateName + "\",   \"processorMessage\": \"notify_type=trade_status_sync&notify_time=2015-07-29+13%3A08%3A32&out_trade_no=008899775512345&notify_reg_time=2015-07-29+11%3A06%3A32&total_fee=15&trade_status=TRADE_FINISHED&sign=YchKjjkr3c6kEdVqXfrZJAFRnG22kha4x9AA0hQrskZYha0cSDQT1heHDdPMC4WEeY6pJmy8hvJG%0D%0AnFUjEBw0hBfmFpRlccAcwVmvaJLXt8apKHVbRGXVhXRVzdG6074djCwAZE4arStscdmVsRXOVjJy%0D%0A73y3DmqkOdT9GgfBWpc3IUBkXQWsL%2BpfUp5I0iuI3P93OvLhnkzkO4MOIAL0y8R3D%2FcTXPXpXLja%0D%0AfVchDpgZrorUbrdlkPH2F6qlLW8KJ9TfMfciOWmAOm3kRTz%2FmTOv%2FVIE7v4W1uejWTpHdWYHoMD%2B%0D%0AC8Fx4rwlbI%2BWrrPiqD8pscXlBQ1mM5QJIc8UpQ%3D%3D&trade_no=2010012489527852&currency=USD&sign_type=RSA&notify_id=70fec0c2730b27528665af4517c27b95\",   \"merchantReferenceNumber\": \"TC66932-1\",   \"originalTransactionDate\": \"2015-08-05 16:08:56.0\",   \"transactionAmount\": \"100\",   \"transactionCurrencyCode\": \"USD\" } }";

            // request.
            // add cert
            request.ClientCertificates.Add(new X509Certificate("C:/Users/nbansal/Desktop/vcasclient.visa.com.p12", "password")); 
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";

            // Get the request stream.
            StreamWriter dataStream = new StreamWriter(request.GetRequestStream());

            // Write the data to the request stream.
            dataStream.Write(postData);
            dataStream.Flush();

            // Close the Stream object.
            dataStream.Close();
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException)
            {
                throw;
            }

            var status = ((HttpWebResponse)response).StatusDescription;
            if (string.Compare(status, "Created") == 0)
            {
                return true;
            }

            return false;
        }
Пример #3
0
        /// <summary>
        /// The PostEmailNotification method posts the notification
        /// </summary>
        /// <param name="subscription">The subscription parameter</param>
        /// <param name="notificationTemplate">The notificationTemplate parameter</param>
        /// <returns>The boolean type object</returns>        
        public static bool PostEmailNotification(Subscription subscription, NotificationTemplate notificationTemplate)
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            string templateName = notificationTemplate.TemplateName.Replace('.', '_');
            string nrsEndPoint = "https://sl73cnsaapq001.visa.com:8443/notification/v1/notification-templates/mpos/" + templateName + "/email";
            var request = (HttpWebRequest)WebRequest.Create(nrsEndPoint);
            request.Method = "POST";
            string postData = "{     \"owner\": \"ANet\",     \"toAddress\": \"" + subscription.NotificationEndpoint.Summary + "\",     \"fromAddress\": \"[email protected]\",     \"subject\": \"Email from Event Model POC\",  \"displayName\" : \"ANet EventModelPOC\",   \"data\": {    \"eventType\" : \" " + notificationTemplate.TemplateName + "\"     } } ";
            
            // add cert
            request.ClientCertificates.Add(new X509Certificate("C:/Users/nbansal/Desktop/vcasclient.visa.com.p12", "password"));
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";

            // Get the request stream.
            StreamWriter dataStream = new StreamWriter(request.GetRequestStream());

            // Write the data to the request stream.
            dataStream.Write(postData);
            dataStream.Flush();

            // Close the Stream object.
            dataStream.Close();
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException)
            {
                throw;
            }
            
            var status = ((HttpWebResponse)response).StatusDescription;
            if (string.Compare(status, "Created") == 0)
            {
                return true;
            }

            return false;
        }
 /// <summary>
 /// The Subscribe method
 /// </summary>
 /// <param name="subscription">The subscription to be subscribed</param>
 /// <returns>The Subscription</returns>        
 public override Subscription Subscribe(Subscription subscription)
 {
     return Business.SubscribeV2(subscription);
 }
 /// <summary>
 /// This method Updates Subscription
 /// </summary>
 /// <param name="subscription">The subscription parameter</param>
 /// <returns>The completion status of update subscription method</returns>        
 public override bool UpdateSubscription(Subscription subscription)
 {
     return Business.UpdateSubscriptionV2(subscription);
 }
 /// <summary>
 /// The Subscribe method
 /// </summary>
 /// <param name="subscription">The subscription to be subscribed</param>
 /// <returns>The Subscription</returns>        
 public virtual Subscription Subscribe(Subscription subscription)
 {
     return this.Business.Subscribe(subscription);
 }
 /// <summary>
 /// This method Updates Subscription for specified id and with specified information
 /// </summary>
 /// <param name="subscription">The subscription parameter</param>
 /// <returns>The completion status of update subscription operation</returns>        
 public virtual bool UpdateSubscription(Subscription subscription)
 {
     return this.Business.UpdateSubscription(subscription);
 }
 /// <summary>
 /// The SubscribeV2 method
 /// </summary>
 /// <param name="subscription">The subscription object parameter</param>
 /// <returns>returns subscription object</returns>        
 public Subscription SubscribeV2(Subscription subscription)
 {
     this.subscriptionDAL.SubscribeToEvent(subscription);
     return subscription;
 }
 /// <summary>
 /// The UpdateSubscriptionV2 method
 /// </summary>
 /// <param name="subscription">The subscription parameter</param>
 /// <returns>returns true or false respectively</returns>        
 public bool UpdateSubscriptionV2(Subscription subscription)
 {
     return this.subscriptionDAL.UpdateSubscription(subscription);
 }
 /// <summary>
 /// The UnsubscribeV2 method
 /// </summary>
 /// <param name="subscriptionId">The subscriptionId parameter</param>
 /// <returns>returns true or false respectively</returns>        
 public bool UnsubscribeV2(int subscriptionId)
 {
     Subscription subscription = new Subscription();
     bool val = this.subscriptionDAL.Unsubscribe(subscriptionId);
     return val;
 }
Пример #11
0
        private void createSubscription(int subscriberId, int eventId, NotificationTypes nType)
        {

            EventType selectedEvent = new EventType() { ID = eventId };
            NotificationEndpoint notificationEP;
            Subscription subscription = new Subscription() { SubscriberID = subscriberId, EventType = selectedEvent };
            string emailEP;
            string smsEP;
            string webhookEP;

            if (nType == NotificationTypes.Email)
            {
                emailEP = txtBoxEmail.Text.Trim();
                bool emailCheck = IsValidEmail(emailEP);
                if (!emailCheck)
                {
                    MessageBox.Show("Invalid EmailID");
                }
                else
                {
                    if (string.Compare(emailEP, "") != 0)
                    {
                        notificationEP = new EmailNotificationSetting() { NotificationType = nType, EmailAddress = emailEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }
            }
            if (nType == NotificationTypes.SMS)
            {
                smsEP = txtBoxSMS.Text.Trim();
                bool phoneCheck = isValidPhoneNumber(smsEP);
                if (!phoneCheck)
                {
                    MessageBox.Show("Invalid Phone Number");
                }
                else
                {
                    if (string.Compare(smsEP, "") != 0)
                    {
                        notificationEP = new SmsNotificationSetting() { NotificationType = nType, PhoneNumber = smsEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }

            }
            if (nType == NotificationTypes.Webhook)
            {
                webhookEP = txtBoxWebhook.Text.Trim();
                bool webhookCheck = Uri.IsWellFormedUriString(webhookEP, UriKind.RelativeOrAbsolute);
                bool webhookhttp = IsValidUrl(webhookEP);
                if (!webhookCheck || webhookhttp == false)
                {
                    MessageBox.Show("Invalid URL");
                }
                else
                {
                    if (string.Compare(webhookEP, "") != 0)
                    {
                        notificationEP = new WebhookNotificationSetting() { NotificationType = nType, Url = webhookEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }

            }
        }
 /// <summary>
 /// The UpdateSubscription method updates a subscription
 /// </summary>
 /// <param name="subscription">The subscription parameter</param>
 /// <returns>The boolean type object</returns>        
 public bool UpdateSubscription(Subscription subscription)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// The GetSubscriptions method gets the subscription
        /// </summary>
        /// <param name="eventType">The eventType parameter</param>
        /// <returns>returns the list of subscriptions</returns>        
        public List<Subscription> GetSubscriptions(string eventType)
        {
            List<Subscription> subscriptions = new List<Subscription>();

            List<DbParameter> parameters = new List<DbParameter>();
            parameters.Add(new StringParameter("eventType", eventType));

            using (IDataReader reader = ExecuteStoredProcReader("GetSubscriptionEventType", parameters))
            {
                while (reader.Read())
                {
                    Subscription newSubsription = new Subscription();

                    int subscriptionId = int.Parse(reader[0].ToString());
                    int subscriberId = int.Parse(reader[1].ToString());
                    int eventTypeId = int.Parse(reader[2].ToString());
                    string description = reader[3].ToString();
                    string notificationType = reader[4].ToString();

                    newSubsription.ID = subscriptionId;
                    newSubsription.SubscriberID = subscriberId;
                    newSubsription.EventType = this.GetEvent(eventTypeId);
                    newSubsription.NotificationEndpoint = this.GetNotification(notificationType, this.ConnectionString, subscriptionId);
                    subscriptions.Add(newSubsription);
                }
            }

            return subscriptions;
        }
Пример #14
0
 /// <summary>
 /// The PostWebhookNotification method
 /// </summary>
 /// <param name="subscription">The subscription parameter</param>
 /// <param name="notificationTemplate">The notificationTemplate parameter</param>
 /// <returns>returns true or false respectively</returns>        
 public static bool PostWebhookNotification(Subscription subscription, NotificationTemplate notificationTemplate)
 {
     return NRS.NRS.PostWebhookNotification(subscription, notificationTemplate);
 }