Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{error: key_error_code:ERROR_B2B_API_RETURNED_ERROR, key_error_result:{"code":"401","success":false}, status: FAILURE} #1

Closed
amanji1208 opened this issue Dec 1, 2023 · 15 comments

Comments

@amanji1208
Copy link

No description provided.

@amanji1208
Copy link
Author

anybody can help me please, when i am hitting pay api i am getting this response.

@amanji1208 amanji1208 changed the title {error: key_error_code:ERROR_B2B_API_RETURNED_ERROR key_error_result:{"code":"401","success":false } {error: key_error_code:ERROR_B2B_API_RETURNED_ERROR, key_error_result:{"code":"401","success":false}, status: FAILURE} Dec 1, 2023
@safvan-husain
Copy link

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;
}

@rajanarora27
Copy link

Are you still facing the issue ?

@rahmanprofile
Copy link

yes

@rajanarora27
Copy link

Do you have valid credentials like salt and salt index for creating the request?

@rahmanprofile
Copy link

rahmanprofile commented Apr 8, 2024 via email

@rajanarora27
Copy link

Please contact merchant-integration@phonepe.com, and they will guide you through all details.

@rahmanprofile
Copy link

rahmanprofile commented Apr 8, 2024 via email

@rajanarora27
Copy link

rajanarora27 commented Apr 8, 2024

The code is the same. You need valid credentials to generate the request and change the server to production while initiating the SDK.

@chakravartiraj
Copy link

I am facing the same issue while in the process of integrating PhonePe for Subscription Payment

@chakravartiraj
Copy link

The code is the same. You need valid credentials to generate the request and change the server to production while initiating the SDK.

Could you please tell me how to do just that for Subscription Payments?

@rajanarora27
Copy link

Subscription payment is not supported in the PhonPe Payment SDK. Please contact the merchant-integration@phonepe.com , they will guide you for the subscription payments.

@chakravartiraj
Copy link

Subscription payment is not supported in the PhonPe Payment SDK. Please contact the merchant-integration@phonepe.com , they will guide you for the subscription payments.

Thanks! Will do just that. You inout on the matter is much appreciated 😎✌️

@premkamble-1210
Copy link

const [environment, setEnvironment] = React.useState('SANDBOX');
const [merchantId, setMerchantId] = React.useState('PGTESTPAYUAT86');
const [appId, setAppId] = React.useState(null); // Replace with your actual App ID
const [enableLog, setEnableLog] = React.useState(true);

const generateMerchantTransactionId = () => {
const timestamp = Date.now();
const random = Math.floor(Math.random() * 1000000000);
const merchantPrefix = 'T';
return ${merchantPrefix}${timestamp}${random};
}

const submitPayment = async () => {
PhonePePaymentSDK.init(
environment,
merchantId,
appId,
enableLog
).then(() => {
const requestData = {
merchantId:'PGTESTPAYUAT',
merchantTransactionId:'transaction_123',
merchantUserId: '90223250',
amount:1000,
mobileNumber: '9999999999',
callbackUrl: 'https://webhook.site/callback-url', // Replace with your actual callback URL
paymentInstrument: {
type: 'UPI_INTENT',
targetApp: "com.phonepe.app"
}
};

  const salt_key = '099eb0cd-02cf-4e2a-8aca-3e6c6aff0399';
  const salt_index = 1;
  const payload = JSON.stringify(requestData);
  const payload_main = base64.encode(payload);
  console.log('Payload:', payload_main);
  const string = payload_main + '/pg/v1/pay' + salt_key;
  const checksum = sha256(string) + '###' + salt_index;
  console.log('Checksum:', checksum);


  

  PhonePePaymentSDK.startTransaction(
    payload_main,
    checksum,
    null,
    null
  ).then((response) => {
    console.log(response);
    // Handle success
  }).catch((error) => {
    console.log('Transaction Error:', error);
    // Handle error
  });

}).catch((error) => {
  console.log('Initialization Error:', error);
  // Handle initialization error
});

}
same error occurs like this {"error": "key_error_code:ERROR_B2B_API_RETURNED_ERRORkey_error_result:{"success":false,"code":"TOO_MANY_REQUESTS","message":"Too many requests. Please try again.","data":{}}", "status": "FAILURE"} how to resolve this issue

@pvr-07
Copy link

pvr-07 commented Sep 2, 2024

Kindly use the same MID: PGTESTPAYUAT86 in the request payload as well that was given by the integration support team instead of using PGTESTPAYUAT in the request payload. If you still facing any issue, you can write to "merchant-pgsupport@phonepe.com" or raise the query from the PhonePe dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants