Не работает тестовый платёж кошелька Яндекс Денег
Я работаю с API кошелька Яндекс Денег. Хочу согласно документации Яндекс денег сделать тестовый платёж, указав параметр test_payment test_payment. Вот мой Код:
@RequestMapping(value = "/successPayment", method = RequestMethod.GET)
@ResponseBody
public String testMethod(@RequestParam(value = "code", required = true) String code
/* HttpSession session,*/
) throws URISyntaxException, IOException {
//https://money.yandex.ru/oauth/authorize?client_id=id_application&response_type=code&redirect_uri=http://localhost:8080/successPayment&scope=payment.to-account("numberCosehelek").limit(,20)
//Get Token
URL urlgetAccessToken = new URL(" https://money.yandex.ru/oauth/token");
Map<String,Object> paramsForToken = new LinkedHashMap<>();
paramsForToken.put("code",code);
paramsForToken.put("client_id", "id_app");
paramsForToken.put("grant_type", "authorization_code");
paramsForToken.put("redirect_uri", "http://localhost:8080/successPayment");
StringBuilder postDataForToken = new StringBuilder();
for (Map.Entry<String,Object> param : paramsForToken.entrySet()) {
if (postDataForToken.length() != 0) postDataForToken.append('&');
postDataForToken.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postDataForToken.append('=');
postDataForToken.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytesForToken = postDataForToken.toString().getBytes("UTF-8");
HttpURLConnection connForToken = (HttpURLConnection)urlgetAccessToken.openConnection();
connForToken.setRequestMethod("POST");
connForToken.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connForToken.setRequestProperty("Content-Length", String.valueOf(postDataBytesForToken.length));
connForToken.setDoOutput(true);
connForToken.getOutputStream().write(postDataBytesForToken);
Reader inForToken = new BufferedReader(new InputStreamReader(connForToken.getInputStream(), "UTF-8"));
StringBuilder sbForToken = new StringBuilder();
for (int cForToken; (cForToken = inForToken.read()) >= 0;)
sbForToken.append((char)cForToken);
String responseForToken = sbForToken.toString();
ObjectMapper mapperForToken = new ObjectMapper();
AccessToken accessToken = mapperForToken.readValue(responseForToken.toString(), AccessToken.class);
String token=accessToken.getAccess_token();
//request-payment
URL urlRequestPayment = new URL(" https://money.yandex.ru/api/request-payment");
Map<String,Object> paramsForRequestPayment = new LinkedHashMap<>();
paramsForRequestPayment.put("pattern_id","p2p");
paramsForRequestPayment.put("to", "numberCoshelek");
paramsForRequestPayment.put("amount", 20.00);
paramsForRequestPayment.put("message", "perevod");
paramsForRequestPayment.put("comment", "perevod");
paramsForRequestPayment.put("test_payment", true);
paramsForRequestPayment.put("test_result", "success");
StringBuilder postDataRequestPayment = new StringBuilder();
for (Map.Entry<String,Object> param : paramsForRequestPayment.entrySet()) {
if (postDataRequestPayment.length() != 0) postDataRequestPayment.append('&');
postDataRequestPayment.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postDataRequestPayment.append('=');
postDataRequestPayment.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytesRequestPayment = postDataRequestPayment.toString().getBytes("UTF-8");
String bearer=Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)).replaceAll("(\n)", "");
HttpURLConnection connForRequestPayment = (HttpURLConnection)urlRequestPayment.openConnection();
connForRequestPayment.setRequestMethod("POST");
connForRequestPayment.setRequestProperty("Authorization", "Bearer "+token);
connForRequestPayment.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connForRequestPayment.setRequestProperty("Content-Length", String.valueOf(postDataBytesRequestPayment.length));
connForRequestPayment.setDoOutput(true);
connForRequestPayment.getOutputStream().write(postDataBytesRequestPayment);
Reader inRequestPayment = new BufferedReader(new InputStreamReader(connForRequestPayment.getInputStream(), "UTF-8"));
StringBuilder sbForRequestPayment = new StringBuilder();
for (int cForRequestPayment; (cForRequestPayment = inRequestPayment.read()) >= 0;)
sbForRequestPayment.append((char)cForRequestPayment);
String responseForRequestPayment = sbForRequestPayment.toString();
ObjectMapper mapperRequestPayment = new ObjectMapper();
RequestPayment requestPayment = mapperRequestPayment.readValue(responseForRequestPayment.toString(), RequestPayment.class);
String requestId=requestPayment.getRequest_id();
URL urlProcessPayment = new URL(" https://money.yandex.ru/api/process-payment");
Map<String,Object> paramsForProcessPayment = new LinkedHashMap<>();
paramsForProcessPayment.put("request_id",requestId);
StringBuilder postDataProcessPayment = new StringBuilder();
for (Map.Entry<String,Object> param : paramsForProcessPayment.entrySet()) {
if (postDataProcessPayment.length() != 0) postDataProcessPayment.append('&');
postDataProcessPayment.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postDataProcessPayment.append('=');
postDataProcessPayment.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytesProcessPayment = postDataProcessPayment.toString().getBytes("UTF-8");
HttpURLConnection connForProcessPayment = (HttpURLConnection)urlProcessPayment.openConnection();
connForProcessPayment.setRequestMethod("POST");
connForProcessPayment.setRequestProperty("Authorization", "Bearer "+token);
connForProcessPayment.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connForProcessPayment.setRequestProperty("Content-Length", String.valueOf(postDataBytesProcessPayment.length));
connForProcessPayment.setDoOutput(true);
connForProcessPayment.getOutputStream().write(postDataBytesProcessPayment);
Reader inProcessPayment = new BufferedReader(new InputStreamReader(connForProcessPayment.getInputStream(), "UTF-8"));
StringBuilder sbForProcessPayment = new StringBuilder();
for (int cForProcessPayment; (cForProcessPayment = inProcessPayment.read()) >= 0;)
sbForProcessPayment.append((char)cForProcessPayment);
String responseForProcessPayment = sbForProcessPayment.toString();
ObjectMapper mapperProcessPayment = new ObjectMapper();
ProcessPayment processPayment= mapperProcessPayment.readValue(responseForProcessPayment.toString(), ProcessPayment.class);
return responseForRequestPayment;
}
Но я получаю следующий результат:
{
error: "not_enough_funds",
status: "refused"
}
Недостаточно средств. Дело в том, что у меня на счету ничего нет. Но как я понял тестовый платёж не предполагает перевода никаких денег.Но у меня он не работает. Помогите пожалуйста разобраться с проблемой.