Search Unity

[Solved] Unity IAP Facebook WebGL project - purchase callback problems

Discussion in 'Unity IAP' started by Kurius, Jun 12, 2017.

Thread Status:
Not open for further replies.
  1. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    UPDATED
    I've updated this post to describe live production behavior rather than Staged Testing behavior.

    BACKGROUND
    First let me say that I have Unity IAP working perfectly on Android. Now I'm trying to get Unity IAP working properly as a Facebook WebGL game. I am not using Gameroom.
    I've uploaded my game as a Facebook WebGL build to Facebook Web Hosting with Payments Lite selected.
    I'm using...
    Unity IAP 1.11.1
    Facebook 7.9.4

    PROBLEM
    User clicks buy in the Facebook confirm purchase dialog. Then Facebook behind the scenes completes the transaction, displays it in the user's purchase history, does not automatically consume the consumable product, then tries to re-purchase the product, thus throwing an error that the product is already owned, and displays an error dialog to the user. All the while, Unity IAP has no idea this is happening because Unity IAP hasn't received any callbacks yet.

    The user then clicks ok in the Facebook error dialog, focus returns to the game, and Unity IAP finally receives a callback with Purchase Failed. Well yes Facebook's immediate second attempt at re-purchasing the product fails, however Facebook's initial attempt at purchasing succeeded, yet Unity IAP knows nothing about that initial attempt.

    Anyway, the user basically has to restart the game so that Unity IAP reads through all existing products that are already owned, and then finds that particular product and then my game provides the product to the user in the game at that time. Furthermore, Unity IAP is not automatically Consuming the Consumable product. I'm having to manually consume it via...
    string queryString = "/" + purchase_token + "/consume?access_token="+
    AccessToken.CurrentAccessToken.TokenString;
    FB.API(queryString, HttpMethod.POST, ConsumePurchaseCallback);

    PROBLEM - SCENARIO
    Here is the scenario I'm experiencing...

    1. User clicks button in game to call...
    m_Controller.InitiatePurchase ("my.product.1");

    2. The Facebook payment confirm purchase dialog appears. The following output is logged (with IDs x'd out)...
    16:31:46.153 UnityLoader.js:1 UnityIAP FB: Purchase, Product ID my.product.1
    16:31:46.166 blob:https://apps-xxxxxxxxx.apps.fbsbx.com/xxxxxxx:2 purchase({0}): my.product.1
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)
    16:31:46.873 KNZaDrXLXh_.js:140 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.

    3. User clicks "Buy" in the Facebook purchase confirmation dialog
    Facebook then displays an error dialog to the user saying...
    There Was a Problem Processing Your Payment: Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.

    4. The following output is logged...
    16:38:45.055 KNZaDrXLXh_.js:140 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.

    5. User checks their Facebook payments history and sees that in fact they actually successfully purchased the product, as seen at...
    https://www.facebook.com/settings?tab=payments&section=history

    6. User clicks Okay in the Facebook error dialog. The following output is logged...
    16:40:43.793 UnityLoader.js:1 UnityIAP FB: PurchaseCallback Error `There Was a Problem Processing Your Payment: Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.` (ErrorCode 1383001)
    16:40:43.945 KNZaDrXLXh_.js:140 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.

    7. At this point the game has lost focus, so user needs to click anywhere on the screen of the game. Upon doing so, the following output is logged (with IDs x'd out)...
    16:42:01.643 blob:https://apps-xxxxxxx.apps.fbsbx.com/xxxxx:2 onPurchaseFailedEvent({0}): my.product.1
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)
    16:42:01.655 blob:https://apps-xxxx.apps.fbsbx.com/xxxx:2 Purchase failed: my.product.1
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)
    16:42:01.656 blob:https://apps-xxxxx.apps.fbsbx.com/xxxxx:2 Unknown
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)

    8. User restarts the game and then Unity IAP reads through all existing products that are already owned, and then finds that particular product and then my game provides the product to the user in the game at that time. Furthermore, Unity IAP is not automatically Consuming the Consumable product.
     
    Last edited: Jun 13, 2017
  2. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    Ok so the solution ended up being to switch all of my Unity IAP logic to instead use Unity "Codeless IAP". This also meant switching all of my buttons to instead be Unity "IAP Button" via the Window menu -> Unity IAP -> Create IAP Button. Codless IAP and Unity IAP Button handle callbacks differently/better.
    Now Unity IAP works with "Payments Lite" in my Facebook WebGL project with "Simple Application Hosting" by Facebook.
    https://docs.unity3d.com/Manual/UnityIAPCodelessIAP.html
     
  3. JayR

    JayR

    Joined:
    Aug 2, 2016
    Posts:
    84
    Hi @Kurius

    "Codeless IAP" is actually the same code as traditional Unity IAP, it just simplifies the initialization and setup a bit.

    Our QA team noticed a problem with purchase results coming from the Facebook servers last week. That problem appears to have been resolved some time yesterday. The error you reported in #3 from your original post was the source of the rest of the problems because once Facebook reported an error (even though the purchase really succeeded) Unity IAP couldn't consume it. We have asked Facebook to check into this issue. One question they had was whether this was happening with non-test users (all of our tests were with test users in an "always succeeds" case.)
     
  4. JayR

    JayR

    Joined:
    Aug 2, 2016
    Posts:
    84
    Had an update from Facebook that this was an issue fixed on June 12.
     
  5. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    @JayR Thanks for your reply. Yes the issue occurred for both test users and non-test users. I had tried things with both a test project and a live project hosted by Facebook.

    I realize that Codeless IAP is just a simple layer that runs on top of the base Unity IAP code. Perhaps it was just a coincidence that Facebook fixed the issue at the same time that I switched to using Codeless. I was just assuming that the fact that Unity IAP button has you specify a callback method in the Inspector, that this was positively affecting how the callback listeners worked. But again the resolution of all of this might have just been a coincidence.

    While I've got your attention, I just wanted to confirm something else... when changing a Codeless Unity IAP button type to be "Restore" (for iOS purposes), is there anything more I need to do? It seems like the Restore process just happens automatically by clicking a Unity IAP button of type "Restore". Is that correct?
    Thanks
     
  6. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    @JayR I just retested my old builds that weren't using Codeless IAP, and they work now. Yup it was pure coincidence that I switched to Codless IAP at the same time that Facebook fixed the original problem.

    One last question while I've got your attention, upon clicking Buy in the Facebook confirmation popup, then the purchase is processed, and the Facebook purchasing popup correctly disappears. However focus does not return to my game. User must click anywhere on my game screen in order to return focus to my game. Is there a fix or workaround to automatically return focus to my game after the purchase?
    Thanks
     
  7. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    That is correct. If you find this isn't the case, please let us know.

    That is a known issue with Facebook currently. Unfortunately, there aren't any workarounds we are aware of.
     
    Kurius likes this.
Thread Status:
Not open for further replies.