Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing IdempotencyKey, Workaround? #1025

Closed
mrmarcsmith opened this issue May 30, 2019 · 6 comments · Fixed by #1775
Closed

Missing IdempotencyKey, Workaround? #1025

mrmarcsmith opened this issue May 30, 2019 · 6 comments · Fixed by #1775
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@mrmarcsmith
Copy link

Summary

We are currently experiencing an issue where when a customer adds a card it sometimes adds the same card 2-4 times. I noticed that the IdempotencyKey was removed from this framework somewhere along the line. What are we supposed to use instead to block double adding of cards to customers?

Code to reproduce

stripe.createToken(
                                card,

                                new TokenCallback() {
                                    public void onSuccess(Token token) {
                                        HashMap<String, Object> params = new HashMap<String, Object>();
                                        params.put("tokenId", token.getId());
                                        // REDACTED: save to database

                                    }

                                    public void onError(Exception error) {

                                        // Show localized error message
                                        Toast.makeText(getContext(),
                                                error.getMessage(),
                                                Toast.LENGTH_LONG
                                        ).show();
                                    }
                                });

Android version

All

Impacted devices

Galaxy S6

Installation method

build.gradle

SDK version

6.1.2

Other information

@mshafrir-stripe
Copy link
Collaborator

@mrmarcsmith I removed "Idempotency-Key" from Stripe API request headers in #991 because it could only be set internally and was never being set. Was there some way you were setting this header? What are you experiencing after updating?

@mshafrir-stripe mshafrir-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label May 30, 2019
@mrmarcsmith
Copy link
Author

Hi @mshafrir-stripe, Thanks for your prompt reply. To clarify I was never able to use "Idempotency-Key" in this framework but the documentation here says that I should be able to using the RequestOptions builder to add an idempotencyKey.
example code pulled from docs:

Stripe.apiKey = "sk_test_BLA";

Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 2000);
chargeParams.put("currency", "usd");
chargeParams.put("description", "Charge for jenny.rosen@example.com");
chargeParams.put("source", "tok_visa");
// ^ obtained with Stripe.js

RequestOptions options = RequestOptions
  .builder()
  .setIdempotencyKey("4YA9W3QKNuOyaCgb")
  .build();

charge.create(chargeParams, options);

@mshafrir-stripe
Copy link
Collaborator

I believe that documentation is for stripe-java, which is for server-side Java integrations, where we use the secret key.

None of the API methods that can be called from the SDK using the publishable key can actually capture payment, so you shouldn't need an idempotency key to prevent double-charging.

We can implement idempotency in the SDK for double-adding a card and similar scenarios (i.e. it was never implemented in the first place). Can you give me more details about the scenarios you're encountering that result in double-added cards?

@mrmarcsmith
Copy link
Author

mrmarcsmith commented May 30, 2019

Unfortunately I don't have a lot of information as to why the double cards are happening because its all real users who report the issue. We can't reproduce it in our dev environment but enough people have reported it that I know it's a problem with the code and not just a once-off issue. Maybe network requests are failing resulting and two tokens being created therefore 2 cards? I will keep you posted as to what we learn about this bug.

@mshafrir-stripe
Copy link
Collaborator

If you have an "add card" form, is it possible that users are quickly tapping twice on the "submit" button?

@mrmarcsmith
Copy link
Author

I suppose its possible but for us the "best" solution be the one that fixes both network requests or double taps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants