question

Fréderic Duguay avatar image
Fréderic Duguay asked

Facebook canvas payment

Hey there, currently working with unity 5 to create webgl builds and deploy on facebook canvas.

It seems I should be using StartPurchase, PayForPurchase and CompletePurchase in order to have playfab automatically reward items from canvas payment's since it can take days to process depending on the payment method chosen by the user. We do have webhook payments working between facebook and playfab.

 

My first specific question points to this documentation (PayForPurchase)

it seems I should be calling Facebook.Unity.FB.Canvas.Pay() after the PayForPurchase call, but to get a transaction id i would have to invoke facebook's payment dialogue before, what's the actual purchase flow for facebook?

 

My second question would relate to how items are rewarded to the user,

With CompletePurchase it states that items would be rewarded automatically. What happens when it will take a delayed time for the purchase to actually go through? Since I have no control over the RealTimeUpdate (or webhook) because that's been assigned to playfab, is playfab going to wait until the transaction is actually successful to give the items?

 

Thanks in advance for any response!

10 |1200

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

Duncan Stead avatar image
Duncan Stead answered

Just for helping future generations, the whole flow that I finally got to work (including async payments) was:

1) OnClicked: PlayFabClientAPI.StartPurchase(itemRequest, ...);

2) OnStartPurchaseSuccess: FB.Canvas.Pay(productURL, ..., requestId: result.OrderId);

3) OnFBCanvasPayCallback: if (result.ResultDictionary["status"] == "completed" OR "initiated") {

Remember if "initiated" state - that's an async payment

PlayFabClientAPI.PayForPurchase(...)}

4) OnPayForPurchaseSuccess: Start a confirmation timer

5) Timer hit: PlayFabClientAPI.ConfirmPurchase(...)

6) OnConfirmPurchaseFailure: if(asyncPayment) { double the timer and wait some more }

The bits that caught me out were in the OnFBCanvasPayCallback -

1) You can get a separate "initiated" status (that you have to handle as a completed order)

2) The result dictionary is NOT the same running in the Unity Editor as in the WebGL runtime.

I might put the whole code somewhere if anyone cares, but yeah, it's a bit different to the other payment systems, and took me waaaay longer than it should've to make robust, mainly due to the inability to test inside the editor (build to WebGL 5 mins, upload to Facebook 1 min, deploy 30s, run in Facebook with test account 30s, wait for the async operation 30s+, hope it gives some sensible errors), and there being no complete example with a working flow that I could find.

10 |1200

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

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.