#daswass_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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());
}
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
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.
Can you tell me more about what you want to do with the charge.succeeded event there?
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.
In that case you would actually want to set payment_intent_data.setup_future_usage to on_session when creating your checkout session. You have to specify whether the PM will be saved when creating the session, unfortunately they can't be attached to the customer after the fact
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-payment_intent_data-setup_future_usage
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
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
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
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?
I think just setting payment_method_data to always should do the trick. That would tell us to show the PM in subsequent checkout sessions https://docs.stripe.com/api/checkout/sessions/create?api-version=2025-05-28.basil#create_checkout_session-payment_method_data-allow_redisplay
Ie, no need for my savePaymentMethodToCustomer method at all?
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
Lovely ๐
This has been the most clear conversation about this Ive seen anywhere. Youre the best!
Glad I could help!