コード例 #1
0
        public RefundResult DoRefund(String Id)
        {
            // StripeConfiguration.SetApiKey("sk_test_tZluxZhcmbz0AfuvoYm60ic9");
            StripeConfiguration.SetApiKey("sk_live_J8Hzr3keqlfOtLn5zYAJp62S");
            var          chargeService = new StripeChargeService();
            StripeCharge striprefund   = chargeService.Refund(Id);

            RefundResult refundresult = new RefundResult();

            refundresult.Id = striprefund.Id;
            return(refundresult);
        }
コード例 #2
0
ファイル: Stripe.cs プロジェクト: tormnator/Payment-providers
        public override ApiInfo RefundPayment(Order order, IDictionary <string, string> settings)
        {
            try {
                order.MustNotBeNull("order");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("mode", "settings");
                settings.MustContainKey(settings["mode"] + "_secret_key", "settings");

                StripeChargeService chargeService = new StripeChargeService(settings[settings["mode"] + "_secret_key"]);
                StripeCharge        charge        = chargeService.Refund(order.TransactionInformation.TransactionId);

                return(new ApiInfo(charge.Id, GetPaymentState(charge)));
            } catch (Exception exp) {
                LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - RefundPayment", exp);
            }

            return(null);
        }
コード例 #3
0
        private void CreateRefund(Transaction t)
        {
            Stripe.Configuration.SetApiKey(Settings.StripeApiKey);

            var          chargeService = new StripeChargeService();
            StripeCharge stripeCharge  = chargeService.Refund(t.PreviousTransactionNumber,
                                                              (int)(t.Amount * 100));

            if (stripeCharge.Id.Length > 0)
            {
                t.Result.Succeeded       = true;
                t.Result.ReferenceNumber = stripeCharge.Id;
            }
            else
            {
                t.Result.Succeeded               = false;
                t.Result.ResponseCode            = "FAIL";
                t.Result.ResponseCodeDescription = "Stripe Failure";
            }
        }
コード例 #4
0
        private bool CancelStripeSubscription(UserInfo userInfo)
        {
            var      customerService = new StripeCustomerService();
            DateTime?periodEnd;
            DateTime?periodStart;

            try
            {
                //cancels subscription at the end of the current period
                StripeSubscription stripeSubscription = customerService.CancelSubscription(userInfo.PaymentCustomerId);

                //save profile ID and profile status with user info
                userInfo.Subscribed            = false;
                userInfo.PaymentCustomerStatus = stripeSubscription.Status;
                periodEnd   = stripeSubscription.PeriodEnd;
                periodStart = stripeSubscription.PeriodStart;

                db.Entry(userInfo).State = EntityState.Modified;
            }
            catch (Exception e)
            {
                Utilities.LogAppError("Subscription cancel failed: " + e.Message);
                return(false);
            }

            try
            {
                //get the most recent charge
                var chargeService = new StripeChargeService();
                IEnumerable <StripeCharge> response = chargeService.List(1, 0, userInfo.PaymentCustomerId);

                if ((response != null) && (response.Count() > 0))
                {
                    StripeCharge charge = response.ElementAt(0);

                    //refund the charge (if paid)
                    if ((charge != null) && charge.Paid.HasValue && charge.Paid.Value)
                    {
                        int daysIntoPeriod = 0;

                        if (DateTime.Today.Date > periodStart.Value)
                        {
                            daysIntoPeriod = DateTime.Today.Date.Subtract(periodStart.Value).Days;
                        }

                        int   numDaysInPeriod   = periodEnd.Value.Date.Subtract(periodStart.Value.Date).Days;
                        float ratePerDayInCents = charge.AmountInCents.Value / numDaysInPeriod;

                        float amountOwed = daysIntoPeriod * ratePerDayInCents;

                        int?refundAmount = 0;

                        //round amount to nearest int
                        refundAmount = charge.AmountInCents.Value - Convert.ToInt32(amountOwed);

                        StripeCharge stripeCharge = chargeService.Refund(charge.Id, refundAmount);
                    }
                }
            }
            catch (Exception e)
            {
                Utilities.LogAppError("Refund failed: " + e.Message);
                return(false);
            }

            return(true);
        }