/** * NymOS API 1.9.21 * * The contents of this file are subject to the NymOS License, version 1.0. * It is forbidden the use of the codes included on this file, even partially, * for third parties, such as its copy, without express authorization of the * intelectual property and commercial rights owners. A copy of the license * may be obtained at http://nymos.io/source-license. The intelectual * property and comercial rights of this file and codes belong to NymOS S.A. * * Copyright (c) 2017. All rights reserved. * */ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import { CustomHttpUrlEncodingCodec } from '../internal/encoder'; import { AccountInfo } from '../models/account-info.model'; import { AccountLimit } from '../models/account-limit.model'; import { Address } from '../models/address.model'; import { Business } from '../models/business.model'; import { Initiation } from '../models/initiation.model'; import { Problem } from '../models/problem.model'; import { Profile } from '../models/profile.model'; import { Session } from '../models/session.model'; import { SupportTicket } from '../models/support-ticket.model'; import { TempPasscode } from '../models/temp-passcode.model'; @Injectable() export class AccountsService { constructor(protected httpClient: HttpClient) { } /** * Change account's passcode * * @param oldPasscode The `old` passcode with exactly **4** digits. * @param newPasscode The `new` passcode with exactly **4** digits. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public changePasscode(oldPasscode: string, newPasscode: string): Observable { if (oldPasscode === null || oldPasscode === undefined) { throw new Error('Required parameter oldPasscode was null or undefined when calling changePasscode.'); } if (newPasscode === null || newPasscode === undefined) { throw new Error('Required parameter newPasscode was null or undefined when calling changePasscode.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (oldPasscode !== undefined) { queryParameters = queryParameters.set('old_passcode', oldPasscode); } if (newPasscode !== undefined) { queryParameters = queryParameters.set('new_passcode', newPasscode); } let headers = new HttpHeaders(); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/passcode`, { params: queryParameters, headers: headers, } ); } /** * Check email's availability * This `endpoint` can be called to check if given `email` is available to be used prior to requesting its verification. It is usefull while handling form validations from application side. * @param email The email to be checked * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public checkEmailAvailability(email: string): Observable { if (email === null || email === undefined) { throw new Error('Required parameter email was null or undefined when calling checkEmailAvailability.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (email !== undefined) { queryParameters = queryParameters.set('email', email); } let headers = new HttpHeaders(); return this.httpClient.get(`https://accounts-dot-nymos-dev.appspot.com/v1/account/email`, { params: queryParameters, headers: headers, } ); } /** * Confirm email verification * The final step required to complete the `email` verification. Links similar to the bellow will be sent by email and must be intercepted by apps once clicked (deep links): `https://nymos.io/email-verification?email=<email>&hash=<UUID>` * @param hash The unique `hash` sent by email as part of verification link. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public confirmEmailVerification(hash: string): Observable { if (hash === null || hash === undefined) { throw new Error('Required parameter hash was null or undefined when calling confirmEmailVerification.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (hash !== undefined) { queryParameters = queryParameters.set('hash', hash); } let headers = new HttpHeaders(); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/email`, { params: queryParameters, headers: headers, } ); } /** * Confirm mobile verification code * The final step required to complete the mobile verification. * @param id The initiation `id` obtained while calling `POST /v1/account/mobile`. * @param code The **6** digit numeric authentication code (usually received via SMS) * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public confirmMobileVerification(id: string, code: string): Observable { if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling confirmMobileVerification.'); } if (code === null || code === undefined) { throw new Error('Required parameter code was null or undefined when calling confirmMobileVerification.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (id !== undefined) { queryParameters = queryParameters.set('id', id); } if (code !== undefined) { queryParameters = queryParameters.set('code', code); } let headers = new HttpHeaders(); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/mobile`, { params: queryParameters, headers: headers, } ); } /** * Confirm passcode reset flow * * @param id The initiation `id` obtained while calling `POST /v1/account/passcodeReset`. * @param code The **6** digit numeric authentication code (usually received via SMS) * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public confirmPasscodeReset(id: string, code: string): Observable { if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling confirmPasscodeReset.'); } if (code === null || code === undefined) { throw new Error('Required parameter code was null or undefined when calling confirmPasscodeReset.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (id !== undefined) { queryParameters = queryParameters.set('id', id); } if (code !== undefined) { queryParameters = queryParameters.set('code', code); } let headers = new HttpHeaders(); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/passcodeReset`, { params: queryParameters, headers: headers, } ); } /** * Create or Validate account's passcode * Users can optionally set a `passcode` to protect their data. If the device supports `Touch ID`, they can also use their fingerprint instead of `passcode`. This `endpoint` can behave in two different ways: * If user has **never** set a passcode, it will be created and `200` will always be returned. * If user has previously set a passcode, `200 ` will only be returned if it matches with saved one. Apps are encouraged to store passcodes locally and only call this `endpoint` if they don't match. * @param passcode The passcode with exactly **4** digits. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public createOrValidatePasscode(passcode: string): Observable { if (passcode === null || passcode === undefined) { throw new Error('Required parameter passcode was null or undefined when calling createOrValidatePasscode.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (passcode !== undefined) { queryParameters = queryParameters.set('passcode', passcode); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/account/passcode`, { params: queryParameters, headers: headers, } ); } /** * Create a new ticket. * This `endpoint` can be used to create a new support ticket. For *authenticated* users, `full_name`, `email` and `mobile` are optional. For *anonymous* users, `full_name`, (`email` or `mobile`) are also required although this `endpoint` flags them as optional. * @param content * @param subject * @param fullName * @param mobile * @param email * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public createTicket(content: string, subject?: string, fullName?: string, mobile?: string, email?: string): Observable { if (content === null || content === undefined) { throw new Error('Required parameter content was null or undefined when calling createTicket.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (subject !== undefined) { queryParameters = queryParameters.set('subject', subject); } if (content !== undefined) { queryParameters = queryParameters.set('content', content); } if (fullName !== undefined) { queryParameters = queryParameters.set('full_name', fullName); } if (mobile !== undefined) { queryParameters = queryParameters.set('mobile', mobile); } if (email !== undefined) { queryParameters = queryParameters.set('email', email); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/support/tickets`, { params: queryParameters, headers: headers, } ); } /** * Delete account's passcode * * @param currentPasscode The `current` passcode with exactly **4** digits. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public deletePasscode(currentPasscode: string): Observable { if (currentPasscode === null || currentPasscode === undefined) { throw new Error('Required parameter currentPasscode was null or undefined when calling deletePasscode.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (currentPasscode !== undefined) { queryParameters = queryParameters.set('current_passcode', currentPasscode); } let headers = new HttpHeaders(); return this.httpClient.delete(`https://accounts-dot-nymos-dev.appspot.com/v1/account/passcode`, { params: queryParameters, headers: headers, } ); } /** * Initiate email verification * Apps can call this `endpoint` in order to change the email attached to current account. One email verification link similar to bellow will be sent to user's inbox so he can confirm the email's ownership: `https://nymos.io/email-verification?email=<email>&hash=<UUID>` Please be aware to the bellow restrictions: - Email links will expire within `24h` - The same Ip/Device/User can call this `endpoint` up to 10 times within `24h` window - Every time this `endpoint` is called using a non verified email, a new verification link is sent and the previus ones are invalidated (if any) - Multiple calls to this `endpoint` using an already verified email will have no effect (verification links won't be sent, email is kept verified) * @param email The email to be verified * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public initiateEmailVerification(email: string): Observable { if (email === null || email === undefined) { throw new Error('Required parameter email was null or undefined when calling initiateEmailVerification.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (email !== undefined) { queryParameters = queryParameters.set('email', email); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/account/email`, { params: queryParameters, headers: headers, } ); } /** * Initiate mobile authentication * Client apps will call this `endpoint` in order to **signup**, **login** or **change** user's mobile number: - If user is not logged in and mobile number isn't registered yet, `endpoint` consider it as **signup**. - If user is not logged in and mobile number already exists, `endpoint` consider it as **login**. - If user is logged in, `endpoint` consider that user is **changing** his mobile number. ```` +---------+ +---------------+ | |>--(A)-------- Initiate --------->| | | | (w/ mobile number) | | | | | | | |<--(B)-- Initiation accepted ----<| | | | (w/ initiation id) | | | Client | | NymOS | | |>--(C)-------- Confirm --------- >| | | | (w/ initiation id and code) | | | | | | | |<--(D)-- Validation confirmed ---<| | | | (w/ access token) | | +---------+ +---------------+ ```` * @param mobile The mobile phone number. Format with a `+` and country code e.g., +16175551212 ([E.164](https://en.wikipedia.org/wiki/E.164) format) * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public initiateMobileVerification(mobile: string): Observable { if (mobile === null || mobile === undefined) { throw new Error('Required parameter mobile was null or undefined when calling initiateMobileVerification.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (mobile !== undefined) { queryParameters = queryParameters.set('mobile', mobile); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/account/mobile`, { params: queryParameters, headers: headers, } ); } /** * Initiate passcode reset flow * In order to `RESET` account's passcode, users will have to `answer` a `challenge` and confirm the SMS `code` sent to their mobile numbers. Bellow challenges are available: Challenge | Description ------------ | ------------- `last_credit_topup`| The amount of user's last credit top-up accurate to cents (two decimal places) Two steps are needed in order to `RESET` account's passcode: 1. Call `POST /v1/account/passcodeReset` providing the **challenge** and **answer** (SMS will be sent) 2. Call `PUT /v1/account/passcodeReset` providing the **code** reeceived by SMS and the **new_passcode** * @param challenge The question that needs to be answered. * @param answer User's response for selected challenge. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public initiatePasscodeReset(challenge: string, answer: string): Observable { if (challenge === null || challenge === undefined) { throw new Error('Required parameter challenge was null or undefined when calling initiatePasscodeReset.'); } if (answer === null || answer === undefined) { throw new Error('Required parameter answer was null or undefined when calling initiatePasscodeReset.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (challenge !== undefined) { queryParameters = queryParameters.set('challenge', challenge); } if (answer !== undefined) { queryParameters = queryParameters.set('answer', answer); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/account/passcodeReset`, { params: queryParameters, headers: headers, } ); } /** * Link a facebook profile with current account * Users can optionally link [facebook](https://www.facebook.com/) profiles with their accounts. This is often used for `KYC` purposes and form auto filling. While logging in, apps must required the following [permissions](https://developers.facebook.com/docs/facebook-login/permissions): - `public_profile` - `user_friends` - `email` - `user_birthday` - `user_likes` - `user_work_history` - `user_photos` The flow is explained bellow: ```` +---------+ +---------------+ | |>--(A)---------- Login ---------->| | | | (using facebook sdk) | Facebook | | | | Server | | |<--(B)----- Login accepted ------<| | | | (w/ access token) +---------------+ | Client | | | +---------------+ | |>--(C)---------- Link ----------->| | | | (w/ access token) | | | | | NymOS | | |<--(D)-- Validation confirmed ---<| | | | | | +---------+ +---------------+ ```` * @param appId The facebook's app id. It is the same used while setting up [Facebok sdk](https://developers.facebook.com/docs/facebook-login/overview/). * @param accessToken The access token fetched from [Facebok sdk](https://developers.facebook.com/docs/facebook-login/overview/). * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public linkWithFacebook(appId: string, accessToken: string): Observable { if (appId === null || appId === undefined) { throw new Error('Required parameter appId was null or undefined when calling linkWithFacebook.'); } if (accessToken === null || accessToken === undefined) { throw new Error('Required parameter accessToken was null or undefined when calling linkWithFacebook.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (appId !== undefined) { queryParameters = queryParameters.set('app_id', appId); } if (accessToken !== undefined) { queryParameters = queryParameters.set('access_token', accessToken); } let headers = new HttpHeaders(); return this.httpClient.post(`https://accounts-dot-nymos-dev.appspot.com/v1/account/facebook`, { params: queryParameters, headers: headers, } ); } /** * Load user address * * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public loadAddress(): Observable
{ let headers = new HttpHeaders(); return this.httpClient.get
(`https://accounts-dot-nymos-dev.appspot.com/v1/account/business`, { headers: headers, } ); } /** * Load all information related to the account * This `endpoint` is a shortcut for loading all information related to the user's account. * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public loadInfo(): Observable { let headers = new HttpHeaders(); return this.httpClient.get(`https://accounts-dot-nymos-dev.appspot.com/v1/account`, { headers: headers, } ); } /** * Load user's limits * * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public loadLimits(): Observable { let headers = new HttpHeaders(); return this.httpClient.get(`https://accounts-dot-nymos-dev.appspot.com/v1/account/limits`, { headers: headers, } ); } /** * Load user's profile * * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public loadProfile(): Observable { let headers = new HttpHeaders(); return this.httpClient.get(`https://accounts-dot-nymos-dev.appspot.com/v1/account/profile`, { headers: headers, } ); } /** * Update user's address * * @param address * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public saveAddress(address: Address): Observable { if (address === null || address === undefined) { throw new Error('Required parameter address was null or undefined when calling saveAddress.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/address`, address, { headers: headers, } ); } /** * Update user's business * * @param business * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public saveBusiness(business: Business): Observable { if (business === null || business === undefined) { throw new Error('Required parameter business was null or undefined when calling saveBusiness.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/business`, business, { headers: headers, } ); } /** * Update user's profile * * @param profile * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public saveProfile(profile: Profile): Observable { if (profile === null || profile === undefined) { throw new Error('Required parameter profile was null or undefined when calling saveProfile.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.put(`https://accounts-dot-nymos-dev.appspot.com/v1/account/profile`, profile, { headers: headers, } ); } /** * Unlink a facebook profile from current account * Apps can call this method to unlink facebook accounts. Please note that access token isn't necessary because user could have lost access to his facebook. * @param appId The facebook's app id. It is the same used while setting up [Facebok sdk](https://developers.facebook.com/docs/facebook-login/overview/). * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ public unlinkFromFacebook(appId: string): Observable { if (appId === null || appId === undefined) { throw new Error('Required parameter appId was null or undefined when calling unlinkFromFacebook.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (appId !== undefined) { queryParameters = queryParameters.set('app_id', appId); } let headers = new HttpHeaders(); return this.httpClient.delete(`https://accounts-dot-nymos-dev.appspot.com/v1/account/facebook`, { params: queryParameters, headers: headers, } ); } }