Creating Payment but got error

Hello,I am currentlyy trying to create a payment request with the below code.

try {
        const body = {
                amount: 101,
                currency: "INR",
                payment_method: {
                    type: "in_rupay_debit_card"
                }
           };
            const result = await makeRequest('POST', '/v1/payments', body);
            res.json({"output": result})        
          } catch (error) {
            res.json({"output": error})
          }

But getting error !

"body": {
      "status": {
        "error_code": "CREATE_CARD_TYPE_REQUIRES_ONLY_ONE_OF_FIELDS_OR_TOKEN",
        "status": "ERROR",
        "message": "The request tried to add a payment method to a customer, but both the 'type' and 'token' body parameters are set, or they are both unset. The request was rejected. Corrective action: Set one of the following parameters: 'type' or 'token'.",
        "response_code": "CREATE_CARD_TYPE_REQUIRES_ONLY_ONE_OF_FIELDS_OR_TOKEN",
        "operation_id": "b80c5fa2-adaf-4b53-9a56-7aa7fe39937b"
      }
    }

Can anyone suggest me how to resolve it?

Hi @ritikranjan12, if you’re trying to create a payment request you need to look at Get Required Fields for Payment Method to see what to include for the required fields.

If you want to just use the payment method type, this would need to be tokenized for a customer and then you can include the card ID.

Here’s what your request should look like

Create Payment

Request
{
	"amount": 101,
	"currency": "INR",
	"payment_method": {
		"type": "in_rupay_debit_card",
		"fields": {
			"number": "4111111111111111",
			"expiration_month": "12",
			"expiration_year": "23",
			"name": "John Doe",
			"cvv": "345"
		},
		"metadata": {
		"merchant_defined": true
	}
	},
	"capture": true
}
Response
{
    "status": {
        "error_code": "",
        "status": "SUCCESS",
        "message": "",
        "response_code": "",
        "operation_id": "34660636-9842-45f9-983a-895ed3bde92a"
    },
    "data": {
        "id": "payment_be6ebf0d94ad13c87c12348bea96cdab",
        "amount": 101,
        "original_amount": 101,
        "is_partial": false,
        "currency_code": "INR",
        "country_code": "in",
        "status": "CLO",
        "description": "",
        "merchant_reference_id": "",
        "customer_token": "cus_7580469a79f773751a49a8e11013098f",
        "payment_method": "card_c5acbc0404089a7faf113a44e906edf6",
        "payment_method_data": {
            "id": "card_c5acbc0404089a7faf113a44e906edf6",
            "type": "in_rupay_debit_card",
            "category": "card",
            "metadata": {
                "merchant_defined": true
            },
            "image": "",
            "webhook_url": "",
            "supporting_documentation": "",
            "next_action": "not_applicable",
            "name": "John Doe",
            "last4": "1111",
            "acs_check": "unchecked",
            "cvv_check": "unchecked",
            "bin_details": {
                "type": null,
                "brand": null,
                "level": null,
                "country": null,
                "bin_number": "411111"
            },
            "expiration_year": "23",
            "expiration_month": "12",
            "fingerprint_token": "ocfp_2a694038316f52122bbbb3ae926cfda9"
        },
        "auth_code": null,
        "expiration": 1662745417,
        "captured": true,
        "refunded": false,
        "refunded_amount": 0,
        "receipt_email": "",
        "redirect_url": "",
        "complete_payment_url": "",
        "error_payment_url": "",
        "receipt_number": "",
        "flow_type": "",
        "address": null,
        "statement_descriptor": "Test Business",
        "transaction_id": "",
        "created_at": 1662140617,
        "metadata": {},
        "failure_code": "",
        "failure_message": "",
        "paid": true,
        "paid_at": 1662140618,
        "dispute": null,
        "refunds": null,
        "order": null,
        "outcome": null,
        "visual_codes": {},
        "textual_codes": {},
        "instructions": [
            {
                "name": "instructions",
                "steps": [
                    {
                        "step1": "Enter card details."
                    },
                    {
                        "step2": "Goto 3DS page and enter OTP."
                    },
                    {
                        "step3": "Complete payment."
                    }
                ]
            }
        ],
        "ewallet_id": "ewallet_db4ad4a76278f94c4a83dd9b28b483ed",
        "ewallets": [
            {
                "ewallet_id": "ewallet_db4ad4a76278f94c4a83dd9b28b483ed",
                "amount": 101,
                "percent": 100,
                "refunded_amount": 0
            }
        ],
        "payment_method_options": {},
        "payment_method_type": "in_rupay_debit_card",
        "payment_method_type_category": "card",
        "fx_rate": 1,
        "merchant_requested_currency": null,
        "merchant_requested_amount": null,
        "fixed_side": "",
        "payment_fees": null,
        "invoice": "",
        "escrow": null,
        "group_payment": "",
        "cancel_reason": null,
        "initiation_type": "customer_present",
        "mid": "",
        "next_action": "not_applicable",
        "error_code": "",
        "remitter_information": {}
    }
}

Got it!
But It does not provide me the complete url for payment,then how may i proceed further?
I had added my card details too!!

It looks to me like your request contains neither the ‘fields’ object nor the ‘payment_method’ token. You must have one or the other, and not both.

You have to provide a value for ‘complete_payment_url’ and ‘error_payment_url’ when the payment method is in_rupay_debit_card. These are the URLs that your customer is redirected to after he completes the payment or there is an error, respectively.

1 Like