Merchant Account Management

Last Updated on : 2024-06-24 09:13:55download

Use CocoaPods for fast integration

The SDK supports iOS 10.0 and later.

Add the following code block to the Podfile. In the root directory of your project, run pod update.

platform :ios, '10.0'

target 'Your_Project_Name' do
     pod "ThingSmartUserToBKit"
end
  • For more information about CocoaPods, see CocoaPods Guides.
  • Update CocoaPods to the latest version.

Terms

Term Description
Merchant Information about a specified merchant entity, including merchant name and business license.
Main account The main account of the SaaS system, equivalent to the developer account.
Sub-account The sub-account of the SaaS system, to be associated with a main account.

Use [ThingSmartUser sharedInstance] to get the specified ThingSmartUser operation class. Get the user properties in ThingSmartUser.h.

Log in with password

Users can log in to the main account and sub-accounts by using a password. In the case of pre-login (when information about multiple merchants is returned), select a specific merchant and fill in the selected merchant code into the login parameters. Thus, log in with a password.

API description

Logs in with an account and password.

- (void)loginMerchantByPassword:(NSString *_Nonnull)password
                    countryCode:(NSString *_Nonnull)countryCode
                       username:(NSString *_Nonnull)username
                   merchantCode:(NSString *_Nullable)merchantCode
           multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
                        success:(ThingSuccessHandler _Nullable)success
                        failure:(ThingFailureError _Nullable)failure

Parameters

Field Required Description
username Required Account | Email address
password Required The password.
countryCode Required The country code, for example, 86.
merchantCode Optional The code of a specified merchant. This parameter is optional for a single merchant and required for multiple merchants.
multiMerchantHanlder Optional When there is more than one merchant, a callback will be invoked. Users cannot log in successfully but need to select a merchant and log in again.
When there is only one merchant, users can log in successfully.

Sample code

Objective-C:

// Single merchant
[[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:nil success:^{
    NSLog(@"login success");
} failure:^(NSError *error) {
    NSLog(@"login error");
}];

// Multiple merchants
 [[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos) {
    NSLog(@"get merchantCode and login again");
    [[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:@"your_merchantCode" multiMerchantHanlder:nil success:^{
        NSLog(@"login success");
    } failure:^(NSError *error) {
        NSLog(@"login error");
    }];
} success:^{
    NSLog(@"login success");
} failure:^(NSError *error) {
    NSLog(@"login error");
}];

Swift:

// Single merchant
ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: nil, success: {     print("login success")
}, failure: { (error) in
    if let e = error {
        print("login failure: \(e)")
    }
})

// Multiple merchants
 ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: { (result) in ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: "merchant_code", multiMerchantHanlder: nil, success: {         print("login success")
    }, failure: { (error) in
        if let e = error {
            print("login failure: \(e)")
        }
    })
}, success: {
    print("login success")
}, failure: { (error) in
    if let e = error {
        print("login failure: \(e)")
    }
})

Log in with verification code

Get the login verification code, and fill in the verification code into the login parameters. Thus, log in with a verification code. In the case of pre-login (when information about multiple merchants is returned), pass in the specified merchant code to get a new verification code. And then, pass in the verification code and merchant code to log in.

API description

Returns a verification code for login.

- (void)sendMerchantVerifyCodeWithCountryCode:(NSString *_Nonnull)countryCode
                                     username:(NSString *_Nonnull)username
                                     codeType:(ThingMerchantCodeType)codeType
                                 merchantCode:(NSString *_Nullable)merchantCode
                                      success:(ThingSuccessHandler _Nullable)success
                                      failure:(ThingFailureError _Nullable)failure

Parameters

Parameter Description
countryCode The country code, for example, 86.
username The phone number | email address.
codeType The type of the verification code. Pass in ThingMerchantCodeLogin for login.

Sample code

Objective-C:

[[ThingSmartUser sharedInstance]sendMerchantVerifyCodeWithCountryCode:@"your_country_code" username:@"your_username" codeType:ThingMerchantCodeLogin merchantCode:nil success:^{
    NSLog(@"send verify code success");
} failure:^(NSError *error) {
    NSLog(@"send verify code failure: %@", error);
}];

Swift:

ThingSmartUser.sharedInstance()?.sendMerchantVerifyCode(withCountryCode: "your_country_code", username: "your_username", codeType: ThingMerchantCodeType.login, merchantCode: nil, success: {
    print("send verify code success")
}, failure: { (error) in
    if let error = error {
        print("send verify code failure: \(error)")
    }
})

API description

Logs in with a verification code.

