hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

[BUG] Cannot use Payment Method while creating a payment

Open AmmarKhatri opened this issue 11 months ago • 7 comments

Bug Description

Currently using the sandbox environment of Hyperswitch and can successfully create a payment if I fill the information inside of card details in payment_method_data object. The issue is that I cannot utilize payment_token field to attach a payment method that pre-exists against a customer_id.

I use the "List payment methods for a customer" endpoint to retrieve payment_token (which does exist against a user): https://sandbox.hyperswitch.io/customers/{customer_id}/payment_methods

Following is the curl request being made (* represents a digit in cvc): curl --request POST \ --url https://sandbox.hyperswitch.io/payments \ --header 'Content-Type: application/json' \ --header 'api-key: <api-key>' \ --data '{ "amount": 10000, "currency": "USD", "capture_method": "automatic", "authentication_type": "no_three_ds", "confirm": true, "customer": { "id": "cus_824692528" }, "off_session": true, "payment_method": "card", "payment_token": "token_s696F41MDsZELzKTx5ew", "card_cvc": "***" }'

Expected Behavior

Expected response is a 200 status with payment details.

Actual Behavior

Received response(404): {"error":{"type":"invalid_request","message":"Payment method does not exist in our records","code":"HE_02"}}

Steps To Reproduce

Provide an unambiguous set of steps to reproduce this bug. Include code or configuration to reproduce, if relevant.

  1. Go to 'Payments API'
  2. Click on 'Make sure a customer exists and a payment method (preferrably a card) is attached to the customer.'
  3. Try creating a payment with the given Curl request in the bug description.

Context For The Bug

No response

Environment

Are you using hyperswitch hosted version? No If yes, please provide the value of the x-request-id response header to help us debug your issue.

If not (or if building/running locally), please provide the following details: Simply using the sandbox environment to interact and test the API at: https://api-reference.hyperswitch.io/api-reference/

Have you spent some time checking if this bug has been raised before?

  • [X] I checked and didn't find a similar issue

Have you read the Contributing Guidelines?

Are you willing to submit a PR?

None

AmmarKhatri avatar Mar 18 '24 20:03 AmmarKhatri

Hey @AmmarKhatri, I noticed that you're including "off_session": true in the confirm request. Are you attempting a MIT (merchant initiated transaction) where the customer is off-session?

ShankarSinghC avatar Mar 20 '24 09:03 ShankarSinghC

Hey @ShankarSinghC so here is what we wish to achieve. A customer hits an endpoint on our server and we can initiate a payment from customer to merchant (keeping in mind that it should follow all steps of payment cycle and either succeeds or fails within that single hit on that endpoint).

Inserting card details on each hit is unnecessary since we have payment_method created. The endpoint would be hit by the customer so coming back to your question,"off_session": false should be the case.

The error message has changed to: {"error":{"type":"invalid_request","message":"Missing required param: profile_id or business_country, business_label","code":"IR_04"}}

Tried using the api keys to create a business profile against my api-key but its not working nor is providing business_country, business_label working. It leads to error 400:

{"error":{"type":"invalid_request","message":"business_details are not configured in the merchant account","code":"IR_16"}}

AmmarKhatri avatar Mar 20 '24 11:03 AmmarKhatri

Hey @AmmarKhatri, this error occurs when there are multiple business profiles created against a merchant account. In order to create a payment, please pass the profile_id of the corresponding business profile. You can know more about business profiles here.

Narayanbhat166 avatar Mar 20 '24 12:03 Narayanbhat166

Thanks for guiding with the business profile. My query now looks something like this:

curl --request POST \ --url https://sandbox.hyperswitch.io/payments \ --header 'Content-Type: application/json' \ --header 'api-key: <api-key>' \ --data '{ "amount": 10000, "currency": "USD", "capture_method": "automatic", "authentication_type": "no_three_ds", "confirm": true, "customer": { "id": "cus_824692528" }, "off_session": false, "payment_method": "card", "payment_token": "token_lfE2U9m4WmvF6PO1q3vs", "card_cvc": "***", "profile_id": "pro_*************************" }'

The response still remains the same (404): {"error":{"type":"invalid_request","message":"Payment method does not exist in our records","code":"HE_02"}}

AmmarKhatri avatar Mar 20 '24 13:03 AmmarKhatri

Hey @AmmarKhatri, in the case of creation, we do not support token based payments. For token based payments, you need to create a payment and then make a confirm call using the payment token.

Payment Create

curl --request POST \
  --url https://sandbox.hyperswitch.io/payments \
  --header 'Content-Type: application/json' \
  --header 'api-key: <api-key>' \
  --data '{
  "amount": 10000,
  "currency": "USD",
  "capture_method": "automatic",
  "authentication_type": "no_three_ds",
  "confirm": false,
  "customer_id": "cus_824692528"
  }
}'

Payment confirm with the payment_token

curl --request POST \
  --url https://sandbox.hyperswitch.io/payments/{payment_id}/confirm \
  --header 'Content-Type: application/json' \
  --header 'api-key: <api-key>' \
  --data '{
    "payment_method": "card",
    "payment_token": "token_s696F41MDsZELzKTx5ew",
    "card_cvc": "***"
}'

ShankarSinghC avatar Mar 22 '24 15:03 ShankarSinghC

Thank you! @ShankarSinghC

That seems to successfully complete the execution cycle but why do we break it into multiple stages when these calls can be made sequentially? Is it just a missing feature or is there a reason behind it? Just asking for my own understanding.

AmmarKhatri avatar Mar 23 '24 07:03 AmmarKhatri

Hey @AmmarKhatri, As of now, we do not support this feature, but we are working on it. Going forward, we'll be adding support for payment_token based payments using a single payments create call

ShankarSinghC avatar Mar 26 '24 10:03 ShankarSinghC