【发布时间】:2017-10-14 00:25:48
【问题描述】:
我正在使用 Spring Web 服务进行 PayPal IPN 侦听器配置。我在 Google 中搜索过,我找不到太多有用的 Java 实现资源,只有很多 PHP 示例。
我正在尝试使用 PayPal Recurring Payment API 为我的 Web 应用程序创建一个定期付款选项。我有一些高级会员资格,因为我的网站用户必须支付一些钱才能订阅会员资格。我创建了一个计费计划、计费协议,并使用计费协议响应中的批准 URL 从用户那里获得授权。我被困在 IPN 侦听器中。我不知道如何在 Spring Web Service 中配置 IPN 侦听器。我需要在我的 Web 应用程序中具有自动续订功能。这是我的听众
@RequestMapping(value = "ipn", method = RequestMethod.POST)
public @ResponseBody
Map<String,Object> IPNListener(HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
try {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("https://ipnpb.sandbox.paypal.com/cgi-bin/webscr");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cmd", "_notify-validate")); //You need to add this parameter to tell PayPal to verify
for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
String name = e.nextElement();
String value = request.getParameter(name);
params.add(new BasicNameValuePair(name, value));
}
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse resp = client.execute(post);
InputStream is = resp.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String result = "";
String line = null;
while ((line = br.readLine()) != null) {
result += line;
}
String rc = result.trim();
logger.info("IPN Listener Result :: " + rc);
if ("VERIFIED".equals(rc)) {
logger.info("IPN Listener Verified");
// Add Premium Membership for User
}
} catch (Exception e) {
logger.error("IPN Listener Exception ");
e.printStackTrace();
}
return null;
}
我的 Web 应用程序中有很多用户。这里我不知道
如何识别哪个用户的支付完成了?
我需要哪个用户激活高级会员?
在创建计费计划或计费协议时,有什么方法可以配置 member_Id 和 User_Id 以返回 IPN 侦听器?
【问题讨论】:
标签: java spring web-services paypal paypal-ipn