Example #1
0
        public CreditCardDT GetDT()
        {
            CreditCardDT res = new CreditCardDT();

            res.Id         = Id;
            res.CustomerId = CustomerId;
            res.AuthorizePaymentProfileId = AuthorizePaymentProfileId;
            res.Data          = Data;
            res.Succesfull    = Successful;
            res.CreatedAt     = CreatedAt;
            res.LastFourDigit = LastFourDigit;
            return(res);
        }
Example #2
0
        public static bool CreateCustomerProfileTransactionAuthCapture(SiteDT site, InvoiceDT invoice, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message, out string code)
        {
            MerchantAuthenticationType merchantAT = new MerchantAuthenticationType();

            merchantAT.name           = site.AuthorizeLoginId;
            merchantAT.transactionKey = site.AuthorizeTransactionKey;

            ProfileTransactionType      profileTT   = new ProfileTransactionType();
            ProfileTransAuthCaptureType profileTACT = new ProfileTransAuthCaptureType();

            OrderExType orderET = new OrderExType();

            orderET.invoiceNumber = invoice.Id.ToString();

            profileTACT.amount                   = invoice.Amount;
            profileTACT.customerProfileId        = customer.AuthorizeProfileId;
            profileTACT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId;
            profileTACT.order = orderET;

            profileTT.Item = profileTACT;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServiceSoapClient client = new ServiceSoapClient();
            CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty);

            code = string.Empty;

            if (resp.directResponse != null)
            {
                PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse);
                transactionId = paymentGatewayResponse.TransactionId;
                message       = paymentGatewayResponse.ResponseReasonText;

                code = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(x => x.code + " - " + x.text).Aggregate((a, b) => a + "; " + b) : string.Empty;
            }
            else
            {
                transactionId = 0;
                if (resp.messages.Length > 0)
                {
                    message = resp.messages[0].text;
                }
                else
                {
                    message = "";
                }
            }

            return(resp.resultCode == MessageTypeEnum.Ok);
        }
Example #3
0
        public static bool UpdateCustomerPaymentProfile(SiteDT site, CustomerDT customer, CreditCardDT creditCard)
        {
            using (ServiceSoapClient client = new ServiceSoapClient())
            {
                var merchant = new MerchantAuthenticationType()
                {
                    name           = site.AuthorizeLoginId,
                    transactionKey = site.AuthorizeTransactionKey
                };
                var paymentProfileResponse = client.GetCustomerPaymentProfile(merchant, customer.AuthorizeProfileId, creditCard.AuthorizePaymentProfileId);

                if (paymentProfileResponse.resultCode == MessageTypeEnum.Ok)
                {
                    CreditCardType creditCardType = new CreditCardType()
                    {
                        cardCode       = string.Empty,
                        cardNumber     = creditCard.CardNumber,
                        expirationDate = creditCard.ExpDate
                    };

                    var customerUpdate = new CustomerPaymentProfileExType()
                    {
                        billTo = paymentProfileResponse.paymentProfile.billTo,
                        customerPaymentProfileId = paymentProfileResponse.paymentProfile.customerPaymentProfileId,
                        payment = new PaymentType()
                        {
                            Item = creditCardType
                        }
                    };


                    var updateResponse = client.UpdateCustomerPaymentProfile(merchant, customer.AuthorizeProfileId, null, ValidationModeEnum.none);
                    if (updateResponse.resultCode == MessageTypeEnum.Ok)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
Example #4
0
        public static bool CreateCustomerProfileTransactionRefund(SiteDT site, InvoiceDT invoice, TransactionDT transaction, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message)
        {
            //This datetime is when system change.
            int deployYear  = CastleClub.BusinessLogic.Data.GlobalParameters.DeployYear;
            int deployMonth = CastleClub.BusinessLogic.Data.GlobalParameters.DeployMonth;
            int deployDay   = CastleClub.BusinessLogic.Data.GlobalParameters.DeployDay;

            if (invoice.BilledDate >= new DateTime(deployYear, deployMonth, deployDay))
            {
                MerchantAuthenticationType merchantAT = new MerchantAuthenticationType();
                merchantAT.name           = site.AuthorizeLoginId;
                merchantAT.transactionKey = site.AuthorizeTransactionKey;

                ProfileTransactionType profileTT  = new ProfileTransactionType();
                ProfileTransRefundType profileTRT = new ProfileTransRefundType();

                OrderExType orderET = new OrderExType();
                orderET.invoiceNumber = invoice.Id.ToString();

                profileTRT.amount                            = invoice.Amount;
                profileTRT.transId                           = transaction.AuthorizeTransactionId.ToString();
                profileTRT.customerProfileId                 = customer.AuthorizeProfileId;
                profileTRT.customerProfileIdSpecified        = true;
                profileTRT.customerPaymentProfileId          = creditCard.AuthorizePaymentProfileId;
                profileTRT.customerPaymentProfileIdSpecified = true;
                profileTRT.order = orderET;


                profileTT.Item = profileTRT;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                ServiceSoapClient client = new ServiceSoapClient();
                CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty);

                if (resp.directResponse != null)
                {
                    PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse);
                    transactionId = paymentGatewayResponse.TransactionId;
                    message       = paymentGatewayResponse.ResponseReasonText;
                }
                else
                {
                    transactionId = 0;
                    if (resp.messages.Length > 0)
                    {
                        message = resp.messages[0].text;
                    }
                    else
                    {
                        message = "";
                    }
                }

                return(resp.resultCode == MessageTypeEnum.Ok);
            }
            else
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                using (ServiceSoapClient client = new ServiceSoapClient())
                {
                    MerchantAuthenticationType merchant = new MerchantAuthenticationType()
                    {
                        name           = site.AuthorizeLoginId,
                        transactionKey = site.AuthorizeTransactionKey
                    };

                    ProfileTransactionType profileTT  = new ProfileTransactionType();
                    ProfileTransRefundType profileTRT = new ProfileTransRefundType();

                    profileTRT.amount  = invoice.Amount;
                    profileTRT.transId = transaction.AuthorizeTransactionId.ToString();
                    profileTRT.creditCardNumberMasked = "XXXX" + creditCard.LastFourDigit;

                    profileTT.Item = profileTRT;

                    var resp = client.CreateCustomerProfileTransaction(merchant, profileTT, string.Empty);
                    if (resp.resultCode == MessageTypeEnum.Ok)
                    {
                        PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse);
                        transactionId = paymentGatewayResponse.TransactionId;
                        message       = paymentGatewayResponse.ResponseReasonText;
                    }
                    else
                    {
                        transactionId = 0;
                        message       = string.Empty;
                        message       = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(a => a.text).Aggregate((a, b) => a + " - " + b) : string.Empty;
                    }

                    return(resp.resultCode == MessageTypeEnum.Ok);
                }
            }
        }
