/** * 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 { Card } from '../models/card.model'; import { CseCard } from '../models/cse-card.model'; import { Payment } from '../models/payment.model'; import { Problem } from '../models/problem.model'; @Injectable() export class CardsService { constructor(protected httpClient: HttpClient) { } /** * Delete a card * * @param cardId * @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 deleteCard(cardId: string): Observable { if (cardId === null || cardId === undefined) { throw new Error('Required parameter cardId was null or undefined when calling deleteCard.'); } let headers = new HttpHeaders(); return this.httpClient.delete(`https://cards-dot-nymos-dev.appspot.com/v1/cards/${encodeURIComponent(String(cardId))}`, { headers: headers, } ); } /** * Load all cards available for making payments * * @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 loadCards(): Observable> { let headers = new HttpHeaders(); return this.httpClient.get>(`https://cards-dot-nymos-dev.appspot.com/v1/cards`, { headers: headers, } ); } /** * Make a payment using encrypted card * The `card` entity will hold metadata related to the `encrypted` card and must be set as following: - `card_id`, `status`, `created` and `modified` attributes will be filled automatically by the backengine. - `first6`, `last4`, `exp_month`, `exp_year`, `contract` and `gateway` are __mandatory__. - `brand` and `funding` are __optional__ but we strongly recommend setting them. - `address` must not be specified for the time being and will be used later on ([AVS](http://support.worldpay.com/support/kb/gg/corporate-gateway-guide/content/directintegration/authentication.htm#Address)). The bellow gateways are supported: Gateway | Description ------------ | ------------- `worldpay` | Card details must be `encrypted` using [Worldpay](https://github.com/Worldpay) libraries for [Web](https://github.com/Worldpay/worldpay-cse-lib-javascript), [Android](https://github.com/Worldpay/worldpay-cse-lib-android) or [IOS](https://github.com/Worldpay/worldpay-cse-lib-ios) The bellow contracts are supported: Contract | Description ------------ | ------------- `none` | Card will be deleted as soon as curren payment is processed. `auto` | Card details will be saved and can be used while submiting future payments. This `endpoint` can only be called if payment is still at `created` status, which means no source has ever been attached. * @param paymentId The payment id where card will be used as source * @param cseCard * @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 payUsingCseCard(paymentId: string, cseCard: CseCard): Observable { if (paymentId === null || paymentId === undefined) { throw new Error('Required parameter paymentId was null or undefined when calling payUsingCseCard.'); } if (cseCard === null || cseCard === undefined) { throw new Error('Required parameter cseCard was null or undefined when calling payUsingCseCard.'); } let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (paymentId !== undefined) { queryParameters = queryParameters.set('payment_id', paymentId); } let headers = new HttpHeaders(); headers = headers.set("Content-Type", "application/json"); return this.httpClient.post(`https://cards-dot-nymos-dev.appspot.com/v1/cards:pay`, cseCard, { params: queryParameters, headers: headers, } ); } /** * Make a payment using selected card * This `endpoint` can only be called if payment is still on `created` status, which means no source has been attached. * @param cardId * @param paymentId * @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 payUsingSavedCard(cardId: string, paymentId: string): Observable { if (cardId === null || cardId === undefined) { throw new Error('Required parameter cardId was null or undefined when calling payUsingSavedCard.'); } if (paymentId === null || paymentId === undefined) { throw new Error('Required parameter paymentId was null or undefined when calling payUsingSavedCard.'); } 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://cards-dot-nymos-dev.appspot.com/v1/cards/${encodeURIComponent(String(cardId))}:pay`, { params: queryParameters, headers: headers, } ); } }