feat(iap/apple): 添加对appAccountToken的支持以关联订单
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m18s
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m18s
解析JWS中的appAccountToken字段并添加到TransactionPayload结构体 在恢复逻辑中尝试使用appAccountToken关联现有订单
This commit is contained in:
parent
40a45199a5
commit
d8f5628bb1
@ -132,6 +132,22 @@ SIRDAVLcWemp0fMlnfDE4EHmqcD58arEJWsr3aWEhc4BHocOUIGjko0cVWGchrFa
|
||||
if err := tx.Model(&iapmodel.Transaction{}).Create(iapTx).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Try to link with existing order if possible (Best Effort)
|
||||
// Strategy 1: appAccountToken (from JWS) -> OrderNo (UUID)
|
||||
if txp.AppAccountToken != "" {
|
||||
// appAccountToken is usually a UUID string
|
||||
// Try to find order by parsing UUID or matching direct orderNo (if we stored it as uuid)
|
||||
// Since our orderNo is string, we can try to search it.
|
||||
// However, AppAccountToken is strictly UUID format. If our orderNo is not UUID, we might need a mapping.
|
||||
// Assuming orderNo -> UUID conversion was consistent on client side.
|
||||
// Here we just try to update if we find an unpaid order with this ID (if orderNo was used as appAccountToken)
|
||||
_ = l.svcCtx.OrderModel.UpdateOrderStatus(l.ctx, txp.AppAccountToken, 2, tx)
|
||||
}
|
||||
|
||||
// Strategy 2: If we had a way to pass orderNo in restore request (optional field in future), we could use it here.
|
||||
// But for now, we only rely on appAccountToken or just skip order linking.
|
||||
|
||||
exp := iapapple.CalcExpire(txp.PurchaseDate, m.DurationDays)
|
||||
userSub := user.Subscribe{
|
||||
UserId: u.Id,
|
||||
|
||||
@ -71,6 +71,9 @@ func ParseTransactionJWS(jws string) (*TransactionPayload, error) {
|
||||
t := time.UnixMilli(int64(v))
|
||||
resp.RevocationDate = &t
|
||||
}
|
||||
if v, ok := raw["appAccountToken"].(string); ok {
|
||||
resp.AppAccountToken = v
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
||||
@ -9,5 +9,6 @@ type TransactionPayload struct {
|
||||
OriginalTransactionId string `json:"originalTransactionId"`
|
||||
PurchaseDate time.Time `json:"purchaseDate"`
|
||||
RevocationDate *time.Time`json:"revocationDate"`
|
||||
AppAccountToken string `json:"appAccountToken"`
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user