Skip to content

Commit

Permalink
BEDS-239: map apple product ids to internal ids
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsc committed Sep 16, 2024
1 parent 9d1b6fe commit 8388400
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions backend/pkg/userservice/appsubscription_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,29 @@ func rejectReason(valid bool) string {
return "expired"
}

// first 3 trillion dollar company and you can't reuse ids
func mapAppleProductID(productID string) string {
mappings := map[string]string{
"orca.yearly.apple": "orca.yearly",
"orca.apple": "orca",
"dolphin.yearly.apple": "dolphin.yearly",
"dolphin.apple": "dolphin",
"guppy.yearly.apple": "guppy.yearly",
"guppy.apple": "guppy",
}
if mapped, ok := mappings[productID]; ok {
return mapped
}
return productID
}

func verifyApple(apple *api.StoreClient, receipt *types.PremiumData) (*VerifyResponse, error) {
response := &VerifyResponse{
Valid: false,
ExpirationDate: 0,
RejectReason: "",
ProductID: receipt.ProductID, // may be changed by this function to be different than receipt.ProductID
Receipt: receipt.Receipt, // may be changed by this function to be different than receipt.Receipt
ProductID: mapAppleProductID(receipt.ProductID), // may be changed by this function to be different than receipt.ProductID
Receipt: receipt.Receipt, // may be changed by this function to be different than receipt.Receipt
}

if apple == nil {
Expand Down Expand Up @@ -300,7 +316,7 @@ func verifyApple(apple *api.StoreClient, receipt *types.PremiumData) (*VerifyRes
response.RejectReason = "invalid_product_id"
return response, nil
}
response.ProductID = productId // update response to reflect the resolved product id
response.ProductID = mapAppleProductID(productId) // update response to reflect the resolved product id

expiresDateFloat, ok := claims["expiresDate"].(float64)
if !ok {
Expand Down

0 comments on commit 8388400

Please sign in to comment.