Razorpay integration error (not enough arguments in call to client.Order.Create)

316 views Asked by At

Tried to implement, based on the official documentation in razorpay site Code :

 11 func indexpageGet(c *gin.Context) {
 12
 13         client := razorpay.NewClient("rzp_test_zlsYshjhjhjln", "9LtUy4qhghghgh2asp59es")
 14
 15         data := map[string]interface{}{
 16                 "amount":          1234,
 17                 "currency":        "INR",
 18                 "receipt_id":      "some_receipt_id",
 19         }
 20         body, err := client.Order.Create(data)
 21         if err != nil {
 22                 fmt.Println(err)
 23         }
 24
 25         fmt.Println(body)

Compile Error:

./main.go:20:34: not enough arguments in call to client.Order.Create
        have (map[string]interface {})
        want (map[string]interface {}, map[string]string)

My Observation: function client.Order.Create(data) required two arguments I confirmed it from razorpay library (see the function definition part). So the solution is I need to pass second argument (extraHeaders) too.

// Create creates a new order for the given data
func (order *Order) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
    return order.Request.Post(constants.ORDER_URL, data, extraHeaders)
} 

The point I am stuck is what is extraHeaders and what value I need to pass?

2

There are 2 answers

0
Arun On BEST ANSWER

based on the comments in the Question, Made 2 things to made it work : (Refer the comments in below code )

 11 func indexpageGet(c *gin.Context) {
 12
 13         client := razorpay.NewClient("rzp_test_zlsYsrvuUxxhln", "9LtUy4qpLCOtl4Gz2asp59es")
 14
 15         data := map[string]interface{}{
 16                 "amount":          1234,
 17                 "currency":        "INR",
 18                 "receipt":              "110",
 19                 //"receipt_id":      "some_receipt_id", // 1st Mistake in documentation it should be 'receipt', corrected in above line
 20         }
 21         
 22         extraHeader := make(map[string]string) // 2nd Mistake in documentation , corrected by creating an empty map and passed as the second argument in below function.
 23         body, err := client.Order.Create(data,extraHeader)
 24         if err != nil {
 25                 fmt.Println(err)
 26         }
 27
 28         fmt.Println(body)
0
Shreyash Ganvir On

The documentation says that create functions takes two arguments one as map[string]interface{} and the other as extraHeaders which is map[string]string. You can set the extraHeaders parameter to nil and your code will work.