question

Wai Man Penny Yeung avatar image
Wai Man Penny Yeung asked

RedeemCoupon keeps return error "Coupon code not found"

I have downloaded the code from "Generate coupon", I tried with different items and bundle (with correct codes). all of them response "coupon code not found"

is there any step i have missed?( I have followed the exact same step in tutorial)
my function is down below

 public void RedeemPromoCode(string code)

    {


            Debug.Log("CODE = " + code);

            var primaryCatalogName = "Basic"; // In your game, this should just be a constant matching your primary catalog

            var request = new RedeemCouponRequest

            {

                CatalogVersion = primaryCatalogName,

                CouponCode = code // This comes from player input, in this case, one of the coupon codes generated above

            };

            PlayFabClientAPI.RedeemCoupon(request, OnSuccess =>

            {

                Debug.Log("Done");
            },

            OnFailed =>

            {

                Debug.Log(OnFailed.GenerateErrorReport());

            });


    }
game manager
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jordan avatar image
Jordan answered

Can I gather a bit more info about your implementation? Are you using Unity? Where are you calling RedeemPromoCode()?

Just to double check:

 Debug.Log("CODE = " + code);

is returning the same code that the user entered during RedeemPromoCode(), correct? And the primary catalog in the Game Manager is called "Basic"?

Once we get the coupon code working, you can add to your OnSuccess a way to check what was given.

List<ItemInstance> itemIds = OnSuccess.GrantedItems;
Debug.Log("Done. Granted items: " + itemIds);

Thanks for the additional info.

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Wai Man Penny Yeung avatar image Wai Man Penny Yeung commented ·

The debug message is returning as same as what i copy and pate from the csv.
The primary is called "Basic".

and thanks for the advise.

0 Likes 0 ·
Wai Man Penny Yeung avatar image Wai Man Penny Yeung Wai Man Penny Yeung commented ·

the code format is like "XXX-XXXX-XXX"

0 Likes 0 ·
Jordan avatar image Jordan ♦ commented ·

It seems like your function should work. You can try re-writing it to the alternative format, where Success and Fail call functions in this way:

    public void UseCoupon(string couponCode)
    {
        Debug.Log("Got couponCode: " + couponCode);
        var primaryCatalogName = "Basic";
        var request = new RedeemCouponRequest
        {
            CatalogVersion = primaryCatalogName,
            CouponCode = couponCode // This comes from player input
        };
        PlayFabClientAPI.RedeemCoupon(request, CouponSuccess, LogFailure);
    }
    void CouponSuccess(RedeemCouponResult result)
    {
        Debug.Log("coupon was successful. granted item(s): " + result.GrantedItems);
    }
    private void LogFailure(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }

This might bring to light something else that we could be missing.

You could also try creating a new catalog and replacing the CatalogName in the function with the new one. Then generate coupons from that catalog and try those.

0 Likes 0 ·
Wai Man Penny Yeung avatar image Wai Man Penny Yeung Jordan ♦ commented ·

Thank you for your reply, But I have tried both method (alternative format and new catalog). It doesn't work? do i need to upload the csv file to somewhere? or any automate code?

0 Likes 0 ·
Jordan avatar image Jordan ♦ Wai Man Penny Yeung commented ·

You do not need to upload the .csv anywhere.

To test the code, I click COUPONS under my bundle in my catalog, then download 5 coupons. When I go to test, I just copy one of the fields from the .csv and paste it in my running Unity scene, where I am alerted that the items were granted. Each code only works once, and then is no longer valid.

Could you share your TitleID and I could try to look into the issue further?

0 Likes 0 ·
Show more comments
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.