I am trying to integrate bKash Payment Gateway (PGW) in Unity using their rest APIs. The first step is generating token. For which it requires an Username & Password passed in their checkout/token/grant
API's request header. The issue comes from the password. Because it contains special characters the API fails with an error. There is no option to change the password or passing the password anywhere else other then request header. Is there any solution for this?
It works perfectly fine in postman. My code also works fine if the password does not contains ")"
My code:
private IEnumerator CallApi(string api, string json, Action<string> onResponse) { var request = new UnityWebRequest(api, "POST"); byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json); request.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend); request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Accept", "application/json"); request.SetRequestHeader("username", _bkashData.username ?? ""); request.SetRequestHeader("password", _bkashData.password ?? ""); request.SetRequestHeader("X-App-Key", _bkashData.appkey ?? ""); request.SetRequestHeader("Authorization", _token ?? ""); AppUtils.PrintLog($"bKash Api Request: {api} | Request: {json} | pass: {_bkashData.password}", AppConstants.Color.Other3); yield return request.SendWebRequest(); AppUtils.PrintLog($"bKash Api Response: {api} | Response: {request.downloadHandler.text}", AppConstants.Color.Other3); if (request.result == UnityWebRequest.Result.Success) { onResponse(request.downloadHandler.text); } else { AppUtils.PrintLog($"bKash Api Failed: {request.error} | API: {api} | Request: {json}"); } }
The integration guide provided by bKash:
The error I am receiving:
InvalidOperationException: Header value contains invalid charactersUnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at <46c9a6f2bcd549f2b7ce644973f43ea8>:0)bKashHandler+<CallApi>d__15.MoveNext () (at Assets/Scripts/Utils/bKashHandler.cs:71)UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <e509afeff7384f24a8f0ac30527ff01c>:0)UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)bKashHandler:GetToken(Action) (at Assets/Scripts/Utils/bKashHandler.cs:55)bKashHandler:CreatePayment(PriceData) (at Assets/Scripts/Utils/bKashHandler.cs:112)DepositFundScript:OnSubmit() (at Assets/Scripts/GUI/DepositFundScript.cs:328)UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/EventSystem.cs:530)
Test password to reproduce the issue:
")^[su0ZC27M"