You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PhonePe支付接口报错KEY_NOT_CONFIGURED问题解决咨询

解决PhonePe支付接口KEY_NOT_CONFIGURED错误

问题重现

调用PhonePe的pay接口发起支付时触发KEY_NOT_CONFIGURED错误,代码及报错如下:

@GetMapping("/initiate")
public String initiatePayment() {
    String merchantId = "M15IHWI5YI3Y";
    String merchantTransactionId = UUID.randomUUID().toString().substring(0, 34);
    long amount = 100;
    String merchantUserId = "MUID1234";
    String callbackUrl = "https://api.dolby.com/media/webhooks";
    String redirectUrl = "https://sharkdom.com/";
    String redirectMode = "REDIRECT";

    System.out.println("phonepeClient------------------->" + phonepeClient);

    PgPayRequest pgPayRequest = PgPayRequest.PayPagePayRequestBuilder().amount(amount).merchantId(merchantId)
            .merchantTransactionId(merchantTransactionId).callbackUrl(callbackUrl).merchantUserId(merchantUserId)
            .redirectUrl(redirectUrl).redirectMode(redirectMode).build();
    PhonePeResponse<PgPayResponse> payResponse = phonepeClient.pay(pgPayRequest);
}

报错信息:

PhonePeException(super=com.phonepe.sdk.pg.common.http.PhonePeException: , responseCode=400, phonePeResponse=PhonePeResponse(success=false, code=KEY_NOT_CONFIGURED, message=Key not found for the merchant, data={}))

解决步骤

该错误核心是商户对应的密钥未正确配置或无效,按以下顺序排查:

  • 验证PhonePe客户端初始化的密钥配置
    确保初始化phonepeClient时,传入了与M15IHWI5YI3Y匹配的商户密钥,示例初始化代码:

    PhonePeClient phonePeClient = new PhonePeClientBuilder()
        .setMerchantId("M15IHWI5YI3Y")
        .setMerchantKey("从PhonePe商户后台获取的密钥")
        .setEnvironment(Environment.SANDBOX) // 区分沙盒/生产环境,密钥不通用
        .build();
    

    同时检查控制台输出的phonepeClient是否为有效实例,避免未初始化或null的情况。

  • 核对商户后台的密钥状态
    登录PhonePe商户后台,确认M15IHWI5YI3Y商户ID已激活,对应的API密钥未过期、未被禁用;还要确认密钥与当前使用的环境(沙盒/生产)一致,两种环境的密钥独立,不能混用。

  • 检查商户ID与密钥的一致性
    确保初始化phonepeClient时使用的merchantId和请求参数中的merchantId完全相同,避免出现商户ID不匹配的情况。

  • 更新SDK版本(可选)
    如果使用的是旧版PhonePe SDK,尝试升级到最新稳定版,排除版本兼容导致的配置问题。

内容的提问来源于stack exchange,提问作者Ummed Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 05:37:13