Integrating with Fyber’s Virtual Currency Server (VCS)

If you don’t host your own currency service, Fyber provides virtual currency hosting. This is the default setting for mobile applications on your developer dashboard. Keep in mind that to be able to use this feature you need to pass a valid security token when you start the SDK.

Request for New Coins

To request virtual currency use the VirtualCurrencyRequester:

VirtualCurrencyRequester virtualCurrencyRequester = VirtualCurrencyRequester.Create()
    // optional method chaining
    //.AddParameter("key", "value")
    // Overrideing currency Id (when you have more than one currency)
    // Changing the GUI notification behaviour for when the user is rewarded
    // you don't need to add a callback if you are using delegates


To access the response from the Virtual Currency System you’ll need to set these delegates:

void OnEnable()
    FyberCallback.VirtualCurrencySuccess += OnCurrencyResponse;
    FyberCallback.VirtualCurrencyError += OnCurrencyErrorResponse;    

void OnDisable()
    FyberCallback.VirtualCurrencySuccess += OnCurrencyResponse;
    FyberCallback.VirtualCurrencyError += OnCurrencyErrorResponse;    

public void OnCurrencyResponse(VirtualCurrencyResponse response)
    UnityEngine.Debug.Log("Delta of coins: " + response.DeltaOfCoins.ToString() +
                            ". Transaction ID: " + response.LatestTransactionId +
                            ".\nCurreny ID: " + response.CurrencyId +
                            ". Currency Name: " + response.CurrencyName;

public void OnCurrencyErrorResponse(VirtualCurrencyErrorResponse vcsError)
    UnityEngine.Debug.Log(String.Format("Delta of coins request failed.\n" +
                        "Error Type: {0}\nError Code: {1}\nError Message: {2}",
                        vcsError.Type, vcsError.Code, vcsError.Message);

OnCurrencyResponse is called with the answer returned from the server if no error is triggered. The passed response parameter contains the response data. Use response.DeltaOfCoins to obtain the number of coins the user has earned since the last request to VCS and response.LatestTransactionId if you’re interested in the user’s latest transaction ID.

The passed response parameter returned on the first call to VCS from a new installation of your app will always contain the reward amount and transaction ID of the user’s latest transaction in our system. To avoid rewarding a user for a second time in case they have uninstalled and re-installed your app, you can do one of two things:

Option 1: Store it

Store the most recent transaction ID somewhere that will survive an uninstall, and compare it to the transaction ID returned from response.LatestTransactionId. Only rewarding when the stored ID and returned ID don’t match.

Option 2: Fresh install

Ignore the first response from VCS from a fresh install of your app. All subsequent calls to VCS will then behave normally.

Error Types

OnCurrencyErrorResponse(VirtualCurrencyErrorResponse vcsError) is invoked either if the request fails or the server returns an error.

  • vcsError.Type returns the general type of the error, defined in ErrorType . A description of the possible error types is shown below.

    ErrorType Description
    ERROR_INVALID_RESPONSE Returned response is not formatted in an expected way.
    ERROR_INVALID_RESPONSE_SIGNATURE Response doesn’t contain a valid signature. The response signature is verified against your secret token.
    SERVER_RETURNED_ERROR The server returned an error. Use response.getErrorCode() and response.getErrorMessage().
    ERROR_OTHER An error occurred whose cause couldn’t be determined.
  • vcsError.Code and vcsError.Message will return the Congratulations! You’ve earned XX coins! server-provided error code and error message respectively. This methods will only return meaningful data if the error type is ErrorType.SERVER_RETURNED_ERROR

User Notifications

A user notification with the message: Congratulations! You’ve earned XX coins! will be shown by default after a successful response in which the delta of coins is bigger than 0. You can override this behaviour in two ways:

  1. Using the Settings object you get when the Fyber SDK is first started:

     Fyber.Settings settings = Fyber.with(appId, this).start();
  2. Chaining NotifyUserOnReward method on the VirtualCurrencyRequester: