/** * 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 { Payment } from '../models/payment.model'; import { Problem } from '../models/problem.model'; import { RecentContact } from '../models/recent-contact.model'; import { TransferReceiver } from '../models/transfer-receiver.model'; import { TransferReceiverFilter } from '../models/transfer-receiver-filter.model'; import { TransferSendDetails } from '../models/transfer-send-details.model'; import { Wallet } from '../models/wallet.model'; import { WalletTransaction } from '../models/wallet-transaction.model'; @Injectable() export class WalletsService { constructor(protected httpClient: HttpClient) { } /** * Create a new transaction for sending funds to another wallet * This `endpoint` should be called whenever user wants to top up his wallet Note that this api will create the topup transaction but no payment occurs at this level. * @param walletId Target wallet being topped up * @param transferId The transfer id * @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 confirmWalletTransferSendTransaction(walletId: string, transferId: string): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling confirmWalletTransferSendTransaction.'); } if (transferId === null || transferId === undefined) { throw new Error('Required parameter transferId was null or undefined when calling confirmWalletTransferSendTransaction.'); } let headers = new HttpHeaders(); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transfers/${encodeURIComponent(String(transferId))}:confirm`, { headers: headers, } ); } /** * Create new wallet * Create new wallet in specified `currency`. Please note that only one `wallet` per currency is allowed. * @param currency 3-letter [ISO code](https://en.wikipedia.org/wiki/ISO_4217) representing the currency * @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 createWallet(currency: string): Observable { if (currency === null || currency === undefined) { throw new Error('Required parameter currency was null or undefined when calling createWallet.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (currency !== undefined) { queryParameters = queryParameters.set('currency', currency); } let headers = new HttpHeaders(); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets`, { params: queryParameters, headers: headers, } ); } /** * Create a new transaction for topping up the wallet * This `endpoint` should be called whenever user wants to top up his wallet Note that this api will create the topup transaction but no payment occurs at this level. * @param walletId Target wallet being topped up * @param amount The amount being topped up * @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 createWalletTopupTransaction(walletId: string, amount: number): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling createWalletTopupTransaction.'); } if (amount === null || amount === undefined) { throw new Error('Required parameter amount was null or undefined when calling createWalletTopupTransaction.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (amount !== undefined) { queryParameters = queryParameters.set('amount', amount); } let headers = new HttpHeaders(); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transactions:createTopup`, { params: queryParameters, headers: headers, } ); } /** * Create a new transaction for sending funds to another wallet * This `endpoint` should be called whenever user wants to top up his wallet Note that this api will create the topup transaction but no payment occurs at this level. * @param walletId Target wallet being topped up * @param details * @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 createWalletTransferSendTransaction(walletId: string, details?: TransferSendDetails): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling createWalletTransferSendTransaction.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transfers`, details, { headers: headers, } ); } /** * Load agent's recent contacts list * * @param limit This is the maximum number of objects that may be returned. A query may return fewer than the value of `limit` once reached the end of the list of data. * @param after This is the cursor that points to the `end` of the page of data that has been returned. * @param before This is the cursor that points to the `start` of the page of data that has been returned. * @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 loadRecentContacts(limit?: number, after?: string, before?: string): Observable> { let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (limit !== undefined) { queryParameters = queryParameters.set('limit', limit); } if (after !== undefined) { queryParameters = queryParameters.set('after', after); } if (before !== undefined) { queryParameters = queryParameters.set('before', before); } let headers = new HttpHeaders(); return this.httpClient.get>(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/transfers:queryRecentContacts`, { params: queryParameters, headers: headers, } ); } /** * Load a single wallet * * @param walletId The wallet id to be fetched * @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 loadWallet(walletId: string): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling loadWallet.'); } let headers = new HttpHeaders(); return this.httpClient.get(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}`, { headers: headers, } ); } /** * Get a single transaction * This `endpoint` should return a single transaction (High Consistency). * @param walletId The wallet id * @param transactionId The transaction id * @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 loadWalletTransaction(walletId: string, transactionId: string): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling loadWalletTransaction.'); } if (transactionId === null || transactionId === undefined) { throw new Error('Required parameter transactionId was null or undefined when calling loadWalletTransaction.'); } let headers = new HttpHeaders(); return this.httpClient.get(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transactions/${encodeURIComponent(String(transactionId))}`, { headers: headers, } ); } /** * Get list of all transactions related to a specific wallet * This `endpoint` should return list of all transactions associated with specified wallet. Depending on the transaction `type`, additional details will be set on each transaction entry Type | Description ------------ | ------------- `topup` | Will hold information related to topup transactions `nymcard` | A new nymcard transaction will be added when nymcards are topped up `transfer` | Used to represent fund transfer between wallets * @param walletId The wallet id from where transactions will be fetched * @param limit This is the maximum number of objects that may be returned. A query may return fewer than the value of `limit` once reached the end of the list of data. * @param after This is the cursor that points to the `end` of the page of data that has been returned. * @param before This is the cursor that points to the `start` of the page of data that has been returned. * @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 loadWalletTransactions(walletId: string, limit?: number, after?: string, before?: string): Observable> { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling loadWalletTransactions.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (limit !== undefined) { queryParameters = queryParameters.set('limit', limit); } if (after !== undefined) { queryParameters = queryParameters.set('after', after); } if (before !== undefined) { queryParameters = queryParameters.set('before', before); } let headers = new HttpHeaders(); return this.httpClient.get>(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transactions`, { params: queryParameters, headers: headers, } ); } /** * Load list of all user wallets * * @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 loadWallets(): Observable> { let headers = new HttpHeaders(); return this.httpClient.get>(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets`, { headers: headers, } ); } /** * Make a payment using a wallet * This `endpoint` can only be called if payment is still on `created` status, which means no source has been attached. * @param walletId The wallet from where money should be debited * @param paymentId The payment id where wallet will be used as source * @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 payUsingWallet(walletId: string, paymentId: string): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling payUsingWallet.'); } if (paymentId === null || paymentId === undefined) { throw new Error('Required parameter paymentId was null or undefined when calling payUsingWallet.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (paymentId !== undefined) { queryParameters = queryParameters.set('payment_id', paymentId); } let headers = new HttpHeaders(); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}:pay`, { params: queryParameters, headers: headers, } ); } /** * Query transfer receiver * This `endpoint` should be called whenever user wants to top up his wallet Note that this api will create the topup transaction but no payment occurs at this level. * @param walletId Target wallet from where money is eoll be transferred * @param filter * @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 searchTransferReceiver(walletId: string, filter?: TransferReceiverFilter): Observable { if (walletId === null || walletId === undefined) { throw new Error('Required parameter walletId was null or undefined when calling searchTransferReceiver.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.post(`https://wallets-dot-nymos-dev.appspot.com/v1/wallets/${encodeURIComponent(String(walletId))}/transfers:queryReceiver`, filter, { headers: headers, } ); } }