Exemplo n.º 1
0
        public override bool initiatePaymentConsumer(CreditCard creditCard)
        {
            LogRequest("initiatePaymentConsumer", "start");

            Errors.Clear();

            var BCResponse = new BankcardTransactionResponse();

            if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
            {
                BCResponse = GetCreditCardTokenID(PaymentData["Number"].ToString(),
                                                  ((DateTime) PaymentData["ExpDate"]).ToString("MMyy"),
                                                  (int) ((PayCrediCard) PaymentData).Type);
                PaymentData["TokenID"] = BCResponse.PaymentAccountDataToken;

                if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
                {
                    Errors.Add(1, "Unable to generate a valid payment account data token");
                    return false;
                }
            }
            else
            {
                LogRequest("initiatePaymentConsumer", "Token=" + (string) PaymentData["TokenID"]);
            }

            var PayingInvoiceID = (int?) PaymentData["InvoiceID"];
            var userHostAddress = (string) PaymentData["UserHostAddress"];
            var sessionID = (string) PaymentData["SessionID"];
            var Amount = (decimal) PaymentData["Amount"];
            var AddressLine1 = (string) PaymentData["AddressLine1"];
            var AddressLine2 = (string) PaymentData["AddressLine2"];
            var PostCode = (string) PaymentData["PostalCode"];
            var Town = (string) PaymentData["Town"];
            var Country = (string) PaymentData["Country"];

            var DB = new DataClassesDataContext();
            /*var billingAddress = new Address();

            billingAddress.add_AddressLine1 = AddressLine1;
            billingAddress.add_AddressLine2 = AddressLine2;
            billingAddress.add_DateModified = DateTime.Now;
            billingAddress.add_IsDeleted = false;
            billingAddress.add_PostalCode = PostCode;
            billingAddress.add_Town = Town;
            billingAddress.add_Country = Country;
            billingAddress.Add(DB);*/

            creditCard.cca_IsDeleted = false;
            creditCard.cca_IsActive = true;
            creditCard.cca_Ref = (string) PaymentData["TransactionID"];
            creditCard.cca_IPCTokenID = (string) PaymentData["TokenID"];
            creditCard.cca_Is3DS = false;

            var payment = new Payment();
            payment.pay_IsPaidByService = false;
            payment.pay_TypeID = (int) PaymentTypeEnum.CreditCard;
            payment.pay_StatusID = (int) PaymentStatusEnum.Initiated;
            payment.pay_InvoiceID = PayingInvoiceID;
            payment.pay_UserID = null;
            payment.pay_DateModified = DateTime.Now;
            payment.pay_DatePaid = DateTime.Now;
            payment.pay_IP = userHostAddress;
            payment.pay_Amount = Amount;
            payment.pay_UserID = null;
            payment.pay_UsedPP = Convert.ToInt32(PaymentProcessorEnum.IPCommerce);
            payment.pay_InternalRefID = (string) PaymentData["TransactionID"];

            try
            {
                payment.Add(DB, userHostAddress, sessionID);
            }
            catch (Exception ex)
            {
                LogRequest("initiatePaymentConsumer", "Error Mesage : " + ex.Message);
                LogRequest("initiatePaymentConsumer", "Error Stacktrace : " + ex.StackTrace);
            }

            PaymentData["PaymentID"] = payment.pay_ID;
            PaymentData["TransactionID"] = "PID_" + PaymentData["PaymentID"].ToString().PadLeft(7, '0');

            return Errors.Count == 0;
        }
