Skip to main content
Version: v4

Quick Start

Overview

  • Compliance helps games meet national regulations on protecting minors, covering three areas: real-name verification, anti-addiction, and payment limits.
  • For a more detailed feature overview, see Compliance Features.

Integration

  • This guide uses C++ to demonstrate compliance integration; other languages can refer to the corresponding DLL calling methods.
  • Before integrating compliance, read Quick Start to understand the basic integration process, and complete SDK initialization.
Initialization Requirement

You must successfully call TapSDK_Init before calling any Compliance API. Calling compliance functions without initialization or after initialization failure will return errors or unexpected results.

1. Real-Name Verification and Anti-Addiction

Overall integration flow:

  1. Register callbacks for the ComplianceEnsureRealName and ComplianceActionsEvent events
  2. Call TapCompliance_AsyncEnsureRealName to start real-name verification
  3. In the ComplianceEnsureRealName callback, call TapCompliance_EnableAntiAddiction after verification succeeds
  4. Handle the ComplianceActionsEvent callback — show a Toast or Alert based on the action type, or exit the game
#include <atomic>
#include <iostream>
#include <thread>

#include "taptap_api.h"
#include "taptap_compliance.h"

using namespace std;

atomic<int64_t> gRequestID;
atomic<bool> gAntiAddictionPassed;

void complianceEnsureRealNameCallback(TapEventID eventID, void* data);
void complianceActionsCallback(TapEventID eventID, void* data);

int main()
{
// SDK initialization and launch verification are omitted here — assume they have completed successfully

// 1. Register callbacks — only needs to be done once
TapSDK_RegisterCallback(TapEventID::ComplianceEnsureRealName, complianceEnsureRealNameCallback);
TapSDK_RegisterCallback(TapEventID::ComplianceActionsEvent, complianceActionsCallback);

// 2. Start real-name verification. If the player has not verified, TapTap will show the verification UI
TapSDK_Result result = TapCompliance_AsyncEnsureRealName(TapCompliance(), ++gRequestID);
if (result != TapSDK_Result_OK) {
// Request failed to start; no callback will be invoked — recommend exiting the game
return -1;
}

// 3. Main game loop
bool running = true;
while (running) {
// Process SDK callback events
TapSDK_RunCallbacks();

if (!gAntiAddictionPassed) {
// Waiting for real-name verification and anti-addiction check to complete
this_thread::sleep_for(chrono::milliseconds(100));
continue;
}

// Your game logic
// ...

// Adjust sleep duration to match your target frame rate
this_thread::sleep_for(chrono::milliseconds(100));
}

// 4. Clean up
TapSDK_Shutdown();
return 0;
}

// Real-name verification result callback
void complianceEnsureRealNameCallback(TapEventID eventID, void* data){
auto resp = static_cast<TapComplianceEnsureRealNameResponse*>(data);
if (resp->error != nullptr) {
cout << "EnsureRealName callback failed, code=" << resp->error->code
<< ", message=" << (resp->error->message ? resp->error->message : "unknown") << endl;
// Handle the error — recommend exiting the game
exit(-1);
}

switch (resp->status){
case TapComplianceRealNameStatus_Success:
if (TapCompliance_EnableAntiAddiction(TapCompliance()) != TapSDK_Result_OK) {
// Show alert and exit the game
exit(-1);
}
// Anti-addiction module started successfully; TapEventID::ComplianceActionsEvent will be received later
break;
case TapComplianceRealNameStatus_Canceled:
// Show alert and exit the game
exit(-1);
break;
case TapComplianceRealNameStatus_Failed:
// Show alert and exit the game
exit(-1);
break;
default:
// Show alert and exit the game
exit(-1);
break;
}
}


// Anti-addiction notification callback
void complianceActionsCallback(TapEventID eventID, void* data){
auto resp = static_cast<TapComplianceActionsEvent*>(data);
for (uint32_t i = 0; i < resp->count; ++i) {
const TapComplianceAction& action = resp->actions[i];
switch (action.action_type) {
case TapComplianceActionType_Toast:
// Show toast
// ShowToast(action.title, action.description, action.display_duration_seconds);
break;
case TapComplianceActionType_Alert:
// Show alert
// ShowAlert(action.title, action.description, action.display_duration_seconds);
break;
case TapComplianceActionType_Exit:
// Exit the game
exit(-1);
break;
default:
// Default handling
break;
}
}

gAntiAddictionPassed = true;
}

2. Payment Limit Check

Before a player initiates a payment, call TapCompliance_CheckPaymentLimit to check whether the payment is allowed. This is a synchronous call — no callback is needed:

warning

Payment limit checks can only be called after TapCompliance_EnableAntiAddiction has completed.

void TryPurchase(uint32_t amount) {
TapComplianceCheckPaymentLimitRequest req{};
req.amount = amount;

TapComplianceCheckPaymentLimitResponse resp{};
TapSDK_Result result = TapCompliance_CheckPaymentLimit(TapCompliance(), &req, &resp);
if (result != TapSDK_Result_OK) {
// Request failed — recommend rejecting the payment
return;
}

if (!resp.allow) {
// Payment not allowed — show message and block the payment
// ShowAlert(resp.title, resp.description);
return;
}

// Payment allowed — proceed with the payment flow
DoPurchase(amount);
}

3. Report Payment

After a successful payment, call TapCompliance_SubmitPayment to report the amount. This is a synchronous call:

// Call after a successful payment to report the amount
void PurchaseSuccessCallback(uint32_t amount) {
TapComplianceSubmitPaymentRequest req{};
req.amount = amount; // Amount in fen

TapSDK_Result result = TapCompliance_SubmitPayment(TapCompliance(), &req);
if (result != TapSDK_Result_OK) {
// Report failed
}
}

Error Handling

  • All API calls return TapSDK_Result; use it for user feedback or retry. See TapSDK_Result.
    • If the return value is not TapSDK_Result_OK, the request failed to start and no callback will be invoked.
  • When resp->error is non-null in a callback, the request failed; use TapSDK_ErrorCode for feedback or retry. See TapSDK_ErrorCode.