Example #5
0
        public static bool CreateCustomerProfile(SiteDT site, CustomerDT customer, CreditCardDT cc, out long customerProfileId, out long customerPaymentProfileId)
        {
            // if (1 == 0) {
            MerchantAuthenticationType merchantAT = new MerchantAuthenticationType();

            merchantAT.name           = site.AuthorizeLoginId;
            merchantAT.transactionKey = site.AuthorizeTransactionKey;

            CustomerProfileType customerPT = new CustomerProfileType();

            customerPT.merchantCustomerId = customer.Id.ToString();
            customerPT.email           = customer.Email;
            customerPT.paymentProfiles = new CustomerPaymentProfileType[1];

            CustomerPaymentProfileType customerPPT = new CustomerPaymentProfileType();

            customerPPT.customerType          = CustomerTypeEnum.individual;
            customerPPT.customerTypeSpecified = true;
            customerPPT.billTo = new CustomerAddressType()
            {
                firstName = customer.FirstName,
                lastName  = customer.LastName,
                address   = customer.Address,
                city      = customer.City,
                country   = "USA",
                state     = customer.StateId,
                zip       = customer.ZipCode
            };

            CreditCardType ccT = new CreditCardType();

            ccT.cardNumber     = cc.CardNumber;
            ccT.expirationDate = cc.ExpDate;
            ccT.cardCode       = cc.CVV;

            PaymentType payment = new PaymentType();

            payment.Item = ccT;

            customerPPT.payment                  = payment;
            customerPT.paymentProfiles[0]        = customerPPT;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServiceSoapClient client = new ServiceSoapClient();
            CreateCustomerProfileResponseType resp = client.CreateCustomerProfile(merchantAT, customerPT, ValidationModeEnum.testMode);

            customerProfileId        = resp.customerProfileId;
            customerPaymentProfileId = resp.customerPaymentProfileIdList.Length == 1 ? resp.customerPaymentProfileIdList[0] : 0;
            if (resp.resultCode != MessageTypeEnum.Ok)
            {
                string errorValidate = resp.validationDirectResponseList != null && resp.validationDirectResponseList.Count() > 0 ? resp.validationDirectResponseList.ToList().Aggregate((a, b) => a + " || " + b) : string.Empty;
                string error         = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.ToList().Select(a => a.text).Aggregate((a, b) => a + " || " + b) : string.Empty;
                LoggingUtilities.Logger.LogEntry("Resp Error code:" + resp.resultCode.ToString() + ". Errors: " + error + "Error V: " + errorValidate);
            }

            return(resp.resultCode == MessageTypeEnum.Ok);


            /* }
             *
             * else
             * {
             *  customerProfileId = 1;
             *   customerPaymentProfileId = 1;
             *   return true;
             * }*/
        }
