You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
💳 Bus Pay: Universal Payment Integration Framework
Unified Payment Integration, Simplified Development
📖 Project Introduction
Bus Pay is an enterprise-level payment integration framework that provides a unified API for multiple
third-party payment platforms. It abstracts away the complexities of individual payment gateway SDKs, making payment
integration "So easy!" for developers.
This library supports mainstream payment gateways including Alipay, WeChat Pay, UnionPay, PayPal, QQ
Pay, and JD Pay, enabling you to integrate all major payment methods with minimal code changes.
✨ Core Features
🎯 Unified Integration
Single API, Multiple Platforms: Use the same API pattern across all payment providers
Minimal Code Changes: Switch between payment gateways by simply changing configuration
Type-Safe Design: Built with strong typing to reduce runtime errors
Fluent Interface: Chain-style API for intuitive and readable code
🔐 Comprehensive Security
Multiple Encryption Standards: Supports RSA, RSA2, SM2 (Chinese national standard), and AES encryption
Signature Verification: Automatic signature generation and verification for all requests
Certificate Management: Built-in support for merchant certificates and public key verification
Secure Key Storage: Secure handling of private keys, public keys, and certificates
⚡ Rich Payment Capabilities
Feature
Support
Description
Payment Creation
✅
APP, WAP, Web, QR Code, Scan, Mini Program
Order Query
✅
Query order status by transaction ID
Refund Processing
✅
Full and partial refund support
Refund Query
✅
Query refund status and details
Cancel Payment
✅
Cancel pending transactions
Close Order
✅
Close unpaid orders
Transfer/Remit
✅
Single and batch transfers
Bill Download
✅
Download transaction statements
Notify Verification
✅
Automatic callback signature verification
🌍 Supported Payment Providers
Chinese Payment Gateways
Provider
Status
Features
Alipay
✅ Full Support
APP, WAP, Web, QR, Transfer, Refund
WeChat Pay
✅ Full Support
APP, JSAPI, H5, Native, Mini Program
QQ Pay (Tenpay)
✅ Full Support
Similar to WeChat Pay features
JD Pay
✅ Full Support
APP, WAP, Web payment
UnionPay
✅ Full Support
Online and offline payment
International Payment Gateways
Provider
Status
Features
PayPal
✅ Full Support
REST API v2, Web checkout
Other Providers
🚧 Roadmap
Stripe, Square, etc.
🛠️ Advanced Features
Sandbox/Production Mode: Easy switching between test and production environments
Cache Support: Built-in caching for access tokens and certificates (using bus-cache)
HTTP Client Integration: Seamless integration with bus-fabric for request handling
Crypto Operations: Integration with bus-crypto for encryption and signing
Flexible Configuration: Support for multiple merchant accounts and service provider mode
Callback Verification: Built-in signature verification for payment notifications
// ✅ Recommended: Use environment variables or secret managementContextcontext = Context.builder()
.appId(env.get("ALIPAY_APP_ID"))
.privateKey(env.get("ALIPAY_PRIVATE_KEY"))
.publicKey(env.get("ALIPAY_PUBLIC_KEY"))
.build();
// ❌ Not Recommended: Hardcode secretsContextcontext = Context.builder()
.appId("2021001234567890")
.privateKey("MIIEvQIBADANBgkqhkiG9w0BAQE...")
.build();
2. Use Sandbox Environment for Testing
// ✅ Test in sandbox firstComplexcomplex = Registry.ALIPAY;
complex.setSandbox(true);
AliPayProviderprovider = newAliPayProvider(context, complex);
// Test with small amountsmodel.put("total_amount", "0.01");
// After testing, switch to productioncomplex.setSandbox(false);
3. Implement Idempotency for Payment Notifications
@PostMapping("/payment/notify")
publicStringhandleNotify(HttpServletRequestrequest) {
StringoutTradeNo = params.get("out_trade_no");
// Check if order already processedif (orderService.isPaymentProcessed(outTradeNo)) {
return"success"; // Already processed
}
// Process paymentorderService.processPayment(outTradeNo, params);
return"success";
}
4. Use Database Transactions for Payment Processing
@TransactionalpublicvoidhandlePaymentSuccess(StringoutTradeNo, Map<String, String> params) {
// 1. Update order statusOrderorder = orderDao.findByOutTradeNo(outTradeNo);
order.setStatus(OrderStatus.PAID);
order.setTransactionId(params.get("trade_no"));
orderDao.update(order);
// 2. Add user credits/subscriptionsuserService.addPremium(order.getUserId());
// 3. Record payment logpaymentLogDao.insert(params);
}
5. Handle Network Failures Gracefully
try {
Map<String, Object> result = alipayProvider.tradeQuery(model);
// Process result
} catch (PaymentExceptione) {
// Log errorlogger.error("Payment query failed: {}", e.getMessage());
// Retry logicif (retryCount < MAX_RETRY) {
returnretryPaymentQuery(model, retryCount + 1);
}
// Fallback to manual processingreturnmanualVerificationRequired(outTradeNo);
}
6. Validate Input Parameters
privatevoidvalidatePaymentRequest(Map<String, String> model) {
Assert.notNull(model.get("out_trade_no"), "Order number is required");
Assert.notNull(model.get("total_amount"), "Amount is required");
BigDecimalamount = newBigDecimal(model.get("total_amount"));
Assert.isTrue(amount.compareTo(BigDecimal.ZERO) > 0, "Amount must be greater than zero");
Assert.isTrue(amount.compareTo(newBigDecimal("100000")) < 0, "Amount exceeds limit");
// Check if order already existsStringoutTradeNo = model.get("out_trade_no");
Assert.isFalse(orderDao.exists(outTradeNo), "Order already exists");
}
7. Use Asynchronous Notification
// For time-sensitive operations, use message queue@AsyncpublicvoidprocessPaymentNotification(Map<String, String> params) {
// Send to message queue for background processingmqClient.send("payment-notify", params);
}
// Consumer@RabbitListener(queues = "payment-notify")
publicvoidhandlePaymentNotify(Map<String, String> params) {
// Process payment asynchronouslyorderService.processPayment(params);
}
❓ Frequently Asked Questions
Q1: How do I switch between sandbox and production environments?