#clutch-guy_error

1 messages ¡ Page 1 of 1 (latest)

hard smeltBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1412896974033653771

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

cyan depot
#

Hello, can you show me your snippet of code for how you are setting up in Stripe? Like are you creating a checkout session, or is this a page with Stripe elements on it?

#

And how exactly is this failing/getting blocked? Is there an error code or error message that your code throws?

ebon cape
#

We are using Stripe Elements. Here is a screenshot of the Google Pay checkout.

Stand by, I need to copy over the code

#

This is where we create the Setup Intent

        if( model.PaymentProcessor == PaymentProcessorType.Enum.Stripe ) {
            model.ExistingPaymentInfo = GetExistingPaymentInformation(
                paymentEnvironment,
                employment.BillingProviderCustomerId,
                employment.NewestActiveInvoice() != null );

            // keep using the same customerId if they already exist
            if( employment.BillingProviderCustomerId == null ) {
                employment.BillingProviderCustomerId =
                    Framework.Processing.PaymentProcessor.Stripe.SetCustomerForMerchant(
                        employment, employee.PrimaryEmailAddress?.Email, false, model.AuthorizationToken,
                        merchantId: null, paymentEnvironment
                    );
                DataContext.Entities.SaveChanges();
            }

            model.CustomerId = employment.BillingProviderCustomerId;
            //Allow only instant verification for ACH. Stripe documentation: https://docs.stripe.com/payments/ach-debit/set-up-payment?platform=web&payment-ui=direct-api#instant-only-verification
            SetupIntent setupIntent = CreateSetupIntent( paymentEnvironment, model.CustomerId );
            model.ClientSecret = setupIntent.ClientSecret;
            model.SetupIntentId = setupIntent.Id;

        } else {
            model.CustomerId = employment.BillingProviderCustomerId;
        }

Learn how to save payment method details for future ACH Direct Debit payments.

#

And here is the section that charges, it literally follows the SetupIntent creation from above and I probably should have copied all of it at once

       model.Cart = acceptedProducts; //.Where( p => p.BenefitStatusId == (int)Framework.ApplicationAction.Accept ).ToList();

       decimal monthlyPayment = model.Cart.Sum( p => p.MonthlyPremium );
       model.MonthlyTotal = monthlyPayment;

       var paySomethingNow = false;
       var activeInPayInvoice = employment.ActiveInPayInvoice();
       if( exdata.ChargeOnCheckout && (activeInPayInvoice == null || activeInPayInvoice.InvoiceLineItem.Where( x => x.Enrollment != null ).Max( x => x.Enrollment.EffectiveDate ) > DateTime.Now) ) {

           var (charge, credit) = GetChargeAndCreditAmount( monthlyPayment, currentActiveInPayInvoice );

           model.CreditAmount = credit;
           model.ChargeNowAmount = charge;

           paySomethingNow = true;
       }
cyan depot
#

Do you have a public test site where I can se this for myself?
After looking at that code, I don't think the backend code for creating the setup intent is causing this behavior. This is likely a client side setting. Do you have your code for setting up that payment element or express checkout element?

#

Also have you tried filling out the contact info? From the screenshot, I wonder if the billing address is required here and the button is greyed out until that has been supplied

ebon cape
#

Regarding the Contact info, let me try that.. Still, it shouldn't show 0$ as that invoice had 14 and we charged it using a card prior

#

Regarding the public test site.. hmm we were testing this in Production.. I wouldhave to sete it all up and it could take me some time

cyan depot
#

If you are using SetupIntents then it is expected for Google Pay to show $0. If you are immediately charging something, we reccommend using elements in payment mode instead

ebon cape
cyan depot
#

Depends a bit on your setup. When you say "invoice" here, do you mean a Stripe invoice object or is this your own invoice that uses Stripe payment intnets to work? Also are you creating the intent before or after you create your payment element?

ebon cape
#

The invoice is ours. We used to schedule a charge monthly for our customers and now we want to start charging them immediately as soon as they sign up.

Regarding the Intent, the code I shared is run prior to the Rendering of the Stripe Elements.

#

Here is a snippet of the elements code:

            stripe.confirmSetup({
                elements,
                redirect: "if_required",
                confirmParams: {
                    return_url: 'https://www.enrollvb.com/enroll'
                }
            }).then(function (result) {
                $("#processingdialog").modal('hide');
                if (result.error) {
                    alertX(`Something is wrong with your payment information: ${result.error.message}`);
                } else {
                    @if (Model.ChargeNowAmount != null) {
                        <text>
                            $("#confirmPopup").modal( 'show' );
                        </text>
                    }
                    else {
                        <text>
                            submit();
                        </text>
                    }
                }
            });
cyan depot
#

Gotcha, in that case you can just create a payment intent instead of a setup intent, you then pass the payment intent's client secret to the frontend and render the payment element the same way. Then when submitting the form you call confirmPayment instead of confirmSetup. This doc demonstrates that flow https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements

ebon cape
#

So that in order to charge immediately and to have some charge as scheduled, we need to render the Payment Element in 2 different ways?

hard smeltBOT
cyan depot
#

Yes, if you are scheduling a future payment you can use a setup intent, for charging immediately you can use a payment intent and unfortunately the payment element can only render for one at once.

ebon cape
#

Got it. I had an inkling that it was going in that direction... but you laid it all out.

Thank you very much.

ebon cape
#

One more thing, it appears that this isn't an issue with Card payments even though clearly it is with Google Pay?

chrome nova
#

Which issue are you referring to?

ebon cape
#

The issue is that while we are able to successfully charge cards using SetupIntents upon capturing payments, we cannot do so for Google Pay.

This is what I got from Pompey:
Yes, if you are scheduling a future payment you can use a setup intent, for charging immediately you can use a payment intent and unfortunately the payment element can only render for one at once.

chrome nova
#

The issue is that while we are able to successfully charge cards using SetupIntents upon capturing payments, we cannot do so for Google Pay.
This should be possible. Are you facing any problem with Google Pay? You can use Setup Intent to collect Google Pay payment method, then charge it with Payment Intent API directly later

ebon cape
#

Ah..

#

Happen to have an example or point me to the documentation?

#

Oh wait.. now that I read your comment again:

The issue we are having is that so far we have collected payment information and then charge as per schedule each month. Now, for a group of customers, we would like to charge upon checkout. Google Pay works fine with SetupIntents and the scheduled charge but the same code shows me 0$ and I cannot charge it immediately. However, that same code charges Credit Cards. So Pompey confirmed that Google Pay would see 0$ and that I would have to use Payment Intents immediately to charge.

Anyways, that got me thinking and I wanted to just confirm this: with SetupIntents and the scheduled charge code that works, we can charge cards immediately. However, for the Google Pay, we need to use Payment Intents.

chrome nova
#

How does your scheduled card code work? It should work similar for Google Pay

ebon cape
#

Okay, I will try some stuff and reach out if needed. Thank you.