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

Customer Already exists error #377

Open
OutdatedGuy opened this issue Sep 22, 2023 · 13 comments · May be fixed by #415
Open

Customer Already exists error #377

OutdatedGuy opened this issue Sep 22, 2023 · 13 comments · May be fixed by #415
Assignees
Labels

Comments

@OutdatedGuy
Copy link

Steps to reproduce the behavior

  1. Use razorpay-node v2.9.2
  2. Run the below code snippet more than once
  3. See that it works ok the first time and throws error after that
  4. Now downgrade razorpay-node to v2.8.6
  5. And repeat step 2
  6. See no errors are occuring

Expected behavior

If customer with similar data already exists, their data should be returned when fail_existing is set to 0.

Actual behavior

Error is thrown when customer is similar data already exists.

Code snippets

razorpayInstance.customers.create({
  name: "",
  contact: request.phone_number,
  fail_existing: 0,
});

Node version

Node v18.17.1

Library version

razorpay v2.9.2

Additional Information

No response

@OutdatedGuy
Copy link
Author

@ankitdas13 @razorpay can you check on this?

@ankitdas13
Copy link
Contributor

@OutdatedGuy Apologies for the long delay, if you want to throw an error if the customer already existed then dont pass fail_existing property . Please check this doc for more detail
https://razorpay.com/docs/api/customers/create

@ankitdas13 ankitdas13 self-assigned this Dec 11, 2023
@OutdatedGuy
Copy link
Author

OutdatedGuy commented Dec 11, 2023

@OutdatedGuy Apologies for the long delay, if you want to throw an error if the customer already existed then dont pass fail_existing property . Please check this doc for more detail
https://razorpay.com/docs/api/customers/create

@ankitdas13 the docs you mentioned says that if the value of fail_existing property is set to 0 it should return data of the existing customer, NOT throw error.

Screenshot_20231211_145213.jpg

I want to retrieve the data of existing customer if available, but the code is throwing error instead.

@ankitdas13
Copy link
Contributor

@OutdatedGuy Here I'm creating the same customer which is already existing

fail_existing with 0 (Getting the data of the existing customer)

Screenshot 2023-12-11 at 4 35 48 PM

fail_existing with 1 (throw error)

Screenshot 2023-12-11 at 4 42 49 PM

@OutdatedGuy
Copy link
Author

@ankitdas13 Which version of the package are you using? Can you give link to the example above as a repo?

@OutdatedGuy
Copy link
Author

Yo @ankitdas13, below is the code I'm using to create customers and retrieve if already present:

razorpayInstance.customers.create({
  name: userDoc.data()?.name ?? "User",
  contact: request.auth.token.phone_number,
  fail_existing: 0,
});

And this is the error I'm getting if the customer with same details is already present:

{
  statusCode: 400,
  error: {
    code: 'BAD_REQUEST_ERROR',
    description: 'Customer already exists for the merchant',
    source: 'NA',
    step: 'NA',
    reason: 'NA',
    metadata: {}
  }
}

I'm using razorpay version v2.9.2 and a demo razorpay testing key rzp_test_xxxxxx.

I have tried using a live production key just in case and it still throws the error. Please help.

@ankitdas13
Copy link
Contributor

@OutdatedGuy Apologise for the delay. Have you resolved this issue?

@OutdatedGuy
Copy link
Author

@ankitdas13, No, It's giving me the same issue mentioned in this comment.

@KarThikCh-dev
Copy link

for me also the same issue , but while i am trying from public postman collection apis its working as expected but not with node-sdk

@nimesh-trackerbin
Copy link

just pass
fail_existing: "0"
instead of
fail_existing: 0

It seems to be working fine with this.

@OutdatedGuy
Copy link
Author

@nimesh-trackerbin cannot do that in typescript:

Screenshot 2024-02-12 at 6 25 14 PM

@OutdatedGuy
Copy link
Author

@ankitdas13 looks like the issue is when normalizeBoolean is removed in v2.9.2. I checked and the package is working fine in version v2.9.1

v2.9.1...v2.9.2#diff-a98fa4bf7fc9f2f4fab13f09ea5583d3097f5d1bc661b0af3c1759ea3bf053b8L3-R10

Can you verify and fix this ASAP? @ankitdas13

@OutdatedGuy
Copy link
Author

Hi @ankitdas13, is this issue being worked on? We are unable to update the package due to this issue.

OutdatedGuy added a commit to OutdatedGuy/razorpay-node that referenced this issue May 18, 2024
According to [official docs for customer creation](https://razorpay.com/docs/api/customers/create/) using razorpay API, `fail_existing` should be a string.

But the types defined where `boolean`, numeric `1` & `0`.

fixes razorpay#377, fixes razorpay#381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants