Reputation: 444
Here is the documentation link Android SDK: https://developer.phonepe.com/v1/docs/android-pg-sdk-integration . I am trying to integrate phonepe Payment Gateway. When i tried to request payment I got this response In onActivityResult.E/onActivityResult4: key_error_code : ERROR_B2B_API_RETURNED_ERROR and {"success":false, "code":"401"}. What should be the next solution to this?
Upvotes: 2
Views: 2850
Reputation: 23
I had the same issue on flutter, it was due to bad input, I was giving wrong body and salt the correct body and salt:
String getSalt() {
String apiEndPoint = "/pg/v1/pay";
var salt = "099eb0cd-02cf-4e2a-8aca-3e6c6aff0399";
var index = 1;
return sha256
.convert(utf8.encode(getBody() + apiEndPoint + salt))
.toString() +
"###" +
index.toString();
}
String getBody() {
var body = {
"merchantId": "PGTESTPAYUAT",
"merchantTransactionId": "transaction_123",
"merchantUserId": "90223250",
"amount": 1000,
"mobileNumber": "9999999999",
"callbackUrl": "https://webhook.site/55d95b9b-bec9-491e-b257-cbaf0ff7aa7e",
"paymentInstrument": {"type": "UPI_INTENT", "targetApp": "com.phonepe.app"},
"deviceContext": {"deviceOS": "ANDROID"}
}; // Encode the request body to JSON
String jsonBody = jsonEncode(body);
String base64EncodedBody = base64Encode(utf8.encode(jsonBody));
return base64EncodedBody;
}
Upvotes: 1