コード例 #1
0
 public static PaywallReceipt GetReceiptForInvoice(Guid invoiceId)
 {
     PaywallReceipt re = new PaywallReceipt();
     try
     {
         PaymentGateway pg = new PaymentGateway();
         var invoice = pg.GetDisplayInvoice(invoiceId);
         re.InvoiceStatus = invoice.InvoiceStatus;
         re.InvoiceId = invoice.InvoiceId;
         re.NameOfPayment = invoice.Paywall.Name;
         re.DescriptionOfPayment = invoice.Paywall.Description;
         re.EmailForReceipt = invoice.InvoiceBilling.Email;
         re.PaywallId = invoice.Paywall.PaywallId;
         re.Expires = invoice.Paywall.ValidUntil;
         re.GeneratedPassword = invoice.Paywall.PaywallPassword;
         re.AmountPaid = invoice.Paywall.Price;
         re.AmountRefunded = invoice.Refunds.Sum(x => x.RefundAmount);
         re.MerchantId= invoice.Merchant.MerchantId;
         re.Location = invoice.Paywall.PaywallLocation;
                     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return re;
 }
コード例 #2
0
 public static DuesReceipt GetReceiptForDues(Guid invoiceId)
 {
     DuesReceipt re = new DuesReceipt();
     try
     {
         PaymentGateway pg = new PaymentGateway();
         var invoice = pg.GetDisplayInvoice(invoiceId);
         var duesItem = invoice.DuesItems.FirstOrDefault();
         var mem = MemberCache.GetMemberDisplay(duesItem.MemberPaidId);
         re.InvoiceId = invoice.InvoiceId;
         var league = MemberCache.GetLeagueOfMember(duesItem.MemberPaidId);
         re.LeagueId = league.LeagueId;
         re.LeagueName = league.Name;
         re.BasePrice = duesItem.BasePrice;
         re.PriceAfterFees = duesItem.PriceAfterFees;
         re.Fees = duesItem.ProcessorFees;
         re.PaidDuesForMonth = duesItem.PaidForDate;
         re.MemberPaid = mem.DerbyName;
         re.EmailForReceipt = mem.Email;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return re;
 }
コード例 #3
0
 public JsonResult MoveInvoiceToNextStatus(string invoiceId, string status)
 {
     try
     {
         status = status.Replace("Move To", "").Trim();
         PaymentGateway pg = new PaymentGateway();
         string s = status.Replace(" ", "_");
         InvoiceStatus st = (InvoiceStatus)Enum.Parse(typeof(InvoiceStatus), s);
         pg.SetInvoiceStatus(new Guid(invoiceId), st);
         if (st == InvoiceStatus.Shipped)
         {
             var voice = pg.GetDisplayInvoice(new Guid(invoiceId));
             StoreGateway sg = new StoreGateway();
             sg.CompileAndSendShippedEmailsForStore(voice);
         }
         return Json(new { isSuccess = true, status = st.ToString() }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Json(new { isSuccess = false }, JsonRequestBehavior.AllowGet);
 }
コード例 #4
0
 public static LeagueReceipt GetReceiptForInvoice(Guid invoiceId)
 {
     LeagueReceipt re = new LeagueReceipt();
     try
     {
         PaymentGateway pg = new PaymentGateway();
         var invoice = pg.GetDisplayInvoice(invoiceId);
         re.InvoiceId = invoice.InvoiceId;
         re.LeagueId = invoice.Subscription.InternalObject;
         var league = League.LeagueFactory.GetLeague(re.LeagueId);
         re.LeagueName = league.Name;
         re.Expires = invoice.Subscription.ValidUntil;
         re.MembershipStatus = CurrentStatusOfBillingEnum.League_Membership;
         re.AmountPaid = invoice.Subscription.Price;
         re.EmailForReceipt = league.Email;
         re.Status = invoice.InvoiceStatus;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return re;
 }
コード例 #5
0
        private void HandleStripePayments(CreateInvoiceReturn output)
        {
            if (invoice.ChargeType == ChargeTypeEnum.Refund_Paywall)
            {
                invoice.InvoiceStatus = InvoiceStatus.Refund_Started;

                // Create the Stripe Request and get the data back.
                var response = PerformStripeRefund();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    if (response.AmountInCentsRefunded.HasValue && response.AmountInCentsRefunded.Value > 0)
                    {
                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        if (voice.Refunds.Sum(x => x.RefundAmount) + invoice.FinancialData.RefundAmount == voice.TotalIncludingTax)
                            pg.UpdateInvoiceForRefund(invoice.InvoiceId, InvoiceStatus.Refunded, invoice.FinancialData.RefundAmount, invoice.AdminNote);
                        else
                            pg.UpdateInvoiceForRefund(invoice.InvoiceId, InvoiceStatus.Partially_Refunded, invoice.FinancialData.RefundAmount, invoice.AdminNote);

                        voice.RefundAmount = invoice.FinancialData.RefundAmount;
                        Paywall.Paywall pw = new Paywall.Paywall();
                        pw.HandlePaywallRefund(voice);
                        output.Status = InvoiceStatus.Refunded;
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                    output.Status = InvoiceStatus.Failed;
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Subscription)
            {
                CompleteNewStripeSubscription(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Paywall)
            {
                CalculateRDNationFeesForPaywallPurchasesStripe();
                // Create the Stripe Request and get the data back.
                var response = PerformStripePaywallPurchaseCheckout();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        Paywall.Paywall pw = new Paywall.Paywall();
                        pw.HandlePaywallPayments(voice);
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                    output.Status = InvoiceStatus.Failed;
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Cancel_Subscription)
            {
                CancelStripeSubscription(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.SubscriptionUpdated)
            {
                CompleteStripeSubscriptionUpdated(output);
            }
            else if (invoice.ChargeType == ChargeTypeEnum.InStorePurchase)
            {
                CalculateRDNationFeesForInStorePurchasesStripe();
                // Create the Stripe Request and get the data back.
                var response = PerformStripeInStorePurchaseCheckout();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        PaymentGateway pg = new PaymentGateway();
                        var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                        Store.StoreGateway sg = new Store.StoreGateway();
                        sg.HandleStoreItemPayments(voice);
                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                {
                    // Could not create a google link
                    //output.Error = response.Error;
                    output.Status = InvoiceStatus.Failed;
                }
            }
            else if (invoice.ChargeType == ChargeTypeEnum.Stripe_Checkout)
            {

                // Create the Stripe Request and get the data back.
                var response = ChargeStripeCheckoutPayment();
                // If it was successful we will now have a redirect link
                if (response != null)
                {
                    // Try to save the data to our database
                    var result = AddInvoiceToDatabase();

                    if (result)
                    {
                        output.InvoiceId = invoice.InvoiceId;
                        output.Status = InvoiceStatus.Payment_Successful;

                        var emailData = new Dictionary<string, string>
                                        {
                                            { "Why: ", invoice.Note }, 
                                            { "invoiceId",invoice.InvoiceId.ToString().Replace("-","") },
                                            { "Paid",invoice.FinancialData.TotalIncludingTax.ToString("N2")}
                                        };
                        EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT + " Receipt For League Subscription", emailData, EmailServer.EmailServerLayoutsEnum.Default);
                        EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_KRIS_WORLIDGE_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT + " New Payment Made", emailData, EmailServer.EmailServerLayoutsEnum.Default);

                    }
                    else
                    {
                        // Could not save to our database
                        output.Error = "Failed to save to RDN database";
                        output.Status = InvoiceStatus.Failed;
                    }
                }
                else
                {
                    // Could not create a google link
                    //output.Error = response.Error;
                    output.Status = InvoiceStatus.Failed;
                }
            }
        }
コード例 #6
0
        private StripeCharge PerformStripeRefund()
        {
            try
            {
                PaymentGateway pg = new PaymentGateway();
                var merchant = pg.GetMerchant(invoice.MerchantId);
                var voice = pg.GetDisplayInvoice(invoice.InvoiceId);
                int amountInCentsTotalRefund = Convert.ToInt32((invoice.FinancialData.RefundAmount) * 100);
                var chargeService = new StripeChargeService(merchant.StripeConnectToken);
                StripeCharge stripeCharge = chargeService.Refund(voice.CustomerId, amountInCentsTotalRefund);
                invoice.PaymentProviderRefundedId = stripeCharge.Id;

                return stripeCharge;

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }