public async Task <IActionResult> SaveCard([FromBody] SaveCardDto dto) { var options = new PaymentMethodAttachOptions { Customer = dto.CustomerId, }; var service = new PaymentMethodService(); return(Ok(await service.AttachAsync(dto.PaymentMethodIds, options))); }
public async Task AddCreditCardAsync(string customerId, string cardholderName, string number, string cvc, long expMonth, long expYear, string zipCode) { var paymentMethodCreateOptions = new PaymentMethodCreateOptions { Type = "card", Card = new PaymentMethodCardOptions { Number = number, Cvc = cvc, ExpMonth = expMonth, ExpYear = expYear }, BillingDetails = new PaymentMethodBillingDetailsOptions { Name = cardholderName, Address = new AddressOptions { PostalCode = zipCode } } }; var paymentMethodService = new PaymentMethodService(); var paymentMethod = await paymentMethodService.CreateAsync(paymentMethodCreateOptions); var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card" }); foreach (var card in cards) { await paymentMethodService.DetachAsync(card.Id); } var paymentMethodAttachOptions = new PaymentMethodAttachOptions { Customer = customerId }; await paymentMethodService.AttachAsync(paymentMethod.Id, paymentMethodAttachOptions); }
public async Task <Invoice> CreateInvoice( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "invoice/create")] CreatePaymentRequest request, ILogger log) { // このサンプルでは input validation をしていません。 // 既存の Customer に紐づけることもできますが、今回は毎回 Customer を作成します。 var customerCreateOptions = new CustomerCreateOptions { Email = request.Email, PaymentMethod = request.PaymentMethodId, InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = request.PaymentMethodId } }; var customer = await _customerService.CreateAsync(customerCreateOptions); // Attach payment method: // 新規作成した Customer に PaymentMethod を紐づけます。 // paymentMethodMethod は既に別の customer に紐づけられている場合エラーになります。 var options = new PaymentMethodAttachOptions { Customer = customer.Id }; var paymentMethod = await _paymentMethodService.AttachAsync(request.PaymentMethodId, options); // Update customer's default payment method. var customerOptions = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = paymentMethod.Id, } }; await _customerService.UpdateAsync(customer.Id, customerOptions); // Create InvoiceItem. var createOptions = new InvoiceItemCreateOptions { Customer = customer.Id, Price = request.PriceId }; await _invoiceItemService.CreateAsync(createOptions); // Create Invoice var invoiceOptions = new InvoiceCreateOptions { Customer = customer.Id, AutoAdvance = true, }; var invoiceResult = await _invoiceService.CreateAsync(invoiceOptions); //ここで、Stripe の Dashboard > Billing > インボイスにインボイスが追加されます。 return(invoiceResult); }
async public Task <string> AttachPaymentMethodAsync(string id, [FromBody] PaymentMethodAttachOptions paymentMethodAttachOptions) { var res = await _paymentMethodService.AttachAsync(id, paymentMethodAttachOptions, _requestOptions); return(res.Id); }