コード例 #1
0
        public void UpdateBillingInfoWithToken()
        {
            var account = CreateNewAccount();
            var billingInfo = new BillingInfo(account)
            {
                TokenId = "abc123"
            };
            var threw = false;

            try
            {
                billingInfo.Update();
            }
            catch (NotFoundException exception)
            {
                threw = true;
                exception.Errors[0].Symbol.Should().Be("token_invalid");
            }

            threw.Should().Be(true);
        }
コード例 #2
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
 /// <summary>
 /// Description  : To get CABFeeScheduleDetails Report By CABFeeScheduleID.
 /// Created By   : Shiva
 /// Created Date : 9 Oct 2014
 /// Modified By  :
 /// Modified Date:
 /// </summary>
 internal static BillingInfo GetCABFeeScheduleDetailsReportByCABFeeScheduleID(int CABFeeScheduleID)
 {
     System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
     System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
     log.Debug("Start: " + methodBase.Name);
     var CABFeeScheduleDetailsData = new BillingInfo();
     try
     {
         SqlParameter[] sqlParams = new SqlParameter[1];
         sqlParams[0] = new SqlParameter("@CABFeeScheduleID", CABFeeScheduleID);
         var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SPGetCABFeeScheduleDetailsReportByCABFeeScheduleID", sqlParams);
         var safe = new SafeDataReader(reader);
         while (reader.Read())
         {
             var GetCABFeeScheduleDetails = new CABFeeScheduleDetails();
             CABFeeScheduleDetails.FetchCABFeeScheduleDetailsReportByCABFeeScheduleID(GetCABFeeScheduleDetails, safe);
             CABFeeScheduleDetailsData.CABFeeScheduleDetailsList.Add(GetCABFeeScheduleDetails);
         }
         return CABFeeScheduleDetailsData;
     }
     catch (Exception ex)
     {
         log.Error("Error: " + ex);
         return CABFeeScheduleDetailsData;
     }
     finally
     {
         log.Debug("End: " + methodBase.Name);
     }
 }
