1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.fdkankan.pay.service.impl;
- import com.fdkankan.pay.common.ResultCode;
- import com.fdkankan.pay.entity.Order;
- import com.fdkankan.pay.exception.BusinessException;
- import com.fdkankan.pay.service.IOrderService;
- import com.fdkankan.pay.util.alipay.sdk.AlipayService;
- import com.fdkankan.pay.util.paypal.sdk.PaypalService;
- import com.fdkankan.pay.util.stripe.StripeService;
- import com.fdkankan.pay.util.wx.WechatPayService;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- @Service
- public class PayOrderService {
- @Autowired
- IOrderService orderService;
- @Autowired
- WechatPayService wechatPayService ;
- @Autowired
- AlipayService alipayService;
- @Autowired
- PaypalService paypalService;
- @Autowired
- StripeService stripeService;
- public Object openPay(Order param, String ipAddr,String lang) throws Exception {
- if(StringUtils.isBlank(param.getOrderSn()) || param.getPayType() == null){
- throw new BusinessException(ResultCode.PARAM_ERROR);
- }
- //jsApi微信支付,需要公众号openId
- if(param.getPayType() == 1 && StringUtils.isBlank(param.getOpenId())){
- throw new BusinessException(ResultCode.PARAM_ERROR);
- }
- Order order = orderService.getByOrderSn(param.getOrderSn());
- if(order == null){
- throw new BusinessException(ResultCode.ORDER_NOT_EXIST);
- }
- order.setPayType(param.getPayType());
- order.setProductName(param.getProductName());
- //微信支付
- orderService.updateById(order);
- if(param.getPayType() == 0 || param.getPayType() == 1 || param.getPayType() == 2){
- order.setOpenId(param.getOpenId());
- return wechatPayService.openPay(order,ipAddr);
- }
- //支付宝支付
- if(param.getPayType() == 3 || param.getPayType() == 4 ){
- return alipayService.openPay(order,ipAddr);
- }
- //paypal支付
- if(order.getPayType() == 5 ){
- return paypalService.openPay(order,ipAddr);
- }
- //stripe支付
- if(order.getPayType() == 6 ){
- return stripeService.openPay(order,ipAddr,lang);
- }
- return null;
- }
- public Boolean callBack(String orderSn, Integer payType,String result,HttpServletRequest request, HttpServletResponse response) {
- Order order = orderService.getByOrderSn(orderSn);
- if(order == null){
- throw new BusinessException(ResultCode.ORDER_NOT_EXIST);
- }
- if(order.getPayStatus() != 0){
- return false;
- }
- order.setPayType(payType);
- //微信支付回调
- if(order.getPayType() == 0 || order.getPayType() == 1 || order.getPayType() == 2){
- return wechatPayService.callBack(request,response,order,result);
- }
- //支付宝回调
- if(order.getPayType() == 3 || order.getPayType() == 4 ){
- return alipayService.callBack(request,response,order,result);
- }
- //paypal回调
- if(order.getPayType() == 5 ){
- return paypalService.callBack(request,response,order,result);
- }
- //stripe回调
- if(order.getPayType() == 6 ){
- }
- return true;
- }
- }
|