createUserIdRelation static method

Future<CreateUserRelationResponse> createUserIdRelation(
  1. String masterUserId
)

Creates a relation between current user and another user.

This method allows developers to establish a connection between users. Thanks to this relation, sub-user will also own all the purchases master user have made.

For example, you have a user who has two devices and he/she wants to use your app with both of them. If your user has some purchases that made with the first userId, also second userId will be able to see this products as purchased. Whenever there is a change in a user's entitlement to products within your app, the second device user also will be able to get this updates. It's easy to use this feature with appmate only by establishing relationships between the users.

masterUserId Id of the user has the purchases of his/her own. User id can be retrieved via getUserId method.

Callbacks CreateUserRelationResponse and GenericError in case of failure.

Implementation

static Future<CreateUserRelationResponse> createUserIdRelation(
    String masterUserId) async {
  List<Object?>? response = await _channel
      .invokeMethod('createUserIdRelation', {"masterUserId": masterUserId});
  CreateUserRelationResponse result =
      new CreateUserRelationResponse(null, null);
  if (response != null) {
    if (response[0] != null) {
      UserRelation userRelation =
          UserRelation.fromJson(json.decode(response[0].toString()));
      result = new CreateUserRelationResponse(userRelation, null);
    }
    if (response[1] != null) {
      GenericError error =
          GenericError.fromJson(json.decode(response[1]!.toString()));
      result = new CreateUserRelationResponse(null, error);
    }
    return result;
  }
  return result;
}