Stores - Custom Purchaser
Allow players to purchase items from in-game stores [ECON-Stores-04]
Overview
This guide includes everything needed to use the Custom Purchaser in the "Beamable SDK for Unity".
User Experience
When set up properly, the user experience in the game project will be as follows:
Steps
The following steps assumes no dependency on Unity's UnityIAP solution. There is significant custom code required for this solution.
A benefit here is flexible development.
Follow these steps to get started:
Steps | Detail |
---|---|
1. Create Purchaser C# Class | The custom class must implement the IBeamablePurchaser interface. |
2. Register the purchaser with Beamable | `To register the custom implementation, use Beamable's Dependency Injection to add the custom implementation. |
API
Here are API highlights for IBeamablePurchaser
.
The custom purchaser class must implement this interface.
Method Name | Detail |
---|---|
Initialize | • Setup the chosen IAP implementation |
GetLocalizedPrice | • Fetches the localized string from the provider |
StartPurchase | • Start a purchase through the chosen IAP implementation. |
Here are API highlights for beamableAPI.PaymentService
.
The custom purchaser class must reference these methods and call each if/when appropriate.
Method Name | Detail |
---|---|
GetSKUs | • Get commerce SKUs from platform |
BeginPurchase | • Begin purchase request |
CompletePurchase | • Call after the provider has charged the player. Used to verify the legitimacy of the purchase receipt and complete the item fulfillment process |
CancelPurchase | • Cancel purchase request |
FailPurchase | • Fail purchase request |
Inspiration
The UnityBeamablePurchaser
represents a fully-functional Beamable solution for connecting with Unity's native IAP system. Checkout the source-code. Its included in the "Beamable SDK for Unity".
The custom purchaser class must not reference this class. It's only for reference.
Example
A custom purchaser must implement the IBeamablePurchaser
interface. The following snippet is not a fully implemented class.
public class CustomPurchaser : IBeamablePurchaser
{
public Promise<Unit> Initialize(IDependencyProvider provider = null)
{
throw new NotImplementedException();
}
public string GetLocalizedPrice(string skuSymbol)
{
throw new NotImplementedException();
}
public Promise<CompletedTransaction> StartPurchase(string listingSymbol, string skuSymbol)
{
throw new NotImplementedException();
}
}
To use the custom purchaser, you must register it with Beamable's Dependency Injection. That can be done using the following class.
[BeamContextSystem]
public class Registrations
{
[RegisterBeamableDependencies()]
public static void Register(IDependencyBuilder builder)
{
builder.AddSingleton<IBeamablePurchaser, CustomPurchaser>();
}
}
Updated about 2 months ago