public Tuple <bool, StripeCharge> GetTransaction(string id) { StripeCharge response = new StripeCharge(); bool isSuccessful = true; try { StripeConfiguration.SetApiKey(PrivateKey); var charges = new StripeChargeService(); var result = charges.Get(id); return(new Tuple <bool, StripeCharge>(isSuccessful, charges.Get(id))); } catch (StripeException e) { response.FailureMessage = e.StripeError.ErrorType + ": " + e.StripeError.Code + " " + e.StripeError.Message; response.Id = id; isSuccessful = false; } return(new Tuple <bool, StripeCharge>(isSuccessful, response)); }
public static List <Transaction> GetDonorBoxTransactions(string apiKey, DateTime startDate, DateTime endDate) { StripeConfiguration.SetApiKey(apiKey); var transactions = new List <Transaction>(); var balanceClient = new StripeBalanceService(); var parameters = new StripeBalanceTransactionListOptions(); var chargeClient = new StripeChargeService(); var refundClient = new StripeRefundService(); parameters.Created = new StripeDateFilter { GreaterThanOrEqual = startDate, LessThanOrEqual = endDate }; parameters.Limit = 100; foreach (var balanceTransaction in balanceClient.List(parameters).Where(t => t.Type != "payout")) { StripeCharge charge = null; if (balanceTransaction.Type == "charge" || balanceTransaction.Type == "payment") { charge = chargeClient.Get(balanceTransaction.SourceId); } else if (balanceTransaction.Type == "refund") { var chargeId = refundClient.Get(balanceTransaction.SourceId).ChargeId; charge = chargeClient.Get(chargeId); } if (charge?.Status == "succeeded") { transactions.Add(StripeMapping.MapToTransaction(balanceTransaction, charge)); } } return(transactions); }
public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { var result = new RefundPaymentResult(); try { var options = new StripeRefundCreateOptions(); var charge = _chargeService.Get(refundPaymentRequest.Order.CaptureTransactionId); var maximumRefund = charge.Amount - charge.AmountRefunded; options.Amount = (int)Math.Ceiling(refundPaymentRequest.AmountToRefund * 100); if (maximumRefund == 0 && !refundPaymentRequest.IsPartialRefund) //if it's a partial refund the user would not expect to see the order switch to the Refund status { result.NewPaymentStatus = PaymentStatus.Refunded; // this means it has been previously refunded from Stripe admin return(result); } if (options.Amount > maximumRefund) { if (maximumRefund > 0) { result.AddError("This charge has already been partially refunded. Maximum refund amount is: " + (decimal)maximumRefund / 100); } else { result.AddError("This charge has already been fully refunded."); } return(result); } refundPaymentRequest.IsPartialRefund = options.Amount != maximumRefund; _refundService.Create(refundPaymentRequest.Order.CaptureTransactionId, options); result.NewPaymentStatus = refundPaymentRequest.IsPartialRefund ? PaymentStatus.PartiallyRefunded : PaymentStatus.Refunded; return(result); } catch (StripeException exception) { if (!string.IsNullOrEmpty(exception.StripeError.Code)) { result.AddError(exception.StripeError.Message + " Error code: " + exception.StripeError.Code); } else { result.AddError(exception.StripeError.Message); } return(result); } }
public Task <DomainCharge> GetAsync(DomainCharge charge) { return(Task.Run(() => { try { StripeCharge c = _service.Get(charge.Id); return Task.FromResult(_mapper.Map <StripeCharge, DomainCharge>(c)); } catch (StripeException e) { throw new BillingException(string.Format("Failed to get charge by id {0}: {1}", charge.Id, e)); } })); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Do any additional setup after loading the view. StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var chargeService = new StripeChargeService(); chargeService.ExpandBalanceTransaction = true; chargeService.ExpandCustomer = true; chargeService.ExpandInvoice = true; StripeCharge stripeCharge = chargeService.Get("ch_1AxdE22eZvKYlo2CmHLOPLgt"); }
public override ApiInfo GetStatus(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.Get(order.TransactionInformation.TransactionId); return(new ApiInfo(charge.Id, GetPaymentState(charge))); } catch (Exception exp) { LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - GetStatus", exp); } return(null); }
public ActionResult Details(string id) { if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var chargeService = new StripeChargeService(); var stripeCharge = chargeService.Get(id); var charge = new ChargeDetailViewModel { Id = stripeCharge.Id, Amount = stripeCharge.Amount, Created = stripeCharge.Created, CustomerName = stripeCharge.Customer.Email, Paid = stripeCharge.Paid, Refunded = stripeCharge.Refunded, Status = stripeCharge.Status, BalanceTransactionId = stripeCharge.BalanceTransactionId, Captured = stripeCharge.Captured, Currency = stripeCharge.Currency, CustomerId = stripeCharge.CustomerId, Object = stripeCharge.Object, LiveMode = stripeCharge.LiveMode, SourceCardId = stripeCharge.Source.Id, Description = stripeCharge.Description, StatementDescriptor = stripeCharge.StatementDescriptor, FailureCode = stripeCharge.FailureCode, FailureMessage = stripeCharge.FailureMessage, InvoiceId = stripeCharge.InvoiceId, Metadata = stripeCharge.Metadata, ReceiptEmail = stripeCharge.ReceiptEmail, ReceiptNumber = stripeCharge.ReceiptNumber }; return(View(charge)); }
public async Task <ActionResult> Download(int?id, bool?bought, string stripeId) { Service service = db.Services.Find(id); if (id == null) { return(View("NotFound")); } if (service.Video != null) { if (bought == true && stripeId != null) { int nonNullId = id.Value; string strIpAddress = string.Empty; strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (strIpAddress == "" || strIpAddress == null) { strIpAddress = Request.ServerVariables["REMOTE_ADDR"]; } //Don't record analytics coming from garbage IP addresses if (strIpAddress != "::1") { DownloadAnalytic analyitic = new DownloadAnalytic(); analyitic.IPAddress = strIpAddress; analyitic.ServiceId = nonNullId; service.DownloadAnalytics.Add(analyitic); db.SaveChanges(); await PopulateDownloadAnalyticObject(analyitic); } try { var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Get(stripeId); if (stripeCharge.Status == "succeeded") { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("videos"); string userFileName = service.FirstName + "_" + service.LastName + "_Video.mp4"; CloudBlockBlob blob = container.GetBlockBlobReference(service.Video.ConvertedFilePath); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTime.Now.AddYears(100) }; SharedAccessBlobHeaders blobHeaders = new SharedAccessBlobHeaders() { ContentDisposition = "attachment; filename=" + userFileName }; string sasToken = blob.GetSharedAccessSignature(policy, blobHeaders); var sasUrl = blob.Uri.AbsoluteUri + sasToken;//This is the URL you will use. It will force the user to download the vi return(Redirect(sasUrl)); } } catch { return(View("NotFound")); } } //publicly exposing URL for now if (Authorize(service) || service.IsSecured != true) { if (service.Video != null) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("videos"); string userFileName = service.FirstName + "_" + service.LastName + "_Video.mp4"; CloudBlockBlob blob = container.GetBlockBlobReference(service.Video.ConvertedFilePath); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTime.Now.AddYears(100) }; SharedAccessBlobHeaders blobHeaders = new SharedAccessBlobHeaders() { ContentDisposition = "attachment; filename=" + userFileName }; string sasToken = blob.GetSharedAccessSignature(policy, blobHeaders); var sasUrl = blob.Uri.AbsoluteUri + sasToken;//This is the URL you will use. It will force the user to download the vi return(Redirect(sasUrl)); } } } return(View("NotFound")); }
public StripeCharge GetCustomerPayment(string paymentId) { var chargeService = new StripeChargeService(); return(chargeService.Get(paymentId)); }
static void Main(string[] args) { // Set Stripe Api Key StripeConfiguration.SetApiKey(AppConfiguration.StripeApiKey); using (var subscriptionBookingRepository = new SubscriptionBookingRepository()) { var subscriptionBookingList = subscriptionBookingRepository.SubscriptionBookingsList.ToList(); // Each Subscription Bookings subscriptionBookingList.ForEach(subscriptionBookings => { var customerInfos = subscriptionBookingRepository.CustomerInfoList .FirstOrDefault(ci => ci.CustomerId == subscriptionBookings.CustomerId); // Customer Infos if (customerInfos != null) { var subscriptionService = new StripeSubscriptionService(); StripeSubscription subscription = subscriptionService.Get(subscriptionBookings.StripeSubscriptionId); DateTime?canceledDate = subscription.CanceledAt; var invoiceService = new StripeInvoiceService(); // All Invoices of Customer var invoiceItems = invoiceService.List(new StripeInvoiceListOptions { CustomerId = customerInfos.StripeCustomerId } ).OrderBy(ic => ic.Date).ToList(); short cycleNumber = 0; invoiceItems.ForEach(invoice => { if (invoice.SubscriptionId.Equals(subscriptionBookings.StripeSubscriptionId, StringComparison.InvariantCulture)) { cycleNumber++; double totalCharge = (double)invoice.Total / 100; if (!totalCharge.Equals(subscriptionBookings.TotalPrice)) { subscriptionBookings.Price = totalCharge; } DateTime?periodStart = invoice.PeriodStart; DateTime?periodEnd = invoice.PeriodEnd; try { if (periodStart.Value.Date == periodEnd.Value.Date) { periodEnd = periodEnd.Value.AddDays(30); } periodStart = invoice.StripeInvoiceLineItems.Data[0].StripePeriod.Start; periodEnd = invoice.StripeInvoiceLineItems.Data[0].StripePeriod.End; } catch (Exception) { } var subscriptionCycle = new SubscriptionCycles { SubscriptionBookingId = subscriptionBookings.Id, StartDate = periodStart, EndDate = periodEnd, CancelDate = subscriptionBookings.CancelDate, Status = subscriptionBookings.Status, LastUpdatedDate = subscriptionBookings.LastUpdatedDate, LastUpdatedBy = subscriptionBookings.LastUpdatedBy, Price = totalCharge.Equals(0) && subscriptionBookings.PayByCredit > 0 ? subscriptionBookings.PayByCredit : totalCharge, MerchantPrice = subscriptionBookings.MerchantPrice, PayByCredit = subscriptionBookings.PayByCredit, TotalPrice = totalCharge, Quantity = subscriptionBookings.Quantity, StripeInvoiceId = invoice.Id, StripeChargeId = invoice.ChargeId, StripeCouponId = subscriptionBookings.StripeCouponId, CycleNumber = cycleNumber }; var param = new AddSubscriptionCycleParams { CanceledDate = canceledDate, SubscriptionCyclesObject = subscriptionCycle, SubscriptionInvoices = new List <SubscriptionInvoices>() }; SubscriptionInvoices subscriptionInvoice; // Paid Charge if (invoice.Paid) { if (!string.IsNullOrEmpty(invoice.ChargeId)) { var chargeService = new StripeChargeService(); StripeCharge charge = chargeService.Get(invoice.ChargeId); subscriptionInvoice = new SubscriptionInvoices { SubscriptionCyclesId = subscriptionCycle.Id, BookingStatus = subscriptionCycle.Status, Quantity = subscriptionBookings.Quantity, Price = (double)charge.Amount / 100, MerchantPrice = subscriptionBookings.MerchantPrice, PayByCredit = subscriptionBookings.PayByCredit, TotalPrice = (double)charge.Amount / 100, InvoiceStatus = (int)Enums.InvoiceStatus.Charge, StripeChargeId = charge.Id, ChargeAmount = (double)charge.Amount / 100, StripeRefundId = string.Empty, RefundAmount = 0, RefundCreditAmount = 0, StripeCouponId = subscriptionBookings.StripeCouponId, CreatedDate = DateTime.UtcNow, CreatedBy = 1 }; param.SubscriptionInvoices.Add(subscriptionInvoice); // Charge with Refunded if (charge.Refunded || charge.AmountRefunded > 0) { var refundList = charge.Refunds; for (int i = 0; i < refundList.Data.Count; i++) { var refundItem = charge.Refunds.Data[i]; var subscriptionInvoiceRefunded = new SubscriptionInvoices { SubscriptionCyclesId = subscriptionCycle.Id, BookingStatus = subscriptionCycle.Status, Quantity = subscriptionBookings.Quantity, Price = (double)charge.Amount / 100 - (double)refundItem.Amount / 100, MerchantPrice = subscriptionBookings.MerchantPrice, PayByCredit = subscriptionBookings.PayByCredit, TotalPrice = subscriptionBookings.MerchantPrice - (double)refundItem.Amount / 100 - subscriptionBookings.PayByCredit, InvoiceStatus = refundItem.Amount < charge.Amount ? (int)Enums.InvoiceStatus.PartialRefund : (int)Enums.InvoiceStatus.FullRefund, StripeChargeId = charge.Id, ChargeAmount = (double)charge.Amount / 100, StripeRefundId = refundItem.Id, RefundAmount = (double)refundItem.Amount / 100, RefundCreditAmount = 0, StripeCouponId = subscriptionBookings.StripeCouponId, CreatedDate = DateTime.UtcNow, CreatedBy = 1 }; param.SubscriptionInvoices.Add(subscriptionInvoiceRefunded); param.SubscriptionCyclesObject.Price = subscriptionInvoiceRefunded.Price; param.SubscriptionCyclesObject.TotalPrice = subscriptionInvoiceRefunded.TotalPrice; } } } else { // Charge but have Coupon and use DayAxe Credit so Amount = 0 subscriptionInvoice = new SubscriptionInvoices { SubscriptionCyclesId = subscriptionCycle.Id, BookingStatus = subscriptionCycle.Status, Quantity = subscriptionBookings.Quantity, Price = 0, MerchantPrice = subscriptionBookings.MerchantPrice, PayByCredit = subscriptionBookings.PayByCredit, TotalPrice = 0, InvoiceStatus = (int)Enums.InvoiceStatus.Charge, StripeChargeId = string.Empty, ChargeAmount = 0, StripeRefundId = string.Empty, RefundAmount = 0, RefundCreditAmount = 0, StripeCouponId = subscriptionBookings.StripeCouponId, CreatedDate = DateTime.UtcNow, CreatedBy = 1 }; param.SubscriptionInvoices.Add(subscriptionInvoice); } } else { // Closed Charge subscriptionInvoice = new SubscriptionInvoices { SubscriptionCyclesId = subscriptionCycle.Id, BookingStatus = subscriptionCycle.Status, Quantity = subscriptionBookings.Quantity, Price = totalCharge, MerchantPrice = subscriptionBookings.MerchantPrice, PayByCredit = subscriptionBookings.PayByCredit, TotalPrice = totalCharge, InvoiceStatus = (int)Enums.InvoiceStatus.Charge, StripeChargeId = invoice.ChargeId, ChargeAmount = totalCharge, StripeRefundId = string.Empty, RefundAmount = 0, RefundCreditAmount = 0, StripeCouponId = subscriptionBookings.StripeCouponId, CreatedDate = DateTime.UtcNow, CreatedBy = 1 }; param.SubscriptionInvoices.Add(subscriptionInvoice); } subscriptionBookingRepository.AddSubscriptionCycle(param); Console.WriteLine("Update - " + invoice.SubscriptionId); } }); } }); Console.WriteLine("Done!!!"); Console.ReadLine(); } }
public StripeCharge Get(string chargeId) { return(_stripeChargeService.Get(chargeId)); }