Java 在Google应用程序引擎上验证事务
我正试图让交易验证在谷歌Play不可用的国家在Android上进行应用内购买 当使用沙盒API时,我的本地Google应用程序引擎开发服务器上的一切似乎都运行良好。服务器向PayPal发送带有事务ID的请求,并返回包含事务状态的JSON响应 但是,当我将代码上传到Google App Engine时,它会使用带有相应凭据的live API。在那里执行事务验证时,我从Paypal REST SDK中得到以下错误:Java 在Google应用程序引擎上验证事务,java,android,google-app-engine,paypal,Java,Android,Google App Engine,Paypal,我正试图让交易验证在谷歌Play不可用的国家在Android上进行应用内购买 当使用沙盒API时,我的本地Google应用程序引擎开发服务器上的一切似乎都运行良好。服务器向PayPal发送带有事务ID的请求,并返回包含事务状态的JSON响应 但是,当我将代码上传到Google App Engine时,它会使用带有相应凭据的live API。在那里执行事务验证时,我从Paypal REST SDK中得到以下错误: Response Code : 401 with response : {"erro
Response Code : 401 with response : {"error":"invalid_client","error_description":"The client credentials are invalid"}
在HttpServlet中,我使用此选项将常量DEBUG设置为true或false:
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
String dev = config.getServletContext().getServerInfo();
if (dev.contains("Development")) {
Constants.DEBUG = true;
} else {
Constants.DEBUG = false;
}
}
使用下面的代码验证事务ID。它获取用于进行API调用的访问令牌,然后验证事务id。我还创建了一个自定义配置,根据调试常量将GOOGLE_APP_引擎设置为true,并将模式设置为sandbox或live,这是因为我无法使getServletContext.getResourceAsStreamsdk_config.properties工作,因为它拒绝访问错误
public static String getAccessToken() throws PayPalRESTException {
String clientSecret, clientID;
if (Constants.DEBUG) {
clientSecret = Constants.CLIENT_SECRET_SANDBOX;
clientID = Constants.CLIENT_ID_SANDBOX;
} else {
clientSecret = Constants.CLIENT_SECRET_LIVE;
clientID = Constants.CLIENT_ID_LIVE;
}
return new OAuthTokenCredential(clientID, clientSecret,
getPaypalConfig()).getAccessToken();
}
public static Map<String, String> getPaypalConfig() {
Map<String, String> config = new HashMap<>();
config.put(com.paypal.core.Constants.GOOGLE_APP_ENGINE,
String.valueOf(true));
if (Constants.DEBUG) {
config.put(com.paypal.core.Constants.MODE,
com.paypal.core.Constants.SANDBOX);
} else {
config.put(com.paypal.core.Constants.MODE,
com.paypal.core.Constants.LIVE);
}
return config;
}
public static boolean payPalVerifier(String saleId)
throws PayPalRESTException {
if (accessToken == null) {
accessToken = Utils.getAccessToken();
apiContext = new APIContext(accessToken);
apiContext.setConfigurationMap(Utils.getPaypalConfig());
}
boolean completed = false;
Payment pay = Payment.get(apiContext, saleId);
for (Transaction transaction : pay.getTransactions()) {
for (RelatedResources relatedResources : transaction
.getRelatedResources()) {
if (com.pixplicity.Constants.DEBUG) {
completed = relatedResources.getSale().getState()
.equals("completed")
|| relatedResources.getSale().getState()
.equals("pending");
} else {
completed = relatedResources.getSale().getState()
.equals("completed");
}
}
}
return completed;
}
我如何解决这个问题