コード例 #3
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : Get the MSchedule Information
        /// Created By   : Shiva
        /// Created Date : 30 June 2014
        /// Modified By  :
        /// Modified Date:
        /// </summary>
        public static BillingInfo GetMSchedule()
        {
            var GetMSchedule = new BillingInfo();

            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SpGetMSchedule");
                var safe = new SafeDataReader(reader);
                while (reader.Read())
                {
                    var MSchedule = new Billing();
                    MSchedule.FetchBillingFrequencyOrMonthOrFeeInfo(MSchedule, safe);
                    GetMSchedule.BillingList.Add(MSchedule);
                }
                return GetMSchedule;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return GetMSchedule;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #4
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
 /// <summary>
 /// Description  : To get All Billing details by Company AND Fee.
 /// Created By   : Shiva
 /// Created Date : 7 Oct 2014
 /// Modified By  :
 /// Modified Date:
 /// </summary>
 internal static BillingInfo GetAllBillingDetailsByCompanyAndFee(string CompanyID, string CompanySource, string FeeCode, string BillFromDate, string BillToDate, int StartPage, int ResultPerPage, int BillType)
 {
     System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
     System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
     log.Debug("Start: " + methodBase.Name);
     var CABMasterData = new BillingInfo();
     try
     {
         SqlParameter[] sqlParams = new SqlParameter[8];
         sqlParams[0] = new SqlParameter("@ClientCode", CompanyID);
         sqlParams[1] = new SqlParameter("@Source", CompanySource);
         sqlParams[2] = new SqlParameter("@FeeCode", FeeCode);
         sqlParams[3] = new SqlParameter("@BillFromDate", HelperClasses.ConvertDateFormat(BillFromDate));
         sqlParams[4] = new SqlParameter("@BillToDate", HelperClasses.ConvertDateFormat(BillToDate));
         sqlParams[5] = new SqlParameter("@BillType", BillType);
         sqlParams[6] = new SqlParameter("@StartPage", StartPage);
         sqlParams[7] = new SqlParameter("@ResultPerPage", ResultPerPage);
         var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SPGetCABMasterReport", sqlParams);
         var safe = new SafeDataReader(reader);
         while (reader.Read())
         {
             var CabMaster = new CABMaster();
             CABMaster.FetchCABMasterReport(CabMaster, safe);
             CABMasterData.CABMasterList.Add(CabMaster);
             CABMasterData.BillingCount = Convert.ToInt32(reader["BillingCount"]);
         }
         return CABMasterData;
     }
     catch (Exception ex)
     {
         log.Error("Error: " + ex);
         return CABMasterData;
     }
     finally
     {
         log.Debug("End: " + methodBase.Name);
     }
 }
コード例 #5
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : Get the ClientFeeSetting and ClientFeeMapping Information by ClientCode
        /// Created By   : Shiva
        /// Created Date : 2nd July 2014
        /// Modified By  : Shiva
        /// Modified Date: 4 July 2014
        /// </summary>
        public static BillingInfo GetFeeSettingAndMappingsByClientCode(int ClientCode, string SourceID)
        {
            var GetFeeSettingAndMappingInfo = new BillingInfo();

            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[2];
                sqlParams[0] = new SqlParameter("@ClientCode", ClientCode);
                sqlParams[1] = new SqlParameter("@SourceID", SourceID);

                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SPGetFeeSettingAndMappingsByClientCode", sqlParams);
                var safe = new SafeDataReader(reader);
                while (reader.Read())
                {
                    var feeSetting = new FeeSetting();
                    feeSetting.FetchClientFeeSettingInfo(feeSetting, safe);
                    GetFeeSettingAndMappingInfo.ClientFeeSettingList.Add(feeSetting);
                }
                reader.NextResult();
                while (reader.Read())
                {
                    var feeMapping = new FeeMapping();
                    feeMapping.FetchClientFeeMappingInfo(feeMapping, safe);
                    GetFeeSettingAndMappingInfo.ClientFeeMappingList.Add(feeMapping);
                }
                return GetFeeSettingAndMappingInfo;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return GetFeeSettingAndMappingInfo;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #6
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : Get the MFEE in billing settings page
        /// Created By   : Anji
        /// Created Date : 25 May 2015
        /// Modified By  :
        /// Modified Date:
        /// </summary>
        public static BillingInfo GetMFEEforClient(int ClientCode)
        {
            var GetMFee = new BillingInfo();

            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[1];
                sqlParams[0] = new SqlParameter("@ClientCode", ClientCode);
                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SpGetMFeeForClient", sqlParams);
                var safe = new SafeDataReader(reader);
                while (reader.Read())
                {
                    var MFee = new Billing();
                    MFee.FetchBillingFeeInfoClient(MFee, safe);
                    GetMFee.BillingList.Add(MFee);
                }
                return GetMFee;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return GetMFee;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #7
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : Gap analysis by FeeCode and ClientCode.
        /// Created By   : Shiva
        /// Created Date : 15 July 2014
        /// Modified By  :
        /// Modified Date:
        /// </summary>
        public static BillingInfo GetClientScheduleGapByFeeAndClientCode(string FeeCode, int ClientCode, string SourceID)
        {
            var GetGapInfo = new BillingInfo();

            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[3];
                sqlParams[0] = new SqlParameter("@ClientCode", ClientCode);
                sqlParams[1] = new SqlParameter("@SourceID", @SourceID);
                sqlParams[2] = new SqlParameter("@FeeCode", FeeCode);
                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SpGetClientScheduleMapGapAnalysisByCodes_Club", sqlParams);
                var safe = new SafeDataReader(reader);
                while (reader.Read())
                {
                    var GapInfo = new FeeSchedule();
                    GapInfo.FetchClientScheduleGapInfo(GapInfo, safe);
                    GetGapInfo.ClientFeeScheduleList.Add(GapInfo);
                }
                return GetGapInfo;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return GetGapInfo;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #8
0
        public int ApiCardDetails(string json)
        {
            Session session = new Session(json);

            session.CaptureOn = getCaptureDate(LkpDetails["Card"], session.DateStamp, session.CancelationDate);
            int Response = 0;

            if (TempData["TutorModel"] != null)
            {
                UserCache   userCache = JsonConvert.DeserializeObject <UserCache>(TempData["TutorModel"].ToString());
                string      Learner   = String.Concat(userCache.FirstName, userCache.LastName);
                BillingInfo bl        = PaymentDB.GetBillingInfo(userCache.UserId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                //Build API Request
                object jsonParameters = new
                {
                    source = new
                    {
                        type = "id",
                        id   = bl.CardId
                    },
                    amount     = session.Amount * 100,
                    reference  = "Session-" + session.Id,
                    currency   = session.Currency,
                    capture_on = session.CaptureOn
                };
                Console.WriteLine(jsonParameters);
                var     requestUrl     = "https://api.sandbox.checkout.com/payments/";
                string  responseString = ApiRequest(jsonParameters, requestUrl);
                dynamic jObj           = (JObject)JsonConvert.DeserializeObject(responseString);
                //if the API request success add operations to DB
                if (jObj != null)
                {
                    //Operation 1 : Record Learner Payment
                    Operation Op = new Operation
                    {
                        UID             = userCache.UserId,
                        RelationId      = session.Id,
                        RelationEntity  = "Event",
                        Amount          = session.Amount,
                        Currency        = session.Currency,
                        RespDate        = (DateTime)jObj.processed_on,
                        RespDetails     = responseString.Replace("\"", string.Empty),
                        CaptureOn       = getCaptureDate(LkpDetails["Card"], session.DateStamp, session.CancelationDate),
                        Auto            = 0,
                        Description     = session.Title,
                        ServiceId       = session.Service == "F2F" ? LkpDetails["F2F"] : LkpDetails["Online"],
                        RespId          = jObj.id,
                        OprTypeId       = LkpDetails["Payment"],
                        PaymentMethodId = LkpDetails["Card"],
                        SerialId        = Serials["PB"],
                        ObjEntityId     = 1,//Nabih get user Entity id
                        CancelationDate = session.CancelationDate,
                        TutorId         = session.TutorId,
                        TutorName       = session.TutorName
                    };
                    if (Op.CaptureOn != session.DateStamp)
                    {
                        Op.Captured = 1;
                    }
                    Response = PaymentDB.SubmitOperation(Op, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));

                    if (Response != 0)
                    {
                        Op.LinkedOprId = Response;
                        SendNotification(DateTime.Now, Learner, "Card Pymt", session.Amount, Op.Captured);
                        //Operation 2 : Add tutor Revenue

                        decimal revenue = Convert.ToDecimal(Perc["TutorPercentage"]);
                        AddTutorRevenue(Op, session.TutorId, session.TutorName, revenue);
                        //Operation 3 : Subtract Checkout Fees
                        decimal fee = Convert.ToDecimal(Perc["CheckoutFees"]);
                        decimal Per = Convert.ToDecimal(Perc["CheckoutPercentage"]);
                        SubtractFees(Op, "Checkout Fees", fee, Per, Serials["FC"]);
                    }
                    TempData.Keep("TutorModel");
                    return(Response);
                }
            }
            return(Response);
        }
コード例 #9
0
 public virtual int Fill(BillingInfo.viewbillingDataTable dataTable, global::System.Nullable<int> cust_id, string manyer) {
     this.Adapter.SelectCommand = this.CommandCollection[0];
     if ((cust_id.HasValue == true)) {
         this.Adapter.SelectCommand.Parameters[0].Value = ((int)(cust_id.Value));
     }
     else {
         this.Adapter.SelectCommand.Parameters[0].Value = global::System.DBNull.Value;
     }
     if ((manyer == null)) {
         throw new global::System.ArgumentNullException("manyer");
     }
     else {
         this.Adapter.SelectCommand.Parameters[1].Value = ((string)(manyer));
     }
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
コード例 #10
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : To get CABMaster Invoice Preview By MasterID.
        /// Created By   : Shiva
        /// Created Date : 29 Oct 2014
        /// Modified By  :
        /// Modified Date:
        /// </summary>
        internal static BillingInfo GetCABMasterInvoicePreviewByMasterID(int CABMasterID)
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            var CABMasterInvoicePreview = new BillingInfo();
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[1];
                sqlParams[0] = new SqlParameter("@CabMasterID", CABMasterID);
                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SPCABMasterInvoicePreview", sqlParams);
                var safe = new SafeDataReader(reader);
                while (reader.Read())
                {
                    var InvoicePrevie = new CABMasterInvoicePreview();
                    InvoicePrevie.FetchCABMasterInvoicePreviewAddresses(InvoicePrevie, safe);
                    CABMasterInvoicePreview.CABMasterInvoicePreviewList1.Add(InvoicePrevie);
                }
                reader.NextResult();
                while (reader.Read())
                {
                    var InvoicePrevie = new CABMasterInvoicePreview();
                    InvoicePrevie.FetchCABMasterInvoicePreview(InvoicePrevie, safe);
                    CABMasterInvoicePreview.CABMasterInvoicePreviewList2.Add(InvoicePrevie);
                }
                //reader.NextResult();
                //while (reader.Read())
                //{
                //    var InvoicePrevie = new CABMasterInvoicePreview();
                //    InvoicePrevie.FetchCABMasterInvoicePreview(InvoicePrevie, safe);
                //    CABMasterInvoicePreview.CABMasterInvoicePreviewList3.Add(InvoicePrevie);
                //}

                return CABMasterInvoicePreview;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return CABMasterInvoicePreview;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #11
0
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     BillingInfo ds = new BillingInfo();
     global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "viewbillingDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
コード例 #12
0
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     BillingInfo ds = new BillingInfo();
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
コード例 #13
0
 public BillingInfo NewBillingInfo(Account account)
 {
     var billingInfo = new BillingInfo(account)
     {
         FirstName = account.FirstName,
         LastName = account.LastName,
         Address1 = "123 Test St",
         City = "San Francisco",
         State = "CA",
         Country = "US",
         PostalCode = "94105",
         ExpirationMonth = DateTime.Now.Month,
         ExpirationYear = DateTime.Now.Year + 1,
         CreditCardNumber = TestCreditCardNumbers.Visa1,
         VerificationValue = "123"
     };
     return billingInfo;
 }
コード例 #14
0
ファイル: RegistrationInfo.cs プロジェクト: mausch/CsFormlets
 public RegistrationInfo(User user, BillingInfo billing)
 {
     this.user = user;
     this.billing = billing;
 }
コード例 #15
0
ファイル: Billing.cs プロジェクト: reddyjannavarapu/css3
        /// <summary>
        /// Description  : To get Company from Billing third party details.
        /// Created By   : Shiva
        /// Created Date : 27 Aug 2014
        /// Modified By  :
        /// Modified Date:
        /// </summary>
        public static BillingInfo GetCompanyFromBillingThirdParty()
        {
            var billingDataInfo = new BillingInfo();

            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SPGetCompanyFromBillingThirdParty");
                var safe = new SafeDataReader(reader);

                while (reader.Read())
                {
                    var billing = new FeeSetting();
                    billing.FetCompanyFromBillingData(billing, safe);
                    billingDataInfo.ClientFeeSettingList.Add(billing);
                }
                return billingDataInfo;
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
                return billingDataInfo;
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }
コード例 #16
0
 public Checkout()
 {
     BillingInfo = new BillingInfo();
     PaymentInfo = new PaymentInfo();
 }
コード例 #17
0
        public async Task <BillingInfo> GetBillingAsync(ISubscriber subscriber)
        {
            var billingInfo         = new BillingInfo();
            var customerService     = new StripeCustomerService();
            var subscriptionService = new StripeSubscriptionService();
            var chargeService       = new StripeChargeService();
            var invoiceService      = new StripeInvoiceService();

            if (!string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
            {
                var customer = await customerService.GetAsync(subscriber.GatewayCustomerId);

                if (customer != null)
                {
                    if (!string.IsNullOrWhiteSpace(customer.DefaultSourceId) && customer.Sources?.Data != null)
                    {
                        if (customer.DefaultSourceId.StartsWith("card_"))
                        {
                            var source = customer.Sources.Data.FirstOrDefault(s => s.Card?.Id == customer.DefaultSourceId);
                            if (source != null)
                            {
                                billingInfo.PaymentSource = new BillingInfo.BillingSource(source);
                            }
                        }
                        else if (customer.DefaultSourceId.StartsWith("ba_"))
                        {
                            var source = customer.Sources.Data
                                         .FirstOrDefault(s => s.BankAccount?.Id == customer.DefaultSourceId);
                            if (source != null)
                            {
                                billingInfo.PaymentSource = new BillingInfo.BillingSource(source);
                            }
                        }
                    }

                    var charges = await chargeService.ListAsync(new StripeChargeListOptions
                    {
                        CustomerId = customer.Id,
                        Limit      = 20
                    });

                    billingInfo.Charges = charges?.Data?.OrderByDescending(c => c.Created)
                                          .Select(c => new BillingInfo.BillingCharge(c));
                }
            }

            if (!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))
            {
                var sub = await subscriptionService.GetAsync(subscriber.GatewaySubscriptionId);

                if (sub != null)
                {
                    billingInfo.Subscription = new BillingInfo.BillingSubscription(sub);
                }

                if (!sub.CanceledAt.HasValue && !string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
                {
                    try
                    {
                        var upcomingInvoice = await invoiceService.UpcomingAsync(subscriber.GatewayCustomerId);

                        if (upcomingInvoice != null)
                        {
                            billingInfo.UpcomingInvoice = new BillingInfo.BillingInvoice(upcomingInvoice);
                        }
                    }
                    catch (StripeException) { }
                }
            }

            return(billingInfo);
        }