question

brett19 avatar image
brett19 asked

Facebook Canvas Payments and ConfirmPurchase

Hey PlayFab,

I am currently writing the payment processing code for my game.  I have it set up so that we start the purchase using StartPurchase, then we trigger the Facebook Payment Dialog, then once it completes we call PayForPurchase to advise PlayFab that the purchase has completed.  I am becoming confused by the ConfirmPayment API now though.  Everywhere on your website and on the forums, I see that we are supposed to poll this API while a payment is pending, but the API has no errors, and the only results that it returns is the PurchaseDate.  This means it doesn't seem that we can't use that API to tell the status of the payment.  In addition to that, it doesn't even appear that the call is necessary most of the time, as payments settle themselves after a period of time.  Currently I have the logic set to do PayForPurchase, then immediately call ConfirmPayment in case the confirmation was immediate (so most of the time the user gets their purchase immediately).  In the case that the payment is not immediate, it appears PlayFab will, at a later time, automatically complete the purchase (contrary to the suggestion that we need to poll).  Could you guys point me to some information on how this is intended to be implemented, or provide some information here?

P.S. It would be really awesome if you guys could provide better documentation around the flow of your API's as well as providing details about what things even exist (the OpenGraphAPI endpoints for Facebook store items don't appear anywhere in your documentation for instance).

Cheers, Brett

10 |1200

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

brendan avatar image
brendan answered

We'll have a write-up of the non-receipt, non-entitlement purchase systems available shortly. In the meantime, yes, the process is normally select items and establish a "cart" (StartPurchase), state a payment provider (PayForPurchase), and then check that the purchase process is complete and add the items (ConfirmPurchase). The Facebook system is different from others, in that you cannot call PayForPurchase until Facebook has started the payment process.

So you'd use FB.ui with the 'purchaseitem' action to kick this off after StartPurchase. Make sure to use the OrderId from PayForPurcahse as the 'request_id', and for the 'product', you should form the uri like sp"

product: "https://{ {TitleId}}.playfabapi.com/OpenGraphProduct/{ {TitleId}}/{ {StoreId}}/{ {CatalogVersion}}/{ {ItemId}}"

On a successful response, Facebook will return a 'payment_id', which can then be used in the Client/PayForPurchase call as the ProviderTransactionId, like so:

POST https://{ {TitleID}}.playfabapi.com/Client/PayForPurchase
Content-Type: application/json;
X-Authentication: { {SessionTicket}}
{
"OrderId": "{ {OrderId}}",
"ProviderName": "Facebook",
"Currency": "RM",
"ProviderTransactionId": facebookPurchaseId
}

This establishes the PlayFab connection to the purchase, allowing us to query for its status. Once that call has completed, and provided the Facebook purchase completed successfully, you should indeed call ConfirmPuchase with the OrderId, in order to have the items added to the player inventory.

10 |1200

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

brett19 avatar image
brett19 answered

Hey Brendan!
Thanks a ton for the quick reply.  I think I got mildly confused by ConfirmPurchase's behaviour as it returns a `500 Internal Server Error` while a purchase is still being processed, which doesn't make a whole lot of sense.
Cheers, Brett

10 |1200

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

brendan avatar image
brendan answered

Well, you're right that "500 Internal Service Error" isn't correct. When you say it's returned while a purchase is being processed, does that mean only before PayForPurchase has completed successfully, or something else?

10 |1200

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

brett19 avatar image
brett19 answered

If I do a Facebook purchase, and select an asynchronous payment completion of "successful after 30 seconds", I get back 500 Internal Server Error for the first 30s, then finally a successful 200 reply.  That is to say, the following is my sequence of events.
(~0s) PlayFab.StartPurchase - Success
(~0s) FB.Pay
(~10s) FB.Pay {Callback Invoked}
(~10s) PlayFab.PayForPurchase - Success
(~10s) PlayFab.ConfirmPurchase - 500 Internal Server Error
(~11s) PlayFab.ConfirmPurchase - 500 Internal Server Error
(~13s) PlayFab.ConfirmPurchase - 500 Internal Server Error
...
(~41s) PlayFab.ConfirmPurchase - Success

10 |1200

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

brendan avatar image
brendan answered

Very interesting - thanks for the additional details. And I take it there's no additional callback about a change to the purchase state from Facebook after the one at about the 10 second mark in that flow?

10 |1200

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

brett19 avatar image
brett19 answered

Hey Brendan,
That is accurate.  The only thing that would happen after the 10s mark is around the 40s mark there would be a Facebook web-hook dispatch to let PlayFab know that the purchase completed successfully.  In reality, I suspect that the ConfirmPurchase call should actually return a transaction state so that it can be polled until the state becomes confirmed.  Additionally, it would be really helpful if PlayFab provided some way to get a versioned list of store transactions, so we can check if the user has any pending transactions instead of storing it locally.
Cheers, Brett

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.