Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        public override bool completePaymentConsumer(CreditCard creditCard)
        {
            LogRequest("completePaymentConsumer", "start");

            //var DB = new DataClassesDataContext();

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

            if (PrepareToTransact())
            {
                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 BCTransaction = new BankcardTransaction();
                var BCResponse = new BankcardTransactionResponse();

                BCTransaction = SetBankCardTxnData(null, null, 0, Amount, (string) PaymentData["TokenID"],
                                                   (string) PaymentData["TransactionID"]);
                try
                {
                    BCResponse =
                        (BankcardTransactionResponse)
                        CWSTPC.AuthorizeAndCapture(strSessionToken, BCTransaction, strApplicationProfileID, strProfileID,
                                                   strServiceID);
                }
                catch (Exception ex)
                {
                    Errors.Add(2, ex.Message);
                    LogRequest("completePayment", ex.Message);
                    return false;
                }
                //LogRequest("completePaymentConsumer", "status={0} statusCode={1} statusMessage={2} amount={3}", BCResponse.Status, BCResponse.StatusCode, BCResponse.StatusMessage, BCResponse.Amount);
                LogRequest("completePaymentConsumer", "status=" + BCResponse.Status +
                                                      " statusCode=" + BCResponse.StatusCode +
                                                      " statusMessage=" + BCResponse.StatusMessage + " amount=" +
                                                      BCResponse.Amount);
                //ProcessResponse(new ResponseDetails(BCTransaction.TransactionData.Amount, BCResponse,"AuthorizeAndCapture", true));

                if (BCResponse.Status == Status.Failure)
                {
                    Errors.Add(2, BCResponse.StatusCode + " : " + BCResponse.StatusMessage);
                    return false;
                }

                Payment payment = Payment.GetByID(DB, (int) PaymentData["PaymentID"]);
                payment.pay_UsedPP = Convert.ToInt32(PaymentProcessorEnum.IPCommerce);
                payment.pay_ResultCode = BCResponse.StatusCode;
                payment.pay_ResultMessage = BCResponse.StatusMessage;
                payment.pay_InternalRefID = (string) PaymentData["TransactionID"];
                payment.pay_ExternalRefID = BCResponse.TransactionId;
                payment.pay_DateModified = DateTime.Now;
                payment.Update(DB, userHostAddress, sessionID);
            }
            else
            {
                LogRequest("completePaymentConsumer", "failed to complete payment");
                Errors.Add(2, "Failed to PrepareToTransact");
                return false;
            }

            creditCard.cca_IsDeleted = false;
            creditCard.cca_IsActive = true;

            if (creditCard.cca_ID > 0)
            {
                creditCard.Update(DB);
            }
            else
            {
                creditCard.Add(DB);
            }

            DB.SubmitChanges();

            return true;
        }