public async Task <PaymentIntentDao> GetPaymentIntentByCustomerId(string paymentCustomerId, CancellationToken cancellationToken) { Guard.Argument(paymentCustomerId, nameof(paymentCustomerId)).NotNull().NotEmpty().NotWhiteSpace(); var options = new PaymentIntentListOptions { Customer = paymentCustomerId }; var paymentIntent = await _paymentIntentService.ListAsync(options : options, cancellationToken : cancellationToken); return(paymentIntent?.FirstOrDefault().ToPaymentIntentDao()); }
public PaymentIntentServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new PaymentIntentService(this.StripeClient); this.cancelOptions = new PaymentIntentCancelOptions { }; this.captureOptions = new PaymentIntentCaptureOptions { AmountToCapture = 123, }; this.confirmOptions = new PaymentIntentConfirmOptions { ReceiptEmail = "*****@*****.**", }; this.createOptions = new PaymentIntentCreateOptions { Amount = 1000, Currency = "usd", PaymentMethodTypes = new List <string> { "card", }, TransferData = new PaymentIntentTransferDataOptions { Amount = 100, Destination = "acct_123", }, }; this.listOptions = new PaymentIntentListOptions { Limit = 1, }; this.updateOptions = new PaymentIntentUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; }
public PaymentIntentServiceTest(MockHttpClientFixture mockHttpClientFixture) : base(mockHttpClientFixture) { this.service = new PaymentIntentService(); this.cancelOptions = new PaymentIntentCancelOptions { }; this.captureOptions = new PaymentIntentCaptureOptions { AmountToCapture = 123, }; this.confirmOptions = new PaymentIntentConfirmOptions { SaveSourceToCustomer = true, }; this.createOptions = new PaymentIntentCreateOptions { AllowedSourceTypes = new List <string> { "card", }, Amount = 1000, Currency = "usd", TransferData = new PaymentIntentTransferDataOptions { Amount = 100, Destination = "acct_123", } }; this.listOptions = new PaymentIntentListOptions { Limit = 1, }; this.updateOptions = new PaymentIntentUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; }
/// <summary> /// Get a list of payments for an user /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <dynamic> GetPayments(string id) { try { Models.Customer customer = await context.customers.Where(c => c.accountId == id).FirstOrDefaultAsync(); if (customer == null) { return(null); } StripeConfiguration.ApiKey = key; var options = new PaymentIntentListOptions { Limit = 50, Customer = customer.customerId }; var service = new PaymentIntentService(); StripeList <PaymentIntent> payments = await service.ListAsync( options ); List <PaymentIntentInformation> pi = new List <PaymentIntentInformation>(); foreach (var p in payments) { pi.Add(new PaymentIntentInformation { id = p.Id, description = p.Description, value = (double)p.Amount / 100 }); } return(pi); } catch (Exception) { return(null); } }
private List <Payment> _ExportPayment(DateRangeOptions range) { var payments = new List <Payment>(); try { var options = new PaymentIntentListOptions { Limit = 100, Created = range, }; var paymentIntentService = new PaymentIntentService(); var transactionService = new BalanceTransactionService(); var customerService = new CustomerService(); var chargeService = new ChargeService(); StripeList <PaymentIntent> pis = paymentIntentService.List(options); for (int i = 0; i < pis.Data.Count; i++) { var pi = pis.Data[i]; var payment = new Payment() { Description = pi.Description, Created = pi.Created, Amount = Convert.ToDecimal(pi.Amount) / 100, Currency = pi.Currency, Status = pi.Status, StatementDescriptor = pi.StatementDescriptor, CustomerId = pi.CustomerId, CardId = pi.PaymentMethodId, InvoiceId = pi.InvoiceId }; if (pi.Charges.Data.Count > 0) { var charge = pi.Charges.Data[0]; try { charge.BalanceTransaction = transactionService.Get(charge.BalanceTransactionId); payment.Id = charge.Id; payment.ConvertedAmount = Convert.ToDecimal(charge.BalanceTransaction.Amount) / 100; payment.AmountRefunded = Convert.ToDecimal(charge.AmountRefunded) / 100; payment.Fee = Convert.ToDecimal(charge.BalanceTransaction.Fee) / 100; payment.ConvertedCurrency = charge.BalanceTransaction.Currency; payment.Tax = 0; payment.Captured = charge.Captured; payment.Transfer = charge.TransferId; try { if (charge.Refunds.Data.Count > 0) { var refundTx = transactionService.Get(charge.Refunds.Data[0].BalanceTransactionId); payment.ConvertedAmountRefunded = Convert.ToDecimal(refundTx.Amount) / 100; } } catch (Exception) { } } catch (Exception) { } } try { pi.Customer = customerService.Get(pi.CustomerId); payment.CustomerDescription = pi.Customer.Description; payment.CustomerEmail = pi.Customer.Email; } catch (Exception) { } payment.Description = pi.Description; payments.Add(payment); } var optionsC = new ChargeListOptions { Limit = 100, Created = range, }; StripeList <Charge> chs = chargeService.List(optionsC); for (int i = 0; i < chs.Data.Count; i++) { var ch = chs.Data[i]; if (FindPayment(payments, ch.Id)) { continue; } var payment = new Payment() { Id = ch.Id, Description = ch.Description, Created = ch.Created, Amount = Convert.ToDecimal(ch.Amount) / 100, Currency = ch.Currency, Status = ch.Status, StatementDescriptor = ch.StatementDescriptor, CustomerId = ch.CustomerId, Captured = ch.Captured, CardId = ch.PaymentMethod, InvoiceId = ch.InvoiceId, Transfer = ch.TransferId }; try { ch.BalanceTransaction = transactionService.Get(ch.BalanceTransactionId); payment.ConvertedAmount = Convert.ToDecimal(ch.BalanceTransaction.Amount) / 100; payment.AmountRefunded = Convert.ToDecimal(ch.AmountRefunded) / 100; payment.Fee = Convert.ToDecimal(ch.BalanceTransaction.Fee) / 100; payment.ConvertedCurrency = ch.BalanceTransaction.Currency; payment.Tax = 0; } catch (Exception) { } try { ch.Customer = customerService.Get(ch.CustomerId); payment.CustomerDescription = ch.Customer.Description; payment.CustomerEmail = ch.Customer.Email; } catch (Exception) { } payments.Add(payment); } } catch (Exception) { } payments.Sort( delegate(Payment a, Payment b) { return(b.Created.CompareTo(a.Created)); } ); return(payments); }