Example #6
0
        public static void ProcessInvoices()
        {
            using (CastleClubEntities entities = new CastleClubEntities())
            {
                if (CastleClub.BusinessLogic.Data.GlobalParameters.Procces)
                {
                    int            maxFailCount = CastleClub.BusinessLogic.Data.GlobalParameters.FailCount;
                    int            yearMin      = CastleClub.BusinessLogic.Data.GlobalParameters.YearMin;
                    DateTime       min          = new DateTime(yearMin, 1, 1);
                    List <Invoice> list         = entities.Invoices.Where(i => (i.Customer.CancelledDate == null) && (i.CreatedAt >= min) && (!i.FailCount.HasValue || i.FailCount.Value < maxFailCount) && (i.StatusId == InvoiceStatus.NEW.ToString() || i.StatusId == InvoiceStatus.BILLEDFAIL.ToString())).ToList();
                    foreach (Invoice invoice in list)
                    {
                        try
                        {
                            SiteDT       siteDT       = invoice.Customer.Site.GetDT();
                            InvoiceDT    invoiceDT    = invoice.GetDT();
                            CustomerDT   customerDT   = invoice.Customer.GetDT(false);
                            CreditCardDT creditCardDT = invoice.Customer.CreditCards.FirstOrDefault().GetDT();

                            Transaction transaction = new Transaction();
                            transaction.InvoiceId              = invoiceDT.Id;
                            transaction.CreditCardId           = creditCardDT.Id;
                            transaction.AuthorizeTransactionId = 0;
                            transaction.TypeId     = TransactionType.SALE.ToString();
                            transaction.StatusId   = TransactionStatus.FAILED.ToString();
                            transaction.SubmitDate = DateTime.Now;

                            entities.Transactions.Add(transaction);
                            entities.SaveChanges();

                            long   transactionId = 0;
                            string message       = "";
                            string code          = string.Empty;

                            bool succesfull = CIM.CreateCustomerProfileTransactionAuthCapture(siteDT, invoiceDT, customerDT, creditCardDT, out transactionId, out message, out code);

                            if (succesfull)
                            {
                                invoice.Status     = InvoiceStatus.BILLED;
                                invoice.BilledDate = DateTime.Now;

                                transaction.Status = TransactionStatus.SUCCESFULL;
                                transaction.AuthorizeTransactionId = transactionId;

                                invoice.Customer.Referrer.BilledTotal++;
                                invoice.Customer.Referrer.RevenueAmount += invoice.Amount;

                                entities.SaveChanges();
                            }
                            else
                            {
                                invoice.FailCount   = invoice.FailCount.HasValue ? invoice.FailCount.Value + 1 : 1;
                                transaction.Message = message + code;
                                invoice.Status      = InvoiceStatus.BILLEDFAIL;
                                entities.SaveChanges();

                                if (invoice.FailCount >= maxFailCount && entities.NotificationProcess.Any())
                                {
                                    //To do some.
                                    //Send email for notification.

                                    string smtpAddress = CastleClub.BusinessLogic.Data.GlobalParameters.Smtp;
                                    int    portNumber  = 587;
                                    bool   enableSSL   = true;

                                    string emailFrom = CastleClub.BusinessLogic.Data.GlobalParameters.EmailAccount;
                                    string password  = CastleClub.BusinessLogic.Data.GlobalParameters.EmailPassword;
                                    string subject   = "Error an ocurred with invoice: " + invoiceDT.Id;
                                    string body      = "Error ocurred at " + maxFailCount + " time with invoice: " + invoiceDT.Id + ", customerId: " + invoice.CustomerId + ", and with credit card: " + invoice.Customer.CreditCards.FirstOrDefault().Id;

                                    using (System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage())
                                    {
                                        mail.From = new MailAddress(emailFrom);
                                        foreach (var emailTo in entities.NotificationProcess)
                                        {
                                            mail.To.Add(emailTo.To);
                                        }
                                        mail.Subject    = subject;
                                        mail.Body       = body;
                                        mail.IsBodyHtml = false;

                                        using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                                        {
                                            smtp.Credentials = new NetworkCredential(emailFrom, password);
                                            smtp.EnableSsl   = enableSSL;
                                            smtp.Send(mail);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Utils.EventViewer.Writte("CastleClubAdmin", "PaymentTask - Process", ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
                        }
                    }
                }
            }
        }