alipay_app 0.1.1
alipay_app: ^0.1.1 copied to clipboard
Alipay App Pay order builder for Dart/Flutter (server-side).
alipay_app #
Alipay App Pay order builder for Dart/Flutter (server-side).
Security Notice: This package requires your Alipay private key and should only run on a trusted server. Do NOT embed private keys in client apps.
Features #
- App Pay Order String - Build
alipay.trade.app.payorder strings for SDKs (e.g., tobias) - WAP Pay URL - Build
alipay.trade.wap.paygateway URLs for mobile-web / WebView payments - RSA2 Signing - Sign with PKCS#8 private key.
timestampis always Asia/Shanghai (UTC+8) - Passback Params - Optional
passback_paramssupport - Pure Dart - No Flutter dependency
Installation #
dependencies:
alipay_app: ^0.1.1
Quick Start #
import 'package:alipay_app/alipay_app.dart';
void main() {
final config = AlipayAppConfig(
appId: 'your-alipay-app-id',
privateKeyPem: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----',
notifyUrl: 'https://your-server/alipay/notify',
);
final client = AlipayAppClient(config);
final order = client.createAppPayOrder(
outTradeNo: 'order_20260204_0001',
totalAmount: '10.00',
subject: 'Membership Recharge',
passbackParams: 'uid=12345',
);
// Send order.orderString to your mobile app and call the Alipay SDK.
print(order.orderString);
}
Configuration #
| Parameter | Required | Description | Default |
|---|---|---|---|
appId |
Yes | Alipay App ID | - |
privateKeyPem |
Yes | PKCS#8 RSA private key | - |
notifyUrl |
Yes | Async notify callback URL | - |
charset |
No | Request charset | utf-8 |
format |
No | Response format | JSON |
signType |
No | Signature type | RSA2 |
version |
No | API version | 1.0 |
productCode |
No | Product code | QUICK_MSECURITY_PAY |
timeoutExpress |
No | Order timeout | 30m |
API Reference #
AlipayAppConfig #
Configuration holder for app pay.
AlipayAppClient #
App Pay (native SDK)
final order = client.createAppPayOrder(
outTradeNo: 'order_001',
totalAmount: '10.00',
subject: 'Test Order',
passbackParams: 'uid=123',
);
// Send order.orderString to the mobile app → Alipay SDK
WAP Pay (mobile-web / WebView)
final url = client.createWapPayUrl(
outTradeNo: 'order_002',
totalAmount: '10.00',
subject: 'Test Order',
returnUrl: 'https://your-site.com/pay/return',
passbackParams: 'uid=123',
);
// Redirect the browser to `url`
| Parameter | Required | Description |
|---|---|---|
outTradeNo |
Yes | Merchant order number |
totalAmount |
Yes | Amount in yuan, e.g. "10.00" |
subject |
Yes | Order subject / title |
returnUrl |
Yes | Browser redirect URL after payment |
gatewayUrl |
No | Alipay gateway (default: https://openapi.alipay.com/gateway.do) |
passbackParams |
No | Passback string for async notification |
AppPayOrder #
Fields:
orderStringoutTradeNototalAmountsubjecttimestamppassbackParams
Troubleshooting #
| Issue | Cause | Fix |
|---|---|---|
| Signature verification failed | Wrong private key format | Ensure PKCS#8 PEM and remove extra whitespace |
| Notify not received | Unreachable notifyUrl |
Use public HTTPS endpoint and check server logs |
| Invalid amount | Format incorrect | Use 2-decimal string like 10.00 |
Related Packages #
- alipay_qr - QR code precreate & query
- alipay - Combined package
- alipay_serverpod - Serverpod integration
License #
MIT License