feat: add payment provider contract
Introduce shared payment request, response, order status, and provider interface types.
This commit is contained in:
parent
cf5160c9f2
commit
27a452f8d3
49
payment/types.go
Normal file
49
payment/types.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package payment
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderStatusPending = "pending"
|
||||||
|
OrderStatusSuccess = "success"
|
||||||
|
OrderStatusFailed = "failed"
|
||||||
|
OrderStatusClosed = "closed"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PaymentRequest struct {
|
||||||
|
OrderID string
|
||||||
|
Amount int // 美元分
|
||||||
|
Currency string // USD / CNY
|
||||||
|
Description string
|
||||||
|
ReturnURL string
|
||||||
|
NotifyURL string
|
||||||
|
ClientIP string
|
||||||
|
Metadata map[string]string
|
||||||
|
TradeType string // NATIVE / H5 / JSAPI (wxpay)
|
||||||
|
OpenID string // JSAPI 必填 (wxpay)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaymentResponse struct {
|
||||||
|
ProviderOrderID string
|
||||||
|
PaymentURL string // H5/WAP 跳转链接
|
||||||
|
QRCode string // Native 扫码链接
|
||||||
|
RawResponse string
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderStatus struct {
|
||||||
|
ProviderOrderID string
|
||||||
|
Status string // pending / success / failed / closed
|
||||||
|
Amount int
|
||||||
|
Currency string
|
||||||
|
PaidAt *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type Provider interface {
|
||||||
|
Name() string
|
||||||
|
CreatePayment(ctx context.Context, req *PaymentRequest) (*PaymentResponse, error)
|
||||||
|
QueryOrder(ctx context.Context, providerOrderID string) (*OrderStatus, error)
|
||||||
|
VerifyNotification(ctx context.Context, body []byte, headers map[string]string) (*OrderStatus, error)
|
||||||
|
Refund(ctx context.Context, providerOrderID string, amount int) error
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user