question

brendan avatar image
brendan asked

rapidjson assert

studd
started a topic on Tue, 13 January 2015 at 12:29 PM

I'm just messing around with the C++ SDK, and I can't figure out why rapidjson triggers an assert when I'm trying to pay for my order.

Here are the Playfab related functions I call before the assert :

void PFNetwork::login(void* userData)
{
getCredentials();
if (canContactPlayfab())
{
LoginWithPlayFabRequest loginWithPlayFabRequest;
PlayFabSettings::titleId = id; //Title (game) ID
loginWithPlayFabRequest.Username = log; //Playfab login
loginWithPlayFabRequest.Password = pass; //PlayFab password
playFabClientAPI.LoginWithPlayFab(loginWithPlayFabRequest, loginWithPlayFabCallback, errorCallback, userData);
}
}

/**
Callback called when login is done.
/
void loginWithPlayFabCallback(LoginResult& result, void
userData)
{
static_cast<MultiplayerGameState*>(userData)->buyMissiles();
PFNetwork::setCallbackCalled(true);
}

void PFNetwork::buy(string name, int amount, void* userData)
{
StartPurchaseRequest purchaseRequest;
std::listClientModels::ItemPuchaseRequest items;
ClientModels::ItemPuchaseRequest item;
item.ItemId = name;
item.Quantity = amount;
items.push_back(item);
purchaseRequest.Items = items;

playFabClientAPI.StartPurchase(purchaseRequest, multiplePurchaseItemCallback, errorCallback, userData);

}

void multiplePurchaseItemCallback(StartPurchaseResult& result, void* userData)
{
string providerName;
for (auto& p : result.PaymentOptions)
if (p.Currency == "MS")
providerName = p.ProviderName;

PFNetwork::Instance().payForPurchase(providerName, result.OrderId, "MS", userData);

}

void PFNetwork::payForPurchase(string provider, string orderId, string currency, void* userData)
{
PayForPurchaseRequest payRequest;
payRequest.Currency = currency;
payRequest.ProviderName = provider;
payRequest.OrderId = orderId;
playFabClientAPI.PayForPurchase(payRequest, payPurchaseItemCallback, errorCallback, userData);
}

Before the payPurchaseItemCallback is called, I have this assert :

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

·
brendan avatar image
brendan answered

Best Answer
Brendan Vanous said on Thu, 15 January 2015 at 12:19 PM

Aha - very interesting! There are two problems which affected your test:

The main issue is that your catalog item has no "RM" (Real Money - specified as USD pennies, so 199 would be $1.99 USD, for instance) price. The three-stage purchase system (StartPurchase, PayForPurchase, ConfirmPurchase) is specifically for buying items with real-world money. If the intent is to only have this item purchasable with virtual currencies, the PurchaseItem call is the only one you need.

The other is a logical gotcha you've discovered in the catalog system. The CatalogVersion is optional on all the calls, as the system uses your most recent catalog as the default. However, if you've never defined a catalog (such as when you first create a title), there is no default, and setting up a catalog item without specifying the CatalogVersion results in a catalog without a CatalogVersion. I didn't see this because I was using the new Game Manager we'll be releasing shortly (in Beta right now, and I'm a firm believer in the "eat your own dogfood" philosophy), and it lists the catalogs by the CatalogVersion. We'll get that fixed, so that this doesn't trip up anyone else, but in the meantime, I've updated your catalog to have CatalogVersion of "Test".


5 Comments
Brendan Vanous said on Thu, 15 January 2015 at 11:27 AM

Hi Vincent,

Sorry for the delay getting back to you. I don't see a Catalog defined for your game. In order to use any of the purchasing API calls, you will need to set that up first, so that the service has the information needed.

Thanks,

Brendan


studd said on Thu, 15 January 2015 at 12:03 PM

Hi,

Thank you for the reply.

As I can't sign in on the portal with this account (it does not have a studio name), I created another account that I'm using to manage the game.

The game I'm testing things on does have a catalog with the item I'm trying to buy. In case you'd like to check, its titleID is D98D.

I had no problem with buying this item using the PurchaseItem function of the SDK, but for some reason I can't using StartPurchage and PayForPurchase.


Brendan Vanous said on Thu, 15 January 2015 at 12:19 PM

Aha - very interesting! There are two problems which affected your test:

The main issue is that your catalog item has no "RM" (Real Money - specified as USD pennies, so 199 would be $1.99 USD, for instance) price. The three-stage purchase system (StartPurchase, PayForPurchase, ConfirmPurchase) is specifically for buying items with real-world money. If the intent is to only have this item purchasable with virtual currencies, the PurchaseItem call is the only one you need.

The other is a logical gotcha you've discovered in the catalog system. The CatalogVersion is optional on all the calls, as the system uses your most recent catalog as the default. However, if you've never defined a catalog (such as when you first create a title), there is no default, and setting up a catalog item without specifying the CatalogVersion results in a catalog without a CatalogVersion. I didn't see this because I was using the new Game Manager we'll be releasing shortly (in Beta right now, and I'm a firm believer in the "eat your own dogfood" philosophy), and it lists the catalogs by the CatalogVersion. We'll get that fixed, so that this doesn't trip up anyone else, but in the meantime, I've updated your catalog to have CatalogVersion of "Test".


studd said on Thu, 15 January 2015 at 12:39 PM

It's very nice of you !

I didn't even think that no RM could cause that. The virtual currency I added appears in the response properties' payement options. Do you mean that I should avoid this choice, or is it just that I have to add an RM in the catalog before trying to use this ?

I think the SDK's documentation isn't very clear about this (or maybe it's just me, English isn't my first language after all).

Thanks !


Brendan Vanous said on Thu, 15 January 2015 at 5:49 PM

Oh, no - sorry. If all you want to do is make the purchase with a virtual currency, that API flow works fine, but you do need to make sure the provider is set correctly to the Title's ProviderName in the response. I just tested this out using the Web API calls directly to verify. Normally, titles just use PurchaseItem for making virtual-only purchases, which is why I wasn't on the same page with you.

I'd like to test our your repro, to see what the issue you're running into is. Rather than make any assumptions about the specifics of your test with the C++ SDK, could you send your repro to devrel@playfab.com?

And thanks - we're aware that we need to put some more explanation into some of our docs. I'll prioritize adding more details to the purchase flow.

Brendan

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.