- (void)loginMerchantByVerificationCode:(NSString *_Nonnull)code
                            countryCode:(NSString *_Nonnull)countryCode
                               username:(NSString *_Nonnull)username
                           merchantCode:(NSString *_Nullable)merchantCode
                   multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
                                success:(ThingSuccessHandler _Nullable)success
                                failure:(ThingFailureError _Nullable)failure
Field Description
username The account, phone number | email address.
Code The verification code.
countryCode The country code, for example, 86.
merchantCode The code of a specified merchant. This parameter is optional for a single merchant and required for multiple merchants.
multiMerchantHanlder When there is more than one merchant, a callback will be invoked. Users cannot log in successfully but need to select a merchant and log in again.
When there is only one merchant, users can log in successfully.

Sample code

Objective-C:

// Single merchant
 [[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:nil success:^{
        NSLog(@"login success");
} failure:^(NSError *error) {
        NSLog(@"login error");
}];

// Multiple merchants
 [[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos) {
    NSLog(@"get merchantCode and login again");
    [[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:@"merchant_code" multiMerchantHanlder:nil success:^{
        NSLog(@"login success");
    } failure:^(NSError *error) {
        NSLog(@"login error");
    }];
} success:^{
    NSLog(@"login success");
} failure:^(NSError *error) {
    NSLog(@"login error");
}];

Swift:

// Single merchant
ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: nil, success: {     print("login success")
}, failure: { (error) in
    if let e = error {
        print("login failure: \(e)")
    }
})

// Multiple merchants
ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: { (result) in
    ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: "merchant_code", multiMerchantHanlder: nil, success: {
        print("login success")
    }, failure: { (error) in
        if let e = error {
            print("login failure: \(e)")
        }
    })
}, success: {
    print("login success")
}, failure: { (error) in
    if let e = error {
        print("login failure: \(e)")
    }
})

Log in with a third-party account

Authorization process

  1. The third-party server grants an account access to the Tuya Developer Platform. The third party specifies the type of account, such as a system or employee account. For example, businesses, stores, and projects.

  2. The third-party system server sends the authorized account and country code to the Tuya Developer Platform, and requests a ticket.

    Merchant Account Management

Scenario

  1. Concatenate the Tuya’s system domain and the ticket to enable login-free redirection. Example: lighting.console.tuyacn.com?ticket=xxx For example, redirect users to the system website or an H5 page for device control.
  2. The Commercial Lighting App SDK gets the session status using the ticket to access all features of the SDK.

API description

Logs in with a third-party account.

- (void)loginMerchantByTicket:(nonnull NSString*)ticket
         multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
                      success:(nullable ThingSuccessHandler)success
                      failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
ticket The ticket obtained during the authorization process.

Sample code

Objective-C:

- (void)loginByTicket:(NSString *)ticket {
  [[ThingSmartUser sharedInstance] loginMerchantByTicket: ticket
                                                                multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nullable    merchantInfos) {
    NSLog(@"get merchant list");
  } success:^{
    NSLog(@"login by ticket success");
  } failure:^(NSError *error) {
      NSLog(@"login by ticket failure: %@",error);
  }];
}

Swift:

func loginByTicket(ticket: String) {
  ThingSmartUser.sharedInstance()?.loginMerchant(byTicket: ticket, multiMerchantHanlder: nil, success:{
    print("login by ticket success")
  }, failure:{ (error) in
    if let e = error {
      print("login by ticket failure:\(e)")
    }
  })
}

Recover/reset password

Follow these steps to change the password before login:

  1. Get the verification code for resetting the password.
  2. Pass the verification code to get the list of merchants.
  3. Get the respective merchant and invoke the reset password method to change the password.

API description

Returns a verification code for login.

- (void)sendMerchantVerifyCodeWithCountryCode:(NSString *_Nonnull)countryCode
                                     username:(NSString *_Nonnull)username
                                     codeType:(ThingMerchantCodeType)codeType
                                 merchantCode:(NSString *_Nullable)merchantCode
                                      success:(ThingSuccessHandler _Nullable)success
                                      failure:(ThingFailureError _Nullable)failure

Parameters

Parameter Description
countryCode The country code, for example, 86.
username The phone number | email address.
codeType The type of the verification code. Pass in ThingMerchantCodeModifyOrFindPasswordOrQuery.

Sample code

Objective-C:

[[ThingSmartUser sharedInstance]sendMerchantVerifyCodeWithCountryCode:@"your_country_code" username:@"your_username" codeType:ThingMerchantCodeModifyOrFindPasswordOrQuery merchantCode:nil success:^{
    NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
    NSLog(@"sendVerifyCode failure: %@", error);
}];

Swift:

