#paul_customer-defaultpm

1 messages ¡ Page 1 of 1 (latest)

unborn quailBOT
#

👋 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/1220146154113859746

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

signal fjordBOT
shrewd sluice
#

Hello @woeful radish ! I'm sorry I don't really understand what your question means.

woeful radish
#

One sec

#

Let me elaborate

#

What are possible options using back-end server code to set Customers payment method to be default

#

Once payment default is enabled I can add additional subscription or one off payments

shrewd sluice
woeful radish
#

Note these Items are added by customer... But we have a bit complex flow we want to enable for cutomer to add additional products

#

Hmm this is for existing subscription..

#

Does this work for Existing Customer ?

#

not a subscription

shrewd sluice
#

I'm sorry this is really vague so it's hard to help without focusing on our exact product(s) or APIs that you use. You didn't really give me much yet

woeful radish
#

Oh

#

Sure

#

np Let me share

#
       val params: SessionCreateParams = SessionCreateParams.builder()
            //Required for Subscription
            .setMode(SessionCreateParams.Mode.PAYMENT)
            .setSuccessUrl("http://localhost:4242/success?session_id={CHECKOUT_SESSION_ID}")
            .setCancelUrl("http://localhost:4242/cancel?session_id={CHECKOUT_SESSION_ID}")
            //Save payment Method Details
            //Cant use payment Intend in Subscription Mode
            .setPaymentIntentData(
                SessionCreateParams.PaymentIntentData.builder().setSetupFutureUsage(
                    //NEED MORE TESTING THIS MAY NOT WORK 100
                    //https://docs.stripe.com/payments/payment-intents#future-usage
                    SessionCreateParams.PaymentIntentData.SetupFutureUsage.OFF_SESSION
                ).build()
            )
            //Enable customer creation as part of the session
            // Not allowed when in Subscription Mode
            .setCustomerCreation(SessionCreateParams.CustomerCreation.ALWAYS)
            .addLineItem(
                SessionCreateParams.LineItem.builder().setPrice("price_1OwXoHBZuRENdfSAewG3UzmA").setQuantity(1).build()
            )
.build()

        val session: Session = Session.create(params)

        println("URL = "+session.url)
        println(session.toJson())
#

The above can make a payment with Customer for Future usage

#

Create this king of customer

#

Having Id cus_Pm6Ext3WJwHPQ8

shrewd sluice
#

Okay so you are using Stripe Checkout to collect payment method details. Okay, so now what are you asking about that Customer?

woeful radish
#

Using code I want to set for given customer payment method as default

#

This allows me to add Another Subscription or One Off Payments using Invoice

shrewd sluice
#

paul_customer-defaultpm

woeful radish
#

Looking one sec

#

I am trying to set this on this customer cus_Pm4u3QW9v2OL7N

shrewd sluice
#

use what I just linked above

woeful radish
#
        val updateParms =  CustomerUpdateParams.builder().setInvoiceSettings(
            CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod("What do I put in here")
        )

#

so there is above code what goes in there

shrewd sluice
#

Ah I get it now. The pm_123456 which is the PaymentMethod id that you want to make the default

woeful radish
#

Ohh
So this will pm_1OwWkkBZuRENdfSAuD9tKDkv Ok one sec

shrewd sluice
#

yes!

woeful radish
#

Perfect !!!! I got

#
    @Test
    fun `Test customer to update payment method to default`(){
        val resource: Customer = Customer.retrieve("cus_Pm4u3QW9v2OL7N")
        val updateParms =  CustomerUpdateParams.builder().setInvoiceSettings(
            CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod("pm_1OwWkkBZuRENdfSAuD9tKDkv").build()
        ).build()

        val result = resource.update(updateParms)
        println(result.toJson())

    }

I got back

 "invoice_settings": {
    "custom_fields": null,
    "default_payment_method": "pm_1OwWkkBZuRENdfSAuD9tKDkv",
    "footer": null,
    "rendering_options": null
  },
#

Ok I then I am done

#

thank you

#

I am glad I reached out... as this was not that trivial thank you

#

over and out

shrewd sluice
#

Have a great day