/** * 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 { Nymcard } from '../models/nymcard.model'; import { NymcardDetails } from '../models/nymcard-details.model'; import { NymcardPresets } from '../models/nymcard-presets.model'; import { NymcardTransaction } from '../models/nymcard-transaction.model'; import { Problem } from '../models/problem.model'; @Injectable() export class NymcardsService { constructor(protected httpClient: HttpClient) { } /** * Create a new nymcard and returns its first topup transaction * Customers can create nymcards with different brands, currencies, etc... Available nymcard brands: Brand | Description ------------ | ------------- `mastercard` | [MasterCard](https://www.mastercard.com) is the default `brand` used by nymcards when no other is specified. Available nymcard currencies: Currency | Description ------------ | ------------- `usd` | United States Dollar is the default `currency` used by nymcards when no other is specified. Available nymcard statuses: Status | Description ------------ | ------------- `created` | Card has just been created and no topup has been made. While under `created` status, the `credit_card` attribute will always be **null** and will only be set after first topup. `active` | Card is active and can be used for making purchases world wide. `blocked` | Card has been blocked by the user and all purchase attempts will be declined until it gets unblocked In order to create and topup a nymcard for the first time, apps will have to: 1. Call `POST /nymcards::createAndTopup` to create a new nymcard and its first topup transaction. 2. Call `POST /payments/{payment_id}/payUsingWallet` to pay for the topup transaction. Please note that nymcard will be created only after topup has been `authorized` and it won't be returned while listing existing cards. Reloadable nymcards can be topped up multiple times calling the bellow apis: 1. Call `POST /nymcards/{nymcard_id}:createTopup` to create a new topup transaction. 2. Call `POST /payments/{payment_id}/payUsingWallet` to pay for the topup transaction. * @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 createNymcardAndTopup(details: NymcardDetails): Observable { if (details === null || details === undefined) { throw new Error('Required parameter details was null or undefined when calling createNymcardAndTopup.'); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.post(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards:createAndTopup`, details, { headers: headers, } ); } /** * Create a new transaction for topping up the nymcard * This `endpoint` should be called whenever user wants to top up his nymcard. Please note that non reloadable credit cards can be topped up just once. * @param nymcardId Target nymcard 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 createTopupTransaction(nymcardId: string, amount: number): Observable { if (nymcardId === null || nymcardId === undefined) { throw new Error('Required parameter nymcardId was null or undefined when calling createTopupTransaction.'); } if (amount === null || amount === undefined) { throw new Error('Required parameter amount was null or undefined when calling createTopupTransaction.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (amount !== undefined) { queryParameters = queryParameters.set('amount', amount); } let headers = new HttpHeaders(); return this.httpClient.post(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards/${encodeURIComponent(String(nymcardId))}/transactions:createTopup`, { params: queryParameters, headers: headers, } ); } /** * Load nymcard. * * @param nymcardId The nymcard 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 loadNymcard(nymcardId: string): Observable { if (nymcardId === null || nymcardId === undefined) { throw new Error('Required parameter nymcardId was null or undefined when calling loadNymcard.'); } let headers = new HttpHeaders(); return this.httpClient.get(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards/${encodeURIComponent(String(nymcardId))}`, { headers: headers, } ); } /** * Fetch nymcard presets * This `endpoint` must be called in order to load predefined amounts while issuing nymcards. It will take into account user's limits and other restrictions that may apply per market/region. Apps should disable presets with amount smaller than `min` and higher than `max`. * @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 loadNymcardPresets(currency: string): Observable { if (currency === null || currency === undefined) { throw new Error('Required parameter currency was null or undefined when calling loadNymcardPresets.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (currency !== undefined) { queryParameters = queryParameters.set('currency', currency); } let headers = new HttpHeaders(); return this.httpClient.get(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards:presets`, { params: queryParameters, headers: headers, } ); } /** * Load nymcard transaction. * * @param nymcardId The nymcard 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 loadNymcardTransaction(nymcardId: string, transactionId: string): Observable { if (nymcardId === null || nymcardId === undefined) { throw new Error('Required parameter nymcardId was null or undefined when calling loadNymcardTransaction.'); } if (transactionId === null || transactionId === undefined) { throw new Error('Required parameter transactionId was null or undefined when calling loadNymcardTransaction.'); } let headers = new HttpHeaders(); return this.httpClient.get(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards/${encodeURIComponent(String(nymcardId))}/transactions/${encodeURIComponent(String(transactionId))}`, { headers: headers, } ); } /** * Get list of all transactions related to a specific nymcard * * @param nymcardId The nymcard id * @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 loadNymcardTransactions(nymcardId: string, limit?: number, after?: string, before?: string): Observable> { if (nymcardId === null || nymcardId === undefined) { throw new Error('Required parameter nymcardId was null or undefined when calling loadNymcardTransactions.'); } 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://nymcards-dot-nymos-dev.appspot.com/v1/nymcards/${encodeURIComponent(String(nymcardId))}/transactions`, { params: queryParameters, headers: headers, } ); } /** * Load all nymcards * * @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 loadNymcards(): Observable> { let headers = new HttpHeaders(); return this.httpClient.get>(`https://nymcards-dot-nymos-dev.appspot.com/v1/nymcards`, { headers: headers, } ); } }