#Magic Mage

1 messages · Page 1 of 1 (latest)

iron solarBOT
tidal bronze
#

Hi 👋

Can you describe your overall question?

royal wing
#

Basically so far in my code I never added anything that can be used as line items for invoices, and well I have the complex need to be able to credit differences for cases where a customer owes less than what they paid (when they change something after they paid). So for this I am asking if payment intents can accept in a negative amount to cover this use case?

tidal bronze
#

Okay first off.

#

What are you trying to do with Stripe. It sounds like you are trying to create an Invoice but it's not clear

royal wing
#

I create the payment intent like so:

    public static async Task<string> CreatePaymentIntentAsync(string customerName, string email, decimal amount, string description)
    {
        // first obtain customer if it exists, if not then we create it for the payment intent to use.
        var customerService = new CustomerService();
        var customers = customerService.ListAutoPaging(new CustomerListOptions() { Email = email });
        var customer = customers.Where(customer => customer.Email == email).FirstOrDefault();
        if (customer == null)
        {
            var customerOptions = new CustomerCreateOptions
            {
                Name = customerName,
                Email = email,
            };
            customer = customerService.Create(customerOptions);
        }
        var options = new PaymentIntentCreateOptions()
        {
            Amount = (long?)(amount * 100),
            Description = description,
            Currency = "usd",
            Customer = customer.Id,
            AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions()
            {
                Enabled = true,
            },
            SetupFutureUsage = "on_session",
        };
        var service = new PaymentIntentService();
        var paymentIntent = await service.CreateAsync(options);
        return paymentIntent.ClientSecret;
    }

However, due to the lack of things to use invoices in the place of this it looks like I would need to use this, however I am wondering if this can work with negative amounts (for the case where customers need to be credited).

tidal bronze
#

Okay let's keep zooming out then. What is the overall thing you are trying to achieve here? What is is that Payment Intents doesn't allow that is making you consider invoicing?

royal wing
#

I was considering invoices for cases where say a user downgrades a "plan", then credit them, if a user upgrades a "plan", then charge more. However after reading it more, there is no way to update it (without creating a new invoice) after they initially pay.

tidal bronze
#

Are you implementing a Subscription service?

royal wing
#

I would like to make it like that yes, but it's also unclear if it would invoke the webhook every month on successful payments for each customer.

tidal bronze
#

Webhook events aren't something you invoke. They are sent by Stripe and triggered when events occur on your Stripe Account, like a customer paying their invoice.

royal wing
#

Yeah, I was wondering if it would be sent every month when their payments go through if I did it like that.

tidal bronze
#

The webhook event will fire every time a Customer pays their invoice. We fire multiple webhook events in this case. I would recommend testing that process

royal wing
#

ok

tidal bronze
#

You can use the Stripe CLI to see the webhook events that will fire