Implementing Steam Callback

Hi, I am currently working on Microtransactions with Steam. The serverside Part of the whole transaction process is already working and currently i need to implement the SteamCallback OnMicroTxnAuthorizationResponse after I click “authorize” in my SteamOverlay. However the Callback is not working at the Moment, this is what I got so far:
Header file:



     #include "steam/steam_api.h"
     #include "steam/isteamuser.h"
     
     /**
     * Controller UCLASS
     */
     
     class SteamCallbacks{
     public:
         SteamCallbacks();
     
         STEAM_CALLBACK(SteamCallbacks, OnMicroTxnAuthorizationResponse, MicroTxnAuthorizationResponse_t, m_MicroTxnAuthorizationResponse);
     };

CPP File:


SteamCallbacks::SteamCallbacks()
         : m_MicroTxnAuthorizationResponse(this, &SteamCallbacks::OnMicroTxnAuthorizationResponse)
     {};
     
     void SteamCallbacks::OnMicroTxnAuthorizationResponse(MicroTxnAuthorizationResponse_t *pCallback){
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("CALLBACK RECEIVED"));
     }

This Class is in a PlayerController which is parent to a BlueprintController which is DefaultController in a shop only Gamemode. In addition im calling SteamAPI_RunCallbacks() every frame from a blueprint library. I do not know what I am missing to make the callback work and neither the Steamworks Documentation nor the example project are helpfull.

I hope someone knows how to fix my issue.

Hi, I am experiencing a similar issue.
Have you managed to get this working?

Hi, sorry to bump an old thread but I have the same problem.

I have the STEAM_CALLBACK in my gameinstance and the SteamAPI_RunCallbacks() in an actor tick. Everything compile, when the steam overlay opens and I click on autorize but my callback function never fire.
I noticed that for the leaderboard example on steam documentation, you had to make a request (SteamUserStats()->FindLeaderboard( “Best Score” );), is there something similar for microtransactions or is this just for CallResults?

Sorry, i’m still pretty confused with Callbacks.

Is there a blueprint way?

do we still need to register a steam callback or we can add a delegate function to the online subsystem? Been researching for a while

Hi,
This is how I solved it

Header File




DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FTestDelegate, bool, flag, FString, orderid);

class MyProject USteamFunction : public UObject
{
    GENERATED_BODY()

private:

    bool m_bAuthorized;
    uint64 m_ulOrderID;
    bool HasOnlineSubsystem;


    STEAM_CALLBACK(USteamFunction, OnPurchaseResponse, MicroTxnAuthorizationResponse_t); // REQUIRED

private:

    MicroTxnAuthorizationResponse_t response;
    void OnPurchaseResponse(MicroTxnAuthorizationResponse_t *response);

public:
    UPROPERTY(BlueprintAssignable)
        FTestDelegate DpurchaseReceived;

};


CPP




void suint64_to_string(uint64 value, std::string& result) {
    result.clear();
    result.reserve(20); // max. 20 digits possible
    uint64 q = value;
    do {
        result += "0123456789"[q % 10];
        q /= 10;
    } while (q);
    std::reverse(result.begin(), result.end());
}

void USteamFunction::OnPurchaseResponse(MicroTxnAuthorizationResponse_t *pParam)
{

    bool m_bAuthorized = pParam->m_bAuthorized;
    uint64 m_ulOrderID = pParam->m_ulOrderID;

    std::string result;
    suint64_to_string(m_ulOrderID, result);

    FString OrderID(result.c_str());

    DpurchaseReceived.Broadcast(m_bAuthorized, OrderID);

    if (GEngine)
    {
        //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, OrderID);
        //GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Bool: %s"), m_bAuthorized ? TEXT("true") : TEXT("false")));
    }
}



1 Like

Its 2020, and I had to make some changes to RahulSode’s code. Big thanks to him for sharing.

I did my callback inside my game instance so my .h game instance



#include "ThirdParty/Steamworks/Steamv142/sdk/public/steam/steam_api.h"

//needed because steam_aphi.h throws errors otherwise when compiling
#define ARRAY_COUNT( array ) (sizeof(ArrayCountHelper(array)) - 1)


UCLASS()
class PARAGONFIOCOMBAT_API UParagonFioCombat_GameInstance : public UGameInstance
{
GENERATED_BODY()

private:


STEAM_CALLBACK(UParagonFioCombat_GameInstance, OnPurchaseResponse, MicroTxnAuthorizationResponse_t); // REQUIRED

}


my .cpp file



void UParagonFioCombat_GameInstance::OnPurchaseResponse(MicroTxnAuthorizationResponse_t *pParam)
{
bool m_bAuthorized = pParam->m_bAuthorized;
uint64 m_ulOrderID = pParam->m_ulOrderID;

GEngine->AddOnScreenDebugMessage(-1, 30.0f, FColor::Yellow, "Steam MicroTXNAUTHRESPNSE CALLBACK");
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Bool: %s"), m_bAuthorized ? TEXT("true") : TEXT("false")));


}


This was weird because OnPurchaseResponse you don’t have to define in your header file. The callback macro (STEAM_CALLBACK) does the defining so you can directly implement it in your cpp file. Confused me a fair bit.

1 Like

Note, was unable to get the include to compile without wrapping it in the following.

#pragma push_macro(“ARRAY_COUNT”)
#undef ARRAY_COUNT
THIRD_PARTY_INCLUDES_START
#include “ThirdParty/Steamworks/Steamv147/sdk/public/steam/steam_api.h”
THIRD_PARTY_INCLUDES_END
#pragma pop_macro(“ARRAY_COUNT”)

Which I lifted from the SteamWorksCallBacks plugin

1 Like