#sadeghiamir_api

1 messages ยท Page 1 of 1 (latest)

junior urchinBOT
#

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

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

odd dragon
#

๐Ÿ‘‹ happy to help

#

it really depends on your flow

#

I would suggest creating the customer object as early as possible to avoid this issue

#

you can also use custom idempotency keys that are derived from the customer's email perhaps so that you don't create the same customer twice

honest fractal
#

how can I do this?

#

current logic is:
try {
final String email = user.getEmail();
final String userId = user.getId();
log.info("user is {}", user);
CustomerSearchResult result = getStripeCustomers(user);
Customer customer;

            // If no existing customer was found, create a new record
            if (result.getData().isEmpty()) {
                Map<String, String> metaData = new HashMap<>();
                metaData.put("firebaseUID", userId);
                CustomerCreateParams customerCreateParams = CustomerCreateParams.builder()
                        .setName(user.getFirstName())
                        .setEmail(email)
                        .setMetadata(metaData)
                        .build();

                customer = Customer.create(customerCreateParams);
            } else {
                customer = result.getData().get(0);
            }
            return customer;
        } catch (Exception ex) {
            log.error("exception in search or create stripe customer {} for user id {}", ex, user.getId());
        }
#

In my application user can update your email. thus relibale value for this purpose is id

#

please suggest me your idea according the id of user in my application.

odd dragon
#

the idempotency key isn't related to your customer Key but instead it defines the request you're sending

#

please read through the doc I sent you