ThingSmartUser.sharedInstance()?.sendMerchantVerifyCode(withCountryCode: "your_country_code", username: "your_username", codeType: ThingMerchantCodeType.modifyOrFindPasswordOrQuery, merchantCode: nil, success: {
    print("sendVerifyCode success")
}, failure: { (error) in
    if let error = error {
        print("sendVerifyCode failure: \(error)")
    }
})

API description

Returns the list of merchants.

- (void)queryMerchantInfosByVerificationCode:(NSString *_Nonnull)code
                                    username:(NSString *_Nonnull)username
                                 countryCode:(NSString *_Nonnull)countryCode
                                     success:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nullable merchantInfos))success
                                     failure:(ThingFailureError _Nullable)failure

Parameters

Parameter Description
countryCode The country code, for example, 86.
username The phone number | email address.
Code The verification code.

Sample code

Objective-C:

[[ThingSmartUser sharedInstance]queryMerchantInfosByVerificationCode:@"verification_code" username:@"your_username" countryCode:@"country_code" success:^(NSArray<ThingSmartMerchantModel *> * _Nullable merchantInfos) {
    NSLog(@"get merchant list");
} failure:^(NSError *error) {
    NSLog(@"error");
}];

Swift:

ThingSmartUser.sharedInstance()?.queryMerchantInfos(byVerificationCode: "verification_code", username: "your_username", countryCode: "country_code", success: { (result) in
    print("get merchant list")
}, failure: { (error) in
    if let error = error {
        print("failure: \(error)")
    }
})

API description

Recovers the password.

- (void)getBackMerchantPasswordByVerificationCode:(NSString *_Nonnull)code
                                         username:(NSString *_Nonnull)username
                                      countryCode:(NSString *_Nonnull)countryCode
                                      newPassword:(NSString *_Nonnull)newPassword
                                     merchantCode:(NSString *_Nonnull)merchantCode
                                          success:(ThingSuccessHandler _Nullable)success
                                          failure:(ThingFailureError _Nullable)failure
Field Description
username The account, phone number | email address.
newPassword The new password.
Code The verification code.
countryCode The country code, for example, 86.
merchantCode The code of a specified merchant.

Sample code

Objective-C:

[[ThingSmartUser sharedInstance]getBackMerchantPasswordByVerificationCode:@"verification_code" username:@"your_username" countryCode:@"country_code" newPassword:@"new_password" merchantCode:@"merchant_code" success:^{
    NSLog(@"get back password success");
} failure:^(NSError *error) {
    NSLog(@"get back password failure");
}];

Swift:

ThingSmartUser.sharedInstance()?.getBackMerchantPassword(byVerificationCode: "verification_code", username: "username", countryCode: "country_code", newPassword: "new_password", merchantCode: "merchant_code", success: {
    print("get password success")
}, failure: { (error) in
    if let error = error {
        print("get password failure: \(error)")
    }
})

Change password

To change the password after login, users can pass in the old password and new password.

API description

Changes the password.

- (void)resetMerchantPasswordWithUsername:(NSString *_Nonnull)username
                              countryCode:(NSString *_Nonnull)countryCode
                               oldPassword:(NSString *_Nonnull)oldPassword
                               newPassword:(NSString *_Nonnull)newPassword
                                   success:(ThingSuccessHandler _Nullable)success
                                   failure:(ThingFailureError _Nullable)failure
Field Description
oldPassword The old password.
newPassword The new password.
username The account, a mobile phone number.
countryCode The country code, for example, 86.

Sample code

Objective-C:

[[ThingSmartUser sharedInstance]resetMerchantPasswordWithUsername:@"your_user_name" countryCode:@"country_code" oldPassword:@"old_password" newPassword:@"new_password" success:^{
    NSLog(@"reset password success");
} failure:^(NSError *error) {
    NSLog(@"reset password failure");
}];

Swift:

ThingSmartUser.sharedInstance()?.resetMerchantPassword(withUsername: "your_user_name", countryCode: "country_code", oldPassword: "old_password", newPassword: "new_password", success: {
    print("reset password success")
}, failure: { (error) in
    print("reset password failure")
})

Log out

API description

Logs out of an account.

- (void)loginOutMerchantWithSuccess:(ThingSuccessHandler _Nullable)success
                            failure:(ThingFailureError _Nullable)failure

Delete account

API description

Deletes an account.

- (void)cancelMerchantAccount:(nullable ThingSuccessHandler)success
                      failure:(nullable ThingFailureError)failure

Get user information

Gets and synchronizes the latest user information to the local system.

API description

- (void)getMerchantUserInfoWithSuccess:(ThingSuccessHandler _Nullable)success
                            failure:(ThingFailureError _Nullable)failure