razorpay / razorpay-go

Razorpay Go SDK
MIT License
39 stars 25 forks source link

Panic on order create #14

Closed sanbornsen closed 3 years ago

sanbornsen commented 4 years ago

This is how my code looks like

data := map[string]interface{}{
    "amount":          amountInCents,
    "currency":        "INR",
    "receipt_id":      receiptID,
    "payment_capture": 1,
}
extra := map[string]string{}
body, err := os.RPClient.Order.Create(data, extra)
if err != nil {
    glog.Error("Failed from RazorPay - ", err)
}

I am getting this error

Failed from RazorPay - %!v(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)
sanbornsen commented 4 years ago

I figured that the order create request is returning 400 in the SDK but the same request on curl is returning 200. What am I missing?

shashankvivek commented 4 years ago

The documentation is incorrect, it should be receipt and not receipt_id in payload

data := map[string]interface{}{
    "amount":          amountInCents,
    "currency":        "INR",
    "receipt":      receiptID,  // <-- here
    "payment_capture": 1,
}
shyamkumargithub commented 4 years ago

This is how my code look like

data := map[string]interface{}{
    "amount":          1000,
    "currency":        "INR",
    "receipt":      receiptID,
    "payment_capture": 1,
}
extraHeader := map[string]string{
        "API_KEY": "SECRET_KEY",
    }
body, err := client.Order.Create(data, extraHeader)
if err != nil {
        log.Println(err)
}

I am getting this error when i create order with incorrect api key or secret key

%!v(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)

I want to know which type of error is returning

Same request on curl returning 401 response code 
rebootcode commented 4 years ago

401 response code is the error for UnAuthorized error or Invalid Key & Permission Denied

amitmahbubani commented 4 years ago

Few issues with error handling in the library.

  1. Errors are not being hydrated correctly here
  2. The Err attribute isn't set here, and is read later causing nil pointer errors.

Will patch this in an upcoming release.