Midtrans / midtrans-go

This is the Official Go API client/library for Midtrans Payment API. More information about the product and see documentation at http://docs.midtrans.com for more technical details
https://pkg.go.dev/github.com/midtrans/midtrans-go
MIT License
93 stars 25 forks source link

Error response body for create payout and approve payout different #5

Closed richardreynaldo closed 2 years ago

richardreynaldo commented 3 years ago

image

image

resulting in error in unmarshal json when getting the error response body

Xaxxis commented 3 years ago

Hi @richardreynaldo it's expected to create and approve payout has a different payload. You can find the detail docs from iris API documentation

Based on those error screenshots, happened cause you don't send beneficiary_name in create payout request. this is a mandatory field. The minimum request for the body should be like this { "payouts": [ { "beneficiary_name": "John Doe", "beneficiary_account": "1172993826", "beneficiary_bank": "bni", "amount": 100000, "notes": "Payout April 17" } ] }

Also, you can download the Postman collection that covers the Iris API from this page https://docs.midtrans.com/en/technical-reference/postman-collection?id=midtrans-iris-api-postman-collection

Any related general questions, you can reach out to us via email support@midtrans.com Thank you

richardreynaldo commented 3 years ago

hi @Xaxxis I want to know if you do expect the difference in errors of the create and approve error response body is different? you can see that in the create payout error the errors would be "errors": { "0": [ "Beneficiary name can't be blank", "Beneficiary name only allows space, alphanumeric, non-latin letter, non-latin numeric, \".\" and \",\" characters" ] } meanwhile in the approve payout error the errors would be "errors": [ "Reference nos 'ce5u4cppr7fkehf45g' are not queued" ]

Xaxxis commented 3 years ago

Hi @richardreynaldo yes this is expected, those APIs have a different error. On creating payout the error happened due to missing the beneficiary_name field

On the Approve API, we can't find the reference number ce5u4cppr7fkehf45g. Makes sure you send the correct value reference number. However, if Iris didn't find the reference number, it will reproduce the error message "errors": [ "Reference nos 'ce5u4cppr7fkehf45g' are not queued" ]

richardreynaldo commented 3 years ago

@Xaxxis but why does the create payout errors have "0" inside the errors json meanwhile the approve payout doesn't have the "0" inside the json?

richardreynaldo commented 3 years ago

@Xaxxis and because of that the error we got on midtrans.error is this &{Message:Invalid body response, parse error during API request to Midtrans with message: json: cannot unmarshal object into Go struct field CreatePayoutResponse.errors of type []string StatusCode:400 RawError:json: cannot unmarshal object into Go struct field CreatePayoutResponse.errors of type []string RawApiResponse:0xc000656000}

rizdaprasetya commented 3 years ago

I think you refers to the difference of errors JSON structure between that 2 API endpoints, in that case, yes it seems like a valid issue. And currently this Go module can't properly parse the errors response from /payouts. (Potential quick workaround is to change this line to accept interface{} )

But for proper parsing, we'll need to check this with our Iris API team first, and get back to you sometimes around next week. Thanks for reporting.

richardreynaldo commented 3 years ago

@rizdaprasetya ah sorry that's my point, my issues before maybe unclear. thanks a lot for the attention.

rizdaprasetya commented 3 years ago

Sorry late update, few days ago our Iris API team acknowledged the issue, which is a valid issue. They will check & try to improve it. Also the reason why create payout have index as key was because on payout creation, each payout can have more than 1 error.

We are waiting for the proper spec from them to update this Go module accordingly. Thanks! As for now, the workaround is:

Xaxxis commented 2 years ago

Hi @richardreynaldo the issue has been solved on the new version v1.2.2 ya

Thank you