package com.gxwebsoft.payment.enums; /** * 支付渠道枚举 * 定义具体的支付渠道类型 * * @author 科技小王子 * @since 2025-01-26 */ public enum PaymentChannel { /** 微信JSAPI支付 */ WECHAT_JSAPI("wechat_jsapi", "微信JSAPI支付", PaymentType.WECHAT), /** 微信Native支付 */ WECHAT_NATIVE("wechat_native", "微信Native支付", PaymentType.WECHAT_NATIVE), /** 微信H5支付 */ WECHAT_H5("wechat_h5", "微信H5支付", PaymentType.WECHAT), /** 微信APP支付 */ WECHAT_APP("wechat_app", "微信APP支付", PaymentType.WECHAT), /** 微信小程序支付 */ WECHAT_MINI("wechat_mini", "微信小程序支付", PaymentType.WECHAT), /** 支付宝网页支付 */ ALIPAY_WEB("alipay_web", "支付宝网页支付", PaymentType.ALIPAY), /** 支付宝手机网站支付 */ ALIPAY_WAP("alipay_wap", "支付宝手机网站支付", PaymentType.ALIPAY), /** 支付宝APP支付 */ ALIPAY_APP("alipay_app", "支付宝APP支付", PaymentType.ALIPAY), /** 支付宝小程序支付 */ ALIPAY_MINI("alipay_mini", "支付宝小程序支付", PaymentType.ALIPAY), /** 银联网关支付 */ UNION_WEB("union_web", "银联网关支付", PaymentType.UNION_PAY), /** 银联手机支付 */ UNION_WAP("union_wap", "银联手机支付", PaymentType.UNION_PAY), /** 余额支付 */ BALANCE("balance", "余额支付", PaymentType.BALANCE), /** 现金支付 */ CASH("cash", "现金支付", PaymentType.CASH), /** POS机支付 */ POS("pos", "POS机支付", PaymentType.POS); private final String code; private final String name; private final PaymentType paymentType; PaymentChannel(String code, String name, PaymentType paymentType) { this.code = code; this.name = name; this.paymentType = paymentType; } public String getCode() { return code; } public String getName() { return name; } public PaymentType getPaymentType() { return paymentType; } /** * 根据代码获取支付渠道 */ public static PaymentChannel getByCode(String code) { if (code == null) { return null; } for (PaymentChannel channel : values()) { if (channel.code.equals(code)) { return channel; } } return null; } /** * 根据支付类型获取默认渠道 */ public static PaymentChannel getDefaultByPaymentType(PaymentType paymentType) { if (paymentType == null) { return null; } switch (paymentType) { case WECHAT: return WECHAT_JSAPI; case WECHAT_NATIVE: return WECHAT_NATIVE; case ALIPAY: return ALIPAY_WEB; case UNION_PAY: return UNION_WEB; case BALANCE: return BALANCE; case CASH: return CASH; case POS: return POS; default: return null; } } /** * 是否为微信支付渠道 */ public boolean isWechatChannel() { return paymentType.isWechatPay(); } /** * 是否为支付宝支付渠道 */ public boolean isAlipayChannel() { return paymentType == PaymentType.ALIPAY; } /** * 是否为银联支付渠道 */ public boolean isUnionPayChannel() { return paymentType == PaymentType.UNION_PAY; } /** * 是否为第三方支付渠道 */ public boolean isThirdPartyChannel() { return paymentType.isThirdPartyPay(); } /** * 是否支持退款 */ public boolean supportRefund() { return isThirdPartyChannel(); } @Override public String toString() { return String.format("PaymentChannel{code='%s', name='%s', paymentType=%s}", code, name, paymentType); } }