razorpay / razorpay-node

Razorpay node.js bindings
MIT License
182 stars 111 forks source link

Customer Already exists error #377

Open OutdatedGuy opened 1 year ago

OutdatedGuy commented 1 year ago

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 commented 11 months ago

@ankitdas13 @razorpay can you check on this?

ankitdas13 commented 11 months ago

@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

OutdatedGuy commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

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

OutdatedGuy commented 11 months ago

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 commented 10 months ago

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

OutdatedGuy commented 10 months ago

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

KarThikCh-dev commented 9 months ago

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 commented 9 months ago

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

It seems to be working fine with this.

OutdatedGuy commented 9 months ago

@nimesh-trackerbin cannot do that in typescript:

Screenshot 2024-02-12 at 6 25 14 PM
OutdatedGuy commented 9 months ago

@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

https://github.com/razorpay/razorpay-node/compare/v2.9.1...v2.9.2#diff-a98fa4bf7fc9f2f4fab13f09ea5583d3097f5d1bc661b0af3c1759ea3bf053b8L3-R10

Can you verify and fix this ASAP? @ankitdas13

OutdatedGuy commented 7 months ago

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