我是 Stripe API 的新手。我想使用 Spring MVC 在我的Java J2EE应用程序中嵌入支付网关。我正在使用条纹。
到目前为止,我已经完成的工作是将checkout.js
添加到我的结帐页面并点击付费卡片按钮。然后它成功打开一个弹出窗口,其中包含必要的卡片详细信息。
单击付款按钮时,它应转到条带并为我生成令牌,然后重定向到成功页面。但我无法在后端持有那个令牌并做必要的事情。
您能否在 Spring MVC 中提供符合我全部要求的示例代码?
提前致谢。
答案 0 :(得分:0)
mc mirror
@RequestMapping(value =" / checkout",method = RequestMethod.GET) public String checkout(ModelMap map,HttpServletRequest request){
this is my controller to redirect to the checkout page
* /
//String stripePublicKey = "pk_test_vsp3nRQS4PqW0aqP6PG6cdef";
String stripePublicKey = "pk_test_vsp3nRQS4PqW0aqP6PG6cdef";
/* String token = request.getParameter("stripeToken");
System.out.println("print token @@@@@@@@@@@" + token);
答案 1 :(得分:0)
这是我的服务类来收取卡 公共类StripeApiImpl实现了StripeApi {
@Override
public Charge charge(ChargeRequest chargeRequest) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", chargeRequest.getAmount());
chargeParams.put("currency", chargeRequest.getCurrency());
chargeParams.put("description", chargeRequest.getDescription());
chargeParams.put("source", chargeRequest.getStripeToken());
return Charge.create(chargeParams);
}
答案 2 :(得分:0)
实际上我想通过条形码退房后收取信用卡或借记卡。我的控制器会在成功交易后对卡进行收费以及结果页面。
@RequestMapping(value="/charge", method = RequestMethod.POST)
public String charge(ChargeRequest chargeRequest, Model model,HttpServletRequest request)
throws StripeException {
Stripe.apiKey = "sk_test_9kYpQEbABJQDw7PGSQ2Ji0m7";
StripeApi stripeApi = new StripeApiImpl();
chargeRequest.setDescription("Example charge");
chargeRequest.setCurrency(Currency.EUR);
chargeRequest.setAmount(5000);
chargeRequest.setStripeEmail("lipsapatra23@gmail.com");
Charge charge = stripeApi.charge(chargeRequest);
model.addAttribute("id", charge.getId());
model.addAttribute("status", charge.getStatus());
model.addAttribute("chargeId", charge.getId());
model.addAttribute("balance_transaction", charge.getBalanceTransaction());
return "result";
}