Steam Microtransactions payment Add-on
This Add-on receives the Steamworks SDK MicroTxnAuthorizationResponse_t callback on Windows and macOS and passes it to the app. It passes the result of the app user authorizing or canceling the payment in the Steam overlay as is, without processing it.
The Payments module handles Steam order creation and payment result saving, and the app server requests receipt verification through the Hive Axyl Server API. For the call order, see InitiatePurchaseAsync().
Module information
- Package:
com.com2usplatform.hiveaxyl.payments.addon.steam - Interface:
ISteamMicrotransactionsPlugin - Namespace:
Hive.Axyl.Payments.Addon.Steam - Registration method:
AddSteamMicrotransactions() - Supported platforms: Windows, macOS
- Minimum requirements: macOS 15+, Unity 6000.0+
Prerequisites
The SDK does not initialize the Steam API. The app must call SteamAPI.Init() once when it starts, and call SteamAPI.RunCallbacks() every frame so that authorization callbacks are delivered.
If you start receiving callbacks before initializing the Steam API, no exception is thrown; the call ends with a Failure that contains the FailedPrecondition code. To check whether the Steamworks SDK is ready to use, see ISteamworksContext.
Registration and retrieval
Register the Add-on together with the Payments module in the registration step of HiveBootstrap.Initialize, and then retrieve it with HiveCore.TryResolve<T>().
using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity; // HiveBootstrap
using Hive.Axyl.Payments;
using Hive.Axyl.Payments.Addon.Steam;
HiveBootstrap.Initialize(config, builder =>
{
builder.AddPayments()
.AddSteamMicrotransactions();
});
if (HiveCore.TryResolve<ISteamMicrotransactionsPlugin>(out var steam))
{
// Code that runs only in Windows and macOS builds
}
Not registered in the Unity Editor
This Add-on is registered only in players built for Windows or macOS. It is not registered in the Unity Editor even when the platform matches, so using HiveCore.Resolve<T>() throws RegistrationNotFoundException. Always check with TryResolve<T>() before using it.
For the package installation and registration procedure, see Install the Steam payment plugin.
Method summary
Every method takes CancellationToken ct = default as its last parameter. For the calling conventions, see Call context.
This Add-on provides the following methods.
- StartCallbackListenerAsync(): Start receiving payment authorization callbacks
- StopCallbackListenerAsync(): Stop receiving payment authorization callbacks
Methods
StartCallbackListenerAsync
Starts receiving the Steamworks MicroTxnAuthorizationResponse_t callback. While receiving, authorization results are delivered through the MicroTxnAuthorizationResponse event.
- Response: StartCallbackListenerResponse
Result cases — SteamMicrotransactionsServiceStartCallbackListenerResult
| Result case | Wire code | Description |
|---|---|---|
Success | — | Started receiving callbacks. |
AlreadyStarted | already_started | Callback reception has already started. |
UnknownOutcome | UNKNOWN | A new result that this SDK version does not recognize. |
Failure | FAILURE | The call could not be completed. Check the cause with the HiveError in Problem. If the Steam API was not initialized, Code is FailedPrecondition and ExternalCode is STEAMWORKS_NOT_INITIALIZED. |
Exceptions
ObjectDisposedException: When called after the plugin is disposed
Call example
using Hive.Axyl.Payments.Addon.Steam;
steam.MicroTxnAuthorizationResponse += response =>
{
if (response.Authorized)
{
// The app user authorized the payment. Save the payment result with RecordStorePurchaseAsync.
}
else
{
// The app user canceled the payment.
}
};
var result = await steam.StartCallbackListenerAsync();
switch (result)
{
case SteamMicrotransactionsServiceStartCallbackListenerResult.Success:
case SteamMicrotransactionsServiceStartCallbackListenerResult.AlreadyStarted:
// Ready to receive callbacks. Start the payment with InitiatePurchaseAsync.
break;
default:
// If the Steam API was not initialized, the call ends with Failure.
break;
}
For the implementation procedure, see Receive the Steam payment authorization callback.
StopCallbackListenerAsync
Stops receiving callbacks. Calling it when callbacks are not being received is not an error. Because it is a cleanup operation, it stops receiving even if ct is already canceled.
- Response: StopCallbackListenerResponse
Result cases — SteamMicrotransactionsServiceStopCallbackListenerResult
| Result case | Wire code | Description |
|---|---|---|
Success | — | Stopped receiving callbacks. |
UnknownOutcome | UNKNOWN | A new result that this SDK version does not recognize. |
Failure | FAILURE | The call could not be completed. Check the cause with the HiveError in Problem. |
Exceptions
ObjectDisposedException: When called after the plugin is disposed
For the implementation procedure, see Stop receiving Steam callbacks.
Events
MicroTxnAuthorizationResponse
Raised when Steamworks delivers the MicroTxnAuthorizationResponse_t callback after the app user authorizes or cancels the payment in the Steam overlay. It is raised only while callbacks are being received through StartCallbackListenerAsync(), and because it is invoked on the engine main thread, you can use engine APIs inside the handler.
| Parameter | Type | Description |
|---|---|---|
| — | SteamMicroTxnResponse | The raw data of the authorization callback. |
For the implementation procedure, see Receive the payment authorization status through the MicroTxnAuthorizationResponse event.
Data types
StartCallbackListenerResponse
No fields.
SteamMicroTxnResponse
The raw data of the Steamworks MicroTxnAuthorizationResponse_t callback. Because the values are passed without processing, the app is responsible for interpreting them. AppId and OrderId use the same unsigned integer types as the Steamworks native struct.
| Property | Type | Required | Description |
|---|---|---|---|
AppId | uint | Required | The m_unAppID value, which is the Steam AppID. This is public information. |
OrderId | ulong | Required | The m_ulOrderID value. This is the order ID passed to InitTxn when the order was created, returned through the authorization callback, and it differs from transid, the transaction ID that Steam issues. Because it is sensitive information, SDK logs show only its last four digits. |
Authorized | bool | Required | The m_bAuthorized value. true if the app user authorized the payment in the Steam overlay, and false if they canceled it. |
StopCallbackListenerResponse
No fields.