-
Notifications
You must be signed in to change notification settings - Fork 919
paypal_发起支付接口
精致的吴彦祖 edited this page Dec 14, 2020
·
1 revision
package com.paypal.test.controller.paypal;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.DefaultCurType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.PayOrder;
import com.egzosn.pay.paypal.bean.PayPalTransactionType;
import com.paypal.test.StringUnits;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.queue.PredicatedQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/paypal")
@Slf4j
@RestController
public class PaypalController {
@Autowired
private PayService service;
@RequestMapping("/pay")
public String pay() {
log.info("Payment initiated by user.");
PayOrder payOrder = new PayOrder("subject say something", "Order payment", new BigDecimal(4),
StringUnits.getUUID(),
PayPalTransactionType.sale);
payOrder.setCurType(DefaultCurType.USD);
Map orderInfo = service.orderInfo(payOrder);
String result=service.buildRequest(orderInfo, MethodType.POST);
log.info("result:{}",result);
return result;
}
@RequestMapping("/cancel")
public Object cancel(HttpServletRequest request){
Map<String,Object> map=StringUnits.getRequestValue(request);
return "You have cancelled the payment.";
}
@RequestMapping("/success")
public Object success(HttpServletRequest request) throws IOException {
Map<String,Object> params=service.getParameter2Map(request.getParameterMap(),request.getInputStream());
if(service.verify(params)){
log.info("Congratulations,payment sucessful.");
//做逻辑处理
return "Congratulations,payment sucessful.";
}
return "It's a pity that the payment failed.";
}
}