While I managed to get Virtual Currency transactions functioning on our project some time ago, I've been having some difficulty with figuring out the proper implementation of the StartPurchase/PayForPurchase/ConfirmPurchase sequence in C# when handling Real Money (RM) transactions.
In this example I'm trying to use Real Money to purchase a catalog item that will grant the user Virtual Currency (VC).
Here's what I have so far:
//Try to purchase the 100 VC pack ~Adam
#region Start the Purchase
//Declare the item to purchase ~Adam
ItemPuchaseRequest itemToPurchase = new ItemPuchaseRequest();
itemToPurchase.ItemId = "currency_pack_100";
itemToPurchase.Quantity = 1;
//Create a request to purchase the item ~adam
StartPurchaseRequest startRequest = new StartPurchaseRequest();
startRequest.CatalogVersion = items[CurrencyPackNumber].CatalogVersion;
startRequest.StoreId = "currency_pack_100";
startRequest.Items[0] = itemToPurchase;
StartPurchaseResult startResult = new StartPurchaseResult();//ERROR HERE
PlayFabClientAPI.StartPurchaseCallback startCallback = new PlayFabClientAPI.StartPurchaseCallback(startResult);
ErrorCallback purchaseErrorCallback = new ErrorCallback((PlayFabError error) => new PlayFabError());
PlayFabClientAPI.StartPurchase (startRequest,startCallback, purchaseErrorCallback);
#endregion
#region Pay for the Purchase
//Create a request to pay for the item ~Adam
PayForPurchaseRequest payRequest = new PayForPurchaseRequest();
payRequest.OrderId = startResult.OrderId;
payRequest.ProviderName = "PayPal";
payRequest.Currency = "RM";
// payRequest.Items[0] = itemToPurchase;
PayForPurchaseResult payResult = new PayForPurchaseResult();//ERROR HERE
PlayFabClientAPI.PayForPurchaseCallback payCallback = new PlayFabClientAPI.PayForPurchaseCallback(payResult);
PlayFabClientAPI.PayForPurchase(payRequest,payCallback, purchaseErrorCallback);
#endregion
#region Confirm the Purchase
ConfirmPurchaseRequest confirmRequest = new ConfirmPurchaseRequest();
confirmRequest.OrderId = startResult.OrderId;
ConfirmPurchaseResult confirmResult = new ConfirmPurchaseResult();//ERROR HERE
PlayFabClientAPI.ConfirmPurchaseCallback confirmCallback = new PlayFabClientAPI.ConfirmPurchaseCallback(confirmResult);
PlayFabClientAPI.ConfirmPurchase (confirmRequest, confirmCallback, purchaseErrorCallback);
#endregion
I think I mostly have it set up right, but I'm not sure how to properly access the OrderID from the StartPurchase results to use for PayForPurchase and ConfirmPurchase. My current thought was to declare a StartPurchaseResult variable whose OrderId I can reference, but attempting to declare such a variable gives me the following error:
"Expression denotes a 'variable', where a 'type' or 'method group' was expected"
If anyone could please point out where I am going wrong here, it would be greatly appreciated.