#daswass_code

1 messages ยท Page 1 of 1 (latest)

merry dewBOT
#

๐Ÿ‘‹ 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/1379466420319944796

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

quartz gyro
#
SessionCreateParams.Builder builder = SessionCreateParams.builder();
        buildLineItemsForCheckout(resident, amount, fee, builder);

        Map<String, String> metadata = PropManPayments.ResidentAccount.createMetadataObject(namespace, resident);
        metadata.put("amount", CurrencyUtils.formatCurrency(amount));
        metadata.put(METADATA_KEY_RECURRING, Boolean.toString(recurring));

        builder.setPaymentIntentData(
                        SessionCreateParams.PaymentIntentData.builder()
                                .setApplicationFeeAmount(applicationFeeCents)
                                .putAllMetadata(metadata)
                                .build()
                )
                .setMode(SessionCreateParams.Mode.PAYMENT)
                .setCustomerCreation(SessionCreateParams.CustomerCreation.ALWAYS)
                .setCancelUrl(RESIDENT_PORTAL_URL + "?paymentSuccess=false")
                .setSuccessUrl(RESIDENT_PORTAL_URL + "?paymentSuccess=true")
                .setPaymentMethodConfiguration(stripeAccount.getEnvironment().getPaymentMethodConfigId(payWithCard))
                .putAllMetadata(metadata);

        StripeAccount customer = resident.getBillingDetails().getStripeAccount();
        if (customer != null) {
            builder.setCustomer(customer.getAccountId());
        }
brave glacier
#

Hello, if you use a customer, turn on payment method saving, allow them to re-use a saved payment method, there wouldn't be a verification again. If you re-use the customer but don't save the PM there would be. I don't know much about fees but I would imagine that would avoid or still get the fee respectively. If you write in to our support team they would know more about how the fees actually work

quartz gyro
#

Ok, so I think I have to handle the charge.succeeded webhook to capture the payment method that was successful and update the customer object in Stripe

#

I spoke to support earlier and they seems to think just creating a customer would avoid repeated fees, but I just dont believe it, and theres no way to test this.

brave glacier
#

Can you tell me more about what you want to do with the charge.succeeded event there?

quartz gyro
#

Theres a payment_method and payment_method_details

#

Im going to create a customer with CustomerCreation.ALWAYS (this is new), and then when the charge succeeds, update the Customer to associate with this payment method.

#

All of this is an attempt to avoid multiple verificatoin fees for the same customer paying with the same account every month

#

Stripe is alreayd collecting 5$ fot the ACH payment itself. I can explain a one time 1.50 verification fee, but tacking that on to every payment is not going to fly with my customers. Its a "hidden" charge that only shows up monthly when connected accounts do payouts.

brave glacier
#

And then to get it to redisplay on the next Checkout Session you would have to set other params, figuring out what those are again

quartz gyro
#

Ok. Something like this wont work?

private void savePaymentMethodToCustomer(Charge charge, Resident resident) {
        StripeAccount stripeAccount = resident.getBillingDetails().getStripeAccount();
        if (stripeAccount == null) {
            logger.warning("No Stripe account found for resident: " + resident.getAccountString());
            return;
        }

        String paymentMethodId = charge.getPaymentMethod();

        try {
            Customer customer = stripeAccess.CustomerRetrieve(stripeAccount);
            PaymentMethod paymentMethod = stripeAccess.PaymentMethodRetrieve(paymentMethodId);

            PaymentMethodAttachParams attachParams = PaymentMethodAttachParams.builder()
                    .setCustomer(customer.getId())
                    .build();
            stripeAccess.PaymentMethodAttach(paymentMethod, attachParams);

            CustomerUpdateParams params = CustomerUpdateParams.builder()
                    .setDefaultSource(paymentMethodId)
                    .build();
            stripeAccess.CustomerUpdate(customer, params);
        } catch (Exception e) {
            logger.warning(
                    "Failed to attach payment method to resident's Customer account '" + resident.getAccountString() + "': " + e.getMessage());
        }
    }
#

Id like to be able to charge both on-session and off-session (in the case of recurring payments setup through my system)

#

The first payment would have to be on-session, but after that, we should be verified and I could create the payment intent with the customer and paymentintent from the Customer default source

brave glacier
#

Correct, either the PM will be assosciated with the customer along with the confirm, or it will only exist as a one time use PM that can't be attached to the customer afterwards.
In that case you can set payment_intent_data.setup_future_usage to off_session that will tell us to set up the PM for being charged when the customer is not around. Apologies but I got sidetracked when looking in to how to get the PMs to redisplay in checkout, looking in to that again

quartz gyro
#

No worries, thanks!

#

If Im reading the above correctly, if I set the create customer to always, stripe will automatically associate the PM to the customer account if I also set setup_future_usage to off_session?

brave glacier
quartz gyro
#

Ie, no need for my savePaymentMethodToCustomer method at all?

brave glacier
#

Correct, if you set all three of those we should create a customer, attach the PM to it, and that PM would be usable in recurring payments and display in subsequent sessions for that customer

quartz gyro
#

Lovely ๐Ÿ™‚

#

This has been the most clear conversation about this Ive seen anywhere. Youre the best!

brave glacier
#

Glad I could help!