Exemplo n.º 2
0
        public override bool initiatePaymentDirectDebit()
        {
            LogRequest("initiatePaymentDirectDebit", "start");

            DataClassesDataContext DB = (DataClassesDataContext) PaymentData["DB"] ?? new DataClassesDataContext();

            DirectDebit currentDirectDebit = DirectDebit.GetByID(DB, (int) PaymentData["DirectDebitID"]);
            //Invoice currentInvoice = currentDirectDebit.Invoice; // Invoice.GetByID(DB, (int)PaymentData["InvoiceID"]);
            Invoice currentInvoice = currentDirectDebit.Invoice ?? Invoice.GetByID(DB, (int) PaymentData["InvoiceID"]);
                // Invoice.GetByID(DB, (int)PaymentData["InvoiceID"]);
            CreditCard currentCreditCard = currentDirectDebit.CreditCard;
                // CreditCard.GetById(DB, currentDirectDebit.ddd_CreditCardID);

            if (!currentDirectDebit.ddd_IsActive ||
                (currentDirectDebit.ddd_IsNumberOfPayments &&
                 currentDirectDebit.ddd_PaymentsCommited >= currentDirectDebit.ddd_NumberOfPayments.Value) ||
                (currentInvoice.inv_StatusID != (int) InvoiceStatusEnum.Outstanding &&
                 currentInvoice.inv_StatusID != (int) InvoiceStatusEnum.PartPaid) ||
                currentInvoice.inv_IsRemovedByUser ||
                currentCreditCard.cca_IsDeleted ||
                !currentCreditCard.cca_IsActive
                )
            {
                return false;
            }
            decimal amountToPay = currentInvoice.inv_DueAmount - (currentInvoice.inv_PaidAmount ?? 0);
            if (currentDirectDebit.ddd_IsSingle &&
                Convert.ToDecimal(currentDirectDebit.ddd_ScheduledPaymentAmount.Value) < amountToPay)
            {
                amountToPay = Convert.ToDecimal(currentDirectDebit.ddd_ScheduledPaymentAmount.Value);
            }

            string email;
            if (currentCreditCard.cca_UserID == null)
            {
                //E SP case, so we take the email from the first payment
                email = currentCreditCard.Payments.Last().pay_Email;
            }
            else
            {
                //E take all notification emails for that user

                //:TODO Last() exception error
                //email = ConsumerEmail.ConsumerGetSendNotificationEmails(DB, currentCreditCard.cca_UserID.Value).Last().cem_Email;

                IList<string> emails = new List<string>();
                emails =
                    ConsumerEmail.ConsumerGetSendNotificationEmails(DB, currentCreditCard.cca_UserID.Value).Select(
                        ce => ce.cem_Email).ToList();
                email = emails[emails.Count - 1];
            }

            var currentPayment = new Payment
                                     {
                                         pay_IsPaidByService = true,
                                         pay_TypeID = (int) PaymentTypeEnum.CreditCard,
                                         pay_StatusID = (int) PaymentStatusEnum.Initiated,
                                         pay_InvoiceID = (int) PaymentData["InvoiceID"],
                                         pay_CreditCardID = currentDirectDebit.CreditCard.cca_ID,
                                         // (int) PaymentData["CreditCardID"],
                                         pay_UserID = currentDirectDebit.CreditCard.cca_UserID,
                                         // (int) PaymentData["UserID"],
                                         pay_DateModified = DateTime.Now,
                                         pay_DatePaid = DateTime.Now,
                                         pay_Amount = amountToPay,
                                         // (decimal) PaymentData["Amount"],
                                         pay_Email = email,
                                         //(string) PaymentData["Email"]?? "",
                                         pay_InternalRefID = (string) PaymentData["TransactionID"],
                                         pay_ExternalRefID = (string) PaymentData["TransactionID"]
                                     };

            currentPayment.Add(DB, "", "");

            PaymentData["PaymentID"] = currentPayment.pay_ID;
            PaymentData["PaycorpCID"] = currentPayment.Invoice.Merchant.mer_PaycorpCID;
            PaymentData["Amount"] = amountToPay;
            PaymentData["TransactionID"] = "DD_PID_" + PaymentData["PaymentID"].ToString().PadLeft(7, '0');
            PaymentData["TokenID"] = currentCreditCard.cca_IPCTokenID;
            PaymentData["ExpDate"] = currentCreditCard.cca_ExpirationDate;

            return true;
        }
Exemplo n.º 3
0
        public override bool initiatePayment()
        {
            LogRequest("initiatePayment", "start");
            Errors.Clear();

            var BCResponse = new BankcardTransactionResponse();

            if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
            {
                BCResponse = GetCreditCardTokenID(PaymentData["Number"].ToString(),
                                                  ((DateTime) PaymentData["ExpDate"]).ToString("MMyy"),
                                                  (int) ((PayCrediCard) PaymentData).Type);
                PaymentData["TokenID"] = BCResponse.PaymentAccountDataToken;

                if (string.IsNullOrEmpty((string) PaymentData["TokenID"]))
                {
                    Errors.Add(1, "Unable to generate a valid payment account data token");
                    return false;
                }
            }

            var PayingInvoiceID = (int) PaymentData["InvoiceID"];
            var userHostAddress = (string) PaymentData["UserHostAddress"];
            var sessionID = (string) PaymentData["SessionID"];
            var Amount = (decimal) PaymentData["Amount"];
            var AddressLine1 = (string) PaymentData["AddressLine1"];
            var AddressLine2 = (string) PaymentData["AddressLine2"];
            var PostCode = (string) PaymentData["PostalCode"];
            var Town = (string) PaymentData["Town"];
            var Country = (string) PaymentData["Country"];

            var DB = new DataClassesDataContext();
            var billingAddress = new Address();

            billingAddress.add_AddressLine1 = AddressLine1;
            billingAddress.add_AddressLine2 = AddressLine2;
            billingAddress.add_DateModified = DateTime.Now;
            billingAddress.add_IsDeleted = false;
            billingAddress.add_PostalCode = PostCode;
            billingAddress.add_Town = Town;
            billingAddress.add_Country = Country;
            billingAddress.Add(DB);

            var cc = new CreditCard();
            cc.cca_AddressID = billingAddress.add_ID;
            cc.cca_CardNumber = BCResponse.MaskedPAN;
            cc.cca_IsDeleted = false;
            cc.cca_IsActive = true;
            cc.cca_Ref = (string) PaymentData["TransactionID"];
            cc.cca_Is3DS = false;
            cc.cca_ExpirationDate = ((PayCrediCard) PaymentData).ExpirationDate;
            cc.cca_DateModified = DateTime.Now;
            cc.cca_NameOnCard = ((PayCrediCard) PaymentData).HolderName;
            cc.cca_IssueNumber = ((PayCrediCard) PaymentData).IssueNumber;
            cc.CVV = ((PayCrediCard) PaymentData).CVV;
            cc.cca_CardType = (short) ((PayCrediCard) PaymentData).Type;
            cc.cca_IPCTokenID = (string) PaymentData["TokenID"];
            cc.Add(DB);

            var payment = new Payment();
            payment.pay_CreditCardID = cc.cca_ID;
            payment.pay_IsPaidByService = false;
            payment.pay_TypeID = (int) PaymentTypeEnum.CreditCard;
            payment.pay_StatusID = (int) PaymentStatusEnum.Initiated;
            payment.pay_InvoiceID = PayingInvoiceID;
            payment.pay_UserID = null; //logged user
            payment.pay_DateModified = DateTime.Now;
            payment.pay_DatePaid = DateTime.Now;
            payment.pay_IP = userHostAddress;
            payment.pay_Amount = Amount;
            payment.pay_UserID = null;
            payment.pay_Email = PaymentData["Email"].ToString();
            ;
            payment.pay_UsedPP = Convert.ToInt32(PaymentProcessorEnum.IPCommerce);
            payment.pay_InternalRefID = (string) PaymentData["TransactionID"];
            payment.pay_ExternalRefID = BCResponse.TransactionId;
            payment.CreditCard = cc;
            payment.Add(DB, userHostAddress, sessionID);

            PaymentData["PaymentID"] = payment.pay_ID;
            PaymentData["TransactionID"] = "PID_" + PaymentData["PaymentID"].ToString().PadLeft(7, '0');

            return Errors.Count == 0;
        }