From 09f83674617feb0249beae9cc923f2a696e92273 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Wed, 17 May 2023 17:11:28 +0200 Subject: [PATCH 01/52] Client Refactor,Remove Ajax --- package.json | 1 - src/BuckarooClient.ts | 11 +-- src/Constants/Endpoints.ts | 4 +- src/Models/Request.ts | 117 ++++++---------------- src/PaymentMethods/PaymentMethod.ts | 4 +- src/Request/Client.ts | 147 +++++++--------------------- src/Request/Headers.ts | 37 +++++-- src/Request/Hmac.ts | 41 ++++---- src/Request/HttpsClient.ts | 55 +++++++++++ src/Request/Response.ts | 28 ++---- src/Utils/Types.ts | 4 +- tests/BuckarooClient.test.ts | 4 +- tests/Client.test.ts | 24 +++++ 13 files changed, 220 insertions(+), 257 deletions(-) create mode 100644 src/Request/HttpsClient.ts create mode 100644 tests/Client.test.ts diff --git a/package.json b/package.json index d04f07a9..8a9a5cdd 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "typescript": "^4.9.4" }, "dependencies": { - "axios": "^1.3.5", "crypto-js": "^4.1.1", "ip-address": "^8.1.0" }, diff --git a/src/BuckarooClient.ts b/src/BuckarooClient.ts index 8d2f5a29..934d8c28 100644 --- a/src/BuckarooClient.ts +++ b/src/BuckarooClient.ts @@ -1,12 +1,7 @@ import { IConfig, ICredentials } from './Utils/Types' import { Client } from './Request/Client' -let _client: Client -export function initializeBuckarooClient(credentials: ICredentials, config?: IConfig) { - if (!_client) { - _client = Client.initialize(credentials, config) - } - return _client +export function initializeBuckarooClient(credentials: ICredentials, config: IConfig) { + + return Client.initialize(credentials, config) } -const BuckarooClient = () => (_client instanceof Client ? _client : Client.initialize()) -export default BuckarooClient diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index afdb6cad..ce8478e1 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -1,6 +1,6 @@ enum Endpoints { - LIVE = 'https://checkout.buckaroo.nl/', - TEST = 'https://testcheckout.buckaroo.nl/' + LIVE = 'checkout.buckaroo.nl', + TEST = 'testcheckout.buckaroo.nl' } enum RequestType { Data = 1, diff --git a/src/Models/Request.ts b/src/Models/Request.ts index f79e874c..df421eea 100644 --- a/src/Models/Request.ts +++ b/src/Models/Request.ts @@ -2,63 +2,52 @@ import { ITransaction } from './ITransaction' import { IServiceList, IServices } from './ServiceList' import { IParameter } from './Parameters' import { firstUpperCase } from '../Utils/Functions' -import { AdditionalParameter, ServiceParameters } from '../Utils/Types' +import {AdditionalParameter, ServiceParameters} from '../Utils/Types' import { IPProtocolVersion } from '../Constants/IPProtocolVersion' export class Request { - protected _data: { [key: string]: any } = {} - get data(): object { - return this._data - } - public setRequestDataKey(key: string, data: any) { - this._data[key] = data - } - public filter(data: ITransaction | (ITransaction & ServiceParameters)) { - return Object.keys(data) - .filter((key) => this._data[key] === undefined && data[key] !== undefined) - .reduce((obj: ServiceParameters, key) => { - obj[key] = data[key] - return obj - }, {}) - } -} + private readonly _data: ITransaction -export class TransactionRequest extends Request { + constructor(data:ITransaction) { + this._data = data + } get data(): ITransaction { return this._data } - public get services(): IServices | undefined { - return this._data['services'] - } - public set services(services: IServices | undefined) { - this._data['services'] = services - } - public setServices(services: IServiceList) { - this.services = { ServiceList: [services] } - } - public addServices(serviceList: IServiceList) { - if (this.services) { - this.services.ServiceList.push(serviceList) - } else { - this.setServices(serviceList) + getFormattedData():object { + let data:any = {} + if (this._data.additionalParameters) { + data.additionalParameters = this.formatAdditionalParameters() + } + if (this._data.customParameters) { + data.customParameters = this.formatCustomParameters() + } + if (this._data.clientIP) { + data.clientIP = this.formatClientIp() } + return data } - formatAdditionalParameters() { - if (this.data.additionalParameters) { - this.setRequestDataKey('additionalParameters', { - additionalParameter: this.formatParametersMap(this.data.additionalParameters) - }) + return { + additionalParameter: this.formatParametersMap(this._data.additionalParameters) } } formatCustomParameters() { - if (this.data.customParameters) { - this.setRequestDataKey('customParameters', { - list: this.formatParametersMap(this.data.customParameters) - }) + return { + list: this.formatParametersMap(this._data.customParameters) } } - protected formatParametersMap(value: AdditionalParameter): IParameter[] { + public formatClientIp() { + let ip = this._data.clientIP + if (typeof ip === 'string') { + ip = { + type: IPProtocolVersion.getVersion(ip), + address: ip + } + } + return ip + } + protected formatParametersMap(value: AdditionalParameter = {}): IParameter[] { return Object.keys(value).map((key, value) => { return { Name: key, @@ -66,50 +55,6 @@ export class TransactionRequest extends Request { } }) } - public basicParameters: Record = { - clientIP: true, - currency: true, - returnURL: true, - returnURLError: true, - returnURLCancel: true, - returnURLReject: true, - pushURL: true, - pushURLFailure: true, - invoice: true, - order: true, - amountDebit: true, - amountCredit: true, - description: true, - originalTransactionKey: true, - originalTransactionReference: true, - culture: true, - startRecurrent: true, - continueOnIncomplete: true, - servicesSelectableByClient: true, - servicesExcludedForClient: true, - customParameters: true, - additionalParameters: true - } - public setBasicParameters(data: ITransaction) { - for (const key in data) { - if (this.basicParameters[key]) { - this._data[key] = data[key] - } - } - this.formatAdditionalParameters() - this.formatCustomParameters() - this.setClientIp() - } - - public setClientIp() { - let ip = this.data.clientIP - if (ip && typeof ip === 'string') { - this.setRequestDataKey('clientIP', { - type: IPProtocolVersion.getVersion(ip), - address: ip - }) - } - } public formatServiceParameters( data: ServiceParameters, groups: { GroupID?: number; GroupType: string } = { GroupType: '' }, diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index e514ad36..6dc3a4a7 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -1,4 +1,4 @@ -import { TransactionRequest } from '../Models/Request' +import { Request } from '../Models/Request' import { IConfig, ServiceParameters } from '../Utils/Types' import { RequestType } from '../Constants/Endpoints' import { ITransaction } from '../Models/ITransaction' @@ -8,7 +8,7 @@ export default abstract class PaymentMethod { protected readonly _requiredFields: Array = ['currency', 'pushURL'] protected _paymentName = '' protected _serviceVersion = 0 - protected _request: TransactionRequest = new TransactionRequest() + protected _request: Request = new Request() private _action = '' get paymentName(): string { return this._paymentName diff --git a/src/Request/Client.ts b/src/Request/Client.ts index e76c0887..b10ee727 100644 --- a/src/Request/Client.ts +++ b/src/Request/Client.ts @@ -3,35 +3,27 @@ import PaymentMethod from '../PaymentMethods/PaymentMethod' import { ITransaction } from '../Models/ITransaction' import { IConfig, ICredentials } from '../Utils/Types' import { SpecificationResponse, SpecificationsResponse } from '../Models/SpecificationResponse' -import axios, { AxiosInstance } from 'axios' import { TransactionResponse } from '../Models/TransactionResponse' import RequestHeaders from './Headers' import HttpMethods from '../Constants/HttpMethods' -import httpMethods from '../Constants/HttpMethods' +import HttpsClient from "./HttpsClient"; -export class Client { +export class Client extends HttpsClient{ private static _credentials: ICredentials private static _config: IConfig - public axios: AxiosInstance = axios.create() - private headers: RequestHeaders = new RequestHeaders() - private constructor() {} - static initialize(credentials?: ICredentials, config?: IConfig) { - if (!credentials || !credentials.websiteKey || !credentials.secretKey) - throw new Error('Initialize Buckaroo Client with credentials!!') + private constructor() { + super() + this.options.host = this.getConfig().mode === 'live' ? Endpoints.LIVE : Endpoints.TEST + this.options.protocol = 'https:' + } + static initialize(credentials: ICredentials, config: IConfig) { + + this._credentials = credentials + this._config = config - this._credentials = { - secretKey: credentials.secretKey, - websiteKey: credentials.websiteKey - } + this._config.currency = config?.currency || 'EUR' + this._config.mode = config?.mode || 'test' - this._config = { - mode: config?.mode || 'test', - currency: config?.currency || 'EUR', - returnURL: config?.returnURL || '', - returnURLCancel: config?.returnURLCancel || '', - pushURL: config?.pushURL || '', - baseUrl: config?.baseUrl || '' - } return new Client() } getCredentials = (): ICredentials => { @@ -40,109 +32,42 @@ export class Client { getConfig = (): IConfig => { return Client._config } - private getEndpoint(path: string) { - const baseUrl = this.getConfig().mode === 'live' ? Endpoints.LIVE : Endpoints.TEST - return baseUrl + path - } - - private getTransactionUrl(path: string = ''): string { - return this.getEndpoint('json/Transaction') + path - } - - private getDataRequestUrl(path: string = ''): string { - return this.getEndpoint('json/DataRequest') + path - } - - protected getSpecificationUrl( - paymentName: string, - serviceVersion: number, - type: RequestType = RequestType.Transaction - ) { - return type === RequestType.Transaction - ? this.getTransactionUrl( - `/Specification/${paymentName}?serviceVersion=${serviceVersion}` - ) - : this.getDataRequestUrl( - `/Specification/${paymentName}?serviceVersion=${serviceVersion}` - ) + request(data: string = ''): Promise { + this.headers.setAuthHeader(this.options,data,this.getCredentials()) + return super.request(data); } - call(config: { method: httpMethods; url: string; data?: object }) { - this.headers.setAuthHeader(config.method, config.url, config.data) - return this.axios.request({ ...config, headers: this.headers.headers }) + transactionRequest(data: ITransaction): Promise { + this.options.path = this.transactionRequestUrl() + this.options.method = HttpMethods.METHOD_POST + return this.request(JSON.stringify(data)) } - post(url: string, data: object) { - return this.call({ - method: HttpMethods.METHOD_POST, - url, - data: data - }) + dataRequest(data: object): Promise { + this.options.path = this.dataRequestUrl() + this.options.method = HttpMethods.METHOD_GET + return this.request(JSON.stringify(data)) } - get(url: string) { - return this.call({ - method: HttpMethods.METHOD_GET, - url - }) + private transactionRequestUrl(path:string = ''):string { + return '/json/Transaction' + path } - - transactionRequest(data: ITransaction) { - data.pushURL = data.pushURL || this.getConfig().pushURL - - return this.post(this.getTransactionUrl(), data).then((res) => { - return new TransactionResponse(res) - }) - } - dataRequest(data: ITransaction) { - return this.post(this.getDataRequestUrl(), data).then((res) => { - return new TransactionResponse(res) - }) - } - specification(paymentName: string, serviceVersion = 0, type?: RequestType) { - const url = this.getSpecificationUrl(paymentName, serviceVersion, type) - return this.get(url).then((response) => { - return new SpecificationResponse(response.data) - }) + private dataRequestUrl(path:string = ''):string { + return '/json/DataRequest' + path } - specifications( - paymentMethods: PaymentMethod[] | { paymentName: string; serviceVersion: number }[], - type: RequestType = RequestType.Transaction - ) { - let data = { - Services: paymentMethods.map((paymentMethod) => { - return { - Name: paymentMethod.paymentName, - Version: paymentMethod.serviceVersion - } - }) - } - const url = - type === RequestType.Transaction - ? this.getTransactionUrl('/Specifications') - : this.getDataRequestUrl('/Specifications') - - return this.call({ - method: HttpMethods.METHOD_POST, - url, - data - }).then((response) => { - return new SpecificationsResponse(response.data) - }) - } status(transactionKey: string) { - const url = this.getTransactionUrl(`/Status/${transactionKey}`) - return this.get(url) + this.options.path = this.transactionRequestUrl(`/Status/${transactionKey}`) + + return this.request() } cancelInfo(transactionKey: string) { - const url = this.getTransactionUrl(`/Cancel/${transactionKey}`) - return this.get(url) + this.options.path = this.transactionRequestUrl(`/Cancel/${transactionKey}`) + return this.request() } refundInfo(transactionKey: string) { - const url = this.getTransactionUrl(`/RefundInfo/${transactionKey}`) - return this.get(url) + return this.transactionRequestUrl(`/RefundInfo/${transactionKey}`) } invoiceInfo(invoiceKey: string) { - const url = this.getTransactionUrl(`/InvoiceInfo/${invoiceKey}`) - return this.get(url) + return this.transactionRequestUrl(`/InvoiceInfo/${invoiceKey}`) + } } diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index 981a1a9b..ed0644a1 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,25 +1,44 @@ -import { RawAxiosRequestHeaders } from 'axios' import { Hmac } from './Hmac' +import HttpMethods from "../Constants/HttpMethods"; +import {ICredentials} from "../Utils/Types"; +import {RequestOptions} from "https"; + +type requestHeaders = { + 'Content-type': string + Accept: string + Culture: string + Authorization: string +} + export default class RequestHeaders { - headers: RawAxiosRequestHeaders = {} - defaultHeaders(): RawAxiosRequestHeaders { - return { + private readonly headers:requestHeaders; + constructor() { + this.headers = { 'Content-type': 'application/json', Accept: 'application/json', - Culture: 'en-GB' + Culture: 'nl-NL', + Authorization: '' } } - addHeaders(headers: RawAxiosRequestHeaders) { + getHeaders():requestHeaders { + return this.headers + } + setHeaders(headers: requestHeaders) { Object.keys(headers).forEach((key) => { this.headers[key] = headers[key] }) } - removeHeaders(headers: RawAxiosRequestHeaders) { + removeHeaders(headers: requestHeaders) { Object.keys(headers).forEach((key) => { delete this.headers[key] }) } - setAuthHeader(method: string, url: string, data?: object) { - this.headers.Authorization = new Hmac(method, url, data).createHeader() + setAuthHeader(options: RequestOptions, data: string, credentials: ICredentials) { + let method = options.method == HttpMethods.METHOD_POST? HttpMethods.METHOD_POST : HttpMethods.METHOD_GET + let url = options.host || '' + if(options.path){ + url += options.path + } + this.headers.Authorization = new Hmac(method, url, data).createHeader(credentials.websiteKey, credentials.secretKey) } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 4e4c1abc..9b70e9c1 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -1,7 +1,6 @@ import md5 from 'crypto-js/md5' import hmacSHA256 from 'crypto-js/hmac-sha256' import Base64 from 'crypto-js/enc-base64' -import buckarooClient from '../BuckarooClient' import HttpMethods from '../Constants/HttpMethods' export class Hmac { @@ -11,25 +10,33 @@ export class Hmac { time: string method: string constructor( - method: HttpMethods | string, - url: string = '', - data: string | object = '', + method: HttpMethods, + url: string , + data: string | object, nonce?: string, time?: string ) { + this.method = method this.url = url this.data = data this.nonce = nonce || '' - this.method = method this.time = time || '' } - createHeader() { - this.nonce = 'nonce_' + Math.floor(Math.random() * 9999999 + 1) - this.time = String(Math.round(Date.now() / 1000)) - return this.getHeader() + setNonce(nonce?:string):void { + this.nonce = nonce? nonce : 'nonce_' + Math.floor(Math.random() * 9999999 + 1) + } + setTime(time?:Date):string { + return time? + String(Math.round(Date.parse(time.toISOString()) / 1000)): + String(Math.round(Date.now() / 1000)) + } + createHeader(websiteKey:string,secretKey:string) { + this.setNonce() + this.setTime() + return this.getHmacHeader(websiteKey, secretKey) } getUrlFormat() { - let urlFormatted: URL | string = new URL(this.url) + let urlFormatted: URL | string = new URL('https://'+this.url) if (this.url) { urlFormatted = urlFormatted.host + urlFormatted.pathname + urlFormatted.search urlFormatted = this.url.replace(/^[^:/.]*[:/]+/i, '') @@ -47,12 +54,12 @@ export class Hmac { } return base64Data } - hashData(hashString: string) { - return Base64.stringify(hmacSHA256(hashString, buckarooClient().getCredentials().secretKey)) + hashData(hashString: string,secretKey:string) { + return Base64.stringify(hmacSHA256(hashString, secretKey)) } - getHashString() { + getHashString(websiteKey:string) { return ( - buckarooClient().getCredentials().websiteKey + + websiteKey + this.method + this.getUrlFormat() + this.time + @@ -60,12 +67,12 @@ export class Hmac { this.getBase64Data() ) } - getHeader() { - let hashString = this.getHashString() + getHmacHeader(websiteKey:string,secretKey:string) { + let hashString = this.getHashString(websiteKey) return ( `hmac ` + - `${buckarooClient().getCredentials().websiteKey}:${this.hashData(hashString)}:${ + `${websiteKey}:${this.hashData(hashString,secretKey)}:${ this.nonce }:${this.time}` ) diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts new file mode 100644 index 00000000..7307376a --- /dev/null +++ b/src/Request/HttpsClient.ts @@ -0,0 +1,55 @@ +import {RequestOptions} from "https"; +import RequestHeaders from "./Headers"; + +const https = require('https'); + +export default class HttpsClient { + + private _client = https + private _headers:RequestHeaders = new RequestHeaders() + private _options:RequestOptions = {} + + + get client(): any { + return this._client; + } + + get headers(): RequestHeaders { + return this._headers; + } + + get options():Omit { + return this._options; + } + + request(data:string = ''): Promise { + this._options.headers = this._headers.getHeaders() + + return new Promise((resolve, reject) => { + + const req = https.request(this._options, res => { + + let responseData:Array = []; + res.on('data', chunk => { + responseData.push(chunk); + }); + + res.on('end', () => { + let returnData = '' + try { + returnData = JSON.parse(Buffer.concat(responseData).toString()); + } catch (e) { + reject(e); + } + resolve(returnData); + }); + }).on('error', err => { + reject(err.message); + }); + if(data){ + req.write(data); + } + req.end(); + }); + } +} diff --git a/src/Request/Response.ts b/src/Request/Response.ts index dee84493..f044678b 100644 --- a/src/Request/Response.ts +++ b/src/Request/Response.ts @@ -1,31 +1,23 @@ -import { - AxiosResponse, - AxiosResponseHeaders, - InternalAxiosRequestConfig, - RawAxiosResponseHeaders -} from 'axios' + import { Hmac } from './Hmac' -export class Response implements AxiosResponse { +export class Response { get data(): any { return this._data } protected readonly _data: any - config: InternalAxiosRequestConfig - headers: RawAxiosResponseHeaders | AxiosResponseHeaders status: number statusText: string - constructor(response: AxiosResponse) { + constructor(response) { this.status = response.status - this.config = response.config + // this.config = response.config this.statusText = response.statusText - this.headers = response.headers this._data = response.data } - static validate(authorizationHeader: string, method: string, url: string, data?: object) { - let authorization = authorizationHeader.split(':') - let hmac = new Hmac(method, url, data, authorization[2], authorization[3]) - let hash = hmac.hashData(hmac.getHashString()) - return hash === authorization[1] - } + // static validate(authorizationHeader: string, method: string, url: string, data?: object) { + // let authorization = authorizationHeader.split(':') + // let hmac = new Hmac(method, url, data, authorization[2], authorization[3]) + // let hash = hmac.hashData(hmac.getHashString()) + // return hash === authorization[1] + // } } diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 91b12c01..58ed4b82 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -1,6 +1,6 @@ export declare interface IConfig { - mode: 'live' | 'test' - currency: string + mode?: 'live' | 'test' + currency?: string returnURL: string returnURLCancel: string pushURL: string diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index fed52b0b..79ec9529 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,6 +1,6 @@ import { initializeBuckarooClient } from '../src/BuckarooClient' require('dotenv').config() -export default initializeBuckarooClient( +const buckarooClientTest = initializeBuckarooClient( { secretKey: process.env.BPE_SECRET_KEY || '', websiteKey: process.env.BPE_WEBSITE_KEY || '' @@ -14,3 +14,5 @@ export default initializeBuckarooClient( baseUrl: process.env.BPE_BASE_URL || '' } ) + +export default buckarooClientTest diff --git a/tests/Client.test.ts b/tests/Client.test.ts new file mode 100644 index 00000000..78fac28c --- /dev/null +++ b/tests/Client.test.ts @@ -0,0 +1,24 @@ +// @ts-ignore +import buckarooClientTest from './BuckarooClient.test' +import {Request} from "../src/Models/Request"; + + + + +describe('Testing Buckaroo Client', () => { + test('transactionRequest', async () => { + + const transactionRequest = new Request({ + amountDebit: 100, + invoice: 'invoice', + currency: 'EUR', + description: 'description', + servicesSelectableByClient: 'ideal,afterpay', + }) + await buckarooClientTest.transactionRequest(transactionRequest.data) + .then((data) => { + expect(data).toBeDefined() + }) + }) + +}) From ef3532590fb7c64d29583530162099d4126c933d Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Wed, 17 May 2023 17:11:28 +0200 Subject: [PATCH 02/52] Client Refactor,Remove Axios --- package.json | 1 - src/BuckarooClient.ts | 11 +-- src/Constants/Endpoints.ts | 4 +- src/Models/Request.ts | 117 ++++++---------------- src/PaymentMethods/PaymentMethod.ts | 4 +- src/Request/Client.ts | 147 +++++++--------------------- src/Request/Headers.ts | 37 +++++-- src/Request/Hmac.ts | 41 ++++---- src/Request/HttpsClient.ts | 55 +++++++++++ src/Request/Response.ts | 28 ++---- src/Utils/Types.ts | 4 +- tests/BuckarooClient.test.ts | 4 +- tests/Client.test.ts | 24 +++++ 13 files changed, 220 insertions(+), 257 deletions(-) create mode 100644 src/Request/HttpsClient.ts create mode 100644 tests/Client.test.ts diff --git a/package.json b/package.json index d04f07a9..8a9a5cdd 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "typescript": "^4.9.4" }, "dependencies": { - "axios": "^1.3.5", "crypto-js": "^4.1.1", "ip-address": "^8.1.0" }, diff --git a/src/BuckarooClient.ts b/src/BuckarooClient.ts index 8d2f5a29..934d8c28 100644 --- a/src/BuckarooClient.ts +++ b/src/BuckarooClient.ts @@ -1,12 +1,7 @@ import { IConfig, ICredentials } from './Utils/Types' import { Client } from './Request/Client' -let _client: Client -export function initializeBuckarooClient(credentials: ICredentials, config?: IConfig) { - if (!_client) { - _client = Client.initialize(credentials, config) - } - return _client +export function initializeBuckarooClient(credentials: ICredentials, config: IConfig) { + + return Client.initialize(credentials, config) } -const BuckarooClient = () => (_client instanceof Client ? _client : Client.initialize()) -export default BuckarooClient diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index afdb6cad..ce8478e1 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -1,6 +1,6 @@ enum Endpoints { - LIVE = 'https://checkout.buckaroo.nl/', - TEST = 'https://testcheckout.buckaroo.nl/' + LIVE = 'checkout.buckaroo.nl', + TEST = 'testcheckout.buckaroo.nl' } enum RequestType { Data = 1, diff --git a/src/Models/Request.ts b/src/Models/Request.ts index f79e874c..df421eea 100644 --- a/src/Models/Request.ts +++ b/src/Models/Request.ts @@ -2,63 +2,52 @@ import { ITransaction } from './ITransaction' import { IServiceList, IServices } from './ServiceList' import { IParameter } from './Parameters' import { firstUpperCase } from '../Utils/Functions' -import { AdditionalParameter, ServiceParameters } from '../Utils/Types' +import {AdditionalParameter, ServiceParameters} from '../Utils/Types' import { IPProtocolVersion } from '../Constants/IPProtocolVersion' export class Request { - protected _data: { [key: string]: any } = {} - get data(): object { - return this._data - } - public setRequestDataKey(key: string, data: any) { - this._data[key] = data - } - public filter(data: ITransaction | (ITransaction & ServiceParameters)) { - return Object.keys(data) - .filter((key) => this._data[key] === undefined && data[key] !== undefined) - .reduce((obj: ServiceParameters, key) => { - obj[key] = data[key] - return obj - }, {}) - } -} + private readonly _data: ITransaction -export class TransactionRequest extends Request { + constructor(data:ITransaction) { + this._data = data + } get data(): ITransaction { return this._data } - public get services(): IServices | undefined { - return this._data['services'] - } - public set services(services: IServices | undefined) { - this._data['services'] = services - } - public setServices(services: IServiceList) { - this.services = { ServiceList: [services] } - } - public addServices(serviceList: IServiceList) { - if (this.services) { - this.services.ServiceList.push(serviceList) - } else { - this.setServices(serviceList) + getFormattedData():object { + let data:any = {} + if (this._data.additionalParameters) { + data.additionalParameters = this.formatAdditionalParameters() + } + if (this._data.customParameters) { + data.customParameters = this.formatCustomParameters() + } + if (this._data.clientIP) { + data.clientIP = this.formatClientIp() } + return data } - formatAdditionalParameters() { - if (this.data.additionalParameters) { - this.setRequestDataKey('additionalParameters', { - additionalParameter: this.formatParametersMap(this.data.additionalParameters) - }) + return { + additionalParameter: this.formatParametersMap(this._data.additionalParameters) } } formatCustomParameters() { - if (this.data.customParameters) { - this.setRequestDataKey('customParameters', { - list: this.formatParametersMap(this.data.customParameters) - }) + return { + list: this.formatParametersMap(this._data.customParameters) } } - protected formatParametersMap(value: AdditionalParameter): IParameter[] { + public formatClientIp() { + let ip = this._data.clientIP + if (typeof ip === 'string') { + ip = { + type: IPProtocolVersion.getVersion(ip), + address: ip + } + } + return ip + } + protected formatParametersMap(value: AdditionalParameter = {}): IParameter[] { return Object.keys(value).map((key, value) => { return { Name: key, @@ -66,50 +55,6 @@ export class TransactionRequest extends Request { } }) } - public basicParameters: Record = { - clientIP: true, - currency: true, - returnURL: true, - returnURLError: true, - returnURLCancel: true, - returnURLReject: true, - pushURL: true, - pushURLFailure: true, - invoice: true, - order: true, - amountDebit: true, - amountCredit: true, - description: true, - originalTransactionKey: true, - originalTransactionReference: true, - culture: true, - startRecurrent: true, - continueOnIncomplete: true, - servicesSelectableByClient: true, - servicesExcludedForClient: true, - customParameters: true, - additionalParameters: true - } - public setBasicParameters(data: ITransaction) { - for (const key in data) { - if (this.basicParameters[key]) { - this._data[key] = data[key] - } - } - this.formatAdditionalParameters() - this.formatCustomParameters() - this.setClientIp() - } - - public setClientIp() { - let ip = this.data.clientIP - if (ip && typeof ip === 'string') { - this.setRequestDataKey('clientIP', { - type: IPProtocolVersion.getVersion(ip), - address: ip - }) - } - } public formatServiceParameters( data: ServiceParameters, groups: { GroupID?: number; GroupType: string } = { GroupType: '' }, diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index e514ad36..6dc3a4a7 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -1,4 +1,4 @@ -import { TransactionRequest } from '../Models/Request' +import { Request } from '../Models/Request' import { IConfig, ServiceParameters } from '../Utils/Types' import { RequestType } from '../Constants/Endpoints' import { ITransaction } from '../Models/ITransaction' @@ -8,7 +8,7 @@ export default abstract class PaymentMethod { protected readonly _requiredFields: Array = ['currency', 'pushURL'] protected _paymentName = '' protected _serviceVersion = 0 - protected _request: TransactionRequest = new TransactionRequest() + protected _request: Request = new Request() private _action = '' get paymentName(): string { return this._paymentName diff --git a/src/Request/Client.ts b/src/Request/Client.ts index e76c0887..b10ee727 100644 --- a/src/Request/Client.ts +++ b/src/Request/Client.ts @@ -3,35 +3,27 @@ import PaymentMethod from '../PaymentMethods/PaymentMethod' import { ITransaction } from '../Models/ITransaction' import { IConfig, ICredentials } from '../Utils/Types' import { SpecificationResponse, SpecificationsResponse } from '../Models/SpecificationResponse' -import axios, { AxiosInstance } from 'axios' import { TransactionResponse } from '../Models/TransactionResponse' import RequestHeaders from './Headers' import HttpMethods from '../Constants/HttpMethods' -import httpMethods from '../Constants/HttpMethods' +import HttpsClient from "./HttpsClient"; -export class Client { +export class Client extends HttpsClient{ private static _credentials: ICredentials private static _config: IConfig - public axios: AxiosInstance = axios.create() - private headers: RequestHeaders = new RequestHeaders() - private constructor() {} - static initialize(credentials?: ICredentials, config?: IConfig) { - if (!credentials || !credentials.websiteKey || !credentials.secretKey) - throw new Error('Initialize Buckaroo Client with credentials!!') + private constructor() { + super() + this.options.host = this.getConfig().mode === 'live' ? Endpoints.LIVE : Endpoints.TEST + this.options.protocol = 'https:' + } + static initialize(credentials: ICredentials, config: IConfig) { + + this._credentials = credentials + this._config = config - this._credentials = { - secretKey: credentials.secretKey, - websiteKey: credentials.websiteKey - } + this._config.currency = config?.currency || 'EUR' + this._config.mode = config?.mode || 'test' - this._config = { - mode: config?.mode || 'test', - currency: config?.currency || 'EUR', - returnURL: config?.returnURL || '', - returnURLCancel: config?.returnURLCancel || '', - pushURL: config?.pushURL || '', - baseUrl: config?.baseUrl || '' - } return new Client() } getCredentials = (): ICredentials => { @@ -40,109 +32,42 @@ export class Client { getConfig = (): IConfig => { return Client._config } - private getEndpoint(path: string) { - const baseUrl = this.getConfig().mode === 'live' ? Endpoints.LIVE : Endpoints.TEST - return baseUrl + path - } - - private getTransactionUrl(path: string = ''): string { - return this.getEndpoint('json/Transaction') + path - } - - private getDataRequestUrl(path: string = ''): string { - return this.getEndpoint('json/DataRequest') + path - } - - protected getSpecificationUrl( - paymentName: string, - serviceVersion: number, - type: RequestType = RequestType.Transaction - ) { - return type === RequestType.Transaction - ? this.getTransactionUrl( - `/Specification/${paymentName}?serviceVersion=${serviceVersion}` - ) - : this.getDataRequestUrl( - `/Specification/${paymentName}?serviceVersion=${serviceVersion}` - ) + request(data: string = ''): Promise { + this.headers.setAuthHeader(this.options,data,this.getCredentials()) + return super.request(data); } - call(config: { method: httpMethods; url: string; data?: object }) { - this.headers.setAuthHeader(config.method, config.url, config.data) - return this.axios.request({ ...config, headers: this.headers.headers }) + transactionRequest(data: ITransaction): Promise { + this.options.path = this.transactionRequestUrl() + this.options.method = HttpMethods.METHOD_POST + return this.request(JSON.stringify(data)) } - post(url: string, data: object) { - return this.call({ - method: HttpMethods.METHOD_POST, - url, - data: data - }) + dataRequest(data: object): Promise { + this.options.path = this.dataRequestUrl() + this.options.method = HttpMethods.METHOD_GET + return this.request(JSON.stringify(data)) } - get(url: string) { - return this.call({ - method: HttpMethods.METHOD_GET, - url - }) + private transactionRequestUrl(path:string = ''):string { + return '/json/Transaction' + path } - - transactionRequest(data: ITransaction) { - data.pushURL = data.pushURL || this.getConfig().pushURL - - return this.post(this.getTransactionUrl(), data).then((res) => { - return new TransactionResponse(res) - }) - } - dataRequest(data: ITransaction) { - return this.post(this.getDataRequestUrl(), data).then((res) => { - return new TransactionResponse(res) - }) - } - specification(paymentName: string, serviceVersion = 0, type?: RequestType) { - const url = this.getSpecificationUrl(paymentName, serviceVersion, type) - return this.get(url).then((response) => { - return new SpecificationResponse(response.data) - }) + private dataRequestUrl(path:string = ''):string { + return '/json/DataRequest' + path } - specifications( - paymentMethods: PaymentMethod[] | { paymentName: string; serviceVersion: number }[], - type: RequestType = RequestType.Transaction - ) { - let data = { - Services: paymentMethods.map((paymentMethod) => { - return { - Name: paymentMethod.paymentName, - Version: paymentMethod.serviceVersion - } - }) - } - const url = - type === RequestType.Transaction - ? this.getTransactionUrl('/Specifications') - : this.getDataRequestUrl('/Specifications') - - return this.call({ - method: HttpMethods.METHOD_POST, - url, - data - }).then((response) => { - return new SpecificationsResponse(response.data) - }) - } status(transactionKey: string) { - const url = this.getTransactionUrl(`/Status/${transactionKey}`) - return this.get(url) + this.options.path = this.transactionRequestUrl(`/Status/${transactionKey}`) + + return this.request() } cancelInfo(transactionKey: string) { - const url = this.getTransactionUrl(`/Cancel/${transactionKey}`) - return this.get(url) + this.options.path = this.transactionRequestUrl(`/Cancel/${transactionKey}`) + return this.request() } refundInfo(transactionKey: string) { - const url = this.getTransactionUrl(`/RefundInfo/${transactionKey}`) - return this.get(url) + return this.transactionRequestUrl(`/RefundInfo/${transactionKey}`) } invoiceInfo(invoiceKey: string) { - const url = this.getTransactionUrl(`/InvoiceInfo/${invoiceKey}`) - return this.get(url) + return this.transactionRequestUrl(`/InvoiceInfo/${invoiceKey}`) + } } diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index 981a1a9b..ed0644a1 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,25 +1,44 @@ -import { RawAxiosRequestHeaders } from 'axios' import { Hmac } from './Hmac' +import HttpMethods from "../Constants/HttpMethods"; +import {ICredentials} from "../Utils/Types"; +import {RequestOptions} from "https"; + +type requestHeaders = { + 'Content-type': string + Accept: string + Culture: string + Authorization: string +} + export default class RequestHeaders { - headers: RawAxiosRequestHeaders = {} - defaultHeaders(): RawAxiosRequestHeaders { - return { + private readonly headers:requestHeaders; + constructor() { + this.headers = { 'Content-type': 'application/json', Accept: 'application/json', - Culture: 'en-GB' + Culture: 'nl-NL', + Authorization: '' } } - addHeaders(headers: RawAxiosRequestHeaders) { + getHeaders():requestHeaders { + return this.headers + } + setHeaders(headers: requestHeaders) { Object.keys(headers).forEach((key) => { this.headers[key] = headers[key] }) } - removeHeaders(headers: RawAxiosRequestHeaders) { + removeHeaders(headers: requestHeaders) { Object.keys(headers).forEach((key) => { delete this.headers[key] }) } - setAuthHeader(method: string, url: string, data?: object) { - this.headers.Authorization = new Hmac(method, url, data).createHeader() + setAuthHeader(options: RequestOptions, data: string, credentials: ICredentials) { + let method = options.method == HttpMethods.METHOD_POST? HttpMethods.METHOD_POST : HttpMethods.METHOD_GET + let url = options.host || '' + if(options.path){ + url += options.path + } + this.headers.Authorization = new Hmac(method, url, data).createHeader(credentials.websiteKey, credentials.secretKey) } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 4e4c1abc..9b70e9c1 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -1,7 +1,6 @@ import md5 from 'crypto-js/md5' import hmacSHA256 from 'crypto-js/hmac-sha256' import Base64 from 'crypto-js/enc-base64' -import buckarooClient from '../BuckarooClient' import HttpMethods from '../Constants/HttpMethods' export class Hmac { @@ -11,25 +10,33 @@ export class Hmac { time: string method: string constructor( - method: HttpMethods | string, - url: string = '', - data: string | object = '', + method: HttpMethods, + url: string , + data: string | object, nonce?: string, time?: string ) { + this.method = method this.url = url this.data = data this.nonce = nonce || '' - this.method = method this.time = time || '' } - createHeader() { - this.nonce = 'nonce_' + Math.floor(Math.random() * 9999999 + 1) - this.time = String(Math.round(Date.now() / 1000)) - return this.getHeader() + setNonce(nonce?:string):void { + this.nonce = nonce? nonce : 'nonce_' + Math.floor(Math.random() * 9999999 + 1) + } + setTime(time?:Date):string { + return time? + String(Math.round(Date.parse(time.toISOString()) / 1000)): + String(Math.round(Date.now() / 1000)) + } + createHeader(websiteKey:string,secretKey:string) { + this.setNonce() + this.setTime() + return this.getHmacHeader(websiteKey, secretKey) } getUrlFormat() { - let urlFormatted: URL | string = new URL(this.url) + let urlFormatted: URL | string = new URL('https://'+this.url) if (this.url) { urlFormatted = urlFormatted.host + urlFormatted.pathname + urlFormatted.search urlFormatted = this.url.replace(/^[^:/.]*[:/]+/i, '') @@ -47,12 +54,12 @@ export class Hmac { } return base64Data } - hashData(hashString: string) { - return Base64.stringify(hmacSHA256(hashString, buckarooClient().getCredentials().secretKey)) + hashData(hashString: string,secretKey:string) { + return Base64.stringify(hmacSHA256(hashString, secretKey)) } - getHashString() { + getHashString(websiteKey:string) { return ( - buckarooClient().getCredentials().websiteKey + + websiteKey + this.method + this.getUrlFormat() + this.time + @@ -60,12 +67,12 @@ export class Hmac { this.getBase64Data() ) } - getHeader() { - let hashString = this.getHashString() + getHmacHeader(websiteKey:string,secretKey:string) { + let hashString = this.getHashString(websiteKey) return ( `hmac ` + - `${buckarooClient().getCredentials().websiteKey}:${this.hashData(hashString)}:${ + `${websiteKey}:${this.hashData(hashString,secretKey)}:${ this.nonce }:${this.time}` ) diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts new file mode 100644 index 00000000..7307376a --- /dev/null +++ b/src/Request/HttpsClient.ts @@ -0,0 +1,55 @@ +import {RequestOptions} from "https"; +import RequestHeaders from "./Headers"; + +const https = require('https'); + +export default class HttpsClient { + + private _client = https + private _headers:RequestHeaders = new RequestHeaders() + private _options:RequestOptions = {} + + + get client(): any { + return this._client; + } + + get headers(): RequestHeaders { + return this._headers; + } + + get options():Omit { + return this._options; + } + + request(data:string = ''): Promise { + this._options.headers = this._headers.getHeaders() + + return new Promise((resolve, reject) => { + + const req = https.request(this._options, res => { + + let responseData:Array = []; + res.on('data', chunk => { + responseData.push(chunk); + }); + + res.on('end', () => { + let returnData = '' + try { + returnData = JSON.parse(Buffer.concat(responseData).toString()); + } catch (e) { + reject(e); + } + resolve(returnData); + }); + }).on('error', err => { + reject(err.message); + }); + if(data){ + req.write(data); + } + req.end(); + }); + } +} diff --git a/src/Request/Response.ts b/src/Request/Response.ts index dee84493..f044678b 100644 --- a/src/Request/Response.ts +++ b/src/Request/Response.ts @@ -1,31 +1,23 @@ -import { - AxiosResponse, - AxiosResponseHeaders, - InternalAxiosRequestConfig, - RawAxiosResponseHeaders -} from 'axios' + import { Hmac } from './Hmac' -export class Response implements AxiosResponse { +export class Response { get data(): any { return this._data } protected readonly _data: any - config: InternalAxiosRequestConfig - headers: RawAxiosResponseHeaders | AxiosResponseHeaders status: number statusText: string - constructor(response: AxiosResponse) { + constructor(response) { this.status = response.status - this.config = response.config + // this.config = response.config this.statusText = response.statusText - this.headers = response.headers this._data = response.data } - static validate(authorizationHeader: string, method: string, url: string, data?: object) { - let authorization = authorizationHeader.split(':') - let hmac = new Hmac(method, url, data, authorization[2], authorization[3]) - let hash = hmac.hashData(hmac.getHashString()) - return hash === authorization[1] - } + // static validate(authorizationHeader: string, method: string, url: string, data?: object) { + // let authorization = authorizationHeader.split(':') + // let hmac = new Hmac(method, url, data, authorization[2], authorization[3]) + // let hash = hmac.hashData(hmac.getHashString()) + // return hash === authorization[1] + // } } diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 91b12c01..58ed4b82 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -1,6 +1,6 @@ export declare interface IConfig { - mode: 'live' | 'test' - currency: string + mode?: 'live' | 'test' + currency?: string returnURL: string returnURLCancel: string pushURL: string diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index fed52b0b..79ec9529 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,6 +1,6 @@ import { initializeBuckarooClient } from '../src/BuckarooClient' require('dotenv').config() -export default initializeBuckarooClient( +const buckarooClientTest = initializeBuckarooClient( { secretKey: process.env.BPE_SECRET_KEY || '', websiteKey: process.env.BPE_WEBSITE_KEY || '' @@ -14,3 +14,5 @@ export default initializeBuckarooClient( baseUrl: process.env.BPE_BASE_URL || '' } ) + +export default buckarooClientTest diff --git a/tests/Client.test.ts b/tests/Client.test.ts new file mode 100644 index 00000000..78fac28c --- /dev/null +++ b/tests/Client.test.ts @@ -0,0 +1,24 @@ +// @ts-ignore +import buckarooClientTest from './BuckarooClient.test' +import {Request} from "../src/Models/Request"; + + + + +describe('Testing Buckaroo Client', () => { + test('transactionRequest', async () => { + + const transactionRequest = new Request({ + amountDebit: 100, + invoice: 'invoice', + currency: 'EUR', + description: 'description', + servicesSelectableByClient: 'ideal,afterpay', + }) + await buckarooClientTest.transactionRequest(transactionRequest.data) + .then((data) => { + expect(data).toBeDefined() + }) + }) + +}) From f4440bc25844d0ce87f58915ad6c5a9d43893cd8 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Thu, 18 May 2023 16:50:44 +0200 Subject: [PATCH 03/52] refactor httpsClient --- example/BuckarooClient.ts | 2 +- src/Constants/Endpoints.ts | 12 ++--- src/PaymentMethods/PaymentMethod.ts | 2 +- src/Request/BuckarooClient.ts | 83 +++++++++++++++++++++++++++++ src/Request/Client.ts | 73 ------------------------- src/Request/Headers.ts | 66 ++++++++++++++--------- src/Request/Hmac.ts | 22 ++++---- src/Request/HttpsClient.ts | 52 +++++++++--------- src/{BuckarooClient.ts => index.ts} | 5 +- tests/BuckarooClient.test.ts | 2 +- tests/Client.test.ts | 10 ++-- tests/PaymentMethods/Client.test.ts | 2 +- 12 files changed, 180 insertions(+), 151 deletions(-) create mode 100644 src/Request/BuckarooClient.ts delete mode 100644 src/Request/Client.ts rename src/{BuckarooClient.ts => index.ts} (55%) diff --git a/example/BuckarooClient.ts b/example/BuckarooClient.ts index bccdd989..bb32894c 100644 --- a/example/BuckarooClient.ts +++ b/example/BuckarooClient.ts @@ -1,4 +1,4 @@ -import buckarooClient, { initializeBuckarooClient } from '../src/BuckarooClient' +import buckarooClient, { initializeBuckarooClient } from '../src' initializeBuckarooClient( { secretKey: 'secretKey', websiteKey: 'websiteKey' }, diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index ce8478e1..cb5848ec 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -1,10 +1,10 @@ enum Endpoints { - LIVE = 'checkout.buckaroo.nl', - TEST = 'testcheckout.buckaroo.nl' + LIVE = 'https://checkout.buckaroo.nl', + TEST = 'https://testcheckout.buckaroo.nl' } -enum RequestType { - Data = 1, - Transaction = 2 +enum RequestTypePaths { + Data = '/json/DataRequest', + Transaction = '/json/Transaction' } -export { RequestType } +export { RequestTypePaths } export default Endpoints diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index 6dc3a4a7..3bd9d60e 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -2,7 +2,7 @@ import { Request } from '../Models/Request' import { IConfig, ServiceParameters } from '../Utils/Types' import { RequestType } from '../Constants/Endpoints' import { ITransaction } from '../Models/ITransaction' -import buckarooClient from '../BuckarooClient' +import buckarooClient from '../index' import { IServiceList } from '../Models/ServiceList' export default abstract class PaymentMethod { protected readonly _requiredFields: Array = ['currency', 'pushURL'] diff --git a/src/Request/BuckarooClient.ts b/src/Request/BuckarooClient.ts new file mode 100644 index 00000000..2405934e --- /dev/null +++ b/src/Request/BuckarooClient.ts @@ -0,0 +1,83 @@ +import Endpoints, {RequestTypePaths} from '../Constants/Endpoints' +import {ITransaction} from '../Models/ITransaction' +import {IConfig, ICredentials} from '../Utils/Types' +import {SpecificationResponse, SpecificationsResponse} from '../Models/SpecificationResponse' +import {TransactionResponse} from '../Models/TransactionResponse' +import Headers from './Headers' +import HttpMethods from '../Constants/HttpMethods' +import HttpsClient, {HttpsRequestOptions} from "./HttpsClient"; +import {Hmac} from "./Hmac"; + +export class BuckarooClient { + private static _credentials: ICredentials + private static _config: IConfig + private _httpsClient: HttpsClient; + private readonly _headers: Headers = new Headers() + private _hmac :Hmac + private _requestUrl:URL; + + private constructor() { + this._requestUrl = new URL(this.modeUrl) + this._httpsClient = new HttpsClient(this._requestUrl); + + this._hmac = new Hmac(this._httpsClient.options,this._requestUrl); + } + get modeUrl(): Endpoints { + return BuckarooClient._config.mode == 'test' ? Endpoints.TEST : Endpoints.LIVE + } + static initialize(credentials: ICredentials, config: IConfig ) { + + this._credentials = credentials + this._config = { + mode: 'test', + currency: 'EUR', + ...config, + } + return new BuckarooClient() + } + get requestHeaders(): Headers { + return this._headers + } + get requestOptions(): HttpsRequestOptions { + return this._httpsClient.options + } + getCredentials = (): ICredentials => { + return BuckarooClient._credentials + } + getConfig = (): IConfig => { + return BuckarooClient._config + } + private transactionRequestUrl(path:string = ''):string { + return RequestTypePaths.Transaction + path + } + private dataRequestUrl(path:string = ''):string { + return RequestTypePaths.Data + path + } + + request(method,path,data: object = {}): Promise { + this.requestOptions.method = method + this.requestOptions.path = path + + this.requestHeaders.setAuthHeader(this._hmac.createHmacHeader(this.getCredentials())) + return this._httpsClient.request(data) + } + + transactionRequest(data: ITransaction): Promise { + return this.request(HttpMethods.METHOD_POST,this.transactionRequestUrl(),data) + } + dataRequest(data: object): Promise { + return this.request(HttpMethods.METHOD_GET,this.dataRequestUrl(),data) + } + status(transactionKey: string) { + return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/Status/${transactionKey}`)) + } + cancelInfo(transactionKey: string) { + return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/Cancel/${transactionKey}`)) + } + refundInfo(transactionKey: string) { + return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/RefundInfo/${transactionKey}`)) + } + invoiceInfo(invoiceKey: string) { + return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/InvoiceInfo/${invoiceKey}`)) + } +} diff --git a/src/Request/Client.ts b/src/Request/Client.ts deleted file mode 100644 index b10ee727..00000000 --- a/src/Request/Client.ts +++ /dev/null @@ -1,73 +0,0 @@ -import Endpoints, { RequestType } from '../Constants/Endpoints' -import PaymentMethod from '../PaymentMethods/PaymentMethod' -import { ITransaction } from '../Models/ITransaction' -import { IConfig, ICredentials } from '../Utils/Types' -import { SpecificationResponse, SpecificationsResponse } from '../Models/SpecificationResponse' -import { TransactionResponse } from '../Models/TransactionResponse' -import RequestHeaders from './Headers' -import HttpMethods from '../Constants/HttpMethods' -import HttpsClient from "./HttpsClient"; - -export class Client extends HttpsClient{ - private static _credentials: ICredentials - private static _config: IConfig - private constructor() { - super() - this.options.host = this.getConfig().mode === 'live' ? Endpoints.LIVE : Endpoints.TEST - this.options.protocol = 'https:' - } - static initialize(credentials: ICredentials, config: IConfig) { - - this._credentials = credentials - this._config = config - - this._config.currency = config?.currency || 'EUR' - this._config.mode = config?.mode || 'test' - - return new Client() - } - getCredentials = (): ICredentials => { - return Client._credentials - } - getConfig = (): IConfig => { - return Client._config - } - request(data: string = ''): Promise { - this.headers.setAuthHeader(this.options,data,this.getCredentials()) - return super.request(data); - } - - transactionRequest(data: ITransaction): Promise { - this.options.path = this.transactionRequestUrl() - this.options.method = HttpMethods.METHOD_POST - return this.request(JSON.stringify(data)) - } - dataRequest(data: object): Promise { - this.options.path = this.dataRequestUrl() - this.options.method = HttpMethods.METHOD_GET - return this.request(JSON.stringify(data)) - } - private transactionRequestUrl(path:string = ''):string { - return '/json/Transaction' + path - } - private dataRequestUrl(path:string = ''):string { - return '/json/DataRequest' + path - } - - status(transactionKey: string) { - this.options.path = this.transactionRequestUrl(`/Status/${transactionKey}`) - - return this.request() - } - cancelInfo(transactionKey: string) { - this.options.path = this.transactionRequestUrl(`/Cancel/${transactionKey}`) - return this.request() - } - refundInfo(transactionKey: string) { - return this.transactionRequestUrl(`/RefundInfo/${transactionKey}`) - } - invoiceInfo(invoiceKey: string) { - return this.transactionRequestUrl(`/InvoiceInfo/${invoiceKey}`) - - } -} diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index ed0644a1..eb036345 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,44 +1,62 @@ import { Hmac } from './Hmac' import HttpMethods from "../Constants/HttpMethods"; -import {ICredentials} from "../Utils/Types"; -import {RequestOptions} from "https"; +import {BuckarooClient} from "./BuckarooClient"; -type requestHeaders = { - 'Content-type': string - Accept: string - Culture: string - Authorization: string -} -export default class RequestHeaders { - private readonly headers:requestHeaders; +export type RequestHeaders = { + 'Content-type'?: string + Accept?: string + Culture?: string + Authorization?: string + Software?: string +} & { [key: string]: string } + +export default class Headers { + private readonly _headers:RequestHeaders = this.getDefaultHeaders(); constructor() { - this.headers = { + this.setSoftwareHeader() + } + getHeaders():RequestHeaders { + return this._headers + } + getDefaultHeaders() { + return { 'Content-type': 'application/json', Accept: 'application/json', Culture: 'nl-NL', Authorization: '' } } - getHeaders():requestHeaders { - return this.headers + setSoftwareHeader(value: { + PlatformName?:string, + PlatformVersion?:string, + ModuleSupplier?:string, + ModuleName?:string, + ModuleVersion?:string + } = {}):this { + + this._headers.Software = JSON.stringify({ + PlatformName: 'Node SDK', + PlatformVersion: '1.0', + ModuleSupplier: 'Buckaroo', + ModuleName: 'BuckarooPayments', + ModuleVersion: '1.0', + ...value + }) + return this; } - setHeaders(headers: requestHeaders) { + addHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { - this.headers[key] = headers[key] + this._headers[key] = headers[key] }) } - removeHeaders(headers: requestHeaders) { + removeHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { - delete this.headers[key] + delete this._headers[key] }) } - setAuthHeader(options: RequestOptions, data: string, credentials: ICredentials) { - let method = options.method == HttpMethods.METHOD_POST? HttpMethods.METHOD_POST : HttpMethods.METHOD_GET - let url = options.host || '' - if(options.path){ - url += options.path - } - this.headers.Authorization = new Hmac(method, url, data).createHeader(credentials.websiteKey, credentials.secretKey) + setAuthHeader(hmacHeader:string):this { + this._headers.Authorization = hmacHeader + return this; } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 9b70e9c1..384db898 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -2,17 +2,18 @@ import md5 from 'crypto-js/md5' import hmacSHA256 from 'crypto-js/hmac-sha256' import Base64 from 'crypto-js/enc-base64' import HttpMethods from '../Constants/HttpMethods' +import {ICredentials} from "../Utils/Types"; export class Hmac { data: string | object - url: string + url: URL nonce: string time: string method: string constructor( method: HttpMethods, - url: string , - data: string | object, + url: URL, + data: string | object = '', nonce?: string, time?: string ) { @@ -30,19 +31,20 @@ export class Hmac { String(Math.round(Date.parse(time.toISOString()) / 1000)): String(Math.round(Date.now() / 1000)) } - createHeader(websiteKey:string,secretKey:string) { + createHmacHeader(credentials: ICredentials):string { this.setNonce() this.setTime() - return this.getHmacHeader(websiteKey, secretKey) + return this.getHmacHeader(credentials.websiteKey, credentials.secretKey) } getUrlFormat() { - let urlFormatted: URL | string = new URL('https://'+this.url) - if (this.url) { - urlFormatted = urlFormatted.host + urlFormatted.pathname + urlFormatted.search - urlFormatted = this.url.replace(/^[^:/.]*[:/]+/i, '') + let urlFormatted = '' + if (this.url instanceof URL) { + urlFormatted = this.url.host + this.url.pathname + this.url.search + urlFormatted = urlFormatted.replace(/^[^:/.]*[:/]+/i, '') urlFormatted = encodeURIComponent(urlFormatted).toLowerCase() || '' + return urlFormatted } - return urlFormatted + throw new Error('Url is not a string or URL object') } getBase64Data() { let base64Data = this.data diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 7307376a..eb1e551b 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,53 +1,57 @@ import {RequestOptions} from "https"; -import RequestHeaders from "./Headers"; +import httpMethods from "../Constants/HttpMethods"; +import Headers, {RequestHeaders} from "./Headers"; +import Endpoints from "../Constants/Endpoints"; const https = require('https'); +export type HttpsRequestOptions = RequestOptions + & { method: httpMethods,hostname:string,timeout:number ,headers:RequestHeaders} + export default class HttpsClient { private _client = https - private _headers:RequestHeaders = new RequestHeaders() - private _options:RequestOptions = {} - + public options:HttpsRequestOptions + constructor(url:URL) { + this.options = { + method: httpMethods.METHOD_GET, + headers: new Headers().getHeaders(), + hostname: url.hostname, + timeout: 10000, + } + } get client(): any { return this._client; } - - get headers(): RequestHeaders { - return this._headers; - } - - get options():Omit { - return this._options; - } - - request(data:string = ''): Promise { - this._options.headers = this._headers.getHeaders() + request(data:object): Promise { return new Promise((resolve, reject) => { - - const req = https.request(this._options, res => { - + const req = this._client.request(this.options, res => { let responseData:Array = []; + res.on('data', chunk => { responseData.push(chunk); }); res.on('end', () => { - let returnData = '' try { - returnData = JSON.parse(Buffer.concat(responseData).toString()); + resolve(JSON.parse(Buffer.concat(responseData).toString())); } catch (e) { reject(e); } - resolve(returnData); }); }).on('error', err => { reject(err.message); - }); - if(data){ - req.write(data); + }).on('timeout', () => { + req.destroy(); + reject(new Error('Request timeout')); + }).on('close', () => { + req.destroy(); + reject(new Error('Request closed')); + }) + if(Object.keys(data).length > 0){ + req.write(JSON.stringify(data)); } req.end(); }); diff --git a/src/BuckarooClient.ts b/src/index.ts similarity index 55% rename from src/BuckarooClient.ts rename to src/index.ts index 934d8c28..04bb44ce 100644 --- a/src/BuckarooClient.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ import { IConfig, ICredentials } from './Utils/Types' -import { Client } from './Request/Client' +import { BuckarooClient } from './Request/BuckarooClient' export function initializeBuckarooClient(credentials: ICredentials, config: IConfig) { - - return Client.initialize(credentials, config) + return BuckarooClient.initialize(credentials, config) } diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index 79ec9529..fadb26c8 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,4 +1,4 @@ -import { initializeBuckarooClient } from '../src/BuckarooClient' +import { initializeBuckarooClient } from '../src' require('dotenv').config() const buckarooClientTest = initializeBuckarooClient( { diff --git a/tests/Client.test.ts b/tests/Client.test.ts index 78fac28c..2da0643c 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -8,13 +8,9 @@ import {Request} from "../src/Models/Request"; describe('Testing Buckaroo Client', () => { test('transactionRequest', async () => { - const transactionRequest = new Request({ - amountDebit: 100, - invoice: 'invoice', - currency: 'EUR', - description: 'description', - servicesSelectableByClient: 'ideal,afterpay', - }) + const transactionRequest = new Request({}) + buckarooClientTest.request('POST', buckarooClientTest.transactionRequestUrl(), transactionRequest.data) + await buckarooClientTest.transactionRequest(transactionRequest.data) .then((data) => { expect(data).toBeDefined() diff --git a/tests/PaymentMethods/Client.test.ts b/tests/PaymentMethods/Client.test.ts index a849f32a..5d02d283 100644 --- a/tests/PaymentMethods/Client.test.ts +++ b/tests/PaymentMethods/Client.test.ts @@ -1,7 +1,7 @@ import { uniqid } from '../../src/Utils/Functions' require('../BuckarooClient.test') -import buckarooClient from '../../src/BuckarooClient' +import buckarooClient from '../../src' const client = buckarooClient() test('PaymentStatus', async () => { From e876377825c866a09929ca1f63894b17ca6d42c8 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Tue, 3 Oct 2023 09:39:58 +0200 Subject: [PATCH 04/52] V1.0 --- CHANGELOG.md | 20 ++ README.md | 20 +- example/BuckarooClient.ts | 33 --- example/CreditManagment.ts | 26 -- example/Transaction/creditCard.ts | 15 + example/Transaction/ideal.ts | 24 ++ .../additional_services/creditManagment.ts | 67 +++++ .../{ => additional_services}/subscription.ts | 26 +- example/buckarooClient.ts | 13 + example/creditCard.ts | 16 - example/ideal.ts | 19 -- example/klarna.ts | 27 -- example/response/push.ts | 44 +++ package.json | 2 +- src/Constants/Endpoints.ts | 7 +- src/Constants/HttpMethods.ts | 4 +- src/Constants/IPProtocolVersion.ts | 10 + src/Constants/RecipientCategory.ts | 6 +- src/Handlers/Credentials.ts | 25 ++ src/Handlers/Reply/ReplyHandler.ts | 80 +++++ src/Models/IParameters.ts | 43 +++ src/Models/IRequest.ts | 41 +++ src/Models/IServiceList.ts | 52 ++++ src/Models/ITransaction.ts | 45 --- src/Models/Interfaces/IAddress.ts | 34 +++ src/Models/Interfaces/IArticle.ts | 46 +++ src/Models/Interfaces/IBankAccount.ts | 18 ++ src/Models/Interfaces/ICustomer.ts | 30 ++ src/Models/Interfaces/IDebtor.ts | 10 + src/Models/Interfaces/IEmail.ts | 16 + src/Models/Interfaces/IPhone.ts | 19 ++ src/Models/Interfaces/IRecipient.ts | 90 ++++++ src/Models/Model.ts | 124 ++++++++ src/Models/Parameters.ts | 6 - src/Models/Request.ts | 107 ------- src/Models/Response/BatchRequestResponse.ts | 14 + src/Models/Response/HttpClientResponse.ts | 43 +++ .../Response/SpecificationRequestResponse.ts | 66 +++++ src/Models/Response/TransactionResponse.ts | 205 +++++++++++++ src/Models/ServiceList.ts | 11 - src/Models/ServiceParameters.ts | 25 ++ src/Models/Services/IAddress.ts | 10 - src/Models/Services/IPhone.ts | 8 - src/Models/Services/ITransactionResponse.ts | 105 ------- src/Models/SpecificationResponse.ts | 113 ------- src/Models/TransactionResponse.ts | 133 --------- src/PaymentMethods/Afterpay/Model/Address.ts | 27 ++ src/PaymentMethods/Afterpay/Model/Article.ts | 43 ++- src/PaymentMethods/Afterpay/Model/Customer.ts | 71 ++--- src/PaymentMethods/Afterpay/Model/Pay.ts | 60 +++- src/PaymentMethods/Afterpay/Model/Phone.ts | 18 ++ .../Afterpay/Model/Recipient.ts | 29 ++ src/PaymentMethods/Afterpay/Model/Refund.ts | 23 ++ src/PaymentMethods/Afterpay/index.ts | 41 ++- .../AfterpayDigiAccept/Model/Article.ts | 34 +++ .../AfterpayDigiAccept/Model/Customer.ts | 29 ++ .../AfterpayDigiAccept/Model/Pay.ts | 67 +++++ .../AfterpayDigiAccept/Services/Address.ts | 34 +++ .../AfterpayDigiAccept/Services/Phone.ts | 6 + .../AfterpayDigiAccept/index.ts | 36 ++- src/PaymentMethods/Alipay/index.ts | 16 +- src/PaymentMethods/ApplePay/Models/Pay.ts | 13 +- src/PaymentMethods/ApplePay/index.ts | 18 +- src/PaymentMethods/Bancontact/Models/Pay.ts | 19 +- src/PaymentMethods/Bancontact/index.ts | 32 +- src/PaymentMethods/BankTransfer/Models/Pay.ts | 40 ++- src/PaymentMethods/BankTransfer/index.ts | 15 +- src/PaymentMethods/Belfius/index.ts | 12 +- src/PaymentMethods/Billink/Models/Address.ts | 12 + src/PaymentMethods/Billink/Models/Article.ts | 17 +- src/PaymentMethods/Billink/Models/Capture.ts | 20 ++ src/PaymentMethods/Billink/Models/Customer.ts | 57 ++-- src/PaymentMethods/Billink/Models/Pay.ts | 52 +++- src/PaymentMethods/Billink/Models/Phone.ts | 12 + src/PaymentMethods/Billink/Models/Refund.ts | 11 + src/PaymentMethods/Billink/index.ts | 32 +- .../BuckarooVoucher/Models/Create.ts | 23 +- .../BuckarooVoucher/Models/Pay.ts | 10 +- src/PaymentMethods/BuckarooVoucher/index.ts | 30 +- .../BuckarooWallet/Models/BankAccount.ts | 7 + .../BuckarooWallet/Models/Customer.ts | 12 + .../BuckarooWallet/Models/Wallet.ts | 50 ++-- src/PaymentMethods/BuckarooWallet/index.ts | 69 +++-- .../CreditCard/Models/CardData.ts | 11 + src/PaymentMethods/CreditCard/Models/Pay.ts | 8 - .../CreditCard/Models/SecurityCode.ts | 11 + src/PaymentMethods/CreditCard/index.ts | 88 +++--- src/PaymentMethods/CreditClick/Models/Pay.ts | 17 +- .../CreditClick/Models/Refund.ts | 14 +- src/PaymentMethods/CreditClick/index.ts | 17 +- .../Models/AddOrUpdateProductLines.ts | 29 +- .../CreditManagement/Models/Address.ts | 6 + .../CreditManagement/Models/Article.ts | 50 +++- .../CreditManagement/Models/CreditNote.ts | 23 +- .../CreditManagement/Models/Debtor.ts | 22 +- .../CreditManagement/Models/DebtorInfo.ts | 21 ++ .../CreditManagement/Models/Invoice.ts | 128 +++++--- .../CreditManagement/Models/PaymentPlan.ts | 53 +++- .../Models/multiInfoInvoice.ts | 13 +- src/PaymentMethods/CreditManagement/index.ts | 74 ++--- src/PaymentMethods/EPS/index.ts | 8 +- .../Emandates/Models/ICreate.ts | 13 - .../Emandates/Models/IModify.ts | 8 - .../Emandates/Models/Mandate.ts | 44 +++ src/PaymentMethods/Emandates/index.ts | 25 +- src/PaymentMethods/GiftCard/Models/Pay.ts | 50 ++++ src/PaymentMethods/GiftCard/Models/Refund.ts | 16 + src/PaymentMethods/GiftCard/index.ts | 20 +- src/PaymentMethods/Giropay/Models/Pay.ts | 17 +- src/PaymentMethods/Giropay/index.ts | 16 +- src/PaymentMethods/Ideal/Models/Pay.ts | 13 +- src/PaymentMethods/Ideal/index.ts | 41 +-- .../IdealQR/Models/IGenerate.ts | 47 +++ src/PaymentMethods/IdealQR/index.ts | 10 + src/PaymentMethods/{iDin => Idin}/index.ts | 1 + src/PaymentMethods/In3/Models/Article.ts | 24 ++ src/PaymentMethods/In3/Models/Pay.ts | 87 +++--- src/PaymentMethods/In3/Models/Phone.ts | 13 + src/PaymentMethods/In3/Models/Recipient.ts | 112 +++++++ src/PaymentMethods/In3/Models/Refund.ts | 21 ++ src/PaymentMethods/In3/index.ts | 21 +- src/PaymentMethods/In3Old/Models/Address.ts | 7 + src/PaymentMethods/In3Old/Models/Article.ts | 10 + src/PaymentMethods/In3Old/Models/Company.ts | 7 + src/PaymentMethods/In3Old/Models/Pay.ts | 75 +++++ src/PaymentMethods/In3Old/Models/Phone.ts | 7 + src/PaymentMethods/In3Old/Models/Subtotal.ts | 14 + src/PaymentMethods/In3Old/index.ts | 13 + src/PaymentMethods/KBC/index.ts | 9 +- src/PaymentMethods/Klarna/Models/Article.ts | 16 +- src/PaymentMethods/Klarna/Models/Pay.ts | 44 ++- src/PaymentMethods/Klarna/Models/Recipient.ts | 51 ++-- .../Klarna/Services/KlarnaAddress.ts | 21 ++ .../Klarna/Services/KlarnaPhone.ts | 10 + src/PaymentMethods/Klarna/index.ts | 24 +- src/PaymentMethods/KlarnaKP/Models/IPay.ts | 10 +- .../KlarnaKP/Models/IReserve.ts | 42 +++ src/PaymentMethods/KlarnaKP/index.ts | 40 ++- .../Marketplaces/Models/ISplit.ts | 6 +- src/PaymentMethods/Marketplaces/index.ts | 15 +- src/PaymentMethods/NoService/index.ts | 5 + src/PaymentMethods/PayByBank/Models/IPay.ts | 15 + src/PaymentMethods/PayByBank/index.ts | 28 ++ .../PayPerEmail/Models/invitation.ts | 4 +- src/PaymentMethods/PayPerEmail/index.ts | 5 +- src/PaymentMethods/PayablePaymentMethod.ts | 37 +-- src/PaymentMethods/Payconiq/index.ts | 16 +- .../PaymentInitiation/Models/IPay.ts | 6 - src/PaymentMethods/PaymentInitiation/index.ts | 14 - src/PaymentMethods/PaymentMethod.ts | 150 +++++----- src/PaymentMethods/Paypal/Models/Address.ts | 35 +++ src/PaymentMethods/Paypal/Models/ExtraInfo.ts | 33 ++- src/PaymentMethods/Paypal/Models/Pay.ts | 23 +- src/PaymentMethods/Paypal/Models/Phone.ts | 7 + src/PaymentMethods/Paypal/index.ts | 23 +- src/PaymentMethods/PiM/index.ts | 18 +- src/PaymentMethods/PointOfSale/index.ts | 14 +- src/PaymentMethods/Przelewy24/Models/Pay.ts | 26 +- src/PaymentMethods/Przelewy24/index.ts | 11 +- src/PaymentMethods/SEPA/Models/Emandate.ts | 4 +- src/PaymentMethods/SEPA/Models/ExtraInfo.ts | 9 +- src/PaymentMethods/SEPA/Models/Pay.ts | 55 +++- src/PaymentMethods/SEPA/index.ts | 37 ++- src/PaymentMethods/Sofort/index.ts | 17 +- .../Subscriptions/Models/Company.ts | 7 + .../Subscriptions/Models/Configuration.ts | 33 +++ .../Subscriptions/Models/ISubscription.ts | 167 ++++++++--- .../Subscriptions/Models/RatePlan.ts | 137 +++++---- .../Subscriptions/Models/RatePlanCharge.ts | 59 ++++ .../Models/ResumeSubscription.ts | 7 + src/PaymentMethods/Subscriptions/index.ts | 60 ++-- src/PaymentMethods/Surepay/Models/Verify.ts | 6 +- src/PaymentMethods/Surepay/index.ts | 10 +- src/PaymentMethods/Thunes/index.ts | 34 +-- src/PaymentMethods/Tinka/Models/Pay.ts | 4 +- src/PaymentMethods/Tinka/index.ts | 9 +- src/PaymentMethods/Trustly/Models/Pay.ts | 4 +- src/PaymentMethods/Trustly/index.ts | 8 +- src/PaymentMethods/WeChatPay/index.ts | 13 +- src/PaymentMethods/iDealQR/Models/Generate.ts | 14 - src/PaymentMethods/iDealQR/index.ts | 11 - src/Request/BuckarooClient.ts | 83 ------ src/Request/DataModels.ts | 124 ++++++++ src/Request/Headers.ts | 68 ++--- src/Request/Hmac.ts | 139 +++++---- src/Request/HttpsClient.ts | 104 ++++--- src/Request/Request.ts | 127 ++++++++ src/Request/Response.ts | 23 -- src/Services/TransactionService.ts | 31 ++ src/Utils/Functions.ts | 97 +++++- src/Utils/MethodTypes.ts | 200 +++++++++++++ src/Utils/Types.ts | 31 +- src/index.ts | 60 +++- tests/BuckarooClient.test.ts | 10 +- tests/Client.test.ts | 104 ++++++- tests/Models/index.ts | 67 +++++ tests/PaymentMethods/AfterPay.test.ts | 186 ++++++------ .../PaymentMethods/AfterPayDigiAccept.test.ts | 109 ++++++- tests/PaymentMethods/Alipay.test.ts | 22 +- tests/PaymentMethods/ApplePay.test.ts | 29 +- tests/PaymentMethods/Bancontact.test.ts | 31 +- tests/PaymentMethods/BankTransfer.test.ts | 29 +- tests/PaymentMethods/Belfius.test.ts | 16 +- tests/PaymentMethods/Billink.test.ts | 138 +++++---- tests/PaymentMethods/BuckarooVoucher.test.ts | 18 +- tests/PaymentMethods/BuckarooWallet.test.ts | 78 +++-- tests/PaymentMethods/Client.test.ts | 52 ---- tests/PaymentMethods/CreditCard.test.ts | 222 +++++++------- tests/PaymentMethods/CreditClick.test.ts | 18 +- tests/PaymentMethods/CreditManagment.test.ts | 280 ++++++++++++------ tests/PaymentMethods/Emandate.test.ts | 41 +-- tests/PaymentMethods/Giftcard.test.ts | 32 +- tests/PaymentMethods/GiroPay.test.ts | 24 +- tests/PaymentMethods/Ideal.test.ts | 33 +-- tests/PaymentMethods/IdealQR.test.ts | 39 ++- tests/PaymentMethods/In3.test.ts | 146 ++++++--- tests/PaymentMethods/In3Old.test.ts | 80 +++++ tests/PaymentMethods/KBC.test.ts | 14 +- tests/PaymentMethods/Klarna.test.ts | 111 ++++--- tests/PaymentMethods/KlarnaKp.test.ts | 93 +++++- tests/PaymentMethods/Marketplaces.test.ts | 4 +- tests/PaymentMethods/PayPerEmail.test.ts | 4 +- tests/PaymentMethods/Payconiq.test.ts | 16 +- .../PaymentMethods/PaymentInitiation.test.ts | 8 +- tests/PaymentMethods/Paypal.test.ts | 28 +- tests/PaymentMethods/PiM.test.ts | 21 +- tests/PaymentMethods/Przelewy24.test.ts | 24 +- tests/PaymentMethods/SEPA.test.ts | 2 +- tests/PaymentMethods/Sofort.test.ts | 14 +- tests/PaymentMethods/Subscriptions.test.ts | 110 ++++--- tests/PaymentMethods/SurePay.test.ts | 4 +- tests/PaymentMethods/Thunes.test.ts | 36 +-- tests/PaymentMethods/Tinka.test.ts | 2 +- tests/PaymentMethods/Trustly.test.ts | 2 +- tests/PaymentMethods/WechatPay.test.ts | 2 +- tsconfig.json | 8 +- 236 files changed, 6297 insertions(+), 2880 deletions(-) create mode 100644 CHANGELOG.md delete mode 100644 example/BuckarooClient.ts delete mode 100644 example/CreditManagment.ts create mode 100644 example/Transaction/creditCard.ts create mode 100644 example/Transaction/ideal.ts create mode 100644 example/additional_services/creditManagment.ts rename example/{ => additional_services}/subscription.ts (59%) create mode 100644 example/buckarooClient.ts delete mode 100644 example/creditCard.ts delete mode 100644 example/ideal.ts delete mode 100644 example/klarna.ts create mode 100644 example/response/push.ts create mode 100644 src/Handlers/Credentials.ts create mode 100644 src/Handlers/Reply/ReplyHandler.ts create mode 100644 src/Models/IParameters.ts create mode 100644 src/Models/IRequest.ts create mode 100644 src/Models/IServiceList.ts delete mode 100644 src/Models/ITransaction.ts create mode 100644 src/Models/Interfaces/IAddress.ts create mode 100644 src/Models/Interfaces/IArticle.ts create mode 100644 src/Models/Interfaces/IBankAccount.ts create mode 100644 src/Models/Interfaces/ICustomer.ts create mode 100644 src/Models/Interfaces/IDebtor.ts create mode 100644 src/Models/Interfaces/IEmail.ts create mode 100644 src/Models/Interfaces/IPhone.ts create mode 100644 src/Models/Interfaces/IRecipient.ts create mode 100644 src/Models/Model.ts delete mode 100644 src/Models/Parameters.ts delete mode 100644 src/Models/Request.ts create mode 100644 src/Models/Response/BatchRequestResponse.ts create mode 100644 src/Models/Response/HttpClientResponse.ts create mode 100644 src/Models/Response/SpecificationRequestResponse.ts create mode 100644 src/Models/Response/TransactionResponse.ts delete mode 100644 src/Models/ServiceList.ts create mode 100644 src/Models/ServiceParameters.ts delete mode 100644 src/Models/Services/IAddress.ts delete mode 100644 src/Models/Services/IPhone.ts delete mode 100644 src/Models/Services/ITransactionResponse.ts delete mode 100644 src/Models/SpecificationResponse.ts delete mode 100644 src/Models/TransactionResponse.ts create mode 100644 src/PaymentMethods/Afterpay/Model/Address.ts create mode 100644 src/PaymentMethods/Afterpay/Model/Phone.ts create mode 100644 src/PaymentMethods/Afterpay/Model/Recipient.ts create mode 100644 src/PaymentMethods/Afterpay/Model/Refund.ts create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts create mode 100644 src/PaymentMethods/Billink/Models/Address.ts create mode 100644 src/PaymentMethods/Billink/Models/Capture.ts create mode 100644 src/PaymentMethods/Billink/Models/Phone.ts create mode 100644 src/PaymentMethods/Billink/Models/Refund.ts create mode 100644 src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts create mode 100644 src/PaymentMethods/BuckarooWallet/Models/Customer.ts create mode 100644 src/PaymentMethods/CreditCard/Models/CardData.ts delete mode 100644 src/PaymentMethods/CreditCard/Models/Pay.ts create mode 100644 src/PaymentMethods/CreditCard/Models/SecurityCode.ts create mode 100644 src/PaymentMethods/CreditManagement/Models/Address.ts create mode 100644 src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts delete mode 100644 src/PaymentMethods/Emandates/Models/ICreate.ts delete mode 100644 src/PaymentMethods/Emandates/Models/IModify.ts create mode 100644 src/PaymentMethods/Emandates/Models/Mandate.ts create mode 100644 src/PaymentMethods/GiftCard/Models/Pay.ts create mode 100644 src/PaymentMethods/GiftCard/Models/Refund.ts create mode 100644 src/PaymentMethods/IdealQR/Models/IGenerate.ts create mode 100644 src/PaymentMethods/IdealQR/index.ts rename src/PaymentMethods/{iDin => Idin}/index.ts (99%) create mode 100644 src/PaymentMethods/In3/Models/Phone.ts create mode 100644 src/PaymentMethods/In3/Models/Recipient.ts create mode 100644 src/PaymentMethods/In3/Models/Refund.ts create mode 100644 src/PaymentMethods/In3Old/Models/Address.ts create mode 100644 src/PaymentMethods/In3Old/Models/Article.ts create mode 100644 src/PaymentMethods/In3Old/Models/Company.ts create mode 100644 src/PaymentMethods/In3Old/Models/Pay.ts create mode 100644 src/PaymentMethods/In3Old/Models/Phone.ts create mode 100644 src/PaymentMethods/In3Old/Models/Subtotal.ts create mode 100644 src/PaymentMethods/In3Old/index.ts create mode 100644 src/PaymentMethods/Klarna/Services/KlarnaAddress.ts create mode 100644 src/PaymentMethods/Klarna/Services/KlarnaPhone.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/IReserve.ts create mode 100644 src/PaymentMethods/NoService/index.ts create mode 100644 src/PaymentMethods/PayByBank/Models/IPay.ts create mode 100644 src/PaymentMethods/PayByBank/index.ts delete mode 100644 src/PaymentMethods/PaymentInitiation/Models/IPay.ts delete mode 100644 src/PaymentMethods/PaymentInitiation/index.ts create mode 100644 src/PaymentMethods/Paypal/Models/Address.ts create mode 100644 src/PaymentMethods/Paypal/Models/Phone.ts create mode 100644 src/PaymentMethods/Subscriptions/Models/Company.ts create mode 100644 src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts create mode 100644 src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts delete mode 100644 src/PaymentMethods/iDealQR/Models/Generate.ts delete mode 100644 src/PaymentMethods/iDealQR/index.ts delete mode 100644 src/Request/BuckarooClient.ts create mode 100644 src/Request/DataModels.ts create mode 100644 src/Request/Request.ts delete mode 100644 src/Request/Response.ts create mode 100644 src/Services/TransactionService.ts create mode 100644 src/Utils/MethodTypes.ts create mode 100644 tests/Models/index.ts delete mode 100644 tests/PaymentMethods/Client.test.ts create mode 100644 tests/PaymentMethods/In3Old.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..6ecbe30f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +--- + +## [Released] + +## [1.0.0] + +- Refactor method calls. +- Batch api calls. +- Response and push validation. +- Add general models. +- Add PayByBank +- Add In3 new + +## [0.9.0] + +- Beta release. diff --git a/README.md b/README.md index 2b4b35ed..deb280d4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -

# Node SDK + [![Latest release](https://badgen.net/github/release/buckaroo-it/BuckarooSDK_Node)](https://github.com/buckaroo-it/BuckarooSDK_Node/releases)

@@ -11,14 +11,17 @@

--- + ### Index -- [About](#about) -- [Requirements](#requirements) -- [Installation](#installation) -- [Example](#example) -- [Contribute](#contribute) -- [Versioning](#versioning) -- [Additional information](#additional-information) + +- [About](#about) +- [Requirements](#requirements) +- [Installation](#installation) +- [Example](#example) +- [Contribute](#contribute) +- [Versioning](#versioning) +- [Additional information](#additional-information) + --- ### About @@ -74,6 +77,7 @@ buckarooClient().cancelInfo(transactionKey) // Retrieve cancellation info Find our full documentation online on [docs.buckaroo.io](https://docs.buckaroo.io/docs/node-sdk). #### Need more examples? + More examples can be found in the [examples folder](https://github.com/buckaroo-it/BuckarooSDK_Node/tree/master/example) ### Contribute diff --git a/example/BuckarooClient.ts b/example/BuckarooClient.ts deleted file mode 100644 index bb32894c..00000000 --- a/example/BuckarooClient.ts +++ /dev/null @@ -1,33 +0,0 @@ -import buckarooClient, { initializeBuckarooClient } from '../src' - -initializeBuckarooClient( - { secretKey: 'secretKey', websiteKey: 'websiteKey' }, - { - mode: 'test', - currency: 'EUR', - pushURL: process.env.BPE_PUSH_URL || '', - returnURL: process.env.BPE_RETURN_URL || '', - returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', - baseUrl: process.env.BPE_BASE_URL || '' - } -) -async function getSpecificationsOfIdeal() { - return await buckarooClient() - .specification('ideal', 1) - .then((res) => { - expect(res).toBeDefined() - }) -} -async function startTransactionRequest() { - return await buckarooClient() - .transactionRequest({ - currency: 'EUR', - amountDebit: 10, - servicesExcludedForClient: 'ideal', - servicesSelectableByClient: 'ideal,bancontactmrcash,paypal' - }) - .then((res) => { - expect(res).toBeDefined() - }) -} -export default buckarooClient diff --git a/example/CreditManagment.ts b/example/CreditManagment.ts deleted file mode 100644 index 8b84f9c4..00000000 --- a/example/CreditManagment.ts +++ /dev/null @@ -1,26 +0,0 @@ -require('./BuckarooClient') -import CreditManagement from '../src/PaymentMethods/CreditManagement' - -const creditManagement = new CreditManagement() - -;(async () => { - try { - const info = await creditManagement.invoiceInfo({ - invoice: 'test1' - }) - - const infoMultiple = await creditManagement.invoiceInfo({ - invoice: 'invoice1', - invoices: [ - { - invoiceNumber: 'invoice2' - }, - { - invoiceNumber: 'invoice3' - } - ] - }) - } catch (error) { - console.warn(error) - } -})() diff --git a/example/Transaction/creditCard.ts b/example/Transaction/creditCard.ts new file mode 100644 index 00000000..ecfb57c6 --- /dev/null +++ b/example/Transaction/creditCard.ts @@ -0,0 +1,15 @@ +require('../buckarooClient') +import CreditCard from '../../src/PaymentMethods/CreditCard' + +const paymentMethod = new CreditCard('nexi') + +;(async () => { + try { + const info = await paymentMethod.pay({ + invoice: 'test1', + amountDebit: 12 + }) + } catch (error) { + console.warn(error) + } +})() diff --git a/example/Transaction/ideal.ts b/example/Transaction/ideal.ts new file mode 100644 index 00000000..6ab2a4b1 --- /dev/null +++ b/example/Transaction/ideal.ts @@ -0,0 +1,24 @@ +import buckarooClient from '../buckarooClient' + +const ideal = buckarooClient.method('ideal') + +//Pay +ideal + .pay({ + amountDebit: 10.1, + issuer: 'ABNANL2A', + description: 'Ideal Payment' + }) + .request() + +//Refund +ideal + .refund({ + originalTransactionKey: '', + amountCredit: 10.1, + invoice: '' + }) + .request() + +//Issuers +ideal.issuers() diff --git a/example/additional_services/creditManagment.ts b/example/additional_services/creditManagment.ts new file mode 100644 index 00000000..14018b96 --- /dev/null +++ b/example/additional_services/creditManagment.ts @@ -0,0 +1,67 @@ +import buckaroo from '../buckarooClient' + +const creditManagement = buckaroo.method('CreditManagement3') + +// Sometimes we need to combine multiple payments. +// By calling "combine" it will combine the payload of the method with the next method or a given payload. + +const invoice = creditManagement.createCombinedInvoice({ + invoice: '', + applyStartRecurrent: false, + invoiceAmount: 10, + invoiceAmountVAT: 1, + invoiceDate: '', + dueDate: '', + schemeKey: '2amq34', + maxStepIndex: 1, + allowedServices: 'ideal,mastercard', + debtor: { + code: 'johnsmith4' + }, + email: 'youremail@example.nl', + phone: { + mobile: '06198765432' + }, + person: { + culture: 'nl-NL', + title: 'Msc', + initials: 'JS', + firstName: 'Test', + lastNamePrefix: 'Jones', + lastName: 'Aflever', + gender: 'male' + }, + company: { + culture: 'nl-NL', + name: 'My Company Corporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741' + }, + address: { + street: 'Hoofdtraat', + houseNumber: '90', + houseNumberAdditional: 'A', + zipcode: '8441ER', + city: 'Heerenveen', + state: 'Friesland', + country: 'NL' + } +}) + +const sepadirectdebit = buckaroo.method('sepadirectdebit') +sepadirectdebit + .combine(invoice.data) + .pay({ + invoice: '', + amountDebit: 10.1, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + collectdate: '2022-06-03', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + customer: { + name: 'John Smith' + } + }) + .request() diff --git a/example/subscription.ts b/example/additional_services/subscription.ts similarity index 59% rename from example/subscription.ts rename to example/additional_services/subscription.ts index b0d1740f..d6077b52 100644 --- a/example/subscription.ts +++ b/example/additional_services/subscription.ts @@ -1,6 +1,6 @@ -require('./BuckarooClient') -import Subscriptions from '../src/PaymentMethods/Subscriptions' -import Ideal from '../src/PaymentMethods/Ideal' +require('../buckarooClient') +import Subscriptions from '../../src/PaymentMethods/Subscriptions' +import Ideal from '../../src/PaymentMethods/Ideal' const subscription = new Subscriptions().createCombined({ address: undefined, @@ -15,15 +15,9 @@ const subscription = new Subscriptions().createCombined({ customerBIC: '', customerIBAN: '', debtor: { code: '' }, - email: { - email: '345345345', - }, + email: '345345345', includeTransaction: false, mandateReference: '', - person: undefined, - phone: undefined, - ratePlan: undefined, - ratePlanCharge: undefined, subscriptionGuid: '', termStartDay: 0, termStartMonth: 0, @@ -32,9 +26,13 @@ const subscription = new Subscriptions().createCombined({ }) ;(async () => { - const combinedPayment = await new Ideal().combine(subscription).pay({ - issuer: 'ABNANL2A', - amountDebit: 10 - }) + const combinedPayment = await new Ideal() + .pay({ + amountDebit: 1, + currency: 'EUR', + description: 'test' + }) + .combine('subscriptions') + .create({}) console.log(combinedPayment) })() diff --git a/example/buckarooClient.ts b/example/buckarooClient.ts new file mode 100644 index 00000000..27f34ebb --- /dev/null +++ b/example/buckarooClient.ts @@ -0,0 +1,13 @@ +import Buckaroo from '../src' + +const buckaroo = Buckaroo.InitializeClient({ + secretKey: 'secret', + websiteKey: 'website' +}) +buckaroo.config = { + mode: 'TEST', + currency: 'EUR', + returnURL: 'https://example.com/return', + pushURL: 'https://example.com/push' +} +export default buckaroo diff --git a/example/creditCard.ts b/example/creditCard.ts deleted file mode 100644 index 28dccab9..00000000 --- a/example/creditCard.ts +++ /dev/null @@ -1,16 +0,0 @@ -require('./BuckarooClient') -import CreditCard from '../src/PaymentMethods/CreditCard' - -const paymentMethod = new CreditCard() - -;(async () => { - try { - const info = await paymentMethod.pay({ - invoice: 'test1', - amountDebit: 12, - name: 'Visa' - }) - } catch (error) { - console.warn(error) - } -})() diff --git a/example/ideal.ts b/example/ideal.ts deleted file mode 100644 index a808e4ed..00000000 --- a/example/ideal.ts +++ /dev/null @@ -1,19 +0,0 @@ -require('../BuckarooClient.test') - -import Ideal from '../src/PaymentMethods/Ideal' - -const ideal = new Ideal() -async function startIdealPayment() { - return await ideal.pay({ - amountDebit: 10.1, - issuer: 'ABNANL2A', - clientIP: { - address: '123.456.789.123', - type: 0 - }, - description: 'Ideal Payment' - }) -} -startIdealPayment().then((response) => { - response.getRedirectUrl() -}) diff --git a/example/klarna.ts b/example/klarna.ts deleted file mode 100644 index eab0ea7f..00000000 --- a/example/klarna.ts +++ /dev/null @@ -1,27 +0,0 @@ -require('./BuckarooClient') -import Klarna from '../src/PaymentMethods/Klarna' - -const klarna = new Klarna() - -klarna.pay({ - article: [ - { - description: '', - grossUnitPrice: 0, - identifier: '', - quantity: '', - vatPercentage: '' - } - ], - amountDebit: 0, - billingCustomer: { - city: '', - country: '', - email: '', - firstName: '', - lastName: '', - postalCode: '', - street: '', - streetNumber: '' - } -}) diff --git a/example/response/push.ts b/example/response/push.ts new file mode 100644 index 00000000..a8e02cb1 --- /dev/null +++ b/example/response/push.ts @@ -0,0 +1,44 @@ +import buckaroo from '../buckarooClient' +import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler' + +//START HTTP POST PUSH +let post_data = `{ + "brq_amount": "10.10", + "brq_currency": "EUR", + "brq_customer_name": "J. de Tèster", + "brq_invoicenumber": "SDKDevelopment.com_INVOICE_NO_628c6d032af90", + "brq_ordernumber": "SDKDevelopment.com_ORDER_NO_628c6d032af95", + "brq_payer_hash": "2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da", + "brq_payment": "D44ACDD0F99D4A1C811D2CD3EFDB05BA", + "brq_payment_method": "ideal", + "brq_SERVICE_ideal_consumerBIC": "RABONL2U", + "brq_SERVICE_ideal_consumerIBAN": "NL44RABO0123456789", + "brq_SERVICE_ideal_consumerIssuer": "ABN AMRO", + "brq_SERVICE_ideal_consumerName": "J. de Tèster", + "brq_SERVICE_ideal_transactionId": "0000000000000001", + "brq_statuscode": "190", + "brq_statuscode_detail": "S001", + "brq_statusmessage": "Transaction successfully processed", + "brq_test": "true", + "brq_timestamp": "2022-05-24 07:29:09", + "brq_transactions": "4C1BE53E2C42412AB32A799D9316E7DD", + "brq_websitekey": "IBjihN7Fhp", + "brq_signature": "bf7a62c830da2d2e004199919a8fe0d53b0668f5", +}` + +let reply_handler = new ReplyHandler(buckaroo.credentials, post_data) +reply_handler.validate() +reply_handler.isValid() // Return either true or false +//END HTTP POST PUSH + +//START JSON PUSH +const auth_header = + 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572' +post_data = + '{"Transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"Transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}' +const uri = 'https://buckaroo.dev/push' + +reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri) +reply_handler.validate() +reply_handler.isValid() // Return either true or false +//END JSON PUSH diff --git a/package.json b/package.json index 8a9a5cdd..650e2349 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@buckaroo/buckaroo_sdk", "version": "0.9.0", "description": "Buckaroo payment SDK", - "main": "dist/BuckarooClient.js", + "main": "dist/index.js", "engines": { "node": ">=6.14" }, diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index cb5848ec..67f4e11a 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -2,9 +2,10 @@ enum Endpoints { LIVE = 'https://checkout.buckaroo.nl', TEST = 'https://testcheckout.buckaroo.nl' } -enum RequestTypePaths { +export enum RequestTypes { Data = '/json/DataRequest', - Transaction = '/json/Transaction' + Transaction = '/json/Transaction', + BatchData = '/json/batch/DataRequests', + BatchTransaction = '/json/batch/Transactions' } -export { RequestTypePaths } export default Endpoints diff --git a/src/Constants/HttpMethods.ts b/src/Constants/HttpMethods.ts index da99d999..2903572c 100644 --- a/src/Constants/HttpMethods.ts +++ b/src/Constants/HttpMethods.ts @@ -1,5 +1,5 @@ enum HttpMethods { - METHOD_GET = 'GET', - METHOD_POST = 'POST' + GET = 'GET', + POST = 'POST' } export default HttpMethods diff --git a/src/Constants/IPProtocolVersion.ts b/src/Constants/IPProtocolVersion.ts index 47af76ef..3438aea0 100644 --- a/src/Constants/IPProtocolVersion.ts +++ b/src/Constants/IPProtocolVersion.ts @@ -1,5 +1,6 @@ import * as IpAddress from 'ip-address' +import { getIPAddress } from '../Utils/Functions' export class IPProtocolVersion { public static readonly IPV4: number = 0 public static readonly IPV6: number = 1 @@ -14,3 +15,12 @@ export class IPProtocolVersion { throw new Error(`Invalid IP address: ${ipAddress}`) } } + +export class ClientIP { + type: IPProtocolVersion + address: string + constructor(ipAddress: string = getIPAddress()) { + this.type = IPProtocolVersion.getVersion(ipAddress) + this.address = ipAddress + } +} diff --git a/src/Constants/RecipientCategory.ts b/src/Constants/RecipientCategory.ts index 542fed45..6c40fae5 100644 --- a/src/Constants/RecipientCategory.ts +++ b/src/Constants/RecipientCategory.ts @@ -1,7 +1,5 @@ enum RecipientCategory { - PERSON = 'Person', - COMPANY = 'Company', - B2B = 'B2B', - B2C = 'B2C' + PERSON = 'PERSON', + COMPANY = 'COMPANY' } export default RecipientCategory diff --git a/src/Handlers/Credentials.ts b/src/Handlers/Credentials.ts new file mode 100644 index 00000000..c3dec222 --- /dev/null +++ b/src/Handlers/Credentials.ts @@ -0,0 +1,25 @@ +import { ICredentials } from '../Utils/Types' +import Request from '../Request/Request' +import { RequestTypes } from '../Constants/Endpoints' + +export class Credentials implements ICredentials { + secretKey: string + websiteKey: string + constructor(secretKey: string, websiteKey: string) { + this.secretKey = secretKey + this.websiteKey = websiteKey + } + confirm() { + return Request.Specification(RequestTypes.Transaction, { + name: 'ideal', + version: 2 + }) + .request() + .then((response) => { + return response.httpResponse.statusCode === 200 + }) + .catch(() => { + return false + }) + } +} diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts new file mode 100644 index 00000000..96e3e83b --- /dev/null +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -0,0 +1,80 @@ +import crypto from 'crypto' +import { ICredentials } from '../../Utils/Types' +import { Hmac } from '../../Request/Hmac' +import HttpMethods from '../../Constants/HttpMethods' + +export class ReplyHandler { + private readonly _data: object + private readonly uri?: string + private readonly auth_header?: string + private readonly credentials: ICredentials + private _isValid: boolean = false + private strategy: 'JSON' | 'HTTP' = 'JSON' + private method?: string + constructor( + credentials: ICredentials, + data: string, + auth_header?: string, + uri?: string, + httpMethod?: string + ) { + this._data = this.formatStringData(data) + this.credentials = credentials + this.uri = uri + this.auth_header = auth_header + this.method = httpMethod + } + isValid(): boolean { + return this._isValid + } + private formatStringData(value: string) { + try { + let data = JSON.parse(value) + this.strategy = 'JSON' + return data + } catch (e) { + let objData = {} + new URLSearchParams(value).forEach((value, name) => { + objData[name] = value + }) + this.strategy = 'HTTP' + return objData + } + } + validate() { + if (this.strategy === 'HTTP') { + let { brq_signature, BRQ_SIGNATURE, ...data } = this._data as any + this._isValid = this.validateHttp(data, brq_signature || BRQ_SIGNATURE) + return this + } + if (this.strategy === 'JSON' && this.auth_header && this.uri) { + this._isValid = this.validateJson( + this.auth_header, + this.uri, + JSON.stringify(this._data) + ) + return this + } + throw new Error('Invalid response data') + } + private validateJson(auth_header: string, url: string, data: string) { + return new Hmac().validate( + this.credentials, + auth_header, + url, + data, + this.method || HttpMethods.POST + ) + } + private validateHttp(data: object, signature: string) { + let stringData = '' + for (const key in data) { + stringData += key + '=' + data[key] + } + stringData = stringData + this.credentials.websiteKey + + let hash = crypto.createHash('sha1').update(stringData).digest('hex') + + return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)) + } +} diff --git a/src/Models/IParameters.ts b/src/Models/IParameters.ts new file mode 100644 index 00000000..09c968b8 --- /dev/null +++ b/src/Models/IParameters.ts @@ -0,0 +1,43 @@ +import { Model } from './Model' +import { Str } from '../Utils/Functions' + +export interface IParameter { + name: string + value: string | number | boolean + groupType?: string + groupID?: number +} + +export class Parameter extends Model implements IParameter { + set name(value: string) { + this.set('name', Str.ucfirst(value)) + } + + set value(value: ParameterTypes) { + this.set('value', value) + } + + set groupType(value: string) { + this.set('groupType', value) + } + + set groupID(value: number) { + this.set('groupID', value) + } +} + +export type ParameterTypes = string | number | boolean + +export declare type IAdditionalParameters = { + [name: string]: ParameterTypes +} +export declare type ServiceParameterTypes = ParameterTypes | ParameterTypes[] | IServiceParameters + +export declare interface IServiceParameters { + [name: keyof any]: ServiceParameterTypes | undefined +} + +export type IFormattedParameter = { + name: string + value: string | number | boolean +} diff --git a/src/Models/IRequest.ts b/src/Models/IRequest.ts new file mode 100644 index 00000000..d8215430 --- /dev/null +++ b/src/Models/IRequest.ts @@ -0,0 +1,41 @@ +import { ServiceCode } from '../Utils/MethodTypes' +import { IAdditionalParameters } from './IParameters' + +export default interface IRequest { + clientIP?: string + currency?: string + clientUserAgent?: string + returnURL?: string + returnURLError?: string + returnURLCancel?: string + returnURLReject?: string + pushURL?: string + pushURLFailure?: string + invoice?: string + order?: string + amountDebit?: number + amountCredit?: number + description?: string + originalTransactionKey?: string + originalTransactionReference?: { + type: string + reference: string + } + culture?: string + startRecurrent?: boolean + continueOnIncomplete?: boolean + servicesSelectableByClient?: ServiceCode[] | string + servicesExcludedForClient?: ServiceCode[] | string + customParameters?: IAdditionalParameters + additionalParameters?: IAdditionalParameters + [key: string]: any +} +export declare interface IPaymentRequest extends IRequest { + amountDebit: number + amountCredit?: never +} +export declare interface IRefundRequest extends IRequest { + amountCredit: number + amountDebit?: never + originalTransactionKey: string +} diff --git a/src/Models/IServiceList.ts b/src/Models/IServiceList.ts new file mode 100644 index 00000000..dc471d63 --- /dev/null +++ b/src/Models/IServiceList.ts @@ -0,0 +1,52 @@ +import { Model } from './Model' +import { IParameter, Parameter } from './IParameters' + +export interface IService { + name: string + action?: string + version?: number + parameters?: IParameter[] +} +export class Service extends Model implements IService { + constructor(data: IService) { + super(data) + } + set action(value: string) { + this.set('action', value) + } + set name(value: string) { + this.set('name', value) + } + set version(value: number) { + this.set('version', value) + } + set parameters(value: IParameter[]) { + this.set( + 'parameters', + value.map((parameter) => new Parameter(parameter)) + ) + } +} +export class ServiceList extends Model { + constructor(...list: IService[]) { + super({ list: list }) + } + get list(): Service[] { + return this.get('serviceList') + } + set list(services: IService[]) { + this.set( + 'serviceList', + services.map((service) => new Service(service)) + ) + } + addService(service: IService) { + if (this.getService(service.name)) { + throw new Error(`Service ${service.name} already exists`) + } + this.list.push(new Service(service)) + } + getService(name: string) { + return this.list.find((service) => service.name.toLowerCase() === name.toLowerCase()) + } +} diff --git a/src/Models/ITransaction.ts b/src/Models/ITransaction.ts deleted file mode 100644 index 75df864d..00000000 --- a/src/Models/ITransaction.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { AdditionalParameter, IPAddress } from '../Utils/Types' - -export declare interface ITransaction { - clientIP?: string | IPAddress - currency?: string - returnURL?: string - returnURLError?: string - returnURLCancel?: string - returnURLReject?: string - pushURL?: string - pushURLFailure?: string - invoice?: string - order?: string - amountDebit?: number - amountCredit?: number - description?: string - originalTransactionKey?: string - originalTransactionReference?: string - culture?: string - startRecurrent?: boolean - /** - * 0 = No - * 1 = RedirectToHTML - */ - continueOnIncomplete?: 0 | 1 - servicesSelectableByClient?: string - servicesExcludedForClient?: string - customParameters?: AdditionalParameter - additionalParameters?: AdditionalParameter -} - -export declare interface Payload extends Omit { - invoice?: string - order?: string - amountDebit: number -} - -export declare interface RefundPayload extends Omit { - order?: string - amountCredit: number - originalTransactionKey: string -} -export declare interface ICapture extends Payload { - originalTransactionKey: string -} diff --git a/src/Models/Interfaces/IAddress.ts b/src/Models/Interfaces/IAddress.ts new file mode 100644 index 00000000..ccfa2703 --- /dev/null +++ b/src/Models/Interfaces/IAddress.ts @@ -0,0 +1,34 @@ +import { Model } from '../Model' + +export default interface IAddress { + street: string + houseNumber: string + houseNumberAdditional: string + zipcode: string + city: string + state?: string + country: string +} +export class Address extends Model implements IAddress { + set street(street: string) { + this.set('street', street) + } + set houseNumber(houseNumber: string) { + this.set('houseNumber', houseNumber) + } + set houseNumberAdditional(houseNumberAdditional: string) { + this.set('houseNumberAdditional', houseNumberAdditional) + } + set zipcode(zipcode: string) { + this.set('zipcode', zipcode) + } + set city(city: string) { + this.set('city', city) + } + set state(state: string) { + this.set('state', state) + } + set country(country: string) { + this.set('country', country) + } +} diff --git a/src/Models/Interfaces/IArticle.ts b/src/Models/Interfaces/IArticle.ts new file mode 100644 index 00000000..5f373995 --- /dev/null +++ b/src/Models/Interfaces/IArticle.ts @@ -0,0 +1,46 @@ +import { Model } from '../Model' + +export default interface IArticle { + identifier: string + type: string + brand?: string + manufacturer?: string + unitCode: string + price: number + quantity: number + vatPercentage: number + vatCategory: string + description: string +} +export class Article extends Model implements IArticle { + set identifier(identifier: string) { + this.set('identifier', identifier) + } + set type(type: string) { + this.set('type', type) + } + set brand(brand: string) { + this.set('brand', brand) + } + set manufacturer(manufacturer: string) { + this.set('manufacturer', manufacturer) + } + set unitCode(unitCode: string) { + this.set('unitCode', unitCode) + } + set price(price: number) { + this.set('price', price) + } + set quantity(quantity: number) { + this.set('quantity', quantity) + } + set vatPercentage(vatPercentage: number) { + this.set('vatPercentage', vatPercentage) + } + set vatCategory(vatCategory: string) { + this.set('vatCategory', vatCategory) + } + set description(description: string) { + this.set('description', description) + } +} diff --git a/src/Models/Interfaces/IBankAccount.ts b/src/Models/Interfaces/IBankAccount.ts new file mode 100644 index 00000000..fbdc771b --- /dev/null +++ b/src/Models/Interfaces/IBankAccount.ts @@ -0,0 +1,18 @@ +import { Model } from '../Model' + +export default interface IBankAccount { + iban: string + bic: string + accountName: string +} +export class BankAccount extends Model implements IBankAccount { + set accountName(accountName: string) { + this.set('accountName', accountName) + } + set bic(bic: string) { + this.set('bic', bic) + } + set iban(iban: string) { + this.set('iban', iban) + } +} diff --git a/src/Models/Interfaces/ICustomer.ts b/src/Models/Interfaces/ICustomer.ts new file mode 100644 index 00000000..44c91bdf --- /dev/null +++ b/src/Models/Interfaces/ICustomer.ts @@ -0,0 +1,30 @@ +import IAddress, { Address } from './IAddress' +import IPhone, { Phone } from './IPhone' +import { Company, ICompany, IPerson, Person } from './IRecipient' +import { Model } from '../Model' +import recipientCategory from '../../Constants/RecipientCategory' + +export interface ICustomer { + phone?: Partial + email?: string + recipient?: Partial + address?: Partial +} +export class Customer extends Model { + set address(address: Partial) { + this.set('address', new Address(address)) + } + set email(email: string) { + this.set('email', email) + } + set phone(phone: Partial) { + this.set('phone', new Phone(phone)) + } + set recipient(recipient: IPerson | ICompany) { + if (recipient.category === recipientCategory.PERSON) { + this.set('recipient', new Person(recipient)) + } else if (recipient.category === recipientCategory.COMPANY) { + this.set('recipient', new Company(recipient)) + } + } +} diff --git a/src/Models/Interfaces/IDebtor.ts b/src/Models/Interfaces/IDebtor.ts new file mode 100644 index 00000000..53db4cf6 --- /dev/null +++ b/src/Models/Interfaces/IDebtor.ts @@ -0,0 +1,10 @@ +import { Model } from '../Model' + +export default interface IDebtor { + code: string +} +export class Debtor extends Model { + set code(value: string) { + this.set('code', value) + } +} diff --git a/src/Models/Interfaces/IEmail.ts b/src/Models/Interfaces/IEmail.ts new file mode 100644 index 00000000..eb9ffdd9 --- /dev/null +++ b/src/Models/Interfaces/IEmail.ts @@ -0,0 +1,16 @@ +import { Model } from '../Model' + +export default interface IEmail { + email: string +} +export class Email extends Model implements IEmail { + constructor(data: IEmail) { + super(data) + } + get email() { + return '' + } + set email(email: string) { + this.set('email', email) + } +} diff --git a/src/Models/Interfaces/IPhone.ts b/src/Models/Interfaces/IPhone.ts new file mode 100644 index 00000000..2bfef7f3 --- /dev/null +++ b/src/Models/Interfaces/IPhone.ts @@ -0,0 +1,19 @@ +import { Model } from '../Model' + +export default interface IPhone { + landline?: string + mobile?: string + fax?: string +} + +export class Phone extends Model implements IPhone { + set landline(landline: string) { + this.set('landline', landline) + } + set mobile(mobile: string) { + this.set('mobile', mobile) + } + set fax(fax: string) { + this.set('fax', fax) + } +} diff --git a/src/Models/Interfaces/IRecipient.ts b/src/Models/Interfaces/IRecipient.ts new file mode 100644 index 00000000..d273766d --- /dev/null +++ b/src/Models/Interfaces/IRecipient.ts @@ -0,0 +1,90 @@ +import RecipientCategory from '../../Constants/RecipientCategory' +import { Model } from '../Model' +import Gender from '../../Constants/Gender' + +export interface IRecipient { + [key: string]: any +} +export interface IPerson extends IRecipient { + category: RecipientCategory.PERSON + gender: string | Gender + culture: string + careOf?: string + title?: string + initials?: string + firstName: string + lastName?: string + lastNamePrefix?: string + birthDate: string + placeOfBirth: string +} +export interface ICompany extends IRecipient { + category: RecipientCategory.COMPANY + companyName: string + culture: string + vatApplicable: boolean + vatNumber: string + chamberOfCommerce: string +} +export class Person extends Model implements IPerson { + constructor(data: Partial) { + super(data) + } + set birthDate(value: string) { + this.set('birthDate', value) + } + set careOf(value: string) { + this.set('careOf', value) + } + set category(value: RecipientCategory.PERSON) { + this.set('category', value) + } + set culture(value: string) { + this.set('culture', value) + } + set firstName(value: string) { + this.set('firstName', value) + } + set gender(value: string) { + this.set('gender', value) + } + set initials(value: string) { + this.set('initials', value) + } + set lastName(value: string) { + this.set('lastName', value) + } + set lastNamePrefix(value: string) { + this.set('lastNamePrefix', value) + } + set placeOfBirth(value: string) { + this.set('placeOfBirth', value) + } + set title(value: string) { + this.set('title', value) + } +} +export class Company extends Person implements ICompany { + constructor(data: Partial) { + super(data as any) + } + // @ts-ignore + set category(value: RecipientCategory.COMPANY) { + this.set('category', value) + } + set chamberOfCommerce(value: string) { + this.set('chamberOfCommerce', value) + } + set companyName(value: string) { + this.set('companyName', value) + } + set culture(value: string) { + this.set('culture', value) + } + set vatApplicable(value: boolean) { + this.set('vatApplicable', value) + } + set vatNumber(value: string) { + this.set('vatNumber', value) + } +} diff --git a/src/Models/Model.ts b/src/Models/Model.ts new file mode 100644 index 00000000..95779244 --- /dev/null +++ b/src/Models/Model.ts @@ -0,0 +1,124 @@ +import { Str } from '../Utils/Functions' +export class Model { + [key: keyof any]: any + constructor(...args: any[]) { + this.initialize(...args) + } + initialize(data?: any) { + if (data instanceof Object && !Array.isArray(data)) { + if (data.constructor === this.constructor) { + this.setDataProperties(data) + } else this.setOwnProperties(data) + } + } + protected setOwnProperties( + data: object = {}, + properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors() + ) { + for (const key in properties) { + if (properties[key].set) { + let value = data[key] ?? properties[key].get?.call(this) + if (value !== undefined) this[key] = value + } + } + return this + } + protected setDataProperties(data: object = {}) { + for (const dataKey in data) { + if (data.hasOwnProperty(dataKey) && data[dataKey] !== undefined) + this.set(dataKey, data[dataKey]) + } + return this + } + protected privateName(name: string): string { + return Str.ucfirst(name) + } + protected publicName(name: string): string { + return Str.lcfirst(name) + } + protected getAllPropertyDescriptors( + descriptors = {}, + root = Model.prototype + ): { [p: string]: PropertyDescriptor } { + // Loop through the prototype chain + let currentObj = Object.getPrototypeOf(this) + while (currentObj !== root) { + const currentDescriptors = Object.getOwnPropertyDescriptors(currentObj) + + // Merge the descriptors into the result + descriptors = { ...currentDescriptors, ...descriptors } + + // Move up the prototype chain + currentObj = Object.getPrototypeOf(currentObj) + } + return descriptors + } + protected defineProperty(name: string, value: any, hidden: boolean = false) { + let privateName = this.privateName(name) + Object.defineProperty(this, privateName, { + value, + writable: true, + enumerable: !hidden, + configurable: true + }) + let publicName = this.publicName(name) + Object.defineProperty(this, publicName, { + get: () => value, + set: this.has(publicName)?.set ?? ((value) => this.set(publicName, value, hidden)), + enumerable: false, + configurable: true + }) + } + set(name: string, value: any, hidden: boolean = false): this { + this.defineProperty(name, value, hidden) + return this + } + get(prop: string): any { + return this.has(prop)?.get?.call(this) + } + has(prop: string, model = this): PropertyDescriptor | undefined { + return getObjectProperty(model, prop, Model.prototype) + } + getData(callBack?: ((this: any, key: string, value: any) => any) | undefined): { + [key: string]: any + } { + return JSON.parse(JSON.stringify(this), callBack) + } +} + +export class JsonModel extends Model { + constructor(data: object) { + super(data) + } + initialize(data?: any) { + this.setDataProperties(data) + } + + set(key: string, value: any) { + Object.defineProperty(this, Str.lcfirst(key), { + get: this.get.bind(this, value), + enumerable: true + }) + return this + } + get(value: any) { + if (Array.isArray(value)) { + return value.map((v) => new JsonModel(v)) + } + if (value instanceof Object) { + return new JsonModel(value) + } + if (value === null) { + return undefined + } + return value + } +} +export function getObjectProperty(object: object, property: string, root: any = null) { + if (object !== root) { + return ( + Object.getOwnPropertyDescriptor(object, property) ?? + getObjectProperty(Object.getPrototypeOf(object), property, root) + ) + } +} diff --git a/src/Models/Parameters.ts b/src/Models/Parameters.ts deleted file mode 100644 index d7f3db30..00000000 --- a/src/Models/Parameters.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IParameter { - Name: string - Value: string | number | boolean - GroupType?: string - GroupID?: string | number -} diff --git a/src/Models/Request.ts b/src/Models/Request.ts deleted file mode 100644 index df421eea..00000000 --- a/src/Models/Request.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { ITransaction } from './ITransaction' -import { IServiceList, IServices } from './ServiceList' -import { IParameter } from './Parameters' -import { firstUpperCase } from '../Utils/Functions' -import {AdditionalParameter, ServiceParameters} from '../Utils/Types' -import { IPProtocolVersion } from '../Constants/IPProtocolVersion' - -export class Request { - private readonly _data: ITransaction - - constructor(data:ITransaction) { - this._data = data - } - get data(): ITransaction { - return this._data - } - getFormattedData():object { - let data:any = {} - if (this._data.additionalParameters) { - data.additionalParameters = this.formatAdditionalParameters() - } - if (this._data.customParameters) { - data.customParameters = this.formatCustomParameters() - } - if (this._data.clientIP) { - data.clientIP = this.formatClientIp() - } - return data - } - formatAdditionalParameters() { - return { - additionalParameter: this.formatParametersMap(this._data.additionalParameters) - } - } - formatCustomParameters() { - return { - list: this.formatParametersMap(this._data.customParameters) - } - } - public formatClientIp() { - let ip = this._data.clientIP - if (typeof ip === 'string') { - ip = { - type: IPProtocolVersion.getVersion(ip), - address: ip - } - } - return ip - } - protected formatParametersMap(value: AdditionalParameter = {}): IParameter[] { - return Object.keys(value).map((key, value) => { - return { - Name: key, - Value: value || '' - } - }) - } - public formatServiceParameters( - data: ServiceParameters, - groups: { GroupID?: number; GroupType: string } = { GroupType: '' }, - parentKey: string = '', - parameters: IParameter[] = [] - ): IParameter[] { - for (const key in data) { - let value = data[key] - if (typeof value !== 'undefined') { - let name: string | number = firstUpperCase(key) - - if (groups.GroupID === parseInt(key)) { - groups.GroupID++ - name = parseInt(key) - } - if (Array.isArray(value)) { - this.formatServiceParameters( - (value), - { - ...groups, - GroupID: 0 - }, - key, - parameters - ) - } else if (value instanceof Object) { - this.formatServiceParameters( - value, - { - ...groups, - GroupType: - typeof name === 'string' - ? name + groups.GroupType - : firstUpperCase(parentKey) + groups.GroupType - }, - key, - parameters - ) - } else { - parameters.push({ - Name: typeof name === 'string' ? name : firstUpperCase(parentKey), - Value: value, - ...groups - }) - } - } - } - return parameters - } -} diff --git a/src/Models/Response/BatchRequestResponse.ts b/src/Models/Response/BatchRequestResponse.ts new file mode 100644 index 00000000..db4a4bf5 --- /dev/null +++ b/src/Models/Response/BatchRequestResponse.ts @@ -0,0 +1,14 @@ +import { HttpClientResponse } from './HttpClientResponse' + +export class BatchRequestResponse extends HttpClientResponse { + get data(): BatchResponseData { + return this._data as any + } +} +export interface BatchResponseData { + message: string + errors?: { + reference: string + message: string + }[] +} diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts new file mode 100644 index 00000000..1e709203 --- /dev/null +++ b/src/Models/Response/HttpClientResponse.ts @@ -0,0 +1,43 @@ +import { IncomingMessage } from 'http' +import { JsonModel } from '../Model' +import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler' +import { ICredentials } from '../../Utils/Types' + +export interface HttpResponseConstructor { + new (httpResponse: IncomingMessage, data: string): IHttpClientResponse +} +export interface IHttpClientResponse { + httpResponse: IncomingMessage + data: object +} + +export class HttpClientResponse implements IHttpClientResponse { + protected readonly _httpResponse: IncomingMessage + protected readonly _data: object + protected readonly _rawData: string + constructor(httpResponse: IncomingMessage, data: string) { + this._httpResponse = httpResponse + this._rawData = data + this._data = new JsonModel(JSON.parse(data)) + } + get httpResponse(): IncomingMessage { + return this._httpResponse + } + get rawData(): string { + return this._rawData + } + get data() { + return this._data + } + validateResponse(credentials: ICredentials) { + return new ReplyHandler( + credentials, + this._rawData, + this.httpResponse.headers['authorization'], + this.httpResponse.url, + this.httpResponse.method + ) + .validate() + .isValid() + } +} diff --git a/src/Models/Response/SpecificationRequestResponse.ts b/src/Models/Response/SpecificationRequestResponse.ts new file mode 100644 index 00000000..44b76aab --- /dev/null +++ b/src/Models/Response/SpecificationRequestResponse.ts @@ -0,0 +1,66 @@ +import { Str } from '../../Utils/Functions' +import { HttpClientResponse } from './HttpClientResponse' +export class SpecificationRequestResponse extends HttpClientResponse { + get data(): ISpecificationRequestResponse { + return this._data as any + } + getActionRequestParameters(actionName: string): RequestParameter[] | undefined { + let actions = this.data.actions?.find((action) => { + if (Str.ciEquals(action.name, actionName)) { + return action + } + })?.requestParameters + if (actions) { + actions.sort((a, b) => a.name.localeCompare(b.name)) + } + return actions + } +} + +type ListItemDescription = { + value: string + description: string + groupName: string +} +type SupportedCurrency = { + isoNumber: number + code: string + name: string +} + +type Action = { + name: string + type: number + default: boolean + description: string + requestParameters: RequestParameter[] + responseParameters: RequestParameter[] +} +export type RequestParameter = { + listItemDescriptions?: ListItemDescription[] + isRequestParameter: boolean + name: string + dataType: number + maxLength: number + maxOccurs: number + required: boolean + global: boolean + group?: string + description: string + explanationHTML: string + displayName: string + inputPattern: string + autoCompleteType: string +} +export interface ISpecificationRequestResponse { + name: string + version: number + description: string + actions?: Action[] + supportedCurrencies?: SupportedCurrency[] + customParameters?: { + description: 'sample string 1' + dataType: 0 + name: 'sample string 2' + }[] +} diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts new file mode 100644 index 00000000..e8d0230d --- /dev/null +++ b/src/Models/Response/TransactionResponse.ts @@ -0,0 +1,205 @@ +import ResponseStatus from '../../Constants/ResponseStatus' +import { DataFormatter } from '../../Utils/Functions' +import { HttpClientResponse } from './HttpClientResponse' + +import { IFormattedParameter } from '../IParameters' + +export class TransactionResponse extends HttpClientResponse { + get data(): ITransactionResponse { + return this._data as any + } + getStatusCode() { + return this.data.status.code.code.toString() + } + getSubStatusCode() { + return this.data.status.subCode.code.toString() + } + isSuccess() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS + } + isFailed() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED + } + isCanceled() { + return ( + this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || + this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT + ) + } + isAwaitingConsumer() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER + } + isPendingProcessing() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING + } + isWaitingOnUserInput() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT + } + isRejected() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED + } + isValidationFailure() { + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE + } + hasRedirect() { + return ( + this.data.requiredAction?.redirectURL.length > 0 && + this.data.requiredAction?.name === 'Redirect' + ) + } + getRedirectUrl() { + if (this.hasRedirect()) return this.data.requiredAction?.redirectURL + return '' + } + getServices() { + return this.data.services + } + getMethod() { + return this.data.services?.[0].name + } + getServiceAction() { + return this.data.services?.[0].action + } + getCustomParameters() { + return DataFormatter.parametersReverseMap(this.data.customParameters?.list ?? []) + } + getAdditionalParameters() { + return DataFormatter.parametersReverseMap( + this.data.additionalParameters?.additionalParameter ?? + this.data.additionalParameters?.['list'] ?? + [] + ) + } + getTransactionKey() { + return this.data.key + } + getPaymentKey() { + return this.data.paymentKey + } + getAmountDebit() { + return this.data.amountDebit + } + getAmountCredit() { + return this.data.amountCredit + } + hasError() { + return ( + this.data.requestErrors && + Object.keys(this.data.requestErrors).length > 0 && + (this.data.requestErrors.channelErrors.length > 0 || + this.data.requestErrors.serviceErrors.length > 0 || + this.data.requestErrors.actionErrors.length > 0 || + this.data.requestErrors.parameterErrors.length > 0 || + this.data.requestErrors.customParameterErrors.length > 0) + ) + } + getErrorMessage() { + return this.data.status.code.description + } +} + +export declare interface ITransactionResponse { + key: string + name: string + version: number + description: string + status: { + code: { + code: number | string + description: string + } + subCode: { + code: number | string + description: string + } + dateTime: string + } + requiredAction: { + redirectURL: string + requestedInformation: { + name: string + dataType: number + maxLength: number + required: boolean + description: string + }[] + payRemainderDetails: { + remainderAmount: number + currency: string + groupTransaction: string + } + name: string + typeDeprecated: number + } + services: { + action: string + name: string + value: string + versionAsProperty: number + parameters: IFormattedParameter[] + }[] + customParameters?: { + list: IFormattedParameter[] + } + additionalParameters?: { + additionalParameter: IFormattedParameter[] + } + requestErrors: { + channelErrors: { + service: string + action: string + name: string + error: string + errorMessage: string + }[] + serviceErrors: { + name: string + error: string + errorMessage: string + }[] + actionErrors: { + service: string + name: string + error: string + errorMessage: string + }[] + parameterErrors: { + service: string + action: string + name: string + error: string + errorMessage: string + }[] + customParameterErrors: { + name: string + error: string + errorMessage: string + }[] + } + invoice: string + serviceCode: string + isTest: boolean + currency: string + amountDebit: number + amountCredit: number + transactionType: string + mutationType: number + relatedTransactions: { + relationType: string + relatedTransactionKey: string + }[] + consumerMessage: { + mustRead: boolean + cultureName: string + title: string + plainText: string + htmlText: string + } + order: string + issuingCountry: string + startRecurrent: boolean + recurring: boolean + customerName: string + payerHash: string + paymentKey: string +} diff --git a/src/Models/ServiceList.ts b/src/Models/ServiceList.ts deleted file mode 100644 index c162823c..00000000 --- a/src/Models/ServiceList.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IParameter } from './Parameters' - -export declare interface IServices { - ServiceList: IServiceList[] -} -export declare interface IServiceList { - Name?: string - Action?: string - Version?: number - Parameters?: Array -} diff --git a/src/Models/ServiceParameters.ts b/src/Models/ServiceParameters.ts new file mode 100644 index 00000000..3ff64125 --- /dev/null +++ b/src/Models/ServiceParameters.ts @@ -0,0 +1,25 @@ +import { Model } from './Model' +import { DataFormatter } from '../Utils/Functions' +import { IParameter } from './IParameters' + +export class ServiceParameter extends Model { + protected getGroups(groups: { [key: Capitalize]: Capitalize } = {}) { + return groups + } + protected getCountable(countable: Capitalize[] = []) { + return countable + } + protected getAllPropertyDescriptors( + descriptors = {}, + root: Model = ServiceParameter.prototype + ): { [p: string]: PropertyDescriptor } { + return super.getAllPropertyDescriptors(descriptors, root) + } + toParameterList(): IParameter[] { + return DataFormatter.serviceParametersMap( + this.getData(), + this.getGroups(), + this.getCountable() + ) + } +} diff --git a/src/Models/Services/IAddress.ts b/src/Models/Services/IAddress.ts deleted file mode 100644 index 020143ff..00000000 --- a/src/Models/Services/IAddress.ts +++ /dev/null @@ -1,10 +0,0 @@ -type IAddress = { - street: string - houseNumber?: string - houseNumberAdditional: string - zipcode: string - city: string - state?: string - country: string -} -export default IAddress diff --git a/src/Models/Services/IPhone.ts b/src/Models/Services/IPhone.ts deleted file mode 100644 index fab1400f..00000000 --- a/src/Models/Services/IPhone.ts +++ /dev/null @@ -1,8 +0,0 @@ - -type IPhone = { - landline: string - mobile: string - fax: string -} - -export default IPhone diff --git a/src/Models/Services/ITransactionResponse.ts b/src/Models/Services/ITransactionResponse.ts deleted file mode 100644 index 4d191ff5..00000000 --- a/src/Models/Services/ITransactionResponse.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { IServiceList } from '../ServiceList' - -export type AdditionalParameterResponse = { - Name: string - Value: string -} -export declare interface ITransactionResponse { - Key: string - Name: string - Version: number - Description: string - Status: { - Code: { - Code: number | string - Description: string - } - SubCode: { - Code: number | string - Description: string - } - DateTime: string - } - RequiredAction: { - RedirectURL: string - RequestedInformation: { - Name: string - DataType: number - MaxLength: number - Required: boolean - Description: string - }[] - PayRemainderDetails: { - RemainderAmount: number - Currency: string - GroupTransaction: string - } - Name: string - TypeDeprecated: number - } - Services: IServiceList[] - CustomParameters?: { - List: AdditionalParameterResponse[] - } - AdditionalParameters?: { - AdditionalParameter: AdditionalParameterResponse[] - } - RequestErrors: { - ChannelErrors: { - Service: string - Action: string - Name: string - Error: string - ErrorMessage: string - }[] - ServiceErrors: { - Name: string - Error: string - ErrorMessage: string - }[] - ActionErrors: { - Service: string - Name: string - Error: string - ErrorMessage: string - }[] - ParameterErrors: { - Service: string - Action: string - Name: string - Error: string - ErrorMessage: string - }[] - CustomParameterErrors: { - Name: string - Error: string - ErrorMessage: string - }[] - } - Invoice: string - ServiceCode: string - IsTest: boolean - Currency: string - AmountDebit: number - AmountCredit: number - TransactionType: string - MutationType: number - RelatedTransactions: { - RelationType: string - RelatedTransactionKey: string - }[] - ConsumerMessage: { - MustRead: boolean - CultureName: string - Title: string - PlainText: string - HtmlText: string - } - Order: string - IssuingCountry: string - StartRecurrent: boolean - Recurring: boolean - CustomerName: string - PayerHash: string - PaymentKey: string -} diff --git a/src/Models/SpecificationResponse.ts b/src/Models/SpecificationResponse.ts deleted file mode 100644 index b9a58092..00000000 --- a/src/Models/SpecificationResponse.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { firstLowerCase, firstUpperCase } from '../Utils/Functions' - -type ListItemDescription = { - Value: string - Description: string - GroupName: string -} -type Attributes = { - ListItemDescriptions: ListItemDescription[] - Name: string - DataType: number - List: number - MaxLength: number - Required: boolean - Description: string -} -type BasicFields = { - Attributes: Attributes[] - ListItemDescriptions: ListItemDescription[] - Name: string - DataType: number - MaxLength: number - Required: boolean - Description: string -} - -type SupportedCurrency = { - IsoNumber: number - Code: string - Name: string -} - -type Action = { - Name: string - Type: number - Default: boolean - Description: string - RequestParameters: RequestParameter[] - ResponseParameters: RequestParameter[] -} -type RequestParameter = { - ListItemDescriptions: ListItemDescription[] - isRequestParameter: boolean - Name: string - DataType: number - MaxLength: number - MaxOccurs: number - Required: boolean - Global: boolean - Group?: string - Description: string - ExplanationHTML: string - DisplayName: string - InputPattern: string - AutoCompleteType: string -} -interface Services { - Actions?: Action[] - SupportedCurrencies?: SupportedCurrency[] - Name: string - Version: number - Description: string -} -interface ISpecificationResponse { - BasicFields: BasicFields[] - Services: Services[] -} -export class SpecificationsResponse implements ISpecificationResponse { - BasicFields: BasicFields[] - Services: Services[] - constructor(data: ISpecificationResponse) { - this.BasicFields = data.BasicFields - this.Services = data.Services - } -} -export class SpecificationResponse implements Services { - Actions?: Action[] - Description: string - Name: string - SupportedCurrencies?: SupportedCurrency[] - Version: number - constructor(data: Services) { - this.Actions = data.Actions - this.Description = data.Description - this.Name = data.Name - this.SupportedCurrencies = data.SupportedCurrencies - this.Version = data.Version - } - getActionRequestParameters(actionName: string): RequestParameter[] | undefined { - actionName = firstUpperCase(actionName) - let actions = this.Actions?.find((action) => action.Name === actionName)?.RequestParameters - if (actions) { - actions.sort((a, b) => a.Name.localeCompare(b.Name)) - } - return actions - } - getServiceParameters(actionName: string) { - actionName = firstUpperCase(actionName) - let parameters = this.getActionRequestParameters(actionName) - let data: { [key: string]: any } = {} - if (parameters) { - parameters.forEach((param) => { - let current = data - param.Group = param.Group ? firstLowerCase(param.Group) : '' - if (param.Group) { - current = data[param.Group] = data[param.Group] ?? {} - } - current[firstLowerCase(param.Name)] = param.Required - }) - return data - } - } -} diff --git a/src/Models/TransactionResponse.ts b/src/Models/TransactionResponse.ts deleted file mode 100644 index 715d698b..00000000 --- a/src/Models/TransactionResponse.ts +++ /dev/null @@ -1,133 +0,0 @@ -import ResponseStatus from '../Constants/ResponseStatus' -import { ITransactionResponse } from './Services/ITransactionResponse' -import { firstLowerCase } from '../Utils/Functions' -import { Response } from '../Request/Response' -import { AxiosResponse } from 'axios' - -export class TransactionResponse extends Response { - get data(): ITransactionResponse { - return this._data - } - constructor(response: AxiosResponse) { - super(response) - } - getStatusCode() { - return this.data.Status.Code.Code.toString() - } - getSubStatusCode() { - return this.data.Status.SubCode.Code.toString() - } - isSuccess() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS - } - isFailed() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED - } - isCanceled() { - return ( - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT - ) - } - isAwaitingConsumer() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER - } - isPendingProcessing() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING - } - isWaitingOnUserInput() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT - } - isRejected() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED - } - isValidationFailure() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE - } - hasRedirect() { - return ( - this.data.RequiredAction?.RedirectURL.length > 0 && - this.data.RequiredAction?.Name === 'Redirect' - ) - } - getRedirectUrl() { - if (this.hasRedirect()) return this.data.RequiredAction?.RedirectURL - return '' - } - getServices() { - return this.data.Services - } - getMethod() { - return this.data.Services?.[0].Name - } - getServiceAction() { - return this.data.Services?.[0].Action - } - getServiceParameters() { - let parameters = this.data.Services?.[0].Parameters - let data: { [key: string]: any } = {} - if (parameters) { - parameters.forEach((param) => { - let current = param - - if (param.GroupType) { - data[firstLowerCase(param.GroupType)] = - data[firstLowerCase(param.GroupType)] || {} - data[firstLowerCase(param.GroupType)][firstLowerCase(param.Name)] = param.Value - } else { - data[firstLowerCase(current.Name)] = current.Value - } - }) - return data - } - } - getCustomParameters() { - let customParameters = this.data.CustomParameters?.List - let data: { [key: string]: any } = {} - if (customParameters) { - customParameters.forEach((param) => { - data[param.Name] = param.Value - }) - } - return data - } - getAdditionalParameters() { - let additionalParameters = this.data.AdditionalParameters?.AdditionalParameter - let data: { [key: string]: any } = {} - if (additionalParameters) { - additionalParameters.forEach((param) => { - data[param.Name] = param.Value - }) - } - return {} - } - getTransactionKey() { - return this.data.Key - } - getPaymentKey() { - return this.data.PaymentKey - } - hasError() { - return ( - this.data.RequestErrors && - Object.keys(this.data.RequestErrors).length > 0 && - (this.data.RequestErrors.ChannelErrors.length > 0 || - this.data.RequestErrors.ServiceErrors.length > 0 || - this.data.RequestErrors.ActionErrors.length > 0 || - this.data.RequestErrors.ParameterErrors.length > 0 || - this.data.RequestErrors.CustomParameterErrors.length > 0) - ) - } - getErrorMessages() { - const messages: { [errorType: string]: string } = {} - for (const [key, value] of Object.entries(this.data.RequestErrors)) { - if (value.length > 0) { - messages[key] = value.map((error) => error.ErrorMessage).join('') - } - } - return Object.entries(messages) - } - getErrorMessage() { - return this.data.Status.Code.Description - } -} diff --git a/src/PaymentMethods/Afterpay/Model/Address.ts b/src/PaymentMethods/Afterpay/Model/Address.ts new file mode 100644 index 00000000..846e3d4d --- /dev/null +++ b/src/PaymentMethods/Afterpay/Model/Address.ts @@ -0,0 +1,27 @@ +import { Address as IAddress } from '../../../Models/Interfaces/IAddress' + +export default class Address extends IAddress { + get houseNumber(): string { + return this.get('streetNumber') + } + + set houseNumber(phone: string) { + this.set('streetNumber', phone) + } + + get houseNumberAdditional(): string { + return this.get('streetNumberAdditional') + } + + set houseNumberAdditional(phone: string) { + this.set('streetNumberAdditional', phone) + } + + get zipcode(): string { + return this.get('postalCode') + } + + set zipcode(phone: string) { + this.set('postalCode', phone) + } +} diff --git a/src/PaymentMethods/Afterpay/Model/Article.ts b/src/PaymentMethods/Afterpay/Model/Article.ts index e2c3cfbc..3a0e64a1 100644 --- a/src/PaymentMethods/Afterpay/Model/Article.ts +++ b/src/PaymentMethods/Afterpay/Model/Article.ts @@ -1,21 +1,32 @@ -export type IAfterPayArticle = { - type?: - | 'PhysicalArticle' - | 'DigitalArticle' - | 'Giftcard' - | 'Discount' - | 'ShippingFee' - | 'Surcharge' - | 'Info' - | 'ShippingFees' +import IArticle, { Article } from '../../../Models/Interfaces/IArticle' + +export interface IAfterPayArticle extends Partial { + type?: string imageUrl?: string url?: string refundType?: 'Refund' | 'Return' marketPlaceSellerId?: string - identifier: string - unitCode?: string - quantity: number - grossUnitPrice: number - vatPercentage: number - description: string +} +export class AfterPayArticle extends Article { + constructor(article: Interface) { + super(article) + } + get price(): number { + return this.get('grossUnitPrice') + } + set price(price: number) { + this.set('grossUnitPrice', price) + } + set imageUrl(imageUrl: string) { + this.set('imageUrl', imageUrl) + } + set url(url: string) { + this.set('url', url) + } + set refundType(refundType: string) { + this.set('refundType', refundType) + } + set marketPlaceSellerId(marketPlaceSellerId: string) { + this.set('marketPlaceSellerId', marketPlaceSellerId) + } } diff --git a/src/PaymentMethods/Afterpay/Model/Customer.ts b/src/PaymentMethods/Afterpay/Model/Customer.ts index 802f305e..85db1f5f 100644 --- a/src/PaymentMethods/Afterpay/Model/Customer.ts +++ b/src/PaymentMethods/Afterpay/Model/Customer.ts @@ -1,49 +1,28 @@ +import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient' +import IAddress from '../../../Models/Interfaces/IAddress' +import IPhone from '../../../Models/Interfaces/IPhone' +import { Model } from '../../../Models/Model' import RecipientCategory from '../../../Constants/RecipientCategory' +import Phone from './Phone' +import Address from './Address' +import { AfterPayCompany, AfterPayPerson } from './Recipient' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' -type Salutation = 'Mr' | 'Mrs' | 'Miss' -type Customer = { - companyName?: string - firstName: string - lastName: string - birthDate?: string - street: string - streetNumber?: string - streetNumberAdditional?: string - postalCode?: string - city: string - country: string - email: string - careOf?: string - conversationLanguage?: 'NL' | 'FR' | 'DE' | 'FI' - identificationNumber?: string - customerNumber?: string - mobilePhone?: string - phone?: string - salutation?: Salutation +export default class Customer extends Model implements ICustomer { + set recipient(recipient: IPerson | ICompany) { + if (recipient.category === RecipientCategory.PERSON) { + this.set('recipient', new AfterPayPerson(recipient)) + } else if (recipient.category === RecipientCategory.COMPANY) { + this.set('recipient', new AfterPayCompany(recipient)) + } + } + set address(address: IAddress) { + this.set('address', new Address(address)) + } + set email(email: string) { + this.set('email', email) + } + set phone(phone: IPhone) { + this.set('phone', new Phone(phone)) + } } -type Person = { - category: RecipientCategory.PERSON -} -type Company = { - category: RecipientCategory.COMPANY - companyName: string - identificationNumber: string -} -type countryNLBE = { - country: 'NL' | 'BE' - salutation: Salutation - birthDate: string - streetNumber: string - phone: string -} - -type countryFI = { - country: 'FI' - identificationNumber: string -} -type countryDE = { - country: 'DE' -} - -export type AfterPayCustomer = Customer & - ((Person | Company) & (countryNLBE | countryFI | countryDE)) diff --git a/src/PaymentMethods/Afterpay/Model/Pay.ts b/src/PaymentMethods/Afterpay/Model/Pay.ts index 8b133cec..97528023 100644 --- a/src/PaymentMethods/Afterpay/Model/Pay.ts +++ b/src/PaymentMethods/Afterpay/Model/Pay.ts @@ -1,11 +1,15 @@ -import { IAfterPayArticle } from './Article' -import { Payload } from '../../../Models/ITransaction' -import { AfterPayCustomer } from './Customer' -export interface IPay extends Payload { +import { AfterPayArticle, IAfterPayArticle } from './Article' +import Customer from './Customer' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +import { ICustomer } from '../../../Models/Interfaces/ICustomer' + +export interface IPay extends IPaymentRequest { clientIP: string - billingCustomer: AfterPayCustomer - shippingCustomer?: AfterPayCustomer - article: IAfterPayArticle[] + billing: ICustomer + shipping?: ICustomer + articles: IAfterPayArticle[] bankAccount?: string bankCode?: string merchantImageUrl?: string @@ -13,3 +17,45 @@ export interface IPay extends Payload { yourReference?: string ourReference?: string } +export class Pay extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set shipping(shipping: ICustomer) { + this.set('shipping', new Customer(shipping)) + } + set billing(billing: ICustomer) { + this.set('billing', new Customer(billing)) + if (this.get('shipping') === undefined) { + this.shipping = billing + } + } + set articles(articles: IAfterPayArticle[]) { + this.set( + 'articles', + articles.map((article) => new AfterPayArticle(article)) + ) + } + set bankAccount(bankAccount: string) { + this.set('bankAccount', bankAccount) + } + set bankCode(bankCode: string) { + this.set('bankCode', bankCode) + } + set merchantImageUrl(merchantImageUrl: string) { + this.set('merchantImageUrl', merchantImageUrl) + } + set summaryImageUrl(summaryImageUrl: string) { + this.set('summaryImageUrl', summaryImageUrl) + } + set ourReference(ourReference: string) { + this.set('ourReference', ourReference) + } +} diff --git a/src/PaymentMethods/Afterpay/Model/Phone.ts b/src/PaymentMethods/Afterpay/Model/Phone.ts new file mode 100644 index 00000000..1d3d1502 --- /dev/null +++ b/src/PaymentMethods/Afterpay/Model/Phone.ts @@ -0,0 +1,18 @@ +import { Phone as IPhone } from '../../../Models/Interfaces/IPhone' +export default class Phone extends IPhone { + get mobile(): string { + return this.get('mobilePhone') + } + + set mobile(phone: string) { + this.set('mobilePhone', phone) + } + + get landline(): string { + return this.get('phone') + } + + set landline(phone: string) { + this.set('phone', phone) + } +} diff --git a/src/PaymentMethods/Afterpay/Model/Recipient.ts b/src/PaymentMethods/Afterpay/Model/Recipient.ts new file mode 100644 index 00000000..6c15518a --- /dev/null +++ b/src/PaymentMethods/Afterpay/Model/Recipient.ts @@ -0,0 +1,29 @@ +import { Company, IPerson, Person } from '../../../Models/Interfaces/IRecipient' + +export class AfterPayCompany extends Company { + set title(title: string) { + this.set('salutation', title) + } + set chamberOfCommerce(chamberOfCommerce: string) { + this.set('identificationNumber', chamberOfCommerce) + } +} +export interface IAfterPayPerson extends IPerson { + customerNumber?: string + identificationNumber?: string + conversationLanguage?: string +} +export class AfterPayPerson extends Person { + constructor(data: IAfterPayPerson) { + super(data) + } + set customerNumber(customerNumber: string) { + this.set('customerNumber', customerNumber) + } + set identificationNumber(identificationNumber: string) { + this.set('identificationNumber', identificationNumber) + } + set conversationLanguage(conversationLanguage: string) { + this.set('conversationLanguage', conversationLanguage) + } +} diff --git a/src/PaymentMethods/Afterpay/Model/Refund.ts b/src/PaymentMethods/Afterpay/Model/Refund.ts new file mode 100644 index 00000000..cf7a7a89 --- /dev/null +++ b/src/PaymentMethods/Afterpay/Model/Refund.ts @@ -0,0 +1,23 @@ +import { IRefundRequest } from '../../../Models/IRequest' +import { AfterPayArticle, IAfterPayArticle } from './Article' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export interface IRefund extends IRefundRequest { + articles?: IAfterPayArticle[] +} +export class Refund extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Articles: 'Article' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set articles(articles: IAfterPayArticle[]) { + this.set( + 'articles', + articles.map((article) => new AfterPayArticle(article)) + ) + } +} diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index cf87e53e..a7e9bfb3 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -1,39 +1,34 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Model/Pay' -import { ICapture, RefundPayload } from '../../Models/ITransaction' -import { IAfterPayArticle } from './Model/Article' +import { IPay, Pay } from './Model/Pay' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefund, Refund } from './Model/Refund' export default class Afterpay extends PayablePaymentMethod { - protected _paymentName = 'afterpay' + protected _paymentName = 'Afterpay' protected _serviceVersion = 1 - pay(payload: IPay) { - if (payload.billingCustomer) { - payload.shippingCustomer = payload.shippingCustomer || { ...payload.billingCustomer } - } - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload & { article?: IAfterPayArticle[] }) { - return super.refund(payload) + refund(payload: IRefund) { + return super.refund(payload, new Refund(payload)) } authorize(payload: IPay) { - this.action = 'Authorize' - return super.payTransaction(payload) + this.setServiceList('Authorize', new Pay(payload)) + return this.transactionRequest(payload) } - cancelAuthorize(payload: RefundPayload) { - this.action = 'CancelAuthorize' + cancelAuthorize(payload: IRefundRequest) { + this.setServiceList('CancelAuthorize') return super.transactionRequest(payload) } - capture(payload: ICapture) { - this.action = 'Capture' + capture(payload: IPaymentRequest) { + this.setServiceList('Capture', new Pay(payload)) return super.transactionRequest(payload) } - payRemainder(payload:IPay) { - this.action = 'PayRemainder' - return super.transactionRequest(payload) + payRemainder(payload: IPay) { + return super.payRemainder(payload, new Pay(payload)) } - authorizeRemainder(payload:IPay) { - this.action = 'AuthorizeRemainder' + authorizeRemainder(payload: IPay) { + this.setServiceList('AuthorizeRemainder', new Pay(payload)) return super.transactionRequest(payload) } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts new file mode 100644 index 00000000..f7fbfdf6 --- /dev/null +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts @@ -0,0 +1,34 @@ +import { Article as ArticleClass } from '../../../Models/Interfaces/IArticle' + +export default class Article extends ArticleClass { + get identifier(): string { + return this.get('articleId') + } + set identifier(identifier: string) { + this.set('articleId', identifier) + } + get quantity(): number { + return this.get('articleQuantity') + } + set quantity(quantity: number) { + this.set('articleQuantity', quantity) + } + get price(): number { + return this.get('articleUnitprice') + } + set price(price: number) { + this.set('articleUnitprice', price) + } + get vatCategory(): string { + return this.get('articleVatcategory') + } + set vatCategory(vatCategory: string) { + this.set('articleVatcategory', vatCategory) + } + get description(): string { + return this.get('articleDescription') + } + set description(description: string) { + this.set('articleDescription', description) + } +} diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts new file mode 100644 index 00000000..30d77b35 --- /dev/null +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts @@ -0,0 +1,29 @@ +import { Address } from '../Services/Address' +import { Model } from '../../../Models/Model' +import { Phone } from '../Services/Phone' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' + +export class Customer extends Model implements ICustomer { + constructor(data?: ICustomer, prefix?: string) { + super(data, prefix) + } + get prefix() { + return '' + } + initialize(data?: any, prefix: string = '') { + this.set('prefix', prefix, true) + super.initialize(data) + } + set recipient(recipient: ICustomer['recipient']) { + this.set('recipient', recipient) + } + set address(address: ICustomer['address']) { + this.set('address', new Address(address, this.prefix)) + } + set email(email: ICustomer['email']) { + this.set(this.prefix + 'Email', email) + } + set phone(phone: ICustomer['phone']) { + this.set('phone', new Phone(phone)) + } +} diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts new file mode 100644 index 00000000..8ee3faa6 --- /dev/null +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -0,0 +1,67 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import Article from './Article' +import IArticle from '../../../Models/Interfaces/IArticle' +import { Customer } from './Customer' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' + +export interface IPay extends IPaymentRequest { + b2b: boolean + addressesDiffer: boolean + customerIPAddress: string + shippingCosts: number + costCentre: string + department: string + establishmentNumber: number + billing: ICustomer + shipping?: ICustomer + articles: Partial[] +} +export class Pay extends ServiceParameter implements Omit { + protected getGroups() { + return super.getGroups({ + Articles: 'Article' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set addressesDiffer(value: boolean) { + this.set('addressesDiffer', value) + } + set articles(articles: IArticle[]) { + this.set( + 'articles', + articles.map((article) => new Article(article)) + ) + } + set b2b(value: boolean) { + this.set('b2b', value) + } + set billing(billing: ICustomer) { + this.set('billing', new Customer(billing, 'Billing')) + if (this.get('shipping') === undefined) { + this.shipping = billing + } + } + set shipping(shipping: ICustomer) { + this.addressesDiffer = true + this.set('shipping', new Customer(shipping, 'Shipping')) + } + set costCentre(value: string) { + this.set('costCentre', value) + } + set customerIPAddress(value: string) { + this.set('customerIPAddress', value) + } + set department(value: string) { + this.set('department', value) + } + set establishmentNumber(value: number) { + this.set('establishmentNumber', value) + } + set shippingCosts(value: number) { + this.set('shippingCosts', value) + } + protected accept: boolean = true +} diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts new file mode 100644 index 00000000..82a0d66e --- /dev/null +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts @@ -0,0 +1,34 @@ +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +export class Address extends AddressClass { + private get prefix() { + return '' + } + private set prefix(value: string) { + this.set('prefix', value) + } + initialize(data?: any, prefix: string = '') { + this.set('prefix', prefix, true) + super.initialize(data) + } + protected privateName(name: string): string { + return super.privateName(name) + } + + get houseNumberAdditional() { + return this.get('houseNumberSuffix') + } + set houseNumberAdditional(value: string) { + this.set('houseNumberSuffix', value) + } + get zipcode() { + return this.get('postalCode') + } + set zipcode(value: string) { + this.set('postalCode', value) + } + set country(value: string) { + if (this.prefix === 'Shipping' && value === 'NL') { + this.set('countryCode', value) + } else this.set('country', value) + } +} diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts new file mode 100644 index 00000000..11bef31c --- /dev/null +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts @@ -0,0 +1,6 @@ +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' +export class Phone extends PhoneClass { + set mobile(value: string) { + this.set('phoneNumber', value) + } +} diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 1dfeb5f4..4a8b1ed9 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -1,17 +1,35 @@ -import AfterpayClass from '../Afterpay' -import { Payload, RefundPayload } from '../../Models/ITransaction' import { IPay } from '../Afterpay/Model/Pay' +import IRequest, { IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { Pay } from './Model/Pay' -export default class AfterpayDigiAccept extends AfterpayClass { - protected _paymentName = 'afterpaydigiaccept' +export default class AfterpayDigiAccept extends PayablePaymentMethod { + protected _paymentName = 'AfterpayDigiAccept' protected _serviceVersion = 2 - pay(payload: Payload) { - return super.pay(payload) + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } - authorize(payload: Payload) { - return super.authorize(payload) + authorize(payload: IPay) { + this.setServiceList('Authorize', new Pay(payload)) + return super.transactionRequest(payload) + } + cancelAuthorize(payload: IRefundRequest) { + this.setServiceList('CancelAuthorize') + return super.transactionRequest(payload) + } + capture(payload: IRequest) { + this.setServiceList('Capture') + return super.transactionRequest(payload) + } + payRemainder(payload: IPay) { + this.setServiceList('PayRemainder') + return super.transactionRequest(payload) + } + authorizeRemainder(payload: IPay) { + this.setServiceList('AuthorizeRemainder') + return super.transactionRequest(payload) } } diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 4c980c8a..982896df 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,14 +1,16 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import { Parameter } from '../../Models/IParameters' export default class Alipay extends PayablePaymentMethod { - protected _paymentName = 'alipay' - protected _serviceVersion = 1 + protected _paymentName = 'Alipay' - pay(payload: { useMobileView: boolean } & Payload) { - return super.pay(payload) + pay(payload: { useMobileView: boolean } & IPaymentRequest) { + return super.pay(payload, [ + new Parameter({ name: 'useMobileView', value: payload.useMobileView }) + ]) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/ApplePay/Models/Pay.ts b/src/PaymentMethods/ApplePay/Models/Pay.ts index 09317ca4..d38a973e 100644 --- a/src/PaymentMethods/ApplePay/Models/Pay.ts +++ b/src/PaymentMethods/ApplePay/Models/Pay.ts @@ -1,6 +1,15 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { paymentData: string customerCardName: string } +export class Pay extends ServiceParameter { + set paymentData(value: string) { + this.set('paymentData', value) + } + set customerCardName(value: string) { + this.set('customerCardName', value) + } +} diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index e1821ccd..8f09dab7 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -1,15 +1,17 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' export default class ApplePay extends PayablePaymentMethod { - protected _paymentName = 'applepay' - protected _serviceVersion = 1 - + protected _paymentName = 'ApplePay' pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } + payRedirect(payload: IPaymentRequest) { + this.setPayPayload(payload) + return this.transactionRequest() + } } diff --git a/src/PaymentMethods/Bancontact/Models/Pay.ts b/src/PaymentMethods/Bancontact/Models/Pay.ts index c544299f..a1928025 100644 --- a/src/PaymentMethods/Bancontact/Models/Pay.ts +++ b/src/PaymentMethods/Bancontact/Models/Pay.ts @@ -1,17 +1,26 @@ -import { ITransaction, Payload } from '../../../Models/ITransaction' +import IRequest, { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { saveToken?: boolean } -export interface IPayEncrypted extends Payload { +export interface IPayEncrypted extends IPaymentRequest { encryptedCardData: string } -export interface IPayComplete extends ITransaction { +export interface IPayComplete extends IRequest { encryptedCardData: string originalTransactionKey: string } -export interface IPayOneClick extends ITransaction { +export interface IPayOneClick extends IRequest { originalTransactionKey: string amountDebit: number } +export class Pay extends ServiceParameter { + set encryptedCardData(value: string) { + this.set('encryptedCardData', value) + } + set saveToken(value: boolean) { + this.set('saveToken', value) + } +} diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index e2fa72a5..9c747d6e 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -1,35 +1,33 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay, IPayComplete, IPayEncrypted, IPayOneClick } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay' +import { IRefundRequest } from '../../Models/IRequest' export default class Bancontact extends PayablePaymentMethod { - protected _paymentName = 'bancontactmrcash' - protected _serviceVersion = 1 - + protected _paymentName = 'Bancontact' pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } authenticate(payload: IPay) { - this.action = 'Authenticate' - return this.payTransaction(payload) + this.setServiceList('Authenticate', new Pay(payload)) + return this.transactionRequest(payload) } payOneClick(payload: IPayOneClick) { - this.action = 'PayOneClick' - return this.transactionInvoice(payload) + this.setServiceList('PayOneClick', new Pay(payload)) + return this.transactionRequest(payload) } payEncrypted(payload: IPayEncrypted) { - this.action = 'PayEncrypted' - return this.transactionInvoice(payload) + this.setServiceList('PayEncrypted', new Pay(payload)) + return this.transactionRequest(payload) } completePayment(payload: IPayComplete) { - this.action = 'CompletePayment' + this.setServiceList('CompletePayment', new Pay(payload)) return this.dataRequest(payload) } payRecurring(payload: IPayOneClick) { - this.action = 'PayRecurring' - return this.transactionInvoice(payload) + this.setServiceList('PayRecurring', new Pay(payload)) + return this.transactionRequest(payload) } } diff --git a/src/PaymentMethods/BankTransfer/Models/Pay.ts b/src/PaymentMethods/BankTransfer/Models/Pay.ts index 48952681..c9a51a5e 100644 --- a/src/PaymentMethods/BankTransfer/Models/Pay.ts +++ b/src/PaymentMethods/BankTransfer/Models/Pay.ts @@ -1,12 +1,38 @@ -import Gender from '../../../Constants/Gender' -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { - customerFirstName: string - customerLastName: string - customerEmail: string - customerGender?: Gender +export interface IPay extends IPaymentRequest { + customer: Partial sendMail?: boolean dateDue?: string customerCountry?: string } +class BankTransferPerson extends Person { + set firstName(value: string) { + this.set('customerFirstName', value) + } + set lastName(value: string) { + this.set('customerLastName', value) + } + set gender(value: string) { + this.set('customerGender', value) + } +} +export class Pay extends ServiceParameter { + set sendMail(sendMail: boolean) { + this.set('sendMail', sendMail) + } + set dateDue(dateDue: string) { + this.set('dateDue', dateDue) + } + set country(country: string) { + this.set('customerCountry', country) + } + set customer(person: IPerson) { + this.set('customer', new BankTransferPerson(person)) + } + set email(email: string) { + this.set('customerEmail', email) + } +} diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 54f4bb2d..5d556df9 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -1,15 +1,14 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +import { IRefundRequest } from '../../Models/IRequest' -export default class Banktransfer extends PayablePaymentMethod { - protected _paymentName = 'transfer' - protected _serviceVersion = 1 +export default class BankTransfer extends PayablePaymentMethod { + protected _paymentName = 'BankTransfer' pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index aad2e131..adec001c 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,14 +1,12 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' export default class Belfius extends PayablePaymentMethod { - protected _paymentName = 'belfius' - protected _serviceVersion = 1 - - pay(payload: Payload) { + protected _paymentName = 'Belfius' + pay(payload: IPaymentRequest) { return super.pay(payload) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/Billink/Models/Address.ts b/src/PaymentMethods/Billink/Models/Address.ts new file mode 100644 index 00000000..e62fe2a2 --- /dev/null +++ b/src/PaymentMethods/Billink/Models/Address.ts @@ -0,0 +1,12 @@ +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +export class Address extends AddressClass { + set houseNumber(houseNumber: string) { + this.set('streetNumber', houseNumber) + } + set houseNumberAdditional(houseNumberAdditional: string) { + this.set('streetNumberAdditional', houseNumberAdditional) + } + set zipcode(zipcode: string) { + this.set('postalCode', zipcode) + } +} diff --git a/src/PaymentMethods/Billink/Models/Article.ts b/src/PaymentMethods/Billink/Models/Article.ts index 86e1d683..16e25891 100644 --- a/src/PaymentMethods/Billink/Models/Article.ts +++ b/src/PaymentMethods/Billink/Models/Article.ts @@ -1,7 +1,12 @@ -export type IBillinkArticle = { - quantity: number - description: string - identifier: string - grossUnitPriceIncl: number - grossUnitPriceExcl: number +import IArticle, { Article as ArticleClass } from '../../../Models/Interfaces/IArticle' +export interface IBillinkArticle extends Partial { + priceExcl: number +} +export class Article extends ArticleClass { + set priceExcl(priceExcl: number) { + this.set('grossUnitPriceExcl', priceExcl) + } + set price(price: number) { + this.set('grossUnitPriceIncl', price) + } } diff --git a/src/PaymentMethods/Billink/Models/Capture.ts b/src/PaymentMethods/Billink/Models/Capture.ts new file mode 100644 index 00000000..17ac16d0 --- /dev/null +++ b/src/PaymentMethods/Billink/Models/Capture.ts @@ -0,0 +1,20 @@ +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { Article, IBillinkArticle } from './Article' +import { IPaymentRequest } from '../../../Models/IRequest' + +export interface ICapture extends IPaymentRequest { + articles?: IBillinkArticle[] +} +export class Capture extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Articles: 'Article' + }) + } + set articles(articels: IBillinkArticle[]) { + this.set( + 'articles', + articels.map((article) => new Article(article)) + ) + } +} diff --git a/src/PaymentMethods/Billink/Models/Customer.ts b/src/PaymentMethods/Billink/Models/Customer.ts index 31182985..acf943c2 100644 --- a/src/PaymentMethods/Billink/Models/Customer.ts +++ b/src/PaymentMethods/Billink/Models/Customer.ts @@ -1,19 +1,40 @@ -type Salutation = 'Male' | 'Female' | 'Unknown' -export type Customer = { - chamberOfCommerce: string - initials: string - salutation?: Salutation - firstName: string - lastName: string - birthDate?: string - street: string - streetNumber: number - streetNumberAdditional?: string - postalCode: string - city: string - country?: 'NL' | 'BE' - email?: string - careOf?: string - mobilePhone?: string - phone?: string +import IPhone from '../../../Models/Interfaces/IPhone' +import { Phone } from './Phone' +import IAddress from '../../../Models/Interfaces/IAddress' +import { Address } from './Address' +import { Customer } from '../../../Models/Interfaces/ICustomer' +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import recipientCategory from '../../../Constants/RecipientCategory' + +export class BillinkCustomer extends Customer { + set address(address: IAddress) { + this.set('address', new Address(address)) + } + set phone(phone: IPhone) { + this.set('phone', new Phone(phone)) + } + set recipient(recipient: IPerson | ICompany) { + if (recipient.category === recipientCategory.PERSON) { + this.set('recipient', new BillinkPerson(recipient)) + } else if (recipient.category === recipientCategory.COMPANY) { + this.set('recipient', new BillinkCompany(recipient)) + } else throw new Error('Invalid recipient category') + } +} + +export class BillinkPerson extends Person { + set category(category: recipientCategory.PERSON) { + this.set('category', 'B2C') + } + set title(title: string) { + this.set('salutation', title) + } +} +export class BillinkCompany extends Company { + set category(category: recipientCategory.COMPANY) { + this.set('category', 'B2B') + } + set title(title: string) { + this.set('salutation', title) + } } diff --git a/src/PaymentMethods/Billink/Models/Pay.ts b/src/PaymentMethods/Billink/Models/Pay.ts index f61e34f7..45b948c9 100644 --- a/src/PaymentMethods/Billink/Models/Pay.ts +++ b/src/PaymentMethods/Billink/Models/Pay.ts @@ -1,12 +1,50 @@ -import { Payload } from '../../../Models/ITransaction' -import { IBillinkArticle } from './Article' -import { Customer } from './Customer' +import { IPaymentRequest } from '../../../Models/IRequest' +import { Article, IBillinkArticle } from './Article' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { BillinkCustomer } from './Customer' -export interface IPay extends Payload { - billingCustomer: Customer - shippingCustomer?: Customer - article: IBillinkArticle[] +export interface IPay extends IPaymentRequest { + billing: ICustomer + shipping?: ICustomer + articles: IBillinkArticle[] trackandtrace?: string VATNumber?: string summaryImageUrl?: string } +export class Pay extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article' + }) + } + protected getCountable(countable: Capitalize[] = []): Capitalize[] { + return super.getCountable(['Articles']) + } + set billing(billing: ICustomer) { + this.set('billing', new BillinkCustomer(billing)) + if (this.get('shipping') === undefined) { + this.shipping = billing + } + } + set shipping(shipping: ICustomer) { + this.set('shipping', new BillinkCustomer(shipping)) + } + set articles(articles: IBillinkArticle[]) { + this.set( + 'articles', + articles.map((article) => new Article(article)) + ) + } + set trackandtrace(trackandtrace: string) { + this.set('trackandtrace', trackandtrace) + } + set VATNumber(VATNumber: string) { + this.set('VATNumber', VATNumber) + } + set summaryImageUrl(summaryImageUrl: string) { + this.set('summaryImageUrl', summaryImageUrl) + } +} diff --git a/src/PaymentMethods/Billink/Models/Phone.ts b/src/PaymentMethods/Billink/Models/Phone.ts new file mode 100644 index 00000000..4b0e2763 --- /dev/null +++ b/src/PaymentMethods/Billink/Models/Phone.ts @@ -0,0 +1,12 @@ +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' +export class Phone extends PhoneClass { + set fax(fax: string) { + this.set('mobilePhone', fax) + } + set landline(landline: string) { + this.set('mobilePhone', landline) + } + set mobile(mobile: string) { + this.set('mobilePhone', mobile) + } +} diff --git a/src/PaymentMethods/Billink/Models/Refund.ts b/src/PaymentMethods/Billink/Models/Refund.ts new file mode 100644 index 00000000..699608b9 --- /dev/null +++ b/src/PaymentMethods/Billink/Models/Refund.ts @@ -0,0 +1,11 @@ +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IRefundRequest } from '../../../Models/IRequest' + +export interface IRefund extends IRefundRequest { + refundReason?: string +} +export class Refund extends ServiceParameter { + set refundReason(value: string) { + this.set('refundreason', value) + } +} diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 507037d1..64570950 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -1,26 +1,28 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { ICapture, RefundPayload } from '../../Models/ITransaction' - +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +import { IRefund, Refund } from './Models/Refund' +import { Capture, ICapture } from './Models/Capture' export default class Billink extends PayablePaymentMethod { protected _paymentName = 'Billink' - protected _serviceVersion = 1 pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { - return super.refund(payload) + refund(payload: IRefund) { + return super.refund(payload, new Refund(payload)) } authorize(payload: IPay) { - this.action = 'Authorize' - return super.transactionRequest(payload) + this.setPayPayload(payload) + this.setServiceList('Authorize', new Pay(payload)) + return super.transactionRequest() } - cancelAuthorize(payload: RefundPayload) { - this.action = 'CancelAuthorize' - return super.transactionRequest(payload) + cancelAuthorize(payload: IRefund) { + this.setPayload(payload) + this.setServiceList('CancelAuthorize', new Refund(payload)) + return super.transactionRequest() } capture(payload: ICapture) { - this.action = 'Capture' - return super.transactionRequest(payload) + this.setPayPayload(payload) + this.setServiceList('Capture', new Capture(payload)) + return super.transactionRequest() } } diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts index 55821836..319bf55f 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts @@ -1,6 +1,7 @@ -import { ITransaction } from '../../../Models/ITransaction' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface ICreate extends ITransaction { +export interface ICreate extends IRequest { groupReference?: string /** * 1 = Single @@ -11,3 +12,21 @@ export interface ICreate extends ITransaction { validUntil?: string creationBalance: number } + +export class Create extends ServiceParameter { + set groupReference(value: string) { + this.set('groupReference', value) + } + set usageType(value: 1 | 2) { + this.set('usageType', value) + } + set validFrom(value: string) { + this.set('validFrom', value) + } + set validUntil(value: string) { + this.set('validUntil', value) + } + set creationBalance(value: number) { + this.set('creationBalance', value) + } +} diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts index c5fe50bb..3a73ae24 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts @@ -1,5 +1,11 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { voucherCode: string } +export class Pay extends ServiceParameter { + set voucherCode(voucherCode: string) { + this.set('voucherCode', voucherCode) + } +} diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index c1be1ac5..e6ba9509 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -1,27 +1,23 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' -import { ICreate } from './Models/Create' - -export default class Buckaroovoucher extends PayablePaymentMethod { - protected _paymentName = 'buckaroovoucher' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +import IRequest from '../../Models/IRequest' +import { Create, ICreate } from './Models/Create' +export default class BuckarooVoucher extends PayablePaymentMethod { + protected _paymentName = 'BuckarooVoucher' pay(payload: IPay) { - return super.pay(payload) - } - refund(payload: RefundPayload) { - return super.refund(payload) + return super.pay(payload, new Pay(payload)) } - getBalance(payload: Pick) { - this.action = 'GetBalance' + getBalance(payload: IRequest & Pick) { + this.setServiceList('GetBalance', new Pay(payload)) return this.dataRequest(payload) } - createApplication(payload: ICreate) { - this.action = 'CreateApplication' + create(payload: IRequest & ICreate) { + this.setServiceList('CreateApplication', new Create(payload)) return this.dataRequest(payload) } - deactivateVoucher(payload: Pick) { - this.action = 'DeactivateVoucher' + deactivate(payload: IRequest & Pick) { + this.setServiceList('DeactivateVoucher', new Pay(payload)) return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts new file mode 100644 index 00000000..c1d7f376 --- /dev/null +++ b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts @@ -0,0 +1,7 @@ +import { BankAccount as BankAccountClass } from '../../../Models/Interfaces/IBankAccount' + +export class BankAccount extends BankAccountClass { + set iban(value: string) { + this.set('consumerIban', value) + } +} diff --git a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts new file mode 100644 index 00000000..4c9d9366 --- /dev/null +++ b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts @@ -0,0 +1,12 @@ +import { Person } from '../../../Models/Interfaces/IRecipient' +import RecipientCategory from '../../../Constants/RecipientCategory' + +export class Customer extends Person { + set category(value: RecipientCategory.PERSON) {} + set firstName(value: string) { + this.set('consumerFirstName', value) + } + set lastName(value: string) { + this.set('consumerLastName', value) + } +} diff --git a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts index 525def91..4a498fc7 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts @@ -1,20 +1,36 @@ -import { ITransaction, Payload, RefundPayload } from '../../../Models/ITransaction' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPerson } from '../../../Models/Interfaces/IRecipient' +import { Customer } from './Customer' +import IBankAccount from '../../../Models/Interfaces/IBankAccount' +import { BankAccount } from './BankAccount' -interface consumer { - consumerFirstName?: string - consumerLastName?: string - consumerEmail?: string - consumerIban?: string +export interface IWallet extends IRequest { + invoice?: string + walletId?: string + customer?: Partial + bankAccount?: Partial + walletMutationGuid?: string + status?: string } -export interface IWallet extends ITransaction, consumer { - invoice: string - walletId: string -} -export interface IWalletPay extends Payload, consumer { - invoice: string - walletId: string -} -export interface IWalletRefund extends RefundPayload { - invoice: string - walletId: string + +export class Wallet extends ServiceParameter { + set walletId(value: string) { + this.set('walletId', value) + } + set customer(value: Partial) { + this.set('customer', new Customer(value)) + } + set email(value: string) { + this.set('consumerEmail', value) + } + set status(value: string) { + this.set('status', value) + } + set walletMutationGuid(value: string) { + this.set('walletMutationGuid', value) + } + set bankAccount(value: IBankAccount) { + this.set('bankAccount', new BankAccount(value)) + } } diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index a5b0f4f4..2dc5e883 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -1,46 +1,51 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IWallet, IWalletPay, IWalletRefund } from './Models/Wallet' -import { ITransaction } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IWallet, Wallet } from './Models/Wallet' +import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' export default class BuckarooWallet extends PayablePaymentMethod { - protected _paymentName = 'BuckarooWalletCollecting' - protected _serviceVersion = 1 - pay(payload: IWalletPay) { - return super.pay(payload) + protected _paymentName = 'BuckarooWallet' + pay(payload: IWallet & IPaymentRequest) { + return super.pay(payload, new Wallet(payload)) } - refund(payload: IWalletRefund) { + refund(payload: IRefundRequest) { return super.refund(payload) } - deposit(payload: IWalletRefund) { - this.action = 'Deposit' - return super.transactionRequest(payload) + create(payload: IWallet & IRequest) { + this._requiredFields = ['currency'] + this.setPayload(payload) + this.setServiceList('Create', new Wallet(payload)) + return this.dataRequest() } - reserve(payload: IWalletRefund) { - this.action = 'Reserve' - return super.transactionRequest(payload) + deposit(payload: IWallet & IRefundRequest) { + this.setPayload(payload) + this.setServiceList('Deposit', new Wallet(payload)) + return super.transactionRequest() } - withdrawal(payload: IWalletPay) { - this.action = 'Withdrawal' - return super.transactionRequest(payload) + reserve(payload: IWallet & IRefundRequest) { + this.setPayload(payload) + this.setServiceList('Reserve', new Wallet(payload)) + return super.transactionRequest() } - cancel(payload: ITransaction & { walletMutationGuid: string }) { - this.action = 'CancelReservation' - return super.transactionRequest(payload) + withdrawal(payload: IWallet & IPaymentRequest) { + this.setPayPayload(payload) + this.setServiceList('Withdrawal', new Wallet(payload)) + return super.transactionRequest() } - create(payload: IWallet) { - this.action = 'Create' - return this.dataRequest(payload) + cancel(payload: IPaymentRequest & { walletMutationGuid: string }) { + this.setPayPayload(payload) + this.setServiceList('Withdrawal', new Wallet(payload)) + return super.transactionRequest() } - update() { - this.action = 'Update' - return this.dataRequest() + update(payload: IWallet) { + this.setServiceList('Update', new Wallet(payload)) + return this.dataRequest(payload) } - getInfo() { - this.action = 'Getinfo' - return this.dataRequest() + getInfo(payload: IWallet) { + this.setServiceList('GetInfo', new Wallet(payload)) + return this.dataRequest(payload) } - release() { - this.action = 'Release' - return this.dataRequest() + release(payload: IWallet & IRefundRequest) { + this.setServiceList('Release', new Wallet(payload)) + return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/CreditCard/Models/CardData.ts b/src/PaymentMethods/CreditCard/Models/CardData.ts new file mode 100644 index 00000000..2533d088 --- /dev/null +++ b/src/PaymentMethods/CreditCard/Models/CardData.ts @@ -0,0 +1,11 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export interface ICardData extends IPaymentRequest { + encryptedCardData: string +} +export class CardData extends ServiceParameter { + set encryptedCardData(value: string) { + this.set('encryptedCardData', value) + } +} diff --git a/src/PaymentMethods/CreditCard/Models/Pay.ts b/src/PaymentMethods/CreditCard/Models/Pay.ts deleted file mode 100644 index 5d726071..00000000 --- a/src/PaymentMethods/CreditCard/Models/Pay.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Payload } from '../../../Models/ITransaction' - -export interface IEncrypted extends Payload { - encryptedCardData: string -} -export interface ISecurityCodePay extends Payload { - encryptedSecurityCode: string -} diff --git a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts new file mode 100644 index 00000000..119d401c --- /dev/null +++ b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts @@ -0,0 +1,11 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export interface ISecurityCode extends IPaymentRequest { + encryptedSecurityCode: string +} +export class SecurityCode extends ServiceParameter { + set encryptedSecurityCode(value: string) { + this.set('encryptedSecurityCode', value) + } +} diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 3a705428..8227b72d 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -1,50 +1,52 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IEncrypted, ISecurityCodePay } from './Models/Pay' -import { ICapture, Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import { CardData, ICardData } from './Models/CardData' +import { ISecurityCode, SecurityCode } from './Models/SecurityCode' -export type AddName = T & { name: string } -export default class Creditcard extends PayablePaymentMethod { - pay(payload: AddName) { - return super.pay(payload) - } - refund(payload: AddName) { - return super.refund(payload) - } - payEncrypted(payload: AddName) { - this.action = 'PayEncrypted' - return super.pay(payload) - } - payWithSecurityCode(payload: AddName) { - this.action = 'PayWithSecurityCode' - return super.pay(payload) - } - authorize(payload: AddName) { - this.action = 'Authorize' - return super.transactionRequest(payload) - } - authorizeWithSecurityCode(payload: AddName) { - this.action = 'AuthorizeWithSecurityCode' +export default class CreditCard extends PayablePaymentMethod { + protected _paymentName = 'CreditCard' + payEncrypted(payload: ICardData) { + this.setPayPayload(payload) + this.setServiceList('PayEncrypted', new CardData(payload)) + return super.transactionRequest() + } + payWithSecurityCode(payload: ISecurityCode) { + this.setPayPayload(payload) + this.setServiceList('PayWithSecurityCode', new SecurityCode(payload)) + return super.transactionRequest() + } + authorize(payload: IPaymentRequest) { + this.setPayPayload(payload) + this.setServiceList('Authorize') + return super.transactionRequest() + } + authorizeWithSecurityCode(payload: ISecurityCode) { + this.setPayPayload(payload) + this.setServiceList('AuthorizeWithSecurityCode', new SecurityCode(payload)) + return super.transactionRequest() + } + authorizeEncrypted(payload: ICardData) { + this.setPayPayload(payload) + this.setServiceList('AuthorizeEncrypted', new CardData(payload)) + return super.transactionRequest() + } + cancelAuthorize(payload: IRefundRequest) { + this.setServiceList('CancelAuthorize') return super.transactionRequest(payload) } - authorizeEncrypted(payload: AddName) { - this.action = 'AuthorizeEncrypted' - return super.transactionRequest(payload) - } - cancelAuthorize(payload: AddName) { - this.action = 'CancelAuthorize' - return super.transactionRequest(payload) + capture(payload: IRequest) { + this.setPayPayload(payload) + this.setServiceList('Capture') + return super.transactionRequest() } - capture(payload: AddName) { - this.action = 'Capture' - return super.transactionRequest(payload) - } - payRecurrent(payload: AddName) { - this.action = 'PayRecurrent' - return super.transactionRequest(payload) + payRecurrent(payload: IRequest) { + this.setPayPayload(payload) + this.setServiceList('PayRecurrent') + return super.transactionRequest() } - setRequest(payload: any) { - this.paymentName = payload.name || this._paymentName - delete payload.name - super.setRequest(payload) + payRemainderEncrypted(payload: ICardData) { + this.setPayPayload(payload) + this.setServiceList('PayRemainderEncrypted', new CardData(payload)) + return super.transactionRequest() } } diff --git a/src/PaymentMethods/CreditClick/Models/Pay.ts b/src/PaymentMethods/CreditClick/Models/Pay.ts index c24528d7..6d7b76a1 100644 --- a/src/PaymentMethods/CreditClick/Models/Pay.ts +++ b/src/PaymentMethods/CreditClick/Models/Pay.ts @@ -1,7 +1,16 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { IPerson } from '../../../Models/Interfaces/IRecipient' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface Pay extends Payload { - firstName?: string - lastName?: string +export interface IPay extends IPaymentRequest { + person: Partial email?: string } +export class Pay extends ServiceParameter { + set person(value: Partial) { + this.set('person', value) + } + set email(value: string) { + this.set('email', value) + } +} diff --git a/src/PaymentMethods/CreditClick/Models/Refund.ts b/src/PaymentMethods/CreditClick/Models/Refund.ts index 24301516..2f78a778 100644 --- a/src/PaymentMethods/CreditClick/Models/Refund.ts +++ b/src/PaymentMethods/CreditClick/Models/Refund.ts @@ -1,6 +1,7 @@ -import { RefundPayload } from '../../../Models/ITransaction' +import { IRefundRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface Refund extends RefundPayload { +export interface IRefund extends IRefundRequest { description: string refundReason: | 'Duplicate' @@ -9,3 +10,12 @@ export interface Refund extends RefundPayload { | 'RequestedByCustomer' | 'TechnicalError' } + +export class Refund extends ServiceParameter { + set description(value: string) { + this.set('description', value) + } + set refundReason(value: IRefund['refundReason']) { + this.set('refundreason', value) + } +} diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index b1859815..9014b328 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -1,14 +1,13 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Pay } from './Models/Pay' -import { Refund } from './Models/Refund' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +import { IRefund, Refund } from './Models/Refund' export default class CreditClick extends PayablePaymentMethod { - protected _paymentName = 'creditclick' - - pay(payload: Pay) { - return super.pay(payload) + protected _paymentName = 'CreditClick' + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) } - refund(payload: Refund) { - return super.refund(payload) + refund(payload: IRefund) { + return super.refund(payload, new Refund(payload)) } } diff --git a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts index 46ba36b5..d15958a2 100644 --- a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts +++ b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts @@ -1,8 +1,27 @@ -import { ICreditArticle } from './Article' -import { ITransaction } from '../../../Models/ITransaction' +import { CreditArticle, ICreditArticle } from './Article' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface AddOrUpdateProductLines { +export interface IAddOrUpdateProductLines extends IRequest { invoiceKey: string - article: ICreditArticle[] + articles: ICreditArticle[] +} +export class AddOrUpdateProductLines extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set invoiceKey(value: string) { + this.set('invoiceKey', value) + } + set articles(value: ICreditArticle[]) { + this.set( + 'articles', + value.map((article) => new CreditArticle(article)) + ) + } } -export type IAddOrUpdateProductLines = AddOrUpdateProductLines & ITransaction diff --git a/src/PaymentMethods/CreditManagement/Models/Address.ts b/src/PaymentMethods/CreditManagement/Models/Address.ts new file mode 100644 index 00000000..699381b2 --- /dev/null +++ b/src/PaymentMethods/CreditManagement/Models/Address.ts @@ -0,0 +1,6 @@ +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +export class Address extends AddressClass { + set houseNumberAdditional(value: string) { + this.set('houseNumberSuffix', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/Article.ts b/src/PaymentMethods/CreditManagement/Models/Article.ts index 99107c79..89a13e6a 100644 --- a/src/PaymentMethods/CreditManagement/Models/Article.ts +++ b/src/PaymentMethods/CreditManagement/Models/Article.ts @@ -1,10 +1,7 @@ -export interface ICreditArticle { - type: 'Regular' | 'SubTotal' | 'Discount' | 'TotalAmountExVat' | 'TotalVat' | 'TotalAmount' - productName: string - quantity: number - pricePerUnit: number +import IArticle, { Article } from '../../../Models/Interfaces/IArticle' +export interface ICreditArticle extends Partial { totalVat: number - vatPercentage: number + productLine?: string productGroupName?: string productGroupOrderIndex?: number productOrderIndex?: number @@ -14,3 +11,44 @@ export interface ICreditArticle { totalAmountExVat?: number totalAmount?: number } +export class CreditArticle extends Article implements ICreditArticle { + set identifier(value: string) { + this.set('productId', value) + } + set description(value: string) { + this.set('productName', value) + } + set price(value: number) { + this.set('pricePerUnit', value) + } + set productLine(value: string) { + this.set('productLine', value) + } + set productGroupName(value: string) { + this.set('productGroupName', value) + } + set productGroupOrderIndex(value: number) { + this.set('productGroupOrderIndex', value) + } + set productOrderIndex(value: number) { + this.set('productOrderIndex', value) + } + set unitOfMeasurement(value: string) { + this.set('unitOfMeasurement', value) + } + set discountPercentage(value: number) { + this.set('discountPercentage', value) + } + set totalDiscount(value: number) { + this.set('totalDiscount', value) + } + set totalVat(value: number) { + this.set('totalVat', value) + } + set totalAmountExVat(value: number) { + this.set('totalAmountExVat', value) + } + set totalAmount(value: number) { + this.set('totalAmount', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts index f4d83678..9e0cd019 100644 --- a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts +++ b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts @@ -1,10 +1,27 @@ -import { ITransaction } from '../../../Models/ITransaction' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface CreditNote { +export interface ICreditNote extends IRequest { originalInvoiceNumber: string invoiceDate: string invoiceAmount: string invoiceAmountVAT: string sendCreditNoteMessage: string } -export type ICreditNote = CreditNote & ITransaction +export class CreditNote extends ServiceParameter implements ICreditNote { + set originalInvoiceNumber(value: string) { + this.set('originalInvoiceNumber', value) + } + set invoiceDate(value: string) { + this.set('invoiceDate', value) + } + set invoiceAmount(value: string) { + this.set('invoiceAmount', value) + } + set invoiceAmountVAT(value: string) { + this.set('invoiceAmountVAT', value) + } + set sendCreditNoteMessage(value: string) { + this.set('sendCreditNoteMessage', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/Debtor.ts b/src/PaymentMethods/CreditManagement/Models/Debtor.ts index c9eeba95..b7791247 100644 --- a/src/PaymentMethods/CreditManagement/Models/Debtor.ts +++ b/src/PaymentMethods/CreditManagement/Models/Debtor.ts @@ -1,6 +1,6 @@ -import { IInvoice } from './Invoice' +import { IInvoice, Invoice } from './Invoice' -export interface Debtor { +export interface IDebtor extends IInvoice { addressUnreachable?: boolean emailUnreachable?: boolean @@ -11,4 +11,20 @@ export interface Debtor { faxUnreachable?: boolean } -export type IDebtor = Debtor & IInvoice +export class Debtor extends Invoice { + set addressUnreachable(value: boolean) { + this.set('addressUnreachable', value) + } + set emailUnreachable(value: boolean) { + this.set('emailUnreachable', value) + } + set mobileUnreachable(value: boolean) { + this.set('mobileUnreachable', value) + } + set landlineUnreachable(value: boolean) { + this.set('landlineUnreachable', value) + } + set faxUnreachable(value: boolean) { + this.set('faxUnreachable', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts new file mode 100644 index 00000000..b5618073 --- /dev/null +++ b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts @@ -0,0 +1,21 @@ +import { ServiceParameter } from '../../../Models/ServiceParameters' +import IDebtor, { Debtor as DebtorClass } from '../../../Models/Interfaces/IDebtor' +import IRequest from '../../../Models/IRequest' +export interface IDebtorInfo extends IRequest { + debtor: IDebtor +} +export class DebtorInfo extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Debtor: 'Debtor' + }) + } + set debtor(debtor: IDebtor) { + this.set('debtor', new Debtor(debtor)) + } +} +class Debtor extends DebtorClass { + set code(value: string) { + this.set('DebtorCode', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/Invoice.ts b/src/PaymentMethods/CreditManagement/Models/Invoice.ts index 58600cb3..99483890 100644 --- a/src/PaymentMethods/CreditManagement/Models/Invoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/Invoice.ts @@ -1,49 +1,103 @@ -import IPhone from '../../../Models/Services/IPhone' -import IAddress from '../../../Models/Services/IAddress' -import { ICreditArticle } from './Article' -import { ITransaction } from '../../../Models/ITransaction' -import Gender from '../../../Constants/Gender' +import IPhone from '../../../Models/Interfaces/IPhone' +import IAddress from '../../../Models/Interfaces/IAddress' +import { CreditArticle, ICreditArticle } from './Article' +import IRequest from '../../../Models/IRequest' +import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient' +import IDebtor from '../../../Models/Interfaces/IDebtor' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { Address } from './Address' -export interface Invoice { +export interface IInvoice extends IRequest { invoiceAmount: number invoiceAmountVAT?: number invoiceDate: string dueDate: string schemeKey?: string - maxStepIndex?: Number + maxStepIndex?: number allowedServices?: string allowedServicesAfterDueDate?: string - code: string - person: { - culture: string - title: string - initials: string - firstName: string - lastName: string - lastNamePrefix: string - gender: Gender - birthDate: string - placeOfBirth: string - } - company: { - culture: string - name: string - vatApplicable: boolean - vatNumber: string - chamberOfCommerce: string - } - address: Omit & { - houseNumberSuffix?: string - postalCode: string - } - debtor: { - code: string - } - email?: { email: string } + code?: string + person: Partial + company: Partial + address: Partial + debtor: IDebtor + email?: string phone: IPhone - productLine?:ICreditArticle[] + articles?: ICreditArticle[] invoiceNumber?: string applyStartRecurrent?: boolean - [key: string]: any } -export type IInvoice = Invoice & ITransaction +export class Invoice extends ServiceParameter implements IInvoice { + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine', + Address: 'Address', + Company: 'Company', + Person: 'Person', + Debtor: 'Debtor', + Email: 'Email', + Phone: 'Phone' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + + set invoiceAmount(value: number) { + this.set('invoiceAmount', value) + } + set invoiceAmountVAT(value: number) { + this.set('invoiceAmountVAT', value) + } + set invoiceDate(value: string) { + this.set('invoiceDate', value) + } + set dueDate(value: string) { + this.set('dueDate', value) + } + set schemeKey(value: string) { + this.set('schemeKey', value) + } + set maxStepIndex(value: number) { + this.set('maxStepIndex', value) + } + set allowedServices(value: string) { + this.set('allowedServices', value) + } + set allowedServicesAfterDueDate(value: string) { + this.set('allowedServicesAfterDueDate', value) + } + set code(value: string) { + this.set('code', value) + } + set person(value: Partial) { + this.set('person', value) + } + set company(value: Partial) { + this.set('company', value) + } + set address(value: Partial) { + this.set('address', new Address(value)) + } + set debtor(value: IDebtor) { + this.set('debtor', value) + } + set email(value: string) { + this.set('email', value) + } + set phone(value: IPhone) { + this.set('phone', value) + } + set articles(value: ICreditArticle[]) { + this.set( + 'articles', + value.map((article) => new CreditArticle(article)) + ) + } + set invoiceNumber(value: string) { + this.set('invoiceNumber', value) + } + set applyStartRecurrent(value: boolean) { + this.set('applyStartRecurrent', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts index 8eca7925..19565eaa 100644 --- a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts +++ b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts @@ -1,15 +1,48 @@ -import { ITransaction } from '../../../Models/ITransaction' +import IRequest from '../../../Models/IRequest' import CreditManagementInstallmentInterval from '../../../Constants/CreditManagementInstallmentInterval' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPaymentPlan extends ITransaction { - includedInvoiceKey: string - dossierNumber: string - installmentCount: number - installmentAmount: number +export interface IPaymentPlan extends IRequest { + includedInvoiceKey?: string + dossierNumber?: string + installmentCount?: number + installmentAmount?: number initialAmount?: number - startDate: string - interval: CreditManagementInstallmentInterval - paymentPlanCostAmount: number + startDate?: string + interval?: CreditManagementInstallmentInterval + paymentPlanCostAmount?: number paymentPlanCostAmountVat?: number - recipientEmail: string + recipientEmail?: string +} +export class PaymentPlan extends ServiceParameter implements IPaymentPlan { + set includedInvoiceKey(value: string) { + this.set('includedInvoiceKey', value) + } + set dossierNumber(value: string) { + this.set('dossierNumber', value) + } + set installmentCount(value: number) { + this.set('installmentCount', value) + } + set installmentAmount(value: number) { + this.set('installmentAmount', value) + } + set initialAmount(value: number) { + this.set('initialAmount', value) + } + set startDate(value: string) { + this.set('startDate', value) + } + set interval(value: CreditManagementInstallmentInterval) { + this.set('interval', value) + } + set paymentPlanCostAmount(value: number) { + this.set('paymentPlanCostAmount', value) + } + set paymentPlanCostAmountVat(value: number) { + this.set('paymentPlanCostAmountVat', value) + } + set recipientEmail(value: string) { + this.set('recipientEmail', value) + } } diff --git a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts index f9b12c58..f57e9402 100644 --- a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts @@ -1,6 +1,15 @@ -import { ServiceParameters } from '../../../Utils/Types' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IMultiInfoInvoice extends ServiceParameters { +export interface IMultiInfoInvoice extends IRequest { invoice: string invoices?: { invoiceNumber: string }[] } +export class MultiInfoInvoice extends ServiceParameter { + protected getCountable() { + return super.getCountable(['Invoices']) + } + set invoices(value: { invoiceNumber: string }[]) { + this.set('invoices', value) + } +} diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 3dbd7ba5..8371d6db 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -1,86 +1,72 @@ -import { IConfig } from '../../Utils/Types' import PaymentMethod from '../PaymentMethod' -import { IInvoice } from './Models/Invoice' -import { ICreditNote } from './Models/CreditNote' -import { uniqid } from '../../Utils/Functions' -import { IDebtor } from './Models/Debtor' -import { IPaymentPlan } from './Models/PaymentPlan' -import { ITransaction } from '../../Models/ITransaction' -import { IMultiInfoInvoice } from './Models/multiInfoInvoice' +import { IInvoice, Invoice } from './Models/Invoice' +import { CreditNote, ICreditNote } from './Models/CreditNote' +import { Debtor, IDebtor } from './Models/Debtor' +import { IPaymentPlan, PaymentPlan } from './Models/PaymentPlan' +import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice' import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines' +import IRequest from '../../Models/IRequest' +import { IDebtorInfo, DebtorInfo } from './Models/DebtorInfo' +import { ServiceParameter } from '../../Models/ServiceParameters' export default class CreditManagement extends PaymentMethod { - protected _paymentName = 'CreditManagement3' - protected _requiredFields: Array = ['currency'] - + protected _paymentName = 'CreditManagement' protected _serviceVersion = 1 - createInvoice(payload: IInvoice): Promise { - this.action = 'CreateInvoice' - payload.invoice = payload.invoice || uniqid() + protected _requiredFields = ['currency'] + createInvoice(payload: IInvoice) { + this.setServiceList('CreateInvoice', new Invoice(payload)) return this.dataRequest(payload) } createCombinedInvoice(payload: IInvoice) { - this.action = 'CreateCombinedInvoice' - payload.invoice = payload.invoice || uniqid() - this.setRequest(payload) - return this + this.setServiceList('CreateCombinedInvoice', new Invoice(payload)) + return this.transactionRequest(payload) } createCreditNote(payload: ICreditNote) { - this.action = 'CreateCreditNote' - + this.setServiceList('CreateCreditNote', new CreditNote(payload)) return this.dataRequest(payload) } addOrUpdateDebtor(payload: IDebtor) { - this.action = 'AddOrUpdateDebtor' - + this.setServiceList('AddOrUpdateDebtor', new Debtor(payload)) return this.dataRequest(payload) } createPaymentPlan(payload: IPaymentPlan) { - this.action = 'CreatePaymentPlan' - + this.setServiceList('CreatePaymentPlan', new PaymentPlan(payload)) return this.dataRequest(payload) } terminatePaymentPlan(payload: Required>) { - this.action = 'TerminatePaymentPlan' - + this.setServiceList('TerminatePaymentPlan', new PaymentPlan(payload)) return this.dataRequest(payload) } - pauseInvoice(payload: Required>) { - this.action = 'PauseInvoice' - + pauseInvoice(payload: Required>) { + this.setServiceList('PauseInvoice') return this.dataRequest(payload) } - unpauseInvoice(payload: Required>) { - this.action = 'UnpauseInvoice' - + unpauseInvoice(payload: Required>) { + this.setServiceList('UnpauseInvoice') return this.dataRequest(payload) } - invoiceInfo(payload: IMultiInfoInvoice) { - this.action = 'InvoiceInfo' - + this.setServiceList('InvoiceInfo', new MultiInfoInvoice(payload)) return this.dataRequest(payload) } - debtorInfo(payload: Required>) { - this.action = 'DebtorInfo' - + debtorInfo(payload: IDebtorInfo) { + this.setServiceList('DebtorInfo', new DebtorInfo(payload)) return this.dataRequest(payload) } addOrUpdateProductLines(payload: IAddOrUpdateProductLines) { - this.action = 'AddOrUpdateProductLines' + this.setServiceList('AddOrUpdateProductLines', new AddOrUpdateProductLines(payload)) return this.dataRequest(payload) } - resumeDebtorFile(payload: { debtorFileGuid: string }) { - this.action = 'ResumeDebtorFile' - + let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid) + this.setServiceList('ResumeDebtorFile', debtorFile) return this.dataRequest(payload) } pauseDebtorFile(payload: { debtorFileGuid: string }) { - this.action = 'PauseDebtorFile' - + let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid) + this.setServiceList('PauseDebtorFile', debtorFile) return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 7347b1e9..24f5c444 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,10 +1,10 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' export default class EPS extends PayablePaymentMethod { - protected _paymentName = 'eps' + protected _paymentName = 'EPS' - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/Emandates/Models/ICreate.ts b/src/PaymentMethods/Emandates/Models/ICreate.ts deleted file mode 100644 index cecae8e3..00000000 --- a/src/PaymentMethods/Emandates/Models/ICreate.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ITransaction } from '../../../Models/ITransaction' - -interface Create extends ITransaction { - debtorReference: string - sequenceType: 0 | 1 - purchaseId: string - mandateId?: string - language: string - emandateReason?: string - maxAmount?: number -} -export type ICreate = Create & - ({ debtorBankId: string } | Required>) diff --git a/src/PaymentMethods/Emandates/Models/IModify.ts b/src/PaymentMethods/Emandates/Models/IModify.ts deleted file mode 100644 index 5c133af6..00000000 --- a/src/PaymentMethods/Emandates/Models/IModify.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ITransaction } from '../../../Models/ITransaction' - -interface Modify extends Omit { - originalMandateId: string - debtorBankId?: string -} -export type IModify = Modify & - ({ debtorBankId: string } | Required>) diff --git a/src/PaymentMethods/Emandates/Models/Mandate.ts b/src/PaymentMethods/Emandates/Models/Mandate.ts new file mode 100644 index 00000000..a4cfffb1 --- /dev/null +++ b/src/PaymentMethods/Emandates/Models/Mandate.ts @@ -0,0 +1,44 @@ +import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest' + +export interface IMandate extends IRequest { + mandateId?: string + debtorBankId?: string + debtorReference?: string + sequenceType?: 0 | 1 + purchaseId?: string + language?: string + emandateReason?: string + maxAmount?: number + originalMandateId?: string +} + +export class Mandate extends ServiceParameter { + set debtorBankId(value: string) { + this.set('debtorBankId', value) + } + set debtorReference(value: string) { + this.set('debtorReference', value) + } + set sequenceType(value: number) { + this.set('sequenceType', value) + } + set purchaseId(value: string) { + this.set('purchaseId', value) + } + set mandateId(value: string) { + this.set('mandateId', value) + } + set language(value: string) { + this.set('language', value) + } + set emandateReason(value: string) { + this.set('emandateReason', value) + } + set maxAmount(value: number) { + this.set('maxAmount', value) + } + set originalMandateId(value: string) { + this.set('originalMandateId', value) + } +} diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 8649a10f..7e902a39 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -1,31 +1,28 @@ import PaymentMethod from '../PaymentMethod' import { IConfig } from '../../Utils/Types' -import { ICreate } from './Models/ICreate' -import { IModify } from './Models/IModify' +import { IMandate, Mandate } from './Models/Mandate' export default class Emandates extends PaymentMethod { - protected _paymentName = 'emandate' - + protected _paymentName = 'Emandates' _requiredFields: Array = ['currency'] - issuerList() { - this.action = 'GetIssuerList' + this.setServiceList('GetIssuerList') return this.dataRequest() } - createMandate(payload: ICreate) { - this.action = 'CreateMandate' + createMandate(payload: IMandate) { + this.setServiceList('CreateMandate', new Mandate(payload)) return this.dataRequest(payload) } - status(payload: { mandateId: string }) { - this.action = 'GetStatus' + status(payload: IMandate) { + this.setServiceList('GetStatus', new Mandate(payload)) return this.dataRequest(payload) } - modifyMandate(payload: IModify) { - this.action = 'ModifyMandate' + modifyMandate(payload: IMandate) { + this.setServiceList('ModifyMandate', new Mandate(payload)) return this.dataRequest(payload) } - cancelMandate(payload: { mandateId: string; purchaseId: string }) { - this.action = 'CancelMandate' + cancelMandate(payload: IMandate) { + this.setServiceList('CancelMandate', new Mandate(payload)) return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/GiftCard/Models/Pay.ts b/src/PaymentMethods/GiftCard/Models/Pay.ts new file mode 100644 index 00000000..f14f5a9e --- /dev/null +++ b/src/PaymentMethods/GiftCard/Models/Pay.ts @@ -0,0 +1,50 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export default interface IPay extends IPaymentRequest { + fashionChequeCardNumber?: string + fashionChequePin?: string + intersolveCardnumber?: string + intersolvePIN?: string + tcsCardnumber?: string + tcsValidationCode?: string + lastName?: string + email?: string + cardNumber?: string + pin?: string +} +export class Pay extends ServiceParameter { + set fashionChequeCardNumber(value: string) { + this.set('fashionChequeCardNumber', value) + } + set fashionChequePin(value: string) { + this.set('fashionChequePin', value) + } + set intersolveCardnumber(value: string) { + this.set('intersolveCardnumber', value) + } + set intersolvePIN(value: string) { + this.set('intersolvePIN', value) + } + set tcsCardnumber(value: string) { + this.set('tcsCardnumber', value) + } + set tcsValidationCode(value: string) { + this.set('tcsValidationCode', value) + } + set lastName(value: string) { + this.set('lastName', value) + } + set email(value: string) { + this.set('email', value) + } + set cardNumber(value: string) { + this.set('cardNumber', value) + } + set pin(value: string) { + this.set('pin', value) + } + set issuer(value: string) { + this.set('issuer', value) + } +} diff --git a/src/PaymentMethods/GiftCard/Models/Refund.ts b/src/PaymentMethods/GiftCard/Models/Refund.ts new file mode 100644 index 00000000..d2b1c8c6 --- /dev/null +++ b/src/PaymentMethods/GiftCard/Models/Refund.ts @@ -0,0 +1,16 @@ +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IRefundRequest } from '../../../Models/IRequest' + +export interface IRefund extends IRefundRequest { + email?: string + lastName?: string +} + +export class Refund extends ServiceParameter { + set email(value: string) { + this.set('amount', value) + } + set lastName(value: string) { + this.set('lastName', value) + } +} diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 0930c6b4..247b897c 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -1,16 +1,14 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import IPay, { Pay } from './Models/Pay' +import { IRefund, Refund } from './Models/Refund' export default class GiftCard extends PayablePaymentMethod { - pay(payload: Payload & { name: string }) { - return super.pay(payload) - } - refund(payload: RefundPayload & { name: string }) { - return super.refund(payload) + protected _paymentName = 'GiftCard' + + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) } - setRequest(payload: any) { - this.paymentName = payload.name || this._paymentName - delete payload.name - super.setRequest(payload) + refund(payload: IRefund) { + return super.refund(payload, new Refund(payload)) } } diff --git a/src/PaymentMethods/Giropay/Models/Pay.ts b/src/PaymentMethods/Giropay/Models/Pay.ts index 7d46e0f0..483bb6f7 100644 --- a/src/PaymentMethods/Giropay/Models/Pay.ts +++ b/src/PaymentMethods/Giropay/Models/Pay.ts @@ -1,6 +1,15 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface Pay extends Payload { - bic: string - costumerIBAN: string +export interface IPay extends IPaymentRequest { + bic?: string + costumerIBAN?: string +} +export class Pay extends ServiceParameter { + set bic(value: string) { + this.set('bic', value) + } + set costumerIBAN(value: string) { + this.set('costumerIBAN', value) + } } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index db1478d2..3698ca28 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,15 +1,9 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Pay } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' export default class Giropay extends PayablePaymentMethod { - protected _paymentName = 'giropay' - protected _serviceVersion = 1 - - pay(payload: Pay) { - return super.pay(payload) - } - refund(payload: RefundPayload) { - return super.refund(payload) + protected _paymentName = 'Giropay' + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) } } diff --git a/src/PaymentMethods/Ideal/Models/Pay.ts b/src/PaymentMethods/Ideal/Models/Pay.ts index 2c421ab5..dcc69b00 100644 --- a/src/PaymentMethods/Ideal/Models/Pay.ts +++ b/src/PaymentMethods/Ideal/Models/Pay.ts @@ -1,5 +1,10 @@ -import { Payload } from '../../../Models/ITransaction' - -export interface IPay extends Payload { - issuer: string +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' +export interface IPay extends IPaymentRequest { + issuer?: string +} +export class Pay extends ServiceParameter { + set issuer(value: string) { + this.set('issuer', value) + } } diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index ed327a73..4499cb5f 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -1,29 +1,30 @@ -import { IPay } from './Models/Pay' -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import { Pay, IPay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { RequestTypes } from '../../Constants/Endpoints' +import { IRefundRequest } from '../../Models/IRequest' export default class Ideal extends PayablePaymentMethod { - protected _paymentName = 'ideal' + protected _paymentName = 'Ideal' protected _serviceVersion = 2 - - pay(payload: IPay) { - return super.pay(payload) + pay(data: IPay) { + return super.pay(data, new Pay(data)) } - refund(payload: RefundPayload) { - return super.refund(payload) + payRemainder(payload: IPay) { + return super.payRemainder(payload, new Pay(payload)) } issuers() { - return this.specification().then((response) => { - return response - .getActionRequestParameters('Pay') - ?.find((item) => item.Name === 'issuer') - ?.ListItemDescriptions.map((item) => { - return { [item.Value]: item.Description } - }) - }) + return this.specification(RequestTypes.Transaction) + .request() + .then((response) => { + return response + .getActionRequestParameters('Pay') + ?.find((item) => item.name === 'issuer') + ?.listItemDescriptions?.map((item) => { + return { [item.value]: item.description } + }) + }) } - instantRefund(payload: RefundPayload){ - this.action = 'InstantRefund' - return super.refund(payload) + instantRefund(data: IRefundRequest) { + return super.refund(data) } } diff --git a/src/PaymentMethods/IdealQR/Models/IGenerate.ts b/src/PaymentMethods/IdealQR/Models/IGenerate.ts new file mode 100644 index 00000000..7819e7c2 --- /dev/null +++ b/src/PaymentMethods/IdealQR/Models/IGenerate.ts @@ -0,0 +1,47 @@ +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export interface IGenerate extends IRequest { + amount: number + amountIsChangeable: boolean + purchaseId: string + description: string + isOneOff: boolean + expiration: string + isProcessing?: boolean + minAmount: number + maxAmount: number + imageSize: number +} +export class Generate extends ServiceParameter implements IGenerate { + set amount(value: number) { + this.set('amount', value) + } + set amountIsChangeable(value: boolean) { + this.set('amountIsChangeable', value) + } + set purchaseId(value: string) { + this.set('purchaseId', value) + } + set description(value: string) { + this.set('description', value) + } + set isOneOff(value: boolean) { + this.set('isOneOff', value) + } + set expiration(value: string) { + this.set('expiration', value) + } + set isProcessing(value: boolean) { + this.set('isProcessing', value) + } + set minAmount(value: number) { + this.set('minAmount', value) + } + set maxAmount(value: number) { + this.set('maxAmount', value) + } + set imageSize(value: number) { + this.set('imageSize', value) + } +} diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts new file mode 100644 index 00000000..02967a21 --- /dev/null +++ b/src/PaymentMethods/IdealQR/index.ts @@ -0,0 +1,10 @@ +import { Generate, IGenerate } from './Models/IGenerate' +import PaymentMethod from '../PaymentMethod' + +export default class IdealQR extends PaymentMethod { + protected _paymentName = 'IdealQR' + generate(payload: IGenerate) { + this.setServiceList('Generate', new Generate(payload)) + return this.dataRequest() + } +} diff --git a/src/PaymentMethods/iDin/index.ts b/src/PaymentMethods/Idin/index.ts similarity index 99% rename from src/PaymentMethods/iDin/index.ts rename to src/PaymentMethods/Idin/index.ts index d05403b3..34b3b3e7 100644 --- a/src/PaymentMethods/iDin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -2,6 +2,7 @@ import PaymentMethod from '../PaymentMethod' import { IPay } from '../Ideal/Models/Pay' export default class Idin extends PaymentMethod { protected _paymentName = 'Idin' + identify(payload: IPay) { return this.dataRequest(payload) } diff --git a/src/PaymentMethods/In3/Models/Article.ts b/src/PaymentMethods/In3/Models/Article.ts index e69de29b..a03565e1 100644 --- a/src/PaymentMethods/In3/Models/Article.ts +++ b/src/PaymentMethods/In3/Models/Article.ts @@ -0,0 +1,24 @@ +import IArticle, { Article } from '../../../Models/Interfaces/IArticle' + +export interface IIn3Article extends IArticle { + category?: string + url?: string + quantityDescription?: string +} +export class In3Article extends Article implements In3Article { + set category(value: string) { + this.set('category', value) + } + get price() { + return this.get('grossUnitPrice') + } + set price(value: number) { + this.set('grossUnitPrice', value) + } + set url(value: string) { + this.set('url', value) + } + set quantityDescription(value: string) { + this.set('quantityDescription', value) + } +} diff --git a/src/PaymentMethods/In3/Models/Pay.ts b/src/PaymentMethods/In3/Models/Pay.ts index 1053c309..dae1acc5 100644 --- a/src/PaymentMethods/In3/Models/Pay.ts +++ b/src/PaymentMethods/In3/Models/Pay.ts @@ -1,45 +1,48 @@ -import { Payload } from '../../../Models/ITransaction' -import Gender from '../../../Constants/Gender' -import RecipientCategory from '../../../Constants/RecipientCategory' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest' +import { IIn3Article, In3Article } from './Article' +import { IIn3Recipient, In3Recipient } from './Recipient' -type Article = { - code: string - name: string - quantity: number - price: number +export interface IPay extends IPaymentRequest { + invoiceDate?: string + invoiceUrl?: string + billing?: IIn3Recipient + shipping?: Partial + articles?: Partial[] } - -type Address = { - street: string - houseNumber: number - houseNumberSuffix: string - zipCode: string - city: string - country: string -} - -type Company = { - name: string - chamberOfCommerce: string -} -type Person = { - gender: Gender - culture: string - initials: string - lastName: string - birthDate: string -} - -export interface IPay extends Payload { - description: string - clientIP: string - customerType: RecipientCategory.PERSON | RecipientCategory.COMPANY - invoiceDate: string - email: { email: string } - phone: { phone?: string; fax?: string } - company: Company - person: Person - address: Address - productLine: Article[] - subtotalLine: { name: string; value: number }[] +export default class Pay extends ServiceParameter { + protected getGroups(): {} { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set invoiceDate(value: string) { + this.set('invoiceDate', value) + } + set invoiceUrl(value: string) { + this.set('invoiceUrl', value) + } + get billing() { + return new In3Recipient() + } + set billing(billing: IIn3Recipient) { + this.set('billing', new In3Recipient(billing)) + if (this.get('shipping') === undefined) { + this.shipping = billing + } + } + set shipping(shipping: IIn3Recipient) { + this.set('shipping', new In3Recipient(shipping)) + } + set articles(articles: In3Article[]) { + this.set( + 'articles', + articles.map((article) => new In3Article(article)) + ) + } } diff --git a/src/PaymentMethods/In3/Models/Phone.ts b/src/PaymentMethods/In3/Models/Phone.ts new file mode 100644 index 00000000..7715f4b3 --- /dev/null +++ b/src/PaymentMethods/In3/Models/Phone.ts @@ -0,0 +1,13 @@ +import { Phone } from '../../../Models/Interfaces/IPhone' + +export class In3Phone extends Phone { + set landline(value: string) { + this.set('phone', value) + } + set mobile(value: string) { + this.set('phone', value) + } + set fax(value: string) { + this.set('phone', value) + } +} diff --git a/src/PaymentMethods/In3/Models/Recipient.ts b/src/PaymentMethods/In3/Models/Recipient.ts new file mode 100644 index 00000000..478f76be --- /dev/null +++ b/src/PaymentMethods/In3/Models/Recipient.ts @@ -0,0 +1,112 @@ +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import IAddress, { Address } from '../../../Models/Interfaces/IAddress' +import IPhone from '../../../Models/Interfaces/IPhone' +import { In3Phone } from './Phone' +import RecipientCategory from '../../../Constants/RecipientCategory' +import { Model } from '../../../Models/Model' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' + +export interface IIn3Recipient extends ICustomer { + recipient: Partial + phone: IPhone +} +export class In3Recipient extends Model implements In3Recipient { + get recipient(): In3Company | IIn3Person { + return new In3Person({}) + } + set recipient(value: In3Company | IIn3Person) { + if (value.category === RecipientCategory.COMPANY) { + this.set('recipient', new In3Company(value)) + } else if (value.category === RecipientCategory.PERSON) { + this.set('recipient', new In3Person(value)) + } else throw new Error('Invalid recipient category') + } + get address(): IAddress { + return new In3Address() + } + set address(value: IAddress) { + this.set('address', new In3Address(value)) + } + get email(): string { + return '' + } + set email(value: string) { + this.set('email', value) + } + get phone(): IPhone { + return new In3Phone() + } + set phone(value: IPhone) { + this.set('phone', new In3Phone(value)) + } +} + +export interface IIn3Person extends IPerson { + customerNumber: string + identificationNumber: string + conversationLanguage: string + lastName: string +} +export interface IIn3Company extends ICompany { + customerNumber: string +} +export class In3Person extends Person implements IIn3Person { + set category(value: RecipientCategory.PERSON) { + this.set('category', 'B2C') + } + set customerNumber(value: string) { + this.set('customerNumber', value) + } + set identificationNumber(value: string) { + this.set('identificationNumber', value) + } + set conversationLanguage(value: string) { + this.set('conversationLanguage', value) + } +} +export class In3Company extends Company implements IIn3Company { + set category(value: RecipientCategory.COMPANY) { + this.set('category', 'B2B') + } + set customerNumber(value: string) { + this.set('customerNumber', value) + } + get title() { + return this.get('salutation') + } + set title(value: string) { + this.set('salutation', value) + } + get chamberOfCommerce() { + return this.get('cocNumber') + } + set chamberOfCommerce(value: string) { + this.set('cocNumber', value) + } +} +export class In3Address extends Address { + get houseNumber() { + return this.get('streetNumber') + } + set houseNumber(value: string) { + this.set('streetNumber', value) + } + get houseNumberAdditional() { + return this.get('streetNumberSuffix') + } + set houseNumberAdditional(value: string) { + this.set('streetNumberSuffix', value) + } + get zipcode() { + return this.get('postalCode') + } + set zipcode(value: string) { + this.set('postalCode', value) + } + get country() { + return this.get('countryCode') + } + set country(value: string) { + this.set('countryCode', value) + } +} diff --git a/src/PaymentMethods/In3/Models/Refund.ts b/src/PaymentMethods/In3/Models/Refund.ts new file mode 100644 index 00000000..5d0d4987 --- /dev/null +++ b/src/PaymentMethods/In3/Models/Refund.ts @@ -0,0 +1,21 @@ +import { IIn3Article } from './Article' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IRefundRequest } from '../../../Models/IRequest' + +export interface IRefund extends IRefundRequest { + merchantImageUrl: string + summaryImageUrl: string + articles: IIn3Article[] +} +export class Refund extends ServiceParameter { + protected _countable: string[] = ['articles'] + set merchantImageUrl(value: string) { + this.set('merchantImageUrl', value) + } + set summaryImageUrl(value: string) { + this.set('summaryImageUrl', value) + } + set articles(value: IIn3Article[]) { + this.set('article', value) + } +} diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index c7ea9a0a..6040276e 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -1,17 +1,14 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPaymentRequest } from '../../Models/IRequest' +import Pay from './Models/Pay' +import { IRefund, Refund } from './Models/Refund' export default class In3 extends PayablePaymentMethod { - protected _paymentName = 'capayable' - pay(payload: IPay) { - return super.pay(payload) + protected _paymentName = 'In3' + pay(payload: IPaymentRequest) { + return super.pay(payload, new Pay(payload)) } - payInInstallments(payload: IPay) { - this.action = 'PayInInstallments' - return super.payTransaction(payload) - } - refund(payload: RefundPayload) { - return super.refund(payload) + refund(payload: IRefund) { + return super.refund(payload, new Refund(payload)) } } diff --git a/src/PaymentMethods/In3Old/Models/Address.ts b/src/PaymentMethods/In3Old/Models/Address.ts new file mode 100644 index 00000000..acae33e5 --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Address.ts @@ -0,0 +1,7 @@ +import { Address } from '../../../Models/Interfaces/IAddress' + +export class In3OldAddress extends Address { + set houseNumberAddition(houseNumberAddition: string) { + this.set('houseNumberSuffix', houseNumberAddition) + } +} diff --git a/src/PaymentMethods/In3Old/Models/Article.ts b/src/PaymentMethods/In3Old/Models/Article.ts new file mode 100644 index 00000000..56c15263 --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Article.ts @@ -0,0 +1,10 @@ +import { Article } from '../../../Models/Interfaces/IArticle' + +export class In3OldArticle extends Article { + set identifier(identifier: string) { + this.set('code', identifier) + } + set description(description: string) { + this.set('name', description) + } +} diff --git a/src/PaymentMethods/In3Old/Models/Company.ts b/src/PaymentMethods/In3Old/Models/Company.ts new file mode 100644 index 00000000..1d347318 --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Company.ts @@ -0,0 +1,7 @@ +import { Company } from '../../../Models/Interfaces/IRecipient' + +export class In3OldCompany extends Company { + set companyName(companyName: string) { + this.set('name', companyName) + } +} diff --git a/src/PaymentMethods/In3Old/Models/Pay.ts b/src/PaymentMethods/In3Old/Models/Pay.ts new file mode 100644 index 00000000..e455d560 --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Pay.ts @@ -0,0 +1,75 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import RecipientCategory from '../../../Constants/RecipientCategory' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import IArticle from '../../../Models/Interfaces/IArticle' +import { In3OldArticle } from './Article' +import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import IAddress from '../../../Models/Interfaces/IAddress' +import IPhone from '../../../Models/Interfaces/IPhone' +import { ISubtotal, Subtotal } from './Subtotal' +import { In3OldCompany } from './Company' +import { In3OldAddress } from './Address' +import { In3OldPhone } from './Phone' + +export interface IPay extends IPaymentRequest { + description: string + clientIP: string + customerType: RecipientCategory.PERSON | RecipientCategory.COMPANY + invoiceDate: string + email: string + phone: Partial + company: Partial + customer: Partial + address: Partial + articles: Partial[] + subtotals: ISubtotal[] +} +export class Pay extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine', + Subtotals: 'SubtotalLine', + Address: 'Address', + Customer: 'Person', + Company: 'Company', + Phone: 'Phone', + Email: 'Email' + }) + } + protected getCountable() { + return super.getCountable(['Articles', 'Subtotals']) + } + set customerType(value: RecipientCategory) { + this.set('customerType', value) + } + set invoiceDate(value: string) { + this.set('invoiceDate', value) + } + set email(value: string) { + this.set('email', value) + } + set phone(value: Partial) { + this.set('phone', new In3OldPhone(value)) + } + set company(value: Partial) { + this.set('company', new In3OldCompany(value)) + } + set customer(value: Partial) { + this.set('customer', new Person(value)) + } + set address(value: Partial) { + this.set('address', new In3OldAddress(value)) + } + set articles(value: Partial[]) { + this.set( + 'articles', + value.map((article) => new In3OldArticle(article)) + ) + } + set subtotals(value: ISubtotal[]) { + this.set( + 'subtotals', + value.map((subtotal) => new Subtotal(subtotal)) + ) + } +} diff --git a/src/PaymentMethods/In3Old/Models/Phone.ts b/src/PaymentMethods/In3Old/Models/Phone.ts new file mode 100644 index 00000000..e909243e --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Phone.ts @@ -0,0 +1,7 @@ +import { Phone } from '../../../Models/Interfaces/IPhone' + +export class In3OldPhone extends Phone { + set mobile(number) { + this.set('phone', number) + } +} diff --git a/src/PaymentMethods/In3Old/Models/Subtotal.ts b/src/PaymentMethods/In3Old/Models/Subtotal.ts new file mode 100644 index 00000000..99bdd531 --- /dev/null +++ b/src/PaymentMethods/In3Old/Models/Subtotal.ts @@ -0,0 +1,14 @@ +import { Model } from '../../../Models/Model' + +export interface ISubtotal { + name: string + value: number +} +export class Subtotal extends Model implements ISubtotal { + set name(name: string) { + this.set('name', name) + } + set value(value: number) { + this.set('value', value) + } +} diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts new file mode 100644 index 00000000..5ec61b94 --- /dev/null +++ b/src/PaymentMethods/In3Old/index.ts @@ -0,0 +1,13 @@ +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' +export default class In3Old extends PayablePaymentMethod { + protected _paymentName = 'In3Old' + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) + } + payInInstallments(payload: IPay) { + this.setPayPayload(payload) + this.setServiceList('PayInInstallments', new Pay(payload)) + return super.transactionRequest() + } +} diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 07b9258b..538f952e 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,11 +1,10 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' export default class KBC extends PayablePaymentMethod { - protected _paymentName = 'kbcpaymentbutton' - protected _serviceVersion = 1 + protected _paymentName = 'KBC' - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/Klarna/Models/Article.ts b/src/PaymentMethods/Klarna/Models/Article.ts index 3e68c08c..4a0da68f 100644 --- a/src/PaymentMethods/Klarna/Models/Article.ts +++ b/src/PaymentMethods/Klarna/Models/Article.ts @@ -1,9 +1,9 @@ -export type IKlarnaArticle = { - description: string - grossUnitPrice: number - identifier: string - imageUrl?: string - quantity: string - uRL?: string - vatPercentage: string +import { Article } from '../../../Models/Interfaces/IArticle' +export class KlarnaArticle extends Article { + get price() { + return this.get('grossUnitPrice') + } + set price(price: number) { + this.set('grossUnitPrice', price) + } } diff --git a/src/PaymentMethods/Klarna/Models/Pay.ts b/src/PaymentMethods/Klarna/Models/Pay.ts index 805370b2..187de119 100644 --- a/src/PaymentMethods/Klarna/Models/Pay.ts +++ b/src/PaymentMethods/Klarna/Models/Pay.ts @@ -1,9 +1,39 @@ -import { IKlarnaArticle } from './Article' -import { IBilling, IShipping } from './Recipient' -import { Payload } from '../../../Models/ITransaction' +import { KlarnaRecipient } from './Recipient' +import IArticle, { Article } from '../../../Models/Interfaces/IArticle' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { KlarnaArticle } from './Article' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' -export interface IPay extends Payload { - billingCustomer: IBilling - shippingCustomer?: IShipping - article: IKlarnaArticle[] +export interface IPay extends IPaymentRequest { + billing: ICustomer + shipping?: ICustomer + articles: Partial[] +} +export class Pay extends ServiceParameter { + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article' + }) + } + protected getCountable() { + return super.getCountable(['Articles']) + } + set billing(billing: ICustomer) { + this.set('billing', new KlarnaRecipient(billing)) + if (this.get('shipping') === undefined) { + this.shipping = billing + } + } + set shipping(shipping: ICustomer) { + this.set('shipping', new KlarnaRecipient(shipping)) + } + set articles(articles: IArticle[]) { + this.set( + 'articles', + articles.map((article) => new KlarnaArticle(article)) + ) + } } diff --git a/src/PaymentMethods/Klarna/Models/Recipient.ts b/src/PaymentMethods/Klarna/Models/Recipient.ts index d63e9c71..5a4296f8 100644 --- a/src/PaymentMethods/Klarna/Models/Recipient.ts +++ b/src/PaymentMethods/Klarna/Models/Recipient.ts @@ -1,24 +1,29 @@ -export type IBilling = { - city: string - country: string - email: string - firstName: string - lastName: string - phone?: string - postalCode: string - street: string - streetNumber: string - streetNumberAdditional?: string -} -export type IShipping = { - city: string - country: string - email: string - firstName: string - lastName: string - phone?: string - postalCode: string - street: string - streetNumber: string - streetNumberAdditional?: string +import IAddress from '../../../Models/Interfaces/IAddress' +import IPhone from '../../../Models/Interfaces/IPhone' +import { Model } from '../../../Models/Model' +import { KlarnaAddress } from '../Services/KlarnaAddress' +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { KlarnaPhone } from '../Services/KlarnaPhone' +import RecipientCategory from '../../../Constants/RecipientCategory' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' + +export class KlarnaRecipient extends Model implements ICustomer { + set email(email: string) { + this.set('email', email) + } + set address(address: IAddress) { + this.set('address', new KlarnaAddress(address)) + } + set recipient(recipient: Partial) { + if (recipient.category === RecipientCategory.PERSON) { + // @ts-ignore + this.set('recipient', new Person({ ...recipient, category: 'B2C' })) + } else if (recipient.category === RecipientCategory.COMPANY) { + // @ts-ignore + this.set('recipient', new Company({ ...recipient, category: 'B2B' })) + } + } + set phone(phone: IPhone) { + this.set('phone', new KlarnaPhone(phone)) + } } diff --git a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts new file mode 100644 index 00000000..58c41cb4 --- /dev/null +++ b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts @@ -0,0 +1,21 @@ +import IAddress, { Address } from '../../../Models/Interfaces/IAddress' +export class KlarnaAddress extends Address implements IAddress { + get houseNumber(): string { + return this.get('streetNumber') + } + set houseNumber(houseNumber: string) { + this.set('streetNumber', houseNumber) + } + get houseNumberAdditional(): string { + return this.get('streetNumberAdditional') + } + set houseNumberAdditional(houseNumberAdditional: string) { + this.set('streetNumberAdditional', houseNumberAdditional) + } + get zipcode(): string { + return this.get('postalCode') + } + set zipcode(zipcode: string) { + this.set('postalCode', zipcode) + } +} diff --git a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts new file mode 100644 index 00000000..87d2368c --- /dev/null +++ b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts @@ -0,0 +1,10 @@ +import { Phone } from '../../../Models/Interfaces/IPhone' + +export class KlarnaPhone extends Phone { + get mobile(): string { + return this.get('phone') + } + set mobile(mobile: string) { + this.set('phone', mobile) + } +} diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 48ad736e..e25ee5e3 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,20 +1,16 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { IConfig } from '../../Utils/Types' -import { RefundPayload } from '../../Models/ITransaction' +import { IPay, Pay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod' export default class Klarna extends PayablePaymentMethod { - protected _paymentName = 'klarna' - protected _serviceVersion = 1 - protected _requiredFields: Array = ['currency', 'pushURL'] - pay(payload: IPay) { - return super.pay(payload) + protected _paymentName = 'Klarna' + pay(data: IPay) { + return super.pay(data, new Pay(data)) } - refund(payload: RefundPayload) { - return super.refund(payload) + payInInstallments(data: IPay) { + this.setServiceList('PayInInstallments', new Pay(data)) + return super.pay(data) } - payInInstallments(payload: IPay) { - this.action = 'PayInInstallments' - return super.transactionRequest(payload) + payRemainder(payload: IPay) { + return super.payRemainder(payload, new Pay(payload)) } } diff --git a/src/PaymentMethods/KlarnaKP/Models/IPay.ts b/src/PaymentMethods/KlarnaKP/Models/IPay.ts index b0509206..cb5431b8 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IPay.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IPay.ts @@ -1,5 +1,11 @@ -import { ITransaction } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends ITransaction { +export interface IPay extends IPaymentRequest { reservationNumber?: string } +export class Pay extends ServiceParameter { + set reservationNumber(value: string) { + this.set('reservationNumber', value) + } +} diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts new file mode 100644 index 00000000..0dca1eac --- /dev/null +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -0,0 +1,42 @@ +import Gender from '../../../Constants/Gender' +import IRequest from '../../../Models/IRequest' +import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import IArticle from '../../../Models/Interfaces/IArticle' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export interface IReserve extends IRequest { + gender?: Gender.MALE | Gender.FEMALE + billing?: ICustomer + shipping?: ICustomer + articles?: Partial[] + operatingCountry?: string + reservationNumber?: string + shippingSameAsBilling?: boolean + pno?: string +} +export class Reserve extends ServiceParameter implements IReserve { + protected getCountable() { + return super.getCountable(['Articles']) + } + set reservationNumber(value: string) { + this.set('reservationNumber', value) + } + set gender(value: Gender.MALE | Gender.FEMALE) { + this.set('gender', value) + } + set operatingCountry(value: string) { + this.set('operatingCountry', value) + } + set pno(value: string) { + this.set('pno', value) + } + set billing(value: ICustomer) { + this.set('billing', value) + } + set shipping(value: ICustomer) { + this.set('shipping', value) + } + set articles(value: IArticle[]) { + this.set('articles', value) + } +} diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 6ac9175b..9c8a07a5 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -1,34 +1,32 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/IPay' -import { ICapture, Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/IPay' +import IRequest from '../../Models/IRequest' +import { IReserve, Reserve } from './Models/IReserve' -export default class KlarnaKp extends PayablePaymentMethod { - protected _paymentName = 'KlarnaKp' - _serviceVersion = 1 - pay(payload: IPay & Payload) { - return super.pay(payload) +export default class KlarnaKP extends PayablePaymentMethod { + protected _paymentName = 'KlarnaKP' + protected _serviceVersion = 1 + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { - return super.refund(payload) - } - reserve(payload: IPay) { - this.action = 'Reserve' + reserve(payload: IReserve) { + this.setServiceList('Reserve', new Reserve(payload)) return this.dataRequest(payload) } - cancel(payload: IPay) { - this.action = 'CancelReservation' + cancel(payload: IRequest) { + this.setServiceList('CancelReservation') return this.dataRequest(payload) } - update(payload: IPay) { - this.action = 'UpdateReservation' + update(payload: IRequest) { + this.setServiceList('UpdateReservation') return this.dataRequest(payload) } - extend(payload: IPay) { - this.action = 'ExtendReservation' + extend(payload: IRequest) { + this.setServiceList('ExtendReservation') return this.dataRequest(payload) } - addShippingInfo(payload: ICapture) { - this.action = 'AddShippingInfo' + addShippingInfo(payload: IRequest) { + this.setServiceList('AddShippingInfo') return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/Marketplaces/Models/ISplit.ts b/src/PaymentMethods/Marketplaces/Models/ISplit.ts index 80a7ff9f..416d65c5 100644 --- a/src/PaymentMethods/Marketplaces/Models/ISplit.ts +++ b/src/PaymentMethods/Marketplaces/Models/ISplit.ts @@ -1,4 +1,4 @@ -import { ITransaction } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' type Seller = { accountId?: string @@ -9,12 +9,12 @@ type Marketplace = { amount?: number description?: string } -export interface ISplit extends ITransaction { +export interface ISplit extends IPaymentRequest { seller?: Seller[] marketplace?: Marketplace daysUntilTransfer?: number } -export interface ITransfer extends ITransaction { +export interface ITransfer extends IPaymentRequest { seller?: Seller[] marketplace?: Marketplace daysUntilTransfer?: number diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 3c40fa0f..c074954b 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -3,19 +3,16 @@ import { ISplit, ITransfer } from './Models/ISplit' export default class Marketplaces extends PaymentMethod { protected _paymentName = 'Marketplaces' - split(payload: ISplit) { - this.action = 'Split' - this.setRequest(payload) - return this + this.setServiceList('Split') + return this.dataRequest(payload) } transfer(payload: ITransfer) { - this.action = 'Transfer' + this.setServiceList('Transfer') return this.dataRequest(payload) } - refundSupplementary(payload: ISplit = {}) { - this.action = 'RefundSupplementary' - this.setRequest(payload) - return this + refundSupplementary(payload: ISplit) { + this.setServiceList('RefundSupplementary') + return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts new file mode 100644 index 00000000..3d8b4e55 --- /dev/null +++ b/src/PaymentMethods/NoService/index.ts @@ -0,0 +1,5 @@ +import PayablePaymentMethod from '../PayablePaymentMethod' + +export default class NoService extends PayablePaymentMethod { + protected _paymentName = 'noserivce' +} diff --git a/src/PaymentMethods/PayByBank/Models/IPay.ts b/src/PaymentMethods/PayByBank/Models/IPay.ts new file mode 100644 index 00000000..70eae191 --- /dev/null +++ b/src/PaymentMethods/PayByBank/Models/IPay.ts @@ -0,0 +1,15 @@ +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' + +export default interface IPay extends IPaymentRequest { + issuer: string + countryCode: string +} +export class Pay extends ServiceParameter { + set issuer(value: string) { + this.set('issuer', value) + } + set countryCode(value: string) { + this.set('countryCode', value) + } +} diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts new file mode 100644 index 00000000..390eec29 --- /dev/null +++ b/src/PaymentMethods/PayByBank/index.ts @@ -0,0 +1,28 @@ +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' +import IPay, { Pay } from './Models/IPay' + +export default class PayByBank extends PayablePaymentMethod { + protected _paymentName = 'PayByBank' + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)) + } + refund(payload: IRefundRequest) { + return super.refund(payload) + } + issuers() { + return this.specification() + .request() + .then((response) => { + return response + .getActionRequestParameters('Pay') + ?.find((item) => item.name === 'issuer') + ?.listItemDescriptions!.map((item) => { + return { [item.value]: item.description } + }) + }) + .catch((err) => { + console.log(err) + }) + } +} diff --git a/src/PaymentMethods/PayPerEmail/Models/invitation.ts b/src/PaymentMethods/PayPerEmail/Models/invitation.ts index b409126c..67c5c8a4 100644 --- a/src/PaymentMethods/PayPerEmail/Models/invitation.ts +++ b/src/PaymentMethods/PayPerEmail/Models/invitation.ts @@ -1,7 +1,7 @@ -import { Payload } from '../../../Models/ITransaction' +import IRequest from '../../../Models/IRequest' import gender from '../../../Constants/Gender' -export interface IInvitation extends Payload { +export interface IInvitation extends IRequest { customerGender: gender customerFirstName: string customerLastName: string diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index b4803f86..0709bb8d 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -3,11 +3,10 @@ import { IInvitation } from './Models/invitation' import { uniqid } from '../../Utils/Functions' export default class PayPerEmail extends PaymentMethod { - protected _paymentName = 'payperemail' - + protected _paymentName = 'PayPerEmail' paymentInvitation(payload: IInvitation) { - this.action = 'paymentInvitation' payload.invoice = payload.invoice || uniqid() + this.setServiceList('paymentInvitation') return super.transactionRequest(payload) } } diff --git a/src/PaymentMethods/PayablePaymentMethod.ts b/src/PaymentMethods/PayablePaymentMethod.ts index 0d786978..4620e54c 100644 --- a/src/PaymentMethods/PayablePaymentMethod.ts +++ b/src/PaymentMethods/PayablePaymentMethod.ts @@ -1,33 +1,34 @@ import PaymentMethod from './PaymentMethod' +import IRequest, { IPaymentRequest, IRefundRequest } from '../Models/IRequest' import { uniqid } from '../Utils/Functions' -import { ITransaction, Payload, RefundPayload } from '../Models/ITransaction' -import { TransactionResponse } from '../Models/TransactionResponse' -import { IConfig } from '../Utils/Types' +import { ServiceParameter } from '../Models/ServiceParameters' +import { IParameter } from '../Models/IParameters' -export abstract class PayablePaymentMethod extends PaymentMethod { - protected _requiredFields: Array = [ +export default abstract class PayablePaymentMethod extends PaymentMethod { + protected _requiredFields: Array = [ 'currency', 'returnURL', 'returnURLCancel', 'pushURL' ] - protected payTransaction(payload: ITransaction): Promise { + protected setPayPayload(payload: IRequest) { payload.invoice = payload.invoice || uniqid() payload.order = payload.order || uniqid() - - return this.transactionRequest(payload) + super.setPayload(payload) } - pay(payload: Payload) { - this.action = 'Pay' - return this.payTransaction(payload) + pay(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { + this.setPayPayload(payload) + this.setServiceList('Pay', serviceParameters) + return this.transactionRequest() } - - protected refund(payload: RefundPayload) { - this.action = 'Refund' - return this.payTransaction(payload) + payRemainder(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { + this.setPayPayload(payload) + this.setServiceList('PayRemainder', serviceParameters) + return this.transactionRequest() } - protected transactionInvoice(payload: ITransaction): Promise { - payload.invoice = payload.invoice || uniqid() - return this.transactionRequest(payload) + refund(payload: IRefundRequest, serviceParameters?: ServiceParameter | IParameter[]) { + this.setPayload(payload) + this.setServiceList('Refund', serviceParameters) + return this.transactionRequest() } } diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index fb420eff..2670ef03 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,14 +1,10 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' export default class Payconiq extends PayablePaymentMethod { - protected _paymentName = 'payconiq' - - refund(payload: RefundPayload) { - return super.refund(payload) - } - instantRefund(payload: RefundPayload){ - this.action = 'InstantRefund' - return super.refund(payload) + protected _paymentName = 'Payconiq' + instantRefund(payload: IRefundRequest) { + this.setServiceList('InstantRefund') + return this.transactionRequest(payload) } } diff --git a/src/PaymentMethods/PaymentInitiation/Models/IPay.ts b/src/PaymentMethods/PaymentInitiation/Models/IPay.ts deleted file mode 100644 index d5349cc0..00000000 --- a/src/PaymentMethods/PaymentInitiation/Models/IPay.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {Payload} from "../../../Models/ITransaction"; - -export default interface IPay extends Payload { - issuer: string - countryCode: string -} \ No newline at end of file diff --git a/src/PaymentMethods/PaymentInitiation/index.ts b/src/PaymentMethods/PaymentInitiation/index.ts deleted file mode 100644 index 11d71ac3..00000000 --- a/src/PaymentMethods/PaymentInitiation/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' -import IPay from "./Models/IPay"; - -export default class PaymentInitiation extends PayablePaymentMethod { - protected _paymentName = 'PayByBank' - _serviceVersion = 1 - pay(payload: IPay) { - return super.pay(payload) - } - refund(payload: RefundPayload) { - return super.refund(payload) - } -} diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index 3bd9d60e..a9e824cb 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -1,88 +1,102 @@ -import { Request } from '../Models/Request' -import { IConfig, ServiceParameters } from '../Utils/Types' -import { RequestType } from '../Constants/Endpoints' -import { ITransaction } from '../Models/ITransaction' -import buckarooClient from '../index' -import { IServiceList } from '../Models/ServiceList' +import { RequestTypes } from '../Constants/Endpoints' +import IRequest from '../Models/IRequest' +import Buckaroo from '../index' +import Request from '../Request/Request' +import { ServiceList } from '../Models/IServiceList' +import { ServiceParameter } from '../Models/ServiceParameters' +import { IParameter } from '../Models/IParameters' +import { DataRequestData, TransactionData } from '../Request/DataModels' + export default abstract class PaymentMethod { - protected readonly _requiredFields: Array = ['currency', 'pushURL'] - protected _paymentName = '' - protected _serviceVersion = 0 - protected _request: Request = new Request() - private _action = '' - get paymentName(): string { - return this._paymentName + protected _paymentName: string = '' + protected _serviceCode?: string + protected _serviceVersion: number = 0 + protected _payload: IRequest = {} + protected _serviceList: ServiceList = new ServiceList() + constructor(serviceCode?: string) { + this._serviceCode = serviceCode + } + get serviceVersion() { + return this._serviceVersion } - get request(): ITransaction { - return this._request.data + set serviceVersion(value: number) { + this._serviceVersion = value } - protected set paymentName(value: string) { - this._paymentName = value + get serviceCode() { + return this._serviceCode || '' } - get serviceVersion(): number { - return this._serviceVersion + get paymentName() { + return this._paymentName } - protected get action(): string { - return this._action + protected _requiredFields: Array = [] + protected setRequiredFields(requiredFields: Array = this._requiredFields) { + for (const fieldKey of requiredFields) { + let field = this._payload[fieldKey] ?? Buckaroo.Client.config[fieldKey] + if (field === undefined) { + throw new Error(`Missing required config parameter ${String(fieldKey)}`) + } + this._payload[fieldKey] = field + } + return this } - protected set action(value: string) { - this._action = value + protected setPayload(payload: IRequest) { + this.setRequiredFields() + this._payload = { ...this._payload, ...payload } + } + getPayload() { + return this._payload } - public setRequestAction(action:string) { - this._request.services?.ServiceList.forEach((service) => { - service.Action = action + protected setServiceList( + action: string, + serviceParameters?: IParameter[] | ServiceParameter, + serviceCode = this.serviceCode, + serviceVersion = this.serviceVersion + ) { + this._serviceList.addService({ + name: serviceCode, + action: action, + version: serviceVersion, + parameters: + serviceParameters instanceof ServiceParameter + ? serviceParameters.toParameterList() + : serviceParameters }) } - - public setRequest(data: ITransaction | (ITransaction & ServiceParameters) ) { - this._request.setBasicParameters(data) - - this.setRequiredFields() - - this.setServiceParameters(this._request.filter(data)) + getServices() { + return this._serviceList.list } - - protected setServiceParameters(serviceParameters: ServiceParameters) { - let serviceList: IServiceList = { - Action: this.action, - Name: this.paymentName, - Version: this.serviceVersion - } - if (Object.keys(serviceParameters).length > 0) { - serviceList.Parameters = this._request.formatServiceParameters(serviceParameters) + protected transactionRequest(payload?: IRequest) { + let data = new TransactionData({ ...(payload ?? this._payload) }) + if (this._serviceList.list.length > 0) { + data.setServiceList(this._serviceList) } - this._request.addServices(serviceList) + return Request.Transaction(data) } - - protected setRequiredFields() { - for (const requiredField of this._requiredFields) { - if (!this._request.data[requiredField]) - this._request.data[requiredField] = buckarooClient().getConfig()[requiredField] + protected dataRequest(payload?: IRequest) { + let data = new DataRequestData({ ...(payload ?? this._payload) }) + if (this._serviceList.list.length > 0) { + data.setServiceList(this._serviceList) } + return Request.DataRequest(data) } - protected transactionRequest(requestData: ITransaction | (ITransaction & ServiceParameters) ){ - this.setRequest(requestData) - - return buckarooClient().transactionRequest(this._request.data) - } - protected dataRequest(requestData: ITransaction | (ITransaction & ServiceParameters) = {}) { - this.setRequest(requestData) - - return buckarooClient().dataRequest(this._request.data) + public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { + return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }) } - public combine(method: PaymentMethod) { - if (Object.keys(method._request.data).length > 0) { - let services = this._request.services - if (services && method._request.services) { - method._request.services.ServiceList = services.ServiceList.concat( - method._request.services.ServiceList - ) + combine(data: Payload): this + combine(method: Method): this + combine(data): this { + if (data instanceof PaymentMethod) { + data = data.getPayload() + } + let { services, Services, ...payload } = data + for (const key in payload) { + if (payload.hasOwnProperty(key)) { + this._payload[key] = payload[key] } - Object.assign(this._request.data, method._request.data) + } + for (const service of services?.serviceList) { + this.setServiceList(service.action, service.parameters, service.name, service.version) } return this } - public specification(type?: RequestType) { - return buckarooClient().specification(this.paymentName, this.serviceVersion, type) - } } diff --git a/src/PaymentMethods/Paypal/Models/Address.ts b/src/PaymentMethods/Paypal/Models/Address.ts new file mode 100644 index 00000000..aed64475 --- /dev/null +++ b/src/PaymentMethods/Paypal/Models/Address.ts @@ -0,0 +1,35 @@ +import IAddressGlobal, { Address as AddressClass } from '../../../Models/Interfaces/IAddress' + +export interface IAddress extends Partial { + street: string + street2?: string +} +export class Address extends AddressClass { + set street2(value: string) { + this.set('street2', value) + } + set street(value: string) { + this.set('street1', value) + } + get street() { + return this.get('street1') + } + set city(value: string) { + this.set('cityName', value) + } + get city() { + return this.get('cityName') + } + set state(value: string) { + this.set('stateOrProvince', value) + } + get state() { + return this.get('stateOrProvince') + } + set zipcode(value: string) { + this.set('postalCode', value) + } + get zipcode() { + return this.get('postalCode') + } +} diff --git a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts index b6c1ba71..594f69d1 100644 --- a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts +++ b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts @@ -1,3 +1,32 @@ -import { ServiceParameters } from '../../../Utils/Types' +import IPhone from '../../../Models/Interfaces/IPhone' +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { Phone } from './Phone' +import { Address, IAddress } from './Address' +import { IPaymentRequest } from '../../../Models/IRequest' -export interface IExtraInfo extends ServiceParameters {} +export interface IExtraInfo extends IPaymentRequest { + address?: IAddress + customer?: IPerson + phone?: IPhone + noShipping?: string + addressOverride?: boolean +} + +export class ExtraInfo extends ServiceParameter { + set address(value: IAddress) { + this.set('address', new Address(value)) + } + set customer(value: IPerson) { + this.set('customer', new Person(value)) + } + set phone(value: IPhone) { + this.set('phone', new Phone(value)) + } + set noShipping(value: string) { + this.set('noShipping', value) + } + set addressOverride(value: boolean) { + this.set('addressOverride', value) + } +} diff --git a/src/PaymentMethods/Paypal/Models/Pay.ts b/src/PaymentMethods/Paypal/Models/Pay.ts index 4211a012..9c77c877 100644 --- a/src/PaymentMethods/Paypal/Models/Pay.ts +++ b/src/PaymentMethods/Paypal/Models/Pay.ts @@ -1,9 +1,28 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { buyerEmail?: string productName?: string billingAgreementDescription?: string pageStyle?: string payPalOrderId?: string } + +export class Pay extends ServiceParameter { + set buyerEmail(value: string) { + this.set('buyerEmail', value) + } + set productName(value: string) { + this.set('productName', value) + } + set billingAgreementDescription(value: string) { + this.set('billingAgreementDescription', value) + } + set pageStyle(value: string) { + this.set('pageStyle', value) + } + set payPalOrderId(value: string) { + this.set('payPalOrderId', value) + } +} diff --git a/src/PaymentMethods/Paypal/Models/Phone.ts b/src/PaymentMethods/Paypal/Models/Phone.ts new file mode 100644 index 00000000..b6e1c83b --- /dev/null +++ b/src/PaymentMethods/Paypal/Models/Phone.ts @@ -0,0 +1,7 @@ +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' + +export class Phone extends PhoneClass { + set mobile(value: string) { + this.set('phone', value) + } +} diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 26bd0386..296f7a24 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -1,22 +1,25 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { ICapture, RefundPayload } from '../../Models/ITransaction' -import { IPay } from './Models/Pay' -import { IExtraInfo } from './Models/ExtraInfo' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import { IPay, Pay } from './Models/Pay' +import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo' export default class Paypal extends PayablePaymentMethod { - protected _paymentName = 'paypal' + protected _paymentName = 'Paypal' + pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } - payRecurring(payload: ICapture) { - this.action = 'PayRecurring' + payRecurrent(payload: IPaymentRequest) { + this.setPayPayload(payload) + this.setServiceList('PayRecurring') return super.transactionRequest(payload) } extraInfo(payload: IExtraInfo) { - this.action = 'Pay,ExtraInfo' + this.setPayPayload(payload) + this.setServiceList('Pay,ExtraInfo', new ExtraInfo(payload)) return super.transactionRequest(payload) } } diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index 3132fb96..098c5755 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,11 +1,9 @@ -import PaymentMethod from "../PaymentMethod"; -import { IConfig } from "../../Utils/Types"; - +import PaymentMethod from '../PaymentMethod' export default class PiM extends PaymentMethod { - _paymentName = "pim"; - _requiredFields:Array = ["currency"]; - generate(){ - this.action = 'generate' - return this.dataRequest() - } -} \ No newline at end of file + protected _paymentName = 'PiM' + protected _requiredFields = ['currency'] + generate() { + this.setServiceList('Generate') + return this.dataRequest() + } +} diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index 2a4a4ffc..fd9d72d3 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,13 +1,5 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' +import PayablePaymentMethod from '../PayablePaymentMethod' -class Pointofsale extends PayablePaymentMethod { - protected _paymentName = 'pospayment' +export default class PointOfSale extends PayablePaymentMethod { + protected _paymentName = 'PointOfSale' } - -let _pointofsale: Pointofsale -const pointofsale: () => Pointofsale = () => { - if (!_pointofsale) _pointofsale = new Pointofsale() - return _pointofsale -} -export default pointofsale -export { Pointofsale as PointofsaleClass } diff --git a/src/PaymentMethods/Przelewy24/Models/Pay.ts b/src/PaymentMethods/Przelewy24/Models/Pay.ts index 57bfebaa..599cf8f9 100644 --- a/src/PaymentMethods/Przelewy24/Models/Pay.ts +++ b/src/PaymentMethods/Przelewy24/Models/Pay.ts @@ -1,7 +1,23 @@ -import { Payload } from '../../../Models/ITransaction' -export interface IPay extends Payload { - customerFirstName: string - customerLastName: string - customerEmail: string +import { IPaymentRequest } from '../../../Models/IRequest' +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { ServiceParameter } from '../../../Models/ServiceParameters' +export interface IPay extends IPaymentRequest { email: string + customer: Partial +} +export class Pay extends ServiceParameter { + set email(email: string) { + this.set('customerEmail', email) + } + set customer(customer: Partial) { + this.set('customer', new Customer(customer)) + } +} +export class Customer extends Person { + set firstName(email: string) { + this.set('customerFirstName', email) + } + set lastName(email: string) { + this.set('customerLastName', email) + } } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index eaf95969..98aa1c7e 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -1,14 +1,13 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' -import { IPay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' +import { IPay, Pay } from './Models/Pay' export default class Przelewy24 extends PayablePaymentMethod { protected _paymentName = 'Przelewy24' - pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload, new Pay(payload)) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/SEPA/Models/Emandate.ts b/src/PaymentMethods/SEPA/Models/Emandate.ts index 840cbd74..677274a9 100644 --- a/src/PaymentMethods/SEPA/Models/Emandate.ts +++ b/src/PaymentMethods/SEPA/Models/Emandate.ts @@ -1,6 +1,6 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' -export interface IEmandate extends Payload { +export interface IEmandate extends IPaymentRequest { mandateReference: string collectdate?: string } diff --git a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts index 8c564c33..940ad81d 100644 --- a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts +++ b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts @@ -1,7 +1,6 @@ -import IAddress from '../../../Models/Services/IAddress' -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' -export type ExtraInfo = { +export interface IExtraInfo extends IPaymentRequest { customeraccountname: string customerBIC?: string customerIBAN: string @@ -14,6 +13,4 @@ export type ExtraInfo = { customerReferencePartyName?: string houseNumberSuffix: string contractID: string -} & Omit - -export type IExtraInfo = ExtraInfo & Payload +} diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index ebbec1d2..2f1454d2 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -1,10 +1,53 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { ServiceParameter } from '../../../Models/ServiceParameters' -export interface IPay extends Payload { - customeraccountname: string - customerBIC?: string - customerIBAN: string - collectDate: string +export interface IPay extends IPaymentRequest { + customer?: Partial + bic?: string + iban?: string + collectDate?: string mandateReference?: string mandateDate?: string } +export class Pay extends ServiceParameter { + get bic(): string { + return this.get('customerbic') + } + set bic(value: string) { + this.set('customerbic', value) + } + get iban(): string { + return this.get('customerIBAN') + } + set iban(value: string) { + this.set('customerIBAN', value) + } + set collectDate(value: string) { + this.set('collectDate', value) + } + set mandateReference(value: string) { + this.set('mandateReference', value) + } + set mandateDate(value: string) { + this.set('mandateDate', value) + } + set customer(value: Partial) { + this.set('customer', new Customer(value)) + } +} +export class Customer extends Person { + set category(value) {} + get name(): string { + return this.get('customeraccountname') + } + set name(value: string) { + this.set('customeraccountname', value) + } + get firstName(): string { + return this.get('customeraccountname') + } + set firstName(value: string) { + this.set('customeraccountname', value) + } +} diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 2248e3e9..d2ae3de7 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -1,35 +1,34 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { IPay } from './Models/Pay' -import { ICapture, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay' import { IExtraInfo } from './Models/ExtraInfo' import { IEmandate } from './Models/Emandate' import { uniqid } from '../../Utils/Functions' +import { IPaymentRequest } from '../../Models/IRequest' export default class SEPA extends PayablePaymentMethod { - protected _paymentName = 'SepaDirectDebit' - protected _serviceVersion = 1 - + protected _paymentName = 'SEPA' pay(payload: IPay) { - return super.pay(payload) - } - refund(payload: RefundPayload) { - return super.refund(payload) + return super.pay(payload, new Pay(payload)) } authorize(payload: IPay) { - this.action = 'Authorize' - return super.transactionRequest(payload) + this.setPayPayload(payload) + this.setServiceList('Authorize', new Pay(payload)) + return this.transactionRequest() } - payRecurrent(payload: Pick & ICapture) { - this.action = 'PayRecurrent' - return super.transactionRequest(payload) + payRecurrent(payload: Pick & IPaymentRequest) { + this.setPayPayload(payload) + this.setServiceList('PayRecurrent', new Pay(payload)) + return this.transactionRequest() } extraInfo(payload: IExtraInfo) { - this.action = 'Pay,ExtraInfo' - return super.transactionRequest(payload) + this.setPayPayload(payload) + this.setServiceList('Pay,ExtraInfo', new Pay(payload)) + return this.transactionRequest() } payWithEmandate(payload: IEmandate) { - this.action = 'PayWithEmandate' payload.invoice = payload.invoice || uniqid() - return super.transactionRequest(payload) + this.setPayPayload(payload) + this.setServiceList('PayWithEmandate', new Pay(payload)) + return this.transactionRequest() } } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 101e4677..3be20dd9 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,18 +1,17 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' export default class Sofort extends PayablePaymentMethod { - protected _paymentName = 'sofortueberweisung' - protected _serviceVersion = 1 + protected _paymentName = 'Sofort' - pay(payload: Payload) { + pay(payload: IPaymentRequest) { return super.pay(payload) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } - instantRefund(payload: RefundPayload){ - this.action = 'InstantRefund' - return super.refund(payload) + instantRefund(payload: IRefundRequest) { + this.setServiceList('InstantRefund') + return this.transactionRequest(payload) } } diff --git a/src/PaymentMethods/Subscriptions/Models/Company.ts b/src/PaymentMethods/Subscriptions/Models/Company.ts new file mode 100644 index 00000000..31fbef92 --- /dev/null +++ b/src/PaymentMethods/Subscriptions/Models/Company.ts @@ -0,0 +1,7 @@ +import { Company as CompanyClass } from '../../../Models/Interfaces/IRecipient' + +export default class Company extends CompanyClass { + set companyName(companyName: string) { + this.set('name', companyName) + } +} diff --git a/src/PaymentMethods/Subscriptions/Models/Configuration.ts b/src/PaymentMethods/Subscriptions/Models/Configuration.ts index 1d7b56d3..7b20fdda 100644 --- a/src/PaymentMethods/Subscriptions/Models/Configuration.ts +++ b/src/PaymentMethods/Subscriptions/Models/Configuration.ts @@ -1,3 +1,5 @@ +import { Model } from '../../../Models/Model' + export type IConfiguration = { name?: string schemeKey?: string @@ -8,3 +10,34 @@ export type IConfiguration = { generateInvoiceSpecification?: boolean skipPayPerEmail?: boolean } +export class Configuration extends Model implements IConfiguration { + set name(value: string) { + this.set('name', value) + } + set schemeKey(value: string) { + this.set('schemeKey', value) + } + set invoiceNumberPrefix(value: string) { + this.set('invoiceNumberPrefix', value) + } + + set invoiceDescriptionFormat(value: string) { + this.set('invoiceDescriptionFormat', value) + } + + set dueDateDays(value: number) { + this.set('dueDateDays', value) + } + + set allowedServices(value: string) { + this.set('allowedServices', value) + } + + set generateInvoiceSpecification(value: boolean) { + this.set('generateInvoiceSpecification', value) + } + + set skipPayPerEmail(value: boolean) { + this.set('skipPayPerEmail', value) + } +} diff --git a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts index 42eab0ed..0798db1b 100644 --- a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts @@ -1,53 +1,148 @@ -import IPhone from '../../../Models/Services/IPhone' -import IAddress from '../../../Models/Services/IAddress' -import { IRatePlan, IRatePlanCharge } from './RatePlan' -import { IConfiguration } from './Configuration' -import { ServiceParameters } from '../../../Utils/Types' +import IPhone, { Phone } from '../../../Models/Interfaces/IPhone' +import IAddress, { Address } from '../../../Models/Interfaces/IAddress' +import { IRatePlan, IRatePlans, RatePlan } from './RatePlan' +import { IRatePlanCharge, IRatePlanCharges, RatePlanCharge } from './RatePlanCharge' +import { Configuration, IConfiguration } from './Configuration' +import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters' +import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import Company from './Company' +import IDebtor from '../../../Models/Interfaces/IDebtor' +import IBankAccount, { BankAccount } from '../../../Models/Interfaces/IBankAccount' -type Person = { - firstName: string - lastName: string - birthDate: string - gender: string - culture?: string -} -type Company = { - name: string - culture?: string - vatApplicable: boolean - vatNumber: string - chamberOfCommerce: string -} - -export interface ISubscription extends ServiceParameters { - address?: IAddress +export interface ISubscription extends IRequest { + address?: Partial allowedServices?: string b2b?: string billingTiming?: number - company?:Company - addConfiguration?: IConfiguration + company?: Partial + configuration?: IConfiguration configurationCode?: string customerAccountName?: string customerBIC?: string customerIBAN?: string - customerNumberOfDays?: string - debtor?: { - code: string - } - email?: { - email: string - } + debtor?: IDebtor + email?: string includeTransaction?: boolean - fieldName?: string mandateReference?: string - person?: Person + person?: Partial phone?: Partial - ratePlan?: IRatePlan - ratePlanCharge?: IRatePlanCharge subscriptionGuid?: string termStartDay?: number termStartMonth?: number termStartWeek?: string transactionVatPercentage?: number - tokenPaymentMethod?: string + ratePlans?: IRatePlans + ratePlanCharges?: IRatePlanCharges + bankAccount?: IBankAccount +} + +export class Subscription extends ServiceParameter implements ISubscription { + getGroups() { + return super.getGroups({ + Debtor: 'Debtor', + Person: 'Person', + Email: 'Email', + Address: 'Address', + AddRatePlan: 'AddRatePlan', + Configuration: 'AddConfiguration', + UpdateRatePlan: 'UpdateRatePlan', + DisableRatePlan: 'DisableRatePlan', + AddRatePlanCharge: 'AddRatePlanCharge', + UpdateRatePlanCharge: 'UpdateRatePlanCharge', + DisableRatePlanCharge: 'DisableRatePlanCharge' + }) + } + set configurationCode(configurationCode: string) { + this.set('configurationCode', configurationCode) + } + set includeTransaction(includeTransaction: boolean) { + this.set('includeTransaction', includeTransaction) + } + set transactionVatPercentage(transactionVatPercentage: number) { + this.set('transactionVatPercentage', transactionVatPercentage) + } + set subscriptionGuid(value: string) { + this.set('subscriptionGuid', value) + } + set termStartDay(value: number) { + this.set('termStartDay', value) + } + set termStartMonth(value: number) { + this.set('termStartMonth', value) + } + set billingTiming(value: number) { + this.set('billingTiming', value) + } + set termStartWeek(value: string) { + this.set('termStartWeek', value) + } + set b2b(value: string) { + this.set('b2b', value) + } + set mandateReference(value: string) { + this.set('mandateReference', value) + } + set allowedServices(value: string) { + this.set('allowedServices', value) + } + set debtor(value: IDebtor) { + this.set('debtor', value) + } + set bankAccount(value: IBankAccount) { + this.set('bankAccount', new BankAccount(value)) + } + set email(value: string) { + this.set('email', value) + } + set phone(value: IPhone) { + this.set('phone', new Phone(value)) + } + set address(value: IAddress) { + this.set('address', new Address(value)) + } + set person(value: IPerson) { + this.set('person', new Person(value)) + } + set company(value: ICompany) { + this.set('company', new Company(value)) + } + set configuration(value: Configuration) { + this.set('configuration', new Configuration(value)) + } + protected set addRatePlan(value: IRatePlan) { + this.set('addRatePlan', new RatePlan(value)) + } + protected set updateRatePlan(value: IRatePlan) { + this.set('updateRatePlan', new RatePlan(value)) + } + protected set disableRatePlan(value: IRatePlan) { + this.set('disableRatePlan', new RatePlan(value)) + } + protected set addRatePlanCharge(value: IRatePlanCharge) { + this.set('addRatePlanCharge', new RatePlanCharge(value)) + } + set ratePlans(value: IRatePlans) { + for (const key in value) { + if (this.has(key + 'RatePlan')) { + this[key + 'RatePlan'] = value[key] + } + } + } + set ratePlanCharges(value: IRatePlanCharges) { + for (const key in value) { + if (this.has(key + 'RatePlanCharge')) { + this[key + 'RatePlanCharge'] = value[key] + } + } + } + set customerIBAN(value: string) { + this.set('customerIBAN', value) + } + set customerAccountName(value: string) { + this.set('customerAccountName', value) + } + set customerBIC(value: string) { + this.set('customerBIC', value) + } } diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts index 5a7b5c6c..ad6769c5 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts @@ -1,68 +1,83 @@ -type update = { - update: { - startDate: string - endDate?: string - ratePlanGuid: string - } +import { Model } from '../../../Models/Model' + +export interface IRatePlans { + add?: IRatePlan + update?: IRatePlan + disable?: IRatePlan } -type disable = { - disable: { - ratePlanGuid: string - } +export interface IRatePlan { + type?: string + ratePlanGuid?: string + ratePlanCode?: string + startDate?: string + endDate?: string + ratePlanName?: string + ratePlanDescription?: string + currency?: string + billingTiming?: number + automaticTerm?: boolean + billingInterval?: string + customNumberOfDays?: number + termStartDay?: number + termStartWeek?: string + termStartMonth?: string + trialPeriodDays?: number + trialPeriodMonth?: string + inheritPaymentMethod?: boolean } -type add = { - add: { - startDate: string - ratePlanCode?: string - endDate?: string - ratePlanName?: string - ratePlanDescription?: string - currency?: string - billingTiming?: number - automaticTerm?: boolean - billingInterval?: string - customNumberOfDays?: number - termStartDay?: number - termStartWeek?: number - termStartMonth?: number - trialPeriodDays?: number - trialPeriodMonths?: number - inheritPaymentMethod?: boolean +export class RatePlan extends Model implements IRatePlan { + set type(value: string) { + this.set('type', value) } -} - -export type IRatePlan = add | update | disable - -type addCharge = { - add: { - ratePlanChargeCode?: string - ratePlanChargeName?: string - ratePlanChargeProductId?: string - ratePlanChargeDescription?: string - unitOfMeasure?: string - ratePlanChargeType?: string - baseNumberOfUnits?: number - partialBilling?: string - pricePerUnit?: number - priceIncludesVat?: boolean - vatPercentage?: number - b2B?: boolean + set ratePlanGuid(value: string) { + this.set('ratePlanGuid', value) } -} -type updateCharge = { - update: { - ratePlanChargeCode?: string - vatPercentage?: number - ratePlanChargeGuid?: string - baseNumberOfUnits?: string | number - pricePerUnit?: number - priceIncludesVat?: boolean + set ratePlanCode(value: string) { + this.set('ratePlanCode', value) } -} -type disableCharge = { - disable: { - ratePlanChargeGuid?: string + set startDate(value: string) { + this.set('startDate', value) + } + set endDate(value: string) { + this.set('endDate', value) + } + set ratePlanName(value: string) { + this.set('ratePlanName', value) + } + set ratePlanDescription(value: string) { + this.set('ratePlanDescription', value) + } + set currency(value: string) { + this.set('currency', value) + } + set billingTiming(value: number) { + this.set('billingTiming', value) + } + set automaticTerm(value: boolean) { + this.set('automaticTerm', value) + } + set billingInterval(value: string) { + this.set('billingInterval', value) + } + set customNumberOfDays(value: number) { + this.set('customNumberOfDays', value) + } + set termStartDay(value: number) { + this.set('termStartDay', value) + } + set termStartWeek(value: string) { + this.set('termStartWeek', value) + } + set termStartMonth(value: string) { + this.set('termStartMonth', value) + } + set trialPeriodDays(value: number) { + this.set('trialPeriodDays', value) + } + set trialPeriodMonth(value: string) { + this.set('trialPeriodMonth', value) + } + set inheritPaymentMethod(value: boolean) { + this.set('inheritPaymentMethod', value) } } - -export type IRatePlanCharge = addCharge | updateCharge | disableCharge diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts new file mode 100644 index 00000000..f822c246 --- /dev/null +++ b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts @@ -0,0 +1,59 @@ +import { Model } from '../../../Models/Model' + +export interface IRatePlanCharge { + ratePlanChargeCode?: string + ratePlanChargeName?: string + ratePlanChargeProductId?: string + ratePlanChargeDescription?: string + unitOfMeasure?: string + baseNumberOfUnits?: number + partialBilling?: string + pricePerUnit?: number + priceIncludesVat?: boolean + vatPercentage?: number + b2b?: string + ratePlanChargeType?: string +} +export interface IRatePlanCharges { + add?: IRatePlanCharge + update?: IRatePlanCharge + disable?: IRatePlanCharge +} +export class RatePlanCharge extends Model implements IRatePlanCharge { + set ratePlanChargeCode(value: string) { + this.set('ratePlanChargeCode', value) + } + set ratePlanChargeName(value: string) { + this.set('ratePlanChargeName', value) + } + set ratePlanChargeProductId(value: string) { + this.set('rateplanChargeProductId', value) + } + set ratePlanChargeDescription(value: string) { + this.set('rateplanChargeDescription', value) + } + set unitOfMeasure(value: string) { + this.set('unitOfMeasure', value) + } + set baseNumberOfUnits(value: number) { + this.set('baseNumberOfUnits', value) + } + set partialBilling(value: string) { + this.set('partialBilling', value) + } + set pricePerUnit(value: number) { + this.set('pricePerUnit', value) + } + set priceIncludesVat(value: boolean) { + this.set('priceIncludesVat', value) + } + set vatPercentage(value: number) { + this.set('vatPercentage', value) + } + set b2b(value: string) { + this.set('b2B', value) + } + set ratePlanChargeType(value: string) { + this.set('ratePlanChargeType', value) + } +} diff --git a/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts b/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts new file mode 100644 index 00000000..5dfcc542 --- /dev/null +++ b/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts @@ -0,0 +1,7 @@ +import { Subscription } from './ISubscription' + +export class ResumeSubscription extends Subscription { + set resumeDate(resumeDate: string) { + this.set('resumeDate', resumeDate) + } +} diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 53524d9e..f51c92a8 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -1,54 +1,54 @@ -import { ISubscription } from './Models/ISubscription' -import { IConfig } from '../../Utils/Types' +import { ISubscription, Subscription } from './Models/ISubscription' import PaymentMethod from '../PaymentMethod' +import IRequest from '../../Models/IRequest' +import { ResumeSubscription } from './Models/ResumeSubscription' export default class Subscriptions extends PaymentMethod { protected _paymentName = 'Subscriptions' - protected _requiredFields: Array = ['currency'] + protected _serviceVersion = 1 - _serviceVersion = 1 - create(payload: ISubscription): Promise { - this.action = 'CreateSubscription' - return this.dataRequest(payload) + protected setRequiredFields(requiredFields: Array = []) { + return super.setRequiredFields(['currency']) + } + create(payload: ISubscription) { + this.setPayload(payload) + this.setServiceList('CreateSubscription', new Subscription(payload)) + return this.dataRequest() } update(payload: ISubscription) { - this.action = 'UpdateSubscription' - return this.dataRequest(payload) + this.setPayload(payload) + this.setServiceList('UpdateSubscription', new Subscription(payload)) + return this.dataRequest() } createCombined(payload: ISubscription) { - this.action = 'CreateCombinedSubscription' - this.setRequest(payload) - return this + this.setPayload(payload) + this.setServiceList('CreateCombinedSubscription', new Subscription(payload)) + return this.dataRequest() } updateCombined(payload: ISubscription) { - this.action = 'UpdateCombinedSubscription' - this._request.data.startRecurrent = true - this.setRequest(payload) - return this + this.setPayload(payload) + this.setServiceList('UpdateCombinedSubscription', new Subscription(payload)) + return this.dataRequest() } stop(payload: { subscriptionGuid: string }) { - this.action = 'StopSubscription' - return this.dataRequest(payload) + this.setServiceList('StopSubscription', new Subscription(payload)) + return this.dataRequest() } info(payload: { subscriptionGuid: string }) { - this.action = 'SubscriptionInfo' - - return this.dataRequest(payload) + this.setServiceList('StopSubscription', new Subscription(payload)) + return this.dataRequest() } deletePaymentConfig(payload: { subscriptionGuid: string }) { - this.action = 'DeletePaymentConfiguration' - - return this.dataRequest(payload) + this.setServiceList('DeletePaymentConfiguration', new Subscription(payload)) + return this.dataRequest() } pause(payload: { subscriptionGuid: string; resumeDate: string }) { - this.action = 'PauseSubscription' - - return this.dataRequest(payload) + this.setServiceList('PauseSubscription', new ResumeSubscription(payload)) + return this.dataRequest() } resume(payload: { subscriptionGuid: string; resumeDate: string }) { - this.action = 'ResumeSubscription' - - return this.dataRequest(payload) + this.setServiceList('ResumeSubscription', new ResumeSubscription(payload)) + return this.dataRequest() } } diff --git a/src/PaymentMethods/Surepay/Models/Verify.ts b/src/PaymentMethods/Surepay/Models/Verify.ts index cd34962c..76c6df9a 100644 --- a/src/PaymentMethods/Surepay/Models/Verify.ts +++ b/src/PaymentMethods/Surepay/Models/Verify.ts @@ -1,5 +1,5 @@ -import { ITransaction } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' -export interface IVerify extends ITransaction { - customeraccountname: 'string' +export interface IVerify extends IPaymentRequest { + customeraccountname: string } diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 0368e1d5..4d649707 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,11 +1,13 @@ import PaymentMethod from '../PaymentMethod' import { IVerify } from './Models/Verify' - +import { ServiceParameter } from '../../Models/ServiceParameters' export default class Surepay extends PaymentMethod { - protected _paymentName = 'surepay' - _requiredFields = [] + protected _paymentName = 'Surepay' verify(payload: IVerify) { - this.action = 'verify' + this.setServiceList( + 'Verify', + new ServiceParameter().set('customeraccountname', payload.customeraccountname) + ) return this.dataRequest(payload) } } diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index d92c5ba3..93cb09f4 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -1,23 +1,23 @@ -import PaymentMethod from "../PaymentMethod"; -import { ICapture, ITransaction, Payload } from "../../Models/ITransaction"; +import PaymentMethod from '../PaymentMethod' +import IRequest from '../../Models/IRequest' +type key = Required> export default class Thunes extends PaymentMethod { - protected _paymentName = "thunes"; - - getStatus(payload: Required>) { - this.action = 'getStatus' - return this.dataRequest(payload) + protected _paymentName = 'Thunes' + getStatus(payload: key) { + this.setServiceList('getStatus') + return this.dataRequest(payload) } - capture(payload:ICapture) { - this.action = 'capture' - return this.transactionRequest(payload) + capture(payload: IRequest & key) { + this.setServiceList('Capture') + return this.transactionRequest(payload) } - authorize(payload:Payload) { - this.action = 'authorize' - return this.dataRequest(payload) + authorize(payload: IRequest) { + this.setServiceList('Authorize') + return this.dataRequest(payload) } - cancel(payload:Pick) { - this.action = 'cancel' - return this.dataRequest(payload) + cancel(payload: key) { + this.setServiceList('Cancel') + return this.dataRequest(payload) } -} \ No newline at end of file +} diff --git a/src/PaymentMethods/Tinka/Models/Pay.ts b/src/PaymentMethods/Tinka/Models/Pay.ts index f5293b2f..f24d0c46 100644 --- a/src/PaymentMethods/Tinka/Models/Pay.ts +++ b/src/PaymentMethods/Tinka/Models/Pay.ts @@ -1,8 +1,8 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' import { ITinkaArticle } from './Article' import { ITinkaAddress } from './Address' import Gender from '../../../Constants/Gender' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { paymentMethod: string deliveryMethod: string deliveryDate?: string diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index d29260a0..37061180 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,10 +1,9 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' import { IPay } from './Models/Pay' export default class Tinka extends PayablePaymentMethod { - protected _paymentName = 'tinka' - _serviceVersion = 1 + protected _paymentName = 'Tinka' pay(payload: IPay) { if (payload.billingCustomer) { // @ts-ignore @@ -12,7 +11,7 @@ export default class Tinka extends PayablePaymentMethod { } return super.pay(payload) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index e8668393..a84c98f6 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -1,6 +1,6 @@ -import { Payload } from '../../../Models/ITransaction' +import { IPaymentRequest } from '../../../Models/IRequest' -export interface IPay extends Payload { +export interface IPay extends IPaymentRequest { customerCountryCode: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB' customerFirstName: string customerLastName: string diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 95199de1..28d7b5f9 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,15 +1,13 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest } from '../../Models/IRequest' import { IPay } from './Models/Pay' export default class Trustly extends PayablePaymentMethod { protected _paymentName = 'Trustly' - protected _serviceVersion = 1 - pay(payload: IPay) { return super.pay(payload) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 80bbf0ca..7559578e 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,16 +1,15 @@ -import { PayablePaymentMethod } from '../PayablePaymentMethod' -import { Payload, RefundPayload } from '../../Models/ITransaction' +import PayablePaymentMethod from '../PayablePaymentMethod' +import { IRefundRequest, IPaymentRequest } from '../../Models/IRequest' -interface IPay extends Payload { +interface IPay extends IPaymentRequest { locale: 'en-US' | 'zh-CN' | 'zh-TW' } -export default class Wechatpay extends PayablePaymentMethod { - protected _paymentName = 'wechatpay' - +export default class WeChatPay extends PayablePaymentMethod { + protected _paymentName = 'WeChatPay' pay(payload: IPay) { return super.pay(payload) } - refund(payload: RefundPayload) { + refund(payload: IRefundRequest) { return super.refund(payload) } } diff --git a/src/PaymentMethods/iDealQR/Models/Generate.ts b/src/PaymentMethods/iDealQR/Models/Generate.ts deleted file mode 100644 index 7dcd28d7..00000000 --- a/src/PaymentMethods/iDealQR/Models/Generate.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Payload } from '../../../Models/ITransaction' - -export interface Generate extends Payload { - amount: number - amountIsChangeable: boolean - purchaseId: string - Description: string - isOneOff: boolean - expiration: string - isProcessing?: boolean - minAmount: number - maxAmount: number - imageSize: number -} diff --git a/src/PaymentMethods/iDealQR/index.ts b/src/PaymentMethods/iDealQR/index.ts deleted file mode 100644 index b1033c54..00000000 --- a/src/PaymentMethods/iDealQR/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Generate } from './Models/Generate' -import PaymentMethod from '../PaymentMethod' - -export default class IdealQr extends PaymentMethod { - protected _paymentName = 'IdealQr' - generate(payload: Generate) { - this.action = 'generate' - - return this.dataRequest(payload) - } -} diff --git a/src/Request/BuckarooClient.ts b/src/Request/BuckarooClient.ts deleted file mode 100644 index 2405934e..00000000 --- a/src/Request/BuckarooClient.ts +++ /dev/null @@ -1,83 +0,0 @@ -import Endpoints, {RequestTypePaths} from '../Constants/Endpoints' -import {ITransaction} from '../Models/ITransaction' -import {IConfig, ICredentials} from '../Utils/Types' -import {SpecificationResponse, SpecificationsResponse} from '../Models/SpecificationResponse' -import {TransactionResponse} from '../Models/TransactionResponse' -import Headers from './Headers' -import HttpMethods from '../Constants/HttpMethods' -import HttpsClient, {HttpsRequestOptions} from "./HttpsClient"; -import {Hmac} from "./Hmac"; - -export class BuckarooClient { - private static _credentials: ICredentials - private static _config: IConfig - private _httpsClient: HttpsClient; - private readonly _headers: Headers = new Headers() - private _hmac :Hmac - private _requestUrl:URL; - - private constructor() { - this._requestUrl = new URL(this.modeUrl) - this._httpsClient = new HttpsClient(this._requestUrl); - - this._hmac = new Hmac(this._httpsClient.options,this._requestUrl); - } - get modeUrl(): Endpoints { - return BuckarooClient._config.mode == 'test' ? Endpoints.TEST : Endpoints.LIVE - } - static initialize(credentials: ICredentials, config: IConfig ) { - - this._credentials = credentials - this._config = { - mode: 'test', - currency: 'EUR', - ...config, - } - return new BuckarooClient() - } - get requestHeaders(): Headers { - return this._headers - } - get requestOptions(): HttpsRequestOptions { - return this._httpsClient.options - } - getCredentials = (): ICredentials => { - return BuckarooClient._credentials - } - getConfig = (): IConfig => { - return BuckarooClient._config - } - private transactionRequestUrl(path:string = ''):string { - return RequestTypePaths.Transaction + path - } - private dataRequestUrl(path:string = ''):string { - return RequestTypePaths.Data + path - } - - request(method,path,data: object = {}): Promise { - this.requestOptions.method = method - this.requestOptions.path = path - - this.requestHeaders.setAuthHeader(this._hmac.createHmacHeader(this.getCredentials())) - return this._httpsClient.request(data) - } - - transactionRequest(data: ITransaction): Promise { - return this.request(HttpMethods.METHOD_POST,this.transactionRequestUrl(),data) - } - dataRequest(data: object): Promise { - return this.request(HttpMethods.METHOD_GET,this.dataRequestUrl(),data) - } - status(transactionKey: string) { - return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/Status/${transactionKey}`)) - } - cancelInfo(transactionKey: string) { - return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/Cancel/${transactionKey}`)) - } - refundInfo(transactionKey: string) { - return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/RefundInfo/${transactionKey}`)) - } - invoiceInfo(invoiceKey: string) { - return this.request(HttpMethods.METHOD_GET,this.transactionRequestUrl(`/InvoiceInfo/${invoiceKey}`)) - } -} diff --git a/src/Request/DataModels.ts b/src/Request/DataModels.ts new file mode 100644 index 00000000..93709518 --- /dev/null +++ b/src/Request/DataModels.ts @@ -0,0 +1,124 @@ +import IRequest from '../Models/IRequest' +import { Model } from '../Models/Model' +import { ClientIP } from '../Constants/IPProtocolVersion' +import { DataFormatter } from '../Utils/Functions' +import { ServiceCode } from '../Utils/MethodTypes' +import { IService, ServiceList } from '../Models/IServiceList' +import { IAdditionalParameters } from '../Models/IParameters' + +export class TransactionData extends Model implements IRequest { + constructor(data?: IRequest) { + super(data) + } + set clientUserAgent(value: string) { + this.set('clientUserAgent', value) + } + set order(order: string) { + this.set('order', order) + } + set invoice(invoice: string) { + this.set('invoice', invoice) + } + set description(description: string) { + this.set('description', description) + } + set amountCredit(amountCredit: number) { + this.set('amountCredit', amountCredit) + } + set amountDebit(amountDebit: number) { + this.set('amountDebit', amountDebit) + } + set currency(currency: string) { + this.set('currency', currency) + } + set clientIP(ipAddress: string) { + this.set('clientIP', new ClientIP(ipAddress)) + } + set additionalParameters(value: IAdditionalParameters) { + this.set('additionalParameters', { + AdditionalParameter: DataFormatter.parametersMap(value) + }) + } + set customParameters(value: IAdditionalParameters) { + this.set('customParameters', { + List: DataFormatter.parametersMap(value) + }) + } + set pushURL(pushURL: string) { + this.set('pushURL', pushURL) + } + set continueOnIncomplete(value: boolean) { + this.set('continueOnIncomplete', value ? 1 : 0) + } + set culture(value: string) { + this.set('culture', value) + } + set originalTransactionKey(value: string) { + this.set('originalTransactionKey', value) + } + set originalTransactionReference(value: { type: string; reference: string }) { + this.set('originalTransactionReference', value) + } + set pushURLFailure(value: string) { + this.set('pushURLFailure', value) + } + set returnURL(value: string) { + this.set('returnURL', value) + } + set returnURLCancel(value: string) { + this.set('returnURLCancel', value) + } + set returnURLError(value: string) { + this.set('returnURLError', value) + } + set returnURLReject(value: string) { + this.set('returnURLReject', value) + } + set servicesExcludedForClient(services: ServiceCode[] | string) { + this.set( + 'servicesExcludedForClient', + Array.isArray(services) ? services?.join(',') : services + ) + } + get servicesSelectableByClient() { + return '' + } + set servicesSelectableByClient(services: ServiceCode[] | string) { + this.set( + 'servicesSelectableByClient', + Array.isArray(services) ? services?.join(',') : services + ) + } + set startRecurrent(value: boolean) { + this.set('startRecurrent', value) + } + getServiceList(): ServiceList { + return this.get('services') + } + setServiceList(services: ServiceList) { + return this.set('services', services) + } +} +export class DataRequestData extends TransactionData { + set additionalParameters(parameters: IAdditionalParameters) { + this.set('additionalParameters', { + List: DataFormatter.parametersMap(parameters) + }) + } +} +export class SpecificationRequestData extends Model { + constructor(data?: IService[]) { + super({ services: data }) + } + set services(data: IService[]) { + this.set( + 'services', + data.map((service) => { + return { + Name: service.name, + Version: service.version + } + }) + ) + } +} diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index eb036345..2c26ed1d 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,7 +1,4 @@ -import { Hmac } from './Hmac' -import HttpMethods from "../Constants/HttpMethods"; -import {BuckarooClient} from "./BuckarooClient"; - +import { OutgoingHttpHeaders } from 'http' export type RequestHeaders = { 'Content-type'?: string @@ -9,54 +6,57 @@ export type RequestHeaders = { Culture?: string Authorization?: string Software?: string -} & { [key: string]: string } +} & OutgoingHttpHeaders export default class Headers { - private readonly _headers:RequestHeaders = this.getDefaultHeaders(); - constructor() { - this.setSoftwareHeader() - } - getHeaders():RequestHeaders { + private _headers: RequestHeaders = this.getDefaultHeaders() + get headers(): RequestHeaders { return this._headers } - getDefaultHeaders() { - return { - 'Content-type': 'application/json', + protected getDefaultHeaders() { + return { + 'Content-type': 'application/json; charset=utf-8', Accept: 'application/json', Culture: 'nl-NL', - Authorization: '' + Authorization: '', + Channel: 'Web', + Software: JSON.stringify({ + PlatformName: 'Node SDK', + PlatformVersion: '1.0', + ModuleSupplier: 'Buckaroo', + ModuleName: 'BuckarooPayments', + ModuleVersion: '1.0' + }) } } - setSoftwareHeader(value: { - PlatformName?:string, - PlatformVersion?:string, - ModuleSupplier?:string, - ModuleName?:string, - ModuleVersion?:string - } = {}):this { - + setSoftwareHeader( + value: { + platformName?: string + platformVersion?: string + moduleSupplier?: string + moduleName?: string + moduleVersion?: string + } = {} + ): this { this._headers.Software = JSON.stringify({ - PlatformName: 'Node SDK', - PlatformVersion: '1.0', - ModuleSupplier: 'Buckaroo', - ModuleName: 'BuckarooPayments', - ModuleVersion: '1.0', - ...value + PlatformName: value.platformName || 'Node SDK', + PlatformVersion: value.platformVersion || '1.0', + ModuleSupplier: value.moduleSupplier || 'Buckaroo', + ModuleName: value.moduleName || 'BuckarooPayments', + ModuleVersion: value.moduleVersion || '1.0' }) - return this; + return this } - addHeaders(headers: RequestHeaders) { + setHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { this._headers[key] = headers[key] }) + return this } removeHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { delete this._headers[key] }) - } - setAuthHeader(hmacHeader:string):this { - this._headers.Authorization = hmacHeader - return this; + return this } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 384db898..52b6fc8d 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -1,82 +1,91 @@ +import { ICredentials } from '../Utils/Types' import md5 from 'crypto-js/md5' import hmacSHA256 from 'crypto-js/hmac-sha256' import Base64 from 'crypto-js/enc-base64' -import HttpMethods from '../Constants/HttpMethods' -import {ICredentials} from "../Utils/Types"; +import crypto from 'crypto' export class Hmac { - data: string | object - url: URL - nonce: string - time: string - method: string - constructor( - method: HttpMethods, - url: URL, - data: string | object = '', - nonce?: string, - time?: string - ) { - this.method = method - this.url = url - this.data = data - this.nonce = nonce || '' - this.time = time || '' + protected _data?: object + protected _url?: URL + protected _nonce?: string + protected _time?: string + protected _method?: string + + get nonce(): string { + return this._nonce || 'nonce_' + Math.floor(Math.random() * 9999999 + 1) } - setNonce(nonce?:string):void { - this.nonce = nonce? nonce : 'nonce_' + Math.floor(Math.random() * 9999999 + 1) + set nonce(nonce: string) { + this._nonce = nonce } - setTime(time?:Date):string { - return time? - String(Math.round(Date.parse(time.toISOString()) / 1000)): - String(Math.round(Date.now() / 1000)) + get time(): string { + return this._time || String(Math.round(Date.now() / 1000)) } - createHmacHeader(credentials: ICredentials):string { - this.setNonce() - this.setTime() - return this.getHmacHeader(credentials.websiteKey, credentials.secretKey) + set time(time: string) { + this._time = time } - getUrlFormat() { - let urlFormatted = '' - if (this.url instanceof URL) { - urlFormatted = this.url.host + this.url.pathname + this.url.search - urlFormatted = urlFormatted.replace(/^[^:/.]*[:/]+/i, '') - urlFormatted = encodeURIComponent(urlFormatted).toLowerCase() || '' - return urlFormatted - } - throw new Error('Url is not a string or URL object') + get method(): string { + return this._method || 'POST' + } + set method(method: string) { + this._method = method + } + get url(): string | undefined { + if (this._url) + return encodeURIComponent( + this._url.href + .replace(this._url.protocol, '') + .replace(/^[^:/.]*[:/]+/i, '') + .replace(/(^\w+:|^)\/\//, '') + ).toLowerCase() + } + set url(url: string | undefined) { + if (url) this._url = new URL(url) } - getBase64Data() { - let base64Data = this.data - if (this.data) { - if (typeof base64Data === 'object') { - base64Data = JSON.stringify(base64Data) + get data(): string { + return this._data ? JSON.stringify(this._data) : '' + } + set data(data: string) { + try { + let jsonData = JSON.parse(data) + if (Object.keys(jsonData).length > 0) { + this._data = jsonData } - base64Data = Base64.stringify(md5(base64Data)) + } catch (e) {} + } + get base64Data() { + if (this._data) { + return Base64.stringify(md5(this.data)) } - return base64Data + return '' } - hashData(hashString: string,secretKey:string) { - return Base64.stringify(hmacSHA256(hashString, secretKey)) + generate(credentials: ICredentials, nonce?: string, time?: string): string { + this._nonce = nonce || this.nonce + this._time = time || this.time + let hashString = this.getHashString(credentials.websiteKey) + let hashData = this.hashData(hashString, credentials.secretKey) + return `hmac ${credentials.websiteKey}:${hashData}:${this._nonce}:${this._time}` } - getHashString(websiteKey:string) { - return ( - websiteKey + - this.method + - this.getUrlFormat() + - this.time + - this.nonce + - this.getBase64Data() - ) + validate( + credentials: ICredentials, + authHeader: string, + url: string, + data: string, + method: string + ): boolean { + let header = authHeader.split(':') + let providedHash = header[1] + this.nonce = header[2] + this.time = header[3] + this.method = method + this.url = url + this.data = data + let hash = this.hashData(this.getHashString(credentials.websiteKey), credentials.secretKey) + return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(providedHash)) } - getHmacHeader(websiteKey:string,secretKey:string) { - let hashString = this.getHashString(websiteKey) - - return ( - `hmac ` + - `${websiteKey}:${this.hashData(hashString,secretKey)}:${ - this.nonce - }:${this.time}` - ) + protected getHashString(websiteKey: string) { + return websiteKey + this.method + this.url + this.time + this.nonce + this.base64Data + } + protected hashData(hashString: string, secretKey: string) { + return hmacSHA256(hashString, secretKey).toString(Base64) } } diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index eb1e551b..a45196f0 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,59 +1,67 @@ -import {RequestOptions} from "https"; -import httpMethods from "../Constants/HttpMethods"; -import Headers, {RequestHeaders} from "./Headers"; -import Endpoints from "../Constants/Endpoints"; - -const https = require('https'); - -export type HttpsRequestOptions = RequestOptions - & { method: httpMethods,hostname:string,timeout:number ,headers:RequestHeaders} - +import { Agent, RequestOptions } from 'https' +import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse' +import { ReplyHandler } from '../Handlers/Reply/ReplyHandler' +import Buckaroo from '../index' +const https = require('https') +const defaultAgent = new https.Agent({ + keepAlive: true, + keepAliveMsecs: 10000 +}) export default class HttpsClient { - - private _client = https - - public options:HttpsRequestOptions - constructor(url:URL) { - this.options = { - method: httpMethods.METHOD_GET, - headers: new Headers().getHeaders(), - hostname: url.hostname, - timeout: 10000, - } + protected _options: RequestOptions = {} + constructor(agent?: Agent) { + this._options.timeout = 10000 + this._options.agent = agent || defaultAgent + this._options.sessionTimeout = 30000 } - get client(): any { - return this._client; - } - request(data:object): Promise { - + public sendRequest( + url: URL, + data: string, + options: RequestOptions = {}, + responseClass: R + ): Promise> { return new Promise((resolve, reject) => { - const req = this._client.request(this.options, res => { - let responseData:Array = []; - - res.on('data', chunk => { - responseData.push(chunk); - }); - + const req = https.request(url, { + ...this._options, + ...options + }) + req.on('error', (err) => { + reject(err) + }) + req.on('timeout', () => { + req.destroy() + }) + req.on('response', (res) => { + let response: any[] = [] + res.on('data', (chunk) => { + response.push(chunk) + }) res.on('end', () => { try { - resolve(JSON.parse(Buffer.concat(responseData).toString())); + let data = Buffer.concat(response).toString() + new ReplyHandler( + Buckaroo.Client.credentials, + data, + res.headers['authorization'], + url.toString(), + options.method + ).validate() + resolve(new responseClass(res, data) as InstanceType) } catch (e) { - reject(e); + try { + reject(Buffer.concat(response).toString()) + } catch (e) { + reject(e) + } + reject(e) } - }); - }).on('error', err => { - reject(err.message); - }).on('timeout', () => { - req.destroy(); - reject(new Error('Request timeout')); - }).on('close', () => { - req.destroy(); - reject(new Error('Request closed')); + }) }) - if(Object.keys(data).length > 0){ - req.write(JSON.stringify(data)); + if (data) { + req.write(data) } - req.end(); - }); + req.end() + return req + }) } } diff --git a/src/Request/Request.ts b/src/Request/Request.ts new file mode 100644 index 00000000..3ba09df1 --- /dev/null +++ b/src/Request/Request.ts @@ -0,0 +1,127 @@ +import Headers from './Headers' +import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse' +import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels' +import Buckaroo from '../index' +import Endpoints, { RequestTypes } from '../Constants/Endpoints' +import { TransactionResponse } from '../Models/Response/TransactionResponse' +import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse' +import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse' +import HttpMethods from '../Constants/HttpMethods' +import { RequestOptions } from 'https' +import PaymentMethod from '../PaymentMethods/PaymentMethod' +import { ICredentials } from '../Utils/Types' +import { Hmac } from './Hmac' +import { MethodFromServiceCode, ServiceCode } from '../Utils/MethodTypes' +import { IService } from '../Models/IServiceList' + +export default class Request< + HttpResponse extends HttpResponseConstructor = HttpResponseConstructor, + RequestData extends object | undefined = undefined +> extends Headers { + protected _data?: object | object[] | undefined + protected _httpMethod: HttpMethods + protected _path?: string + protected _responseHandler?: HttpResponseConstructor + constructor( + path?: string, + method?: HttpMethods, + data?: RequestData, + responseHandler?: HttpResponse + ) { + super() + this._path = path + this._data = data + this._httpMethod = method || HttpMethods.GET + this._responseHandler = responseHandler + } + get httpMethod(): HttpMethods { + return this._httpMethod + } + get data(): RequestData { + return this._data as any + } + get url(): URL { + return new URL(Endpoints[Buckaroo.Client.config.mode] + (this._path || '')) + } + protected get responseHandler(): HttpResponse { + return (this._responseHandler || HttpClientResponse) as HttpResponse + } + protected setAuthorizationHeader( + data: string, + credentials: ICredentials = Buckaroo.Client.credentials + ): this { + let hmac = new Hmac() + hmac.data = data + hmac.method = this.httpMethod + hmac.url = this.url.toString() + this.headers.Authorization = hmac.generate(credentials) + return this + } + request(options: RequestOptions = {}) { + let data = this._httpMethod === HttpMethods.GET ? '' : JSON.stringify(this._data) + this.setAuthorizationHeader(data) + return Buckaroo.Client.httpClient.sendRequest( + this.url, + data, + { + method: this._httpMethod, + headers: this.headers, + ...options + }, + this.responseHandler + ) + } + static Transaction(data?: TransactionData) { + return new Request(RequestTypes.Transaction, HttpMethods.POST, data, TransactionResponse) + } + static DataRequest(data?: DataRequestData) { + return new Request(RequestTypes.Data, HttpMethods.POST, data, TransactionResponse) + } + static Specification( + type: RequestTypes.Data | RequestTypes.Transaction, + data: IService[] | IService + ) { + if (Array.isArray(data)) { + return new Request( + type + `/Specifications`, + HttpMethods.POST, + new SpecificationRequestData(data), + SpecificationRequestResponse + ) + } + return new Request( + type + `/Specification/${data?.name}?serviceVersion=${data?.version}`, + HttpMethods.GET, + undefined, + SpecificationRequestResponse + ) + } + static BatchTransaction(data: TransactionData[] = []) { + return new Request( + RequestTypes.BatchTransaction, + HttpMethods.POST, + data, + BatchRequestResponse + ) + } + static BatchDataRequest(data: DataRequestData[] = []) { + return new Request(RequestTypes.BatchData, HttpMethods.POST, data, BatchRequestResponse) + } + combine( + method: Method + ): Method extends ServiceCode ? MethodFromServiceCode : Method + combine(request: R): this + combine(data): PaymentMethod | this { + if (!(data instanceof Request)) { + let paymentMethod: PaymentMethod = + data instanceof PaymentMethod ? data : Buckaroo.Client.method(data) + if (this.data instanceof TransactionData) { + paymentMethod.combine(this.data) + } + return paymentMethod + } else { + this._data = { ...this._data, ...data.data } + } + return this + } +} diff --git a/src/Request/Response.ts b/src/Request/Response.ts deleted file mode 100644 index f044678b..00000000 --- a/src/Request/Response.ts +++ /dev/null @@ -1,23 +0,0 @@ - -import { Hmac } from './Hmac' - -export class Response { - get data(): any { - return this._data - } - protected readonly _data: any - status: number - statusText: string - constructor(response) { - this.status = response.status - // this.config = response.config - this.statusText = response.statusText - this._data = response.data - } - // static validate(authorizationHeader: string, method: string, url: string, data?: object) { - // let authorization = authorizationHeader.split(':') - // let hmac = new Hmac(method, url, data, authorization[2], authorization[3]) - // let hash = hmac.hashData(hmac.getHashString()) - // return hash === authorization[1] - // } -} diff --git a/src/Services/TransactionService.ts b/src/Services/TransactionService.ts new file mode 100644 index 00000000..c4e5140c --- /dev/null +++ b/src/Services/TransactionService.ts @@ -0,0 +1,31 @@ +import Request from '../Request/Request' +import HttpMethods from '../Constants/HttpMethods' +import { TransactionResponse } from '../Models/Response/TransactionResponse' +import { RequestTypes } from '../Constants/Endpoints' + +export default class TransactionService { + private readonly _key: string + constructor(key: string) { + this._key = key + } + status() { + return new Request( + `${RequestTypes.Transaction}/Status/${this._key}`, + HttpMethods.GET, + undefined, + TransactionResponse + ).request() + } + refundInfo() { + return new Request( + `${RequestTypes.Transaction}/RefundInfo/${this._key}`, + HttpMethods.GET + ).request() + } + cancelInfo() { + return new Request( + `${RequestTypes.Transaction}/Cancel/${this._key}`, + HttpMethods.GET + ).request() + } +} diff --git a/src/Utils/Functions.ts b/src/Utils/Functions.ts index 48924654..1995cff0 100644 --- a/src/Utils/Functions.ts +++ b/src/Utils/Functions.ts @@ -1,13 +1,102 @@ +import { + IAdditionalParameters, + IFormattedParameter, + IParameter, + IServiceParameters, + ServiceParameterTypes +} from '../Models/IParameters' + export function uniqid(prefix: string = '', random: boolean = false) { const sec = Date.now() * 1000 + Math.random() * 1000 const id = sec.toString(16).replace(/\./g, '').padEnd(14, '0') return `${prefix}${id}${random ? `.${Math.trunc(Math.random() * 100000000)}` : ''}` } +export class Str { + private static replace(search: string[], replace: string, subject: string): string { + let result: string = subject + for (let value of search) { + result = result.split(value).join(replace) + } + return result + } + public static ucfirst(value: string): string { + return value.charAt(0).toUpperCase() + value.slice(1) + } + public static lcfirst(value: string): string { + return value.charAt(0).toLowerCase() + value.slice(1) + } + public static ciEquals(a: string, b: string) { + return a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0 + } +} +export abstract class DataFormatter { + static parametersMap( + parameters: IAdditionalParameters, + index1 = 'Name', + index2 = 'Value' + ): IFormattedParameter[] { + return Object.keys(parameters).map((key) => { + return { + [index1]: Str.ucfirst(key), + [index2]: parameters[key] + } + }) as any + } + static serviceParametersMap( + parameters: IServiceParameters | ServiceParameterTypes | undefined, + groups: { [key: string]: string } = {}, + countable: string[] = [], + parameter: IParameter = { name: '', value: '' }, + parametersArray: IParameter[] = [] + ): IParameter[] { + if (groups[parameter.name]) { + parameter.groupType = Str.ucfirst(groups[parameter.name]) + } + if (parameters instanceof Array) { + parameters.forEach((element) => { + if (countable.includes(parameter.name)) { + parameter.groupID = (parameter.groupID || 0) + 1 + } + this.serviceParametersMap( + element, + groups, + countable, + { ...parameter }, + parametersArray + ) + }) + } else if (typeof parameters === 'object') { + for (const key of Object.keys(parameters)) { + this.serviceParametersMap( + parameters[key], + groups, + countable, + { ...parameter, name: key }, + parametersArray + ) + } + } else if (parameters !== undefined) { + parametersArray.push({ ...parameter, value: parameters }) + } + return parametersArray + } -export function firstUpperCase(propertyName: string) { - return propertyName.charAt(0).toUpperCase() + propertyName.slice(1) + static parametersReverseMap(parameter: IFormattedParameter[] = []): IAdditionalParameters { + return parameter.reduce((total, currentValue) => { + return { ...total, [Str.lcfirst(currentValue.name)]: currentValue.value } + }, {}) + } } +export function getIPAddress() { + const interfaces = require('os').networkInterfaces() + for (const devName in interfaces) { + let iface = interfaces[devName] -export function firstLowerCase(propertyName: string) { - return propertyName.charAt(0).toLowerCase() + propertyName.slice(1) + for (let i = 0; i < iface.length; i++) { + let alias = iface[i] + if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) + return alias.address + } + } + return '0.0.0.0' } diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts new file mode 100644 index 00000000..efee4b52 --- /dev/null +++ b/src/Utils/MethodTypes.ts @@ -0,0 +1,200 @@ +import type Ideal from '../PaymentMethods/Ideal' +import type Afterpay from '../PaymentMethods/Afterpay' +import type AfterpayDigiAccept from '../PaymentMethods/AfterpayDigiAccept' +import type ApplePay from '../PaymentMethods/ApplePay' +import type Bancontact from '../PaymentMethods/Bancontact' +import type Banktransfer from '../PaymentMethods/BankTransfer' +import type Belfius from '../PaymentMethods/Belfius' +import type Billink from '../PaymentMethods/Billink' +import type BuckarooVoucher from '../PaymentMethods/BuckarooVoucher' +import type BuckarooWallet from '../PaymentMethods/BuckarooWallet' +import type CreditCard from '../PaymentMethods/CreditCard' +import type CreditClick from '../PaymentMethods/CreditClick' +import type CreditManagement from '../PaymentMethods/CreditManagement' +import type Emandates from '../PaymentMethods/Emandates' +import type EPS from '../PaymentMethods/EPS' +import type GiftCard from '../PaymentMethods/GiftCard' +import type Giropay from '../PaymentMethods/Giropay' +import type IdealQr from '../PaymentMethods/IdealQR' +import type Idin from '../PaymentMethods/Idin' +import type In3Old from '../PaymentMethods/In3Old' +import type KBC from '../PaymentMethods/KBC' +import type Klarna from '../PaymentMethods/Klarna' +import type KlarnaKp from '../PaymentMethods/KlarnaKP' +import type Marketplaces from '../PaymentMethods/Marketplaces' +import type Payconiq from '../PaymentMethods/Payconiq' +import type PayByBank from '../PaymentMethods/PayByBank' +import type Paypal from '../PaymentMethods/Paypal' +import type PayPerEmail from '../PaymentMethods/PayPerEmail' +import type PiM from '../PaymentMethods/PiM' +import type PointOfSale from '../PaymentMethods/PointOfSale' +import type Przelewy24 from '../PaymentMethods/Przelewy24' +import type SEPA from '../PaymentMethods/SEPA' +import type Sofort from '../PaymentMethods/Sofort' +import type Subscriptions from '../PaymentMethods/Subscriptions' +import type Surepay from '../PaymentMethods/Surepay' +import type Thunes from '../PaymentMethods/Thunes' +import type Tinka from '../PaymentMethods/Tinka' +import type Alipay from '../PaymentMethods/Alipay' +import type Trustly from '../PaymentMethods/Trustly' +import type Wechatpay from '../PaymentMethods/WeChatPay' +import type In3 from '../PaymentMethods/In3' + +export type AllMethods = readonly [ + { class: Afterpay; code: MethodTypes['Afterpay'] }, + { class: AfterpayDigiAccept; code: MethodTypes['AfterpayDigiAccept'] }, + { class: Alipay; code: MethodTypes['Alipay'] }, + { class: ApplePay; code: MethodTypes['ApplePay'] }, + { class: Bancontact; code: MethodTypes['Bancontact'] }, + { class: Banktransfer; code: MethodTypes['BankTransfer'] }, + { class: Belfius; code: MethodTypes['Belfius'] }, + { class: Billink; code: MethodTypes['Billink'] }, + { class: BuckarooVoucher; code: MethodTypes['BuckarooVoucher'] }, + { class: BuckarooWallet; code: MethodTypes['BuckarooWallet'] }, + { class: CreditCard; code: MethodTypes['CreditCard'] }, + { class: CreditClick; code: MethodTypes['CreditClick'] }, + { class: CreditManagement; code: MethodTypes['CreditManagement'] }, + { class: Emandates; code: MethodTypes['Emandates'] }, + { class: EPS; code: MethodTypes['EPS'] }, + { class: GiftCard; code: MethodTypes['GiftCard'] }, + { class: Giropay; code: MethodTypes['Giropay'] }, + { class: Ideal; code: MethodTypes['Ideal'] }, + { class: IdealQr; code: MethodTypes['IdealQR'] }, + { class: Idin; code: MethodTypes['Idin'] }, + { class: In3Old; code: MethodTypes['In3Old'] }, + { class: In3; code: MethodTypes['In3'] }, + { class: KBC; code: MethodTypes['KBC'] }, + { class: Klarna; code: MethodTypes['Klarna'] }, + { class: KlarnaKp; code: MethodTypes['KlarnaKP'] }, + { class: Marketplaces; code: MethodTypes['Marketplaces'] }, + { class: Payconiq; code: MethodTypes['Payconiq'] }, + { class: PayByBank; code: MethodTypes['PayByBank'] }, + { class: Paypal; code: MethodTypes['Paypal'] }, + { class: PayPerEmail; code: MethodTypes['PayPerEmail'] }, + { class: PiM; code: MethodTypes['PiM'] }, + { class: PointOfSale; code: MethodTypes['PointOfSale'] }, + { class: Przelewy24; code: MethodTypes['Przelewy24'] }, + { class: SEPA; code: MethodTypes['SEPA'] }, + { class: Sofort; code: MethodTypes['Sofort'] }, + { class: Subscriptions; code: MethodTypes['Subscriptions'] }, + { class: Surepay; code: MethodTypes['Surepay'] }, + { class: Thunes; code: MethodTypes['Thunes'] }, + { class: Tinka; code: MethodTypes['Tinka'] }, + { class: Trustly; code: MethodTypes['Trustly'] }, + { class: Wechatpay; code: MethodTypes['WeChatPay'] } +] +export type ServiceCode = AllMethods[number]['code'][number] + +export type MethodFromServiceCode< + Code extends ServiceCode, + Methods extends AllMethods[number] = AllMethods[number] +> = { + [Key in Methods['code'][number]]: Methods extends { + class: infer Class + code: readonly (infer Codes)[] + } + ? Extract extends never + ? never + : Class + : never +}[Code] + +export const Methods = { + Afterpay: ['afterpay'], + AfterpayDigiAccept: ['afterpaydigiaccept'], + Alipay: ['alipay'], + ApplePay: ['applepay'], + Bancontact: ['bancontactmrcash'], + BankTransfer: ['transfer'], + Belfius: ['belfius'], + Billink: ['billink'], + BuckarooVoucher: ['buckaroovoucher'], + BuckarooWallet: ['BuckarooWalletCollecting'], + CreditCard: [ + 'creditcard', + 'mastercard', + 'visa', + 'amex', + 'vpay', + 'maestro', + 'visaelectron', + 'cartebleuevisa', + 'cartebancaire', + 'dankort', + 'nexi', + 'postepay' + ], + CreditClick: ['creditclick'], + CreditManagement: ['CreditManagement3'], + Emandates: ['emandate'], + EPS: ['eps'], + GiftCard: [ + 'giftcard', + 'westlandbon', + 'babygiftcard', + 'babyparkgiftcard', + 'beautywellness', + 'boekenbon', + 'boekenvoordeel', + 'designshopsgiftcard', + 'fashioncheque', + 'fashionucadeaukaart', + 'fijncadeau', + 'koffiecadeau', + 'kokenzo', + 'kookcadeau', + 'nationaleentertainmentcard', + 'naturesgift', + 'podiumcadeaukaart', + 'shoesaccessories', + 'webshopgiftcard', + 'wijncadeau', + 'wonenzo', + 'yourgift', + 'vvvgiftcard', + 'parfumcadeaukaart' + ], + Giropay: ['giropay'], + IdealQR: ['idealqr'], + Idin: ['idin'], + In3Old: ['capayable'], + In3: ['In3'], + KBC: ['KBCPaymentButton'], + Klarna: ['klarna'], + Ideal: ['ideal', 'idealprocessing'], + Przelewy24: ['przelewy24'], + KlarnaKP: ['klarnakp'], + Marketplaces: ['Marketplaces'], + PayByBank: ['PayByBank'], + PayPerEmail: ['payperemail'], + Payconiq: ['payconiq'], + Paypal: ['paypal'], + PiM: ['PiM'], + PointOfSale: ['pointofsale'], + SEPA: ['sepadirectdebit'], + Sofort: ['sofortueberweisung'], + Subscriptions: ['subscriptions'], + Surepay: ['surepay'], + Thunes: ['thunes'], + Tinka: ['tinka'], + Trustly: ['trustly'], + WeChatPay: ['wechatpay'] +} as const + +type MethodTypes = typeof Methods +export default function getMethod( + code: Code +): MethodFromServiceCode { + let method: string | undefined + for (const key in Methods) { + if (Methods[key].includes(code)) { + method = key + break + } + } + if (!method) throw new Error(`Wrong payment method code has been given`) + + let methodClass = require(`../PaymentMethods/${method}`).default + + return new methodClass(code) +} diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 58ed4b82..0a362d74 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -1,10 +1,16 @@ +import { ServiceCode } from './MethodTypes' + export declare interface IConfig { - mode?: 'live' | 'test' - currency?: string - returnURL: string - returnURLCancel: string - pushURL: string - baseUrl: string + mode: Mode + currency: string + continueOnIncomplete?: 0 | 1 + returnURL?: string + returnURLCancel?: string + pushURL?: string + returnURLError?: string + returnURLReject?: string + activePaymentMethods?: ServiceCode[] + disabledPaymentMethods?: ServiceCode[] } export declare interface ICredentials { @@ -12,15 +18,4 @@ export declare interface ICredentials { secretKey: string } -export type IPAddress = { - address: string - type: number -} -export type ParameterTypes = string | number | boolean | undefined - -export declare type AdditionalParameter = { - [name: string]: ParameterTypes -} -export declare interface ServiceParameters { - [name: string]: ParameterTypes | ParameterTypes[] | ServiceParameters | ServiceParameters[] -} +export type Mode = 'LIVE' | 'TEST' diff --git a/src/index.ts b/src/index.ts index 04bb44ce..aafcb6fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,58 @@ import { IConfig, ICredentials } from './Utils/Types' -import { BuckarooClient } from './Request/BuckarooClient' - -export function initializeBuckarooClient(credentials: ICredentials, config: IConfig) { - return BuckarooClient.initialize(credentials, config) +import HttpsClient from './Request/HttpsClient' +import { Agent } from 'https' +import getMethod, { MethodFromServiceCode, ServiceCode } from './Utils/MethodTypes' +import Request from './Request/Request' +import NoService from './PaymentMethods/NoService' +import TransactionService from './Services/TransactionService' +import { Credentials } from './Handlers/Credentials' +export default class Buckaroo { + private readonly _credentials: Credentials + private _config: IConfig + private readonly _httpClient: HttpsClient + private static _client: Buckaroo + constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { + this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey) + this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) } + this._httpClient = new HttpsClient(agent) + } + static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent) { + this._client = new this(credentials, config, agent) + return this.Client + } + static get Client(): Buckaroo { + if (this._client) { + return this._client + } + throw new Error('Buckaroo client not initialized') + } + get credentials(): ICredentials { + return this._credentials + } + confirmCredentials() { + return this._credentials.confirm() + } + get config(): IConfig { + return { ...this._config } + } + set config(value: IConfig) { + this._config = value + } + get httpClient() { + return this._httpClient + } + transaction(key: string) { + return new TransactionService(key) + } + get batch() { + return Request.BatchTransaction + } + method(): NoService + method(name: Name): MethodFromServiceCode + method(name?: ServiceCode) { + if (!name) { + return new NoService() + } + return getMethod(name) + } } diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index fadb26c8..0b4d7c1c 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,17 +1,17 @@ -import { initializeBuckarooClient } from '../src' +import Buckaroo from '../src' require('dotenv').config() -const buckarooClientTest = initializeBuckarooClient( + +const buckarooClientTest = Buckaroo.InitializeClient( { secretKey: process.env.BPE_SECRET_KEY || '', websiteKey: process.env.BPE_WEBSITE_KEY || '' }, { - mode: process.env.BPE_MODE === 'live' ? 'live' : 'test', + mode: process.env.BPE_MODE === 'LIVE' ? 'LIVE' : 'TEST', currency: process.env.BPE_CURRENCY_CODE || 'EUR', returnURL: process.env.BPE_RETURN_URL || '', returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', - pushURL: process.env.BPE_PUSH_URL || '', - baseUrl: process.env.BPE_BASE_URL || '' + pushURL: process.env.BPE_PUSH_URL || '' } ) diff --git a/tests/Client.test.ts b/tests/Client.test.ts index 2da0643c..a1879a5b 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -1,20 +1,100 @@ -// @ts-ignore -import buckarooClientTest from './BuckarooClient.test' -import {Request} from "../src/Models/Request"; - - +import Buckaroo from '../src' +import { TransactionData } from '../src/Request/DataModels' +import { TransactionResponse } from '../src/Models/Response/TransactionResponse' +import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse' +import { uniqid } from '../src/Utils/Functions' +import {creditManagementTestInvoice} from "./PaymentMethods/CreditManagment.test"; +require('dotenv').config() +const client = Buckaroo.InitializeClient( + { + secretKey: process.env.BPE_SECRET_KEY || '', + websiteKey: process.env.BPE_WEBSITE_KEY || '' + }, + { + mode: process.env.BPE_MODE === 'LIVE' ? 'LIVE' : 'TEST', + currency: process.env.BPE_CURRENCY_CODE || 'EUR', + returnURL: process.env.BPE_RETURN_URL || '', + returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', + pushURL: process.env.BPE_PUSH_URL || '' + } +) describe('Testing Buckaroo Client', () => { - test('transactionRequest', async () => { + test('Credentials', async () => { + await client + .confirmCredentials() + .then((response) => { + expect(response).toBeTruthy() + }) + .catch((err) => { + expect(err).toBeUndefined() + }) + }) + test('Batch Transaction', async () => { + const transactionData: TransactionData[] = [] + for (let i = 0; i < 3; i++) { + let invoice = client + .method('CreditManagement3') + .createCombinedInvoice(creditManagementTestInvoice()) + .combine('sepadirectdebit') + .pay({ + invoice: uniqid(), + amountDebit: 10.1, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + collectdate: '2024-07-03', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + customer: { + name: 'John Smith' + } + }).data + transactionData.push(invoice) + } - const transactionRequest = new Request({}) - buckarooClientTest.request('POST', buckarooClientTest.transactionRequestUrl(), transactionRequest.data) + await client + .batch(transactionData) + .request() + .then((response) => { + expect(response).toBeTruthy() + }) + .catch((err) => { + expect(err).toBeUndefined() + }) + }) + describe('Transaction', () => { + const transactionService = client.transaction('39F3EC520A3F4A25B0A1899D4FF0E1CB') + test('Transaction Status', async () => { + await transactionService + .status() + .then((res) => { + expect(res instanceof TransactionResponse).toBeTruthy() + }) + .catch((err) => { + expect(err).toBeUndefined() + }) + }) + test('Transaction Cancel Info', async () => { + await transactionService + .cancelInfo() + .then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy() + }) + .catch((err) => { + expect(err).toBeUndefined() + }) + }) - await buckarooClientTest.transactionRequest(transactionRequest.data) - .then((data) => { - expect(data).toBeDefined() + test('Transaction Refund Info', async () => { + await transactionService + .refundInfo() + .then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy() + }) + .catch((err) => { + expect(err).toBeUndefined() + }) }) }) - }) diff --git a/tests/Models/index.ts b/tests/Models/index.ts new file mode 100644 index 00000000..3a924b37 --- /dev/null +++ b/tests/Models/index.ts @@ -0,0 +1,67 @@ +import { ICompany, IPerson } from '../../src/Models/Interfaces/IRecipient' +import { Address } from '../../src/Models/Interfaces/IAddress' +import IArticle from '../../src/Models/Interfaces/IArticle' +import { Phone } from '../../src/Models/Interfaces/IPhone' +import { BankAccount } from '../../src/Models/Interfaces/IBankAccount' +import RecipientCategory from '../../src/Constants/RecipientCategory' +import { getIPAddress } from '../../src/Utils/Functions' + +export const TestPerson: IPerson = { + birthDate: '1990-01-01', + category: RecipientCategory.PERSON, + culture: '321', + firstName: 'John', + gender: 'male', + initials: 'R.T', + lastName: 'Do', + lastNamePrefix: 'testlastprefix', + placeOfBirth: 't', + title: 'title' +} +export const TestCompany: ICompany = { + category: RecipientCategory.COMPANY, + careOf: 'test', + chamberOfCommerce: 'test', + companyName: 'testCompany', + culture: 'culture', + vatApplicable: false, + vatNumber: '321' +} +export const TestAddress = new Address({ + city: 'city', + country: 'NL', + houseNumber: '2313432', + houseNumberAdditional: '324', + state: 'state', + street: 'street', + zipcode: '32323' +}) +export const TestArticle: IArticle = { + description: 'test', + identifier: 'identifier', + price: 10, + quantity: 2, + type: 'PhysicalArticle', + unitCode: '23', + vatCategory: '323', + vatPercentage: 1 +} + +export const TestPhone = new Phone({ + fax: '23232', + landline: '323123', + mobile: '21312332' +}) +export const TestEmail = 'test@hotmail.com' +export const TestBankAccount = new BankAccount({ + accountName: 'accountName', + bic: 'bic', + iban: 'iban' +}) +export const TestBilling = { + recipient: TestPerson, + address: TestAddress, + phone: TestPhone, + email: TestEmail +} +export const TestIp = getIPAddress() diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index 3e24a537..b7701f11 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -1,126 +1,126 @@ -import Afterpay from '../../src/PaymentMethods/Afterpay/index' +import buckarooClientTest from '../BuckarooClient.test' +import { RequestTypes } from '../../src/Constants/Endpoints' import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay' -import { RefundPayload } from '../../src/Models/ITransaction' import RecipientCategory from '../../src/Constants/RecipientCategory' -require('../BuckarooClient.test') -const method = new Afterpay() +const method = buckarooClientTest.method('afterpay') describe('AfterPay methods', () => { - test('Pay', async () => { - await method.pay(payload).then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) + await method + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) }) test('Refund', async () => { - await method.refund({ ...refundPayload }).then((data) => { - expect(data).toBeDefined() - }) + await method + .refund({ + invoice: 'testinvoice 123', //Set invoice number of the transaction to refund + originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', //Set transaction key of the transaction to refund + amountCredit: 1.23 + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) test('Authorize', async () => { - await method.authorize(payload).then((data) => { - expect(data).toBeDefined() - }) + await method + .authorize(paymentPayload) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) test('CancelAuthorize', async () => { - await method.cancelAuthorize(refundPayload).then((data) => { - expect(data).toBeDefined() - }) + await method + .cancelAuthorize({ + invoice: 'testinvoice 123', + originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', + amountCredit: 1.23 + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) test('Capture', async () => { await method .capture({ - amountDebit: 4, - invoice: '123456789', + ...paymentPayload, originalTransactionKey: '123456789' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('PayRemainder', async () => { - await method.payRemainder(payload).then((data) => { - expect(data).toBeDefined() - }) + await method + .payRemainder({} as any) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) test('AuthorizeRemainder', async () => { - await method.authorizeRemainder(payload).then((data) => { - expect(data).toBeDefined() - }) + await method + .authorizeRemainder({} as any) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('Spercifications', async () => { + return method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) -let refundPayload: RefundPayload = { - amountCredit: 14, - originalTransactionKey: '123456789' -} - -let payload: IPay = { - amountDebit: 14, +const paymentPayload: IPay = { clientIP: '127.0.0.1', - - shippingCustomer: { - city: 'rew', - country: 'NL', - street: 'fsd', - streetNumber: '423', - streetNumberAdditional: 'ewr', - postalCode: '1234AB', - email: 'example@hotmail.com', - phone: '+31201234567', - mobilePhone: '+31612345678', - birthDate: '1999-11-21', - careOf: '', - category: RecipientCategory.PERSON, - conversationLanguage: 'NL', - customerNumber: 'a', - firstName: 'a', - identificationNumber: '675', - lastName: 'a', - salutation: 'Mr' - }, - billingCustomer: { - city: 'rew', - country: 'NL', - street: 'fsd', - streetNumber: '423', - streetNumberAdditional: 'ewr', - postalCode: '1234AB', - email: 'example@hotmail.com', - phone: '+31201234567', - mobilePhone: '+31612345678', - birthDate: '1999-11-21', - careOf: '', - category: RecipientCategory.PERSON, - conversationLanguage: 'NL', - customerNumber: 'a', - firstName: 'a', - identificationNumber: '675', - lastName: 'a', - salutation: 'Mr' - }, - article: [ - { - description: 'ter', - identifier: '423f', - imageUrl: '', - quantity: 1, - type: 'PhysicalArticle', - unitCode: '', - url: '', - vatPercentage: 0, - grossUnitPrice: 7 - + amountDebit: 40, + billing: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01', + companyName: 'buckarooTest', + conversationLanguage: 'NL', + identificationNumber: 'IdNumber12345', + customerNumber: 'customerNumber12345' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' }, + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678', + landline: '0513123456' + } + }, + articles: [ { - description: 'ter', - identifier: '423f', - unitCode: '', - type: 'PhysicalArticle', - quantity: 1, - vatPercentage: 0, - grossUnitPrice: 7 + vatPercentage: 21, + price: 10, + description: 'Test', + quantity: 4, + identifier: 'test' } - ] + ], + description: 'Test', + merchantImageUrl: 'https://www.buckaroo.nl/Themes/Buckaroo/Content/images/logo.png' } diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 197fe5ce..6aea7af7 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,27 +1,118 @@ -require('../BuckarooClient.test') -import AfterPayDigiAccept from '../../src/PaymentMethods/AfterpayDigiAccept' +import { RequestTypes } from '../../src/Constants/Endpoints' +import { TestBilling } from '../Models' +import buckarooClientTest from '../BuckarooClient.test' +import { uniqid } from '../../src/Utils/Functions' +import Gender from '../../src/Constants/Gender' +import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay' -const method = new AfterPayDigiAccept() +const method = buckarooClientTest.method('afterpaydigiaccept') describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { await method .authorize({ - amountDebit: 14, - clientIP: '127.0.0.1' + amountDebit: 0, + articles: [], + bankAccount: '', + bankCode: '', + billing: TestBilling, + clientIP: '', + merchantImageUrl: '', + ourReference: '', + summaryImageUrl: '', + yourReference: '' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Pay', async () => { await method - .pay({ - amountDebit: 14, - clientIP: '127.0.0.1' - }) + .pay({ ...paymentPayload, clientIP: '127.0.0.1' }) + .request() .then((data) => { expect(data.data).toBeDefined() }) }) + test('Specification', async () => { + await method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) }) + +const paymentPayload: IPay = { + amountDebit: 40.5, + b2b: true, + addressesDiffer: true, + customerIPAddress: '0.0.0.0', + shippingCosts: 0.5, + costCentre: 'Test', + department: 'Test', + establishmentNumber: 123456, + billing: { + recipient: { + gender: Gender.FEMALE, + initials: 'AB', + lastName: 'Do', + birthDate: '1990-01-01', + culture: 'NL' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + culture: 'NL', + gender: Gender.MALE, + initials: 'YJ', + lastName: 'Jansen', + companyName: 'Buckaroo B.V.', + birthDate: '1990-01-01', + chamberOfCommerce: '12345678', + vatNumber: 'NL12345678' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + articles: [ + { + identifier: uniqid(), + description: 'Blue Toy Car', + price: 10.0, + quantity: 2, + vatCategory: '1' + }, + { + identifier: uniqid(), + description: 'Red Toy Car', + price: 10.0, + quantity: 2, + vatCategory: '1' + } + ] +} diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index c7263d0f..0077dcec 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,32 +1,36 @@ -require('../BuckarooClient.test') -import Alipay from '../../src/PaymentMethods/Alipay' +import buckarooClientTest from '../BuckarooClient.test' -const method = new Alipay() +const alipay = buckarooClientTest.method('alipay') describe('Alipay methods', () => { test('Pay Simple Payload', async () => { - await method + await alipay .pay({ amountDebit: 10, useMobileView: false }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { - await method + await alipay .refund({ amountCredit: 5, originalTransactionKey: 'F397777A251645F8BDD81547B5005B4B' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Specifications', async () => { - await method.specification().then((data) => { - expect(data).toBeDefined() - }) + await alipay + .specification() + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index 7e4b201d..e84c8fd2 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -1,5 +1,7 @@ +import { uniqid } from '../../src/Utils/Functions' + require('../BuckarooClient.test') -import ApplePay from '../../src/PaymentMethods/ApplePay/index' +import ApplePay from '../../src/PaymentMethods/ApplePay' const method = new ApplePay() @@ -11,9 +13,22 @@ describe('Applepay methods', () => { paymentData: 'sad', customerCardName: '87y7y8' }) + .request() .then((data) => { expect(data).toBeDefined() - + }) + }) + test('Pay Redirect Payload', async () => { + await method + .payRedirect({ + amountDebit: 10, + invoice: uniqid(), + servicesSelectableByClient: 'applepay', + continueOnIncomplete: true + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy() }) }) test('Refund', async () => { @@ -22,13 +37,17 @@ describe('Applepay methods', () => { amountCredit: 5, originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Specifications', async () => { - await method.specification().then((data) => { - expect(data).toBeDefined() - }) + await method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index e81e0a6c..14f98d73 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,7 +1,6 @@ -require('../BuckarooClient.test') -import BanContact from '../../src/PaymentMethods/Bancontact/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new BanContact() +const method = buckarooClientTest.method('bancontactmrcash') describe('BanContact methods', () => { test('Pay Simple Payload', async () => { @@ -10,6 +9,7 @@ describe('BanContact methods', () => { amountDebit: 10, saveToken: true }) + .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy() }) @@ -20,14 +20,18 @@ describe('BanContact methods', () => { amountCredit: 5, originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Authenticate', async () => { - await method.authenticate({ amountDebit: 10 }).then((data) => { - expect(data.isWaitingOnUserInput()).toBeDefined() - }) + await method + .authenticate({ amountDebit: 10 }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeDefined() + }) }) test('PayOneClick', async () => { await method @@ -35,6 +39,7 @@ describe('BanContact methods', () => { originalTransactionKey: 'dsad', amountDebit: 12 }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -45,6 +50,7 @@ describe('BanContact methods', () => { originalTransactionKey: 'dsad', encryptedCardData: 'sUIB' }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -55,6 +61,7 @@ describe('BanContact methods', () => { amountDebit: 10, encryptedCardData: 'yrtgdd' }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -65,13 +72,17 @@ describe('BanContact methods', () => { amountDebit: 10, originalTransactionKey: 'sadas' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) - test('Specifications', async () => { - await method.specification().then((data) => { - expect(data).toBeDefined() - }) + test('Specifications', () => { + method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 02449f3f..301d1896 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,29 +1,22 @@ -import BankTransfer from '../../src/PaymentMethods/BankTransfer' import Gender from '../../src/Constants/Gender' - -require('../BuckarooClient.test') - -const method = new BankTransfer() +import buckarooClientTest from '../BuckarooClient.test' +const method = buckarooClientTest.method('transfer') describe('Transfer methods', () => { - test('Specification', async () => { - await method.specification().then((res) => { - expect(res).toBeDefined() - }) - }) test('Pay', async () => { await method .pay({ amountDebit: 10, - customerCountry: 'NL', - customerEmail: 'test@hotmail.com', - customerFirstName: 'test', - customerGender: Gender.FEMALE, - customerLastName: 'Test', - description: 'Test without payment method with ServicesSelectableByClient', - continueOnIncomplete: 1, - servicesSelectableByClient: 'ideal,creditcard' + customer: { + firstName: 'John', + lastName: 'Doe', + gender: Gender.MALE + }, + email: 'test@hotmail.com', + sendMail: true, + dateDue: '2024-10-10' }) + .request() .then((res) => { expect(res.isAwaitingConsumer()).toBeDefined() }) diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index cc70c3a6..c5c4f511 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,7 +1,6 @@ -require('../BuckarooClient.test') -import Belfius from '../../src/PaymentMethods/Belfius/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new Belfius() +const method = buckarooClientTest.method('belfius') describe('testing methods', () => { test('Pay Simple Payload', async () => { @@ -9,6 +8,7 @@ describe('testing methods', () => { .pay({ amountDebit: 10 }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -19,13 +19,17 @@ describe('testing methods', () => { amountCredit: 5, originalTransactionKey: '86CFE2CB5901463EADE061633BDB9EC8' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Specifications', async () => { - await method.specification().then((data) => { - expect(data).toBeDefined() - }) + await method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index b1d92cda..a0083174 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,21 +1,19 @@ -import Billink from '../../src/PaymentMethods/Billink/index' import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay' +import buckarooClientTest from '../BuckarooClient.test' +import RecipientCategory from '../../src/Constants/RecipientCategory' require('../BuckarooClient.test') -const method = new Billink() +const method = buckarooClientTest.method('billink') describe('Billink methods', () => { - test('Specifications', async () => { - await method.specification().then((data) => { - data.getActionRequestParameters('Pay') - expect(data).toBeDefined() - }) - }) test('Pay', async () => { - await method.pay(payload).then((data) => { - expect(data).toBeDefined() - }) + await method + .pay(payload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) }) test('Refund', async () => { await method @@ -23,14 +21,18 @@ describe('Billink methods', () => { amountCredit: 12, originalTransactionKey: 'ytgty' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Authorize', async () => { - await method.authorize(payload).then((data) => { - expect(data).toBeDefined() - }) + await method + .authorize(payload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) }) test('CancelAuthorize', async () => { await method @@ -39,6 +41,7 @@ describe('Billink methods', () => { amountCredit: 10, invoice: 'sdsa' }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -48,49 +51,82 @@ describe('Billink methods', () => { .capture({ originalTransactionKey: 'ytgty', invoice: "'dsa", - amountDebit: 123 + amountDebit: 123, + articles: payload.articles }) + .request() .then((data) => { expect(data).toBeDefined() }) }) }) -let payload: IPay = { - VATNumber: '', - additionalParameters: undefined, - amountDebit: 0, - article: [], - billingCustomer: { - chamberOfCommerce: '', - city: '', - firstName: '', - initials: '', - lastName: '', - postalCode: '', - street: '', - streetNumber: 0 - }, - clientIP: undefined, - continueOnIncomplete: 1, - culture: '', - currency: '', - customParameters: undefined, - description: '', - invoice: '', +const payload: IPay = { + amountDebit: 50.3, order: '', - originalTransactionKey: '', - originalTransactionReference: '', - pushURL: '', - pushURLFailure: '', - returnURL: '', - returnURLCancel: '', - returnURLError: '', - returnURLReject: '', - servicesExcludedForClient: '', - servicesSelectableByClient: '', - shippingCustomer: undefined, - startRecurrent: false, - summaryImageUrl: '', - trackandtrace: '' + invoice: '', + trackAndTrace: 'TR0F123456789', + vATNumber: '2', + billing: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + title: 'Female', + initials: 'JD', + firstName: 'John', + lastName: 'Do', + birthDate: '01-01-1990', + chamberOfCommerce: 'TEST' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433', + landline: '0109876543' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + title: 'Male', + initials: 'JD', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + } + }, + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1, + priceExcl: 5 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1, + priceExcl: 5 + } + ] } diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index d7be1ad4..8a8e5e65 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,7 +1,6 @@ -require('../BuckarooClient.test') -import BuckarooVoucher from '../../src/PaymentMethods/BuckarooVoucher/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new BuckarooVoucher() +const method = buckarooClientTest.method('buckaroovoucher') describe('testing methods', () => { test('Pay', async () => { @@ -10,6 +9,7 @@ describe('testing methods', () => { amountDebit: 12, voucherCode: '' }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -20,6 +20,7 @@ describe('testing methods', () => { amountCredit: 12, originalTransactionKey: '' }) + .request() .then((data) => { expect(data).toBeDefined() }) @@ -27,29 +28,32 @@ describe('testing methods', () => { test('GetBalance', async () => { await method .getBalance({ - voucherCode: '' + voucherCode: 'WP6W-XXXX-XXXX-56T7' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) test('CreateApplication', async () => { await method - .createApplication({ + .create({ creationBalance: 12, usageType: 1, validFrom: '2021-01-01', validUntil: '2024-01-01' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('DeactivateVoucher', async () => { await method - .deactivateVoucher({ + .deactivate({ voucherCode: '' }) + .request() .then((data) => { expect(data).toBeDefined() }) diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index fff1a12d..caaa661e 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -1,7 +1,7 @@ -require('../BuckarooClient.test') -import BuckarooWallet from '../../src/PaymentMethods/BuckarooWallet/index' +import buckarooClientTest from '../BuckarooClient.test' +import { uniqid } from '../../src/Utils/Functions' -const method = new BuckarooWallet() +const method = buckarooClientTest.method('BuckarooWalletCollecting') describe('BuckarooWallet methods', () => { test('Pay', async () => { @@ -11,30 +11,34 @@ describe('BuckarooWallet methods', () => { amountDebit: 12, walletId: '2' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) test('Refund', async () => { await method .refund({ invoice: 'string', - walletId: '2', amountCredit: 12, - originalTransactionKey: '' + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) test('CancelReservation', async () => { await method .cancel({ - invoice: 'dsadsadsa', - walletMutationGuid: '2' + invoice: 'BuckarooWalletInvoiceId', + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', + amountDebit: 1, + walletMutationGuid: '49B018248ECE4346AC20B902' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) test('deposit', async () => { @@ -45,31 +49,69 @@ describe('BuckarooWallet methods', () => { amountCredit: 12, originalTransactionKey: '' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) + test('Update', async () => { + await method + .update({ + walletId: '10', + status: 'Disabled', + email: 'test@buckaroo.nl', + customer: { + firstName: 'John', + lastName: 'string' + }, + bankAccount: { + iban: 'NL13TEST0123456789' + } + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) + }) test('Withdrawal', async () => { await method .withdrawal({ - invoice: 'dasd', - walletId: '654dfcvb', + invoice: 'BuckarooWalletInvoiceId', + walletId: '10', amountDebit: 10, - originalTransactionKey: '' + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) test('Create Wallet', async () => { await method .create({ - invoice: '', - pushURL: '', - walletId: '' + walletId: uniqid(), + email: 'test@buckaroo.nl', + customer: { + firstName: 'John', + lastName: 'string' + }, + bankAccount: { + iban: 'NL13TEST0123456789' + } }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isSuccess()).toBeTruthy() + }) + }) + test('GetInfo', async () => { + await method + .getInfo({ + walletId: '10' + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Client.test.ts b/tests/PaymentMethods/Client.test.ts deleted file mode 100644 index 5d02d283..00000000 --- a/tests/PaymentMethods/Client.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { uniqid } from '../../src/Utils/Functions' - -require('../BuckarooClient.test') -import buckarooClient from '../../src' - -const client = buckarooClient() -test('PaymentStatus', async () => { - await client.status('0AA966B997CB4676B55A07E9C3BA4DB4').then((data) => { - expect(data).toBeDefined() - }) -}) -test('paymentCancelInfo', async () => { - await client.cancelInfo('73902D944DC848CBADC49D9B8A8C2F16').then((data) => { - expect(data).toBeDefined() - }) -}) -test('paymentRefundInfo', async () => { - await client.refundInfo('73902D944DC848CBADC49D9B8A8C2F16').then((data) => { - expect(data).toBeDefined() - }) -}) - -test('paymentInvoiceInfo', async () => { - await client.invoiceInfo('5f5701d44aac88').then((data) => { - expect(data).toBeDefined() - }) -}) - -test('Service specifications', async () => { - let specifications = await client.specifications([ - { - paymentName: 'ideal', - serviceVersion: 1 - } - ]) - expect(specifications).toBeDefined() -}) -test('Client Transaction Request', async () => { - let specifications = await client.transactionRequest({ - invoice: uniqid(''), - order: uniqid(''), - currency: 'EUR', - amountDebit: 0.01, - pushURL: 'http://testcheckout.buckaroo.nl/push', - description: 'Test without payment method with ServicesSelectableByClient', - continueOnIncomplete: 1, - servicesSelectableByClient: 'ideal,paypal,bancontactmrcash', - servicesExcludedForClient: 'ideal' - }) - - expect(specifications).toBeDefined() -}) diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index c38f16cc..ae44fe6f 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -1,115 +1,121 @@ -require('../BuckarooClient.test') -import CreditCard from '../../src/PaymentMethods/CreditCard/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new CreditCard() +const method = buckarooClientTest.method('visa') describe('testing methods', () => { - test('Pay', async () => { - await method + test('Pay', async () => { + await method .pay({ - amountDebit: 10, - name: 'Visa' + amountDebit: 10 }) + .request() .then((data) => { - expect(data).toBeDefined() - }) - }) - test('Refund', async () => { - await method - .refund({ - amountCredit: 5, - name: 'Visa', - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('Authorize', async () => { - await method - .authorize({ - amountDebit: 10, - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('PayEncrypted', async () => { - await method - .payEncrypted({ - amountDebit: 10, - name: 'Visa', - encryptedCardData: '' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('PayWithSecurityCode', async () => { - await method - .payWithSecurityCode({ - amountDebit: 10, - encryptedSecurityCode: 'sad', - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('AuthorizeWithSecurityCode', async () => { - await method - .authorizeWithSecurityCode({ - amountDebit: 10, - encryptedSecurityCode: 'sad', - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('AuthorizeEncrypted', async () => { - await method - .authorizeEncrypted({ - amountDebit: 10, - encryptedCardData: 'sad', - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('CancelAuthorize', async () => { - await method - .cancelAuthorize({ - originalTransactionKey: 'sad', - amountCredit: 10, - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('Capture', async () => { - await method - .capture({ - originalTransactionKey: 'sad', - amountDebit: 10, - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) - test('PayRecurrent', async () => { - await method - .payRecurrent({ - originalTransactionKey: 'sad', - amountDebit: 10, - name: 'Visa' - }) - .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data.isWaitingOnUserInput()).toBeTruthy() + }) + }) + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('Authorize', async () => { + await method + .authorize({ + amountDebit: 10 + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy() + }) + }) + test('PayEncrypted', async () => { + await method + .payEncrypted({ + amountDebit: 10, + name: 'Visa', + encryptedCardData: '' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) + }) + test('PayWithSecurityCode', async () => { + await method + .payWithSecurityCode({ + amountDebit: 10, + encryptedSecurityCode: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('AuthorizeWithSecurityCode', async () => { + await method + .authorizeWithSecurityCode({ + amountDebit: 10, + encryptedSecurityCode: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('AuthorizeEncrypted', async () => { + await method + .authorizeEncrypted({ + amountDebit: 10, + encryptedCardData: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('CancelAuthorize', async () => { + await method + .cancelAuthorize({ + originalTransactionKey: 'sad', + amountCredit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('Capture', async () => { + await method + .capture({ + originalTransactionKey: 'sad', + amountDebit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) + test('PayRecurrent', async () => { + await method + .payRecurrent({ + originalTransactionKey: 'sad', + amountDebit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) + }) }) diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index 5f75fdd4..5f28deeb 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -1,16 +1,21 @@ -require('../BuckarooClient.test') -import CreditClick from '../../src/PaymentMethods/CreditClick/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new CreditClick() +const method = buckarooClientTest.method('creditclick') describe('Testing CreditClick methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 31 + amountDebit: 31, + person: { + firstName: 'test', + lastName: 'test' + }, + email: 't.tester@test.nl' }) + .request() .then((response) => { - expect(response).toBeDefined() + expect(response.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { @@ -21,8 +26,9 @@ describe('Testing CreditClick methods', () => { description: 'test', refundReason: 'Fraudulent' }) + .request() .then((response) => { - expect(response).toBeDefined() + expect(response.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index 0200b350..0e281776 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -1,139 +1,248 @@ -require('../BuckarooClient.test') - -import CreditManagement from '../../src/PaymentMethods/CreditManagement/index' import { IInvoice } from '../../src/PaymentMethods/CreditManagement/Models/Invoice' import Gender from '../../src/Constants/Gender' -import Ideal from '../../src/PaymentMethods/Ideal' import CreditManagementInstallmentInterval from '../../src/Constants/CreditManagementInstallmentInterval' +import buckarooClientTest from '../BuckarooClient.test' +import { uniqid } from '../../src/Utils/Functions' -const creditManagement = new CreditManagement() +const creditManagement = buckarooClientTest.method('CreditManagement3') describe('Testing Credit Management', () => { test('CreateInvoice', async () => { - await creditManagement.createInvoice(invoice()).then((data) => { - expect(data).toBeDefined() - }) + await creditManagement + .createInvoice(creditManagementTestInvoice()) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) + }) + test('CreateInvoice With Articles', async () => { + await creditManagement + .createInvoice( + creditManagementTestInvoice({ + invoice: 'Billingtest101', + description: 'buckaroo_schema_test_PDF', + invoiceAmount: 217.8, + invoiceDate: '2022-01-01', + dueDate: '1990-01-01', + schemeKey: '2amq34', + poNumber: 'PO-12345', + debtor: { + code: 'johnsmith4' + }, + articles: [ + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 1, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123 + }, + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 2, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123 + } + ] + }) + ) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) }) - test('Pause Invoice', async () => { - await creditManagement.pauseInvoice({ invoice: 'd42' }).then((data) => { - expect(data).toBeDefined() - }) + await creditManagement + .pauseInvoice({ invoice: 'Testinvoice184915' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) + }) + test('UnPause Invoice', async () => { + await creditManagement + .unpauseInvoice({ invoice: 'Testinvoice184915' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) + }) + test('Invoice Info', async () => { + await creditManagement + .invoiceInfo({ + invoice: 'INV001', + invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }] + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy() + }) }) test('Debtor Info', async () => { await creditManagement .debtorInfo({ debtor: { - code: 'adsad' + code: 'TestDebtor123123' } }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) - test('Invoice Info', async () => { + test('AddOrUpdateProductLines', async () => { await creditManagement - .invoiceInfo({ - invoice: 'invoice1', - invoices: [ + .addOrUpdateProductLines({ + invoiceKey: 'd42', + articles: [ { - invoiceNumber: 'invoice2' + type: 'Regular', + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + totalVat: 12, + totalAmount: 123, + quantity: 2, + price: 20.1 }, { - invoiceNumber: 'invoice3' + type: 'Regular', + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + totalVat: 12, + totalAmount: 123, + quantity: 1, + price: 10.1 } ] }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) - test('UnPause Invoice', async () => { - await creditManagement.unpauseInvoice({ invoice: 'd42' }).then((data) => { - expect(data).toBeDefined() - }) - }) - test('AddOrUpdateProductLines', async () => { + test('resumeDebtorFile', async () => { await creditManagement - .addOrUpdateProductLines({ - invoiceKey: 'd42', - article: [] - }) + .resumeDebtorFile({ debtorFileGuid: 'd42' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) - test('resumeDebtorFile', async () => { - await creditManagement.resumeDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { - expect(data).toBeDefined() - }) - }) test('pauseDebtorFile', async () => { - await creditManagement.pauseDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { - expect(data).toBeDefined() - }) + await creditManagement + .pauseDebtorFile({ debtorFileGuid: 'd42' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) + }) + test('addOrUpdateDebtor', async () => { + await creditManagement + .addOrUpdateDebtor( + creditManagementTestInvoice({ + addressUnreachable: false, + emailUnreachable: false, + mobileUnreachable: false + }) + ) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) }) test('CreateCombinedInvoice', async () => { - const ideal1 = new Ideal() - const combined = creditManagement.createCombinedInvoice(invoice()) - - await ideal1.combine(combined).pay({ - amountDebit: 10.1, - issuer: 'ABNANL2A' - }) + const combinedInvoice = creditManagement.createCombinedInvoice( + creditManagementTestInvoice() + ) + buckarooClientTest + .method('sepadirectdebit') + .combine(combinedInvoice.data) + .pay({ + iban: 'NL39RABO0300065264', + bic: 'RABONL2U', + mandateReference: 'TestMandateReference', + mandateDate: '2020-01-01', + collectDate: '2020-07-03', + amountDebit: 10.1, + customer: { + name: 'John Smith' + }, + invoice: uniqid('TestInvoice') + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy() + }) }) test('CreatePaymentPlan', async () => { await creditManagement .createPaymentPlan({ - dossierNumber: '', - includedInvoiceKey: '', - initialAmount: 0, - installmentAmount: 0, - installmentCount: 0, + description: 'Payment in two intstallments', + includedInvoiceKey: '20D09973FB5C4DBC9A33DB0F4F707xxx', + dossierNumber: 'PaymentplanJohnsmith123', + installmentCount: 2, + initialAmount: 100, + startDate: '2030-01-01', interval: CreditManagementInstallmentInterval.MONTH, - paymentPlanCostAmount: 0, - paymentPlanCostAmountVat: 0, - recipientEmail: '', - startDate: '' + paymentPlanCostAmount: 3.5, + paymentPlanCostAmountVat: 1.2, + recipientEmail: 'test@buckaroo.nl' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isValidationFailure()).toBeTruthy() }) }) - test('Specifications', async () => { - // + test('pauseInvoice', async () => { await creditManagement .pauseInvoice({ invoice: 'd42' }) + .request() .then((data) => { expect(data).toBeDefined() }) }) }) - -const invoice = (append: object = {}): IInvoice => { +export const creditManagementTestInvoice = (append: object = {}): IInvoice => { return { - code: 'Billingtest101', - // invoiceNumber: 'd42', - description: 'buckaroo_schema_test_PDF', - currency: 'EUR', applyStartRecurrent: false, invoiceAmount: 10, invoiceAmountVAT: 1, invoiceDate: '2022-01-01', dueDate: '2030-01-01', - schemeKey: 'ezf7xn', - // maxStepIndex: 1, + schemeKey: '2amq34', + maxStepIndex: 1, allowedServices: 'ideal,mastercard', debtor: { code: 'johnsmith4' }, - email: { email: 'youremail@example.nl' }, + email: 'youremail@example.nl', phone: { - mobile: '06198765432', - landline: '06198765432', - fax: '06198765432' + mobile: '06198765432' }, person: { culture: 'nl-NL', @@ -142,45 +251,24 @@ const invoice = (append: object = {}): IInvoice => { firstName: 'Test', lastNamePrefix: 'Jones', lastName: 'Aflever', - gender: Gender.MALE, - birthDate: '', - placeOfBirth: '' + gender: Gender.MALE }, company: { culture: 'nl-NL', name: 'My Company Corporation', vatApplicable: true, vatNumber: 'NL140619562B01', - chamberOfCommerce: '' + chamberOfCommerce: '20091741' }, address: { street: 'Hoofdtraat', houseNumber: '90', - houseNumberSuffix: 'A', - postalCode: '8441ER', + houseNumberAdditional: 'A', + zipcode: '8441ER', city: 'Heerenveen', state: 'Friesland', country: 'NL' }, - productLine: [ - { - discountPercentage: 0, - productGroupName: '', - productGroupOrderIndex: 0, - productOrderIndex: 0, - quantity: 0, - totalAmount: 0, - totalAmountExVat: 0, - totalDiscount: 0, - totalVat: 0, - type: 'Regular', - unitOfMeasurement: '', - vatPercentage: 0, - pricePerUnit: 0, - productName: '324' - - } - ], ...append } } diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 5f8cc761..5bf84791 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,41 +1,45 @@ -require('../BuckarooClient.test') -import Emandates from '../../src/PaymentMethods/Emandates' - -const method = new Emandates() +import buckarooClientTest from '../BuckarooClient.test' +const method = buckarooClientTest.method('emandate') describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { - method.issuerList().then((response) => { - expect(response.data).toBeDefined() - }) + await method + .issuerList() + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy() + }) }) test('CreateMandate', async () => { method .createMandate({ debtorReference: 'klant1234', language: 'nl', - continueOnIncomplete: 1, + continueOnIncomplete: true, purchaseId: 'purchaseid1234', sequenceType: 0 }) + .request() .then((response) => { - expect(response.data).toBeDefined() - }).catch((err)=>{ - console.log(err); - }) + expect(response.isPendingProcessing()).toBeTruthy() + }) }) test('GetStatus', async () => { - method.status({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC' }).then((response) => { - expect(response.data).toBeDefined() - }) + method + .status({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC' }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy() + }) }) test('ModifyMandate', async () => { method .modifyMandate({ originalMandateId: '1DC014098EC5C1F40AD803B83A425153BBC', - continueOnIncomplete: 1 + continueOnIncomplete: true }) + .request() .then((response) => { - expect(response.data).toBeDefined() + expect(response.isFailed()).toBeTruthy() }) }) test('CancelMandate', async () => { @@ -44,8 +48,9 @@ describe('Testing Emandates methods', () => { mandateId: '1DC014098EC5C1F40AD803B83A425153BBC', purchaseId: 'purchaseid1234' }) + .request() .then((response) => { - expect(response).toBeDefined() + expect(response.isValidationFailure()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index a9c0dde1..cfb38e13 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -1,28 +1,40 @@ -require('../BuckarooClient.test') -import GiftCard from '../../src/PaymentMethods/GiftCard/index' +import buckarooClientTest from '../BuckarooClient.test' -const method = new GiftCard() +const method = buckarooClientTest.method('boekenbon') describe('GiftCard methods', () => { test('Pay', async () => { - await method + const responsePay = await method .pay({ amountDebit: 10, - name: 'GiftCard' + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '500' }) - .then((data) => { - expect(data).toBeDefined() + .request() + expect(responsePay.isSuccess()).toBeTruthy() + const responseRemainderPay = await buckarooClientTest + .method('ideal') + .payRemainder({ + amountDebit: 10.1, + issuer: 'ABNANL2A', + invoice: responsePay.data.invoice, + originalTransactionKey: + responsePay.data.relatedTransactions[0].relatedTransactionKey }) + .request() + expect(responseRemainderPay.isPendingProcessing()).toBeTruthy() }) test('Refund', async () => { await method .refund({ amountCredit: 5, - name: 'GiftCard', - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + originalTransactionKey: '9F99B530DA5449EB919D27351D28BDF2', + email: '', + lastName: '' }) + .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index f888f133..b90e0508 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -1,28 +1,28 @@ -require('../BuckarooClient.test') -import GiroPay from '../../src/PaymentMethods/Giropay/index' - -const method = new GiroPay() - +import buckarooClientTest from '../BuckarooClient.test' +import { uniqid } from '../../src/Utils/Functions' +const method = buckarooClientTest.method('giropay') describe('Testing Giropay methods', () => { test('Pay', async () => { await method .pay({ - bic: '', - costumerIBAN: '', - amountDebit: 0 + bic: 'GENODETT488', + amountDebit: 10.1 }) + .request() .then((response) => { - expect(response).toBeDefined() + expect(response.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { await method .refund({ - amountCredit: 0, - originalTransactionKey: '' + amountCredit: 10, + invoice: uniqid(), + originalTransactionKey: '2D04704995B74D679AACC59F87XXXXXX' }) + .request() .then((response) => { - expect(response).toBeDefined() + expect(response.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index e2da713e..5c3f0d54 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,8 +1,6 @@ -require('../BuckarooClient.test') import { uniqid } from '../../src/Utils/Functions' -import Ideal from '../../src/PaymentMethods/Ideal/index' - -const ideal = new Ideal() +import buckarooClientTest from '../BuckarooClient.test' +const ideal = buckarooClientTest.method('ideal') describe('testing Ideal methods', () => { test('Issuers', async () => { await ideal.issuers().then((response) => { @@ -14,15 +12,13 @@ describe('testing Ideal methods', () => { .pay({ amountDebit: 10.1, issuer: 'ABNANL2A', - clientIP: { - address: '123.456.789.123', - type: 0 - }, + continueOnIncomplete: false, additionalParameters: { initiated_by_magento: 1, service_action: 'something' } }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy() }) @@ -34,25 +30,26 @@ describe('testing Ideal methods', () => { invoice: uniqid(), originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', amountCredit: 4.23, - clientIP: { - address: '123.456.789.123', - type: 0 - }, + clientIP: '123.456.789.123', additionalParameters: { initiated_by_magento: '1', service_action: 'something' } }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('InstantRefund', async () => { - await ideal.instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', - }).then((data) => { - expect(data).toBeDefined() - }) + await ideal + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }) + .request() + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/IdealQR.test.ts b/tests/PaymentMethods/IdealQR.test.ts index b997db14..6413896d 100644 --- a/tests/PaymentMethods/IdealQR.test.ts +++ b/tests/PaymentMethods/IdealQR.test.ts @@ -1,25 +1,32 @@ -require('../BuckarooClient.test') -import IDealQR from '../../src/PaymentMethods/iDealQR' +import buckarooClientTest from '../BuckarooClient.test' -const method = new IDealQR() - -describe('Testing iDealQR methods', () => { +const method = buckarooClientTest.method('idealqr') +describe('Testing IdealQR methods', () => { test('Pay', async () => { - method + await method .generate({ - amount: 0, - amountDebit: 0, - amountIsChangeable: false, - Description: '', - expiration: '', - imageSize: 0, + description: 'Test purchase', + returnURL: 'https://buckaroo.dev/return', + returnURLCancel: 'https://buckaroo.dev/cancel', + returnURLError: 'https://buckaroo.dev/error', + returnURLReject: 'https://buckaroo.dev/reject', + minAmount: 0.1, + maxAmount: 10.0, + imageSize: 2000, + purchaseId: 'Testpurchase123', isOneOff: false, - maxAmount: 0, - minAmount: 0, - purchaseId: '' + amount: 1.0, + amountIsChangeable: true, + expiration: '2030-09-30', + isProcessing: false, + additionalParameters: { + initiated_by_magento: '1', + service_action: 'something' + } }) + .request() .then((response) => { - expect(response.data).toBeDefined() + expect(response.isSuccess()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 1e1ee3ac..14e55fc6 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -1,57 +1,109 @@ -import In3 from '../../src/PaymentMethods/In3' -import Gender from '../../src/Constants/Gender' +import buckarooClientTest from '../BuckarooClient.test' +import { uniqid } from '../../src/Utils/Functions' +import { IPay } from '../../src/PaymentMethods/In3/Models/Pay' import RecipientCategory from '../../src/Constants/RecipientCategory' -require('../BuckarooClient.test') - -const in3 = new In3() +const in3 = buckarooClientTest.method('In3') describe('Testing In3 methods', () => { test('Pay', async () => { await in3 - .payInInstallments({ - clientIP: '127.0.0.0', - description: 'fdsfsdfdsf', - subtotalLine: [], - amountDebit: 32, - customerType: RecipientCategory.COMPANY, - invoiceDate: '22-01-2018', - person: { - gender: Gender.FEMALE, - culture: 'nl-NL', - initials: 'J.S.', - lastName: 'Aflever', - birthDate: '1990-01-01' - }, - company: { - name: 'My Company B.V.', - chamberOfCommerce: '123456' - }, - address: { - street: 'Hoofdstraat', - houseNumber: 2, - houseNumberSuffix: 'a', - zipCode: '8441EE', - city: 'Heerenveen', - country: 'NL' - }, - email: { - email: 'test@buckaroo.nl' - }, - phone: { - phone: '0612345678' - }, - productLine: [ - { - code: '64381664f2f8b', - price: 10, - quantity: 1, - name: 'Blue Toy Car' - } - ], + .pay(payload) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy() }) - .then((response) => { - expect(response.data).toBeDefined() + }) + test('Refund', async () => { + await in3 + .refund({ + amountCredit: 42, + originalTransactionKey: '', + merchantImageUrl: '', + summaryImageUrl: '', + articles: [] + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeFalsy() }) }) }) + +const payload: IPay = { + amountDebit: 52.3, + description: 'in3 pay', + order: uniqid(), + invoice: uniqid(), + clientIP: '127.0.0.1', + billing: { + recipient: { + category: RecipientCategory.PERSON, + initials: 'J', + firstName: 'John', + lastName: 'Dona', + birthDate: '1990-01-01', + customerNumber: '12345', + companyName: 'Buckaroo', + chamberOfCommerce: '123456' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'J', + firstName: 'John', + lastName: 'Dona', + chamberOfCommerce: '123456' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + } + }, + articles: [ + { + identifier: 'Articlenumber1', + type: 'Physical', + description: 'Blue Toy Car', + category: 'test product', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + type: 'Physical', + description: 'Red Toy Car', + category: 'test product', + vatPercentage: 21, + quantity: 1, + price: 10.1 + }, + { + identifier: 'USPShippingID', + type: 'Physical', + description: 'UPS', + category: 'test product', + vatPercentage: 21, + quantity: 1, + price: 2 + } + ] +} diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts new file mode 100644 index 00000000..af3cc398 --- /dev/null +++ b/tests/PaymentMethods/In3Old.test.ts @@ -0,0 +1,80 @@ +import buckarooClientTest from '../BuckarooClient.test' +import Gender from '../../src/Constants/Gender' +import RecipientCategory from '../../src/Constants/RecipientCategory' + +const capayable = buckarooClientTest.method('capayable') + +describe('Testing capayable methods', () => { + test('Pay', async () => { + await capayable + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy() + }) + }) + test('Refund', async () => { + await capayable + .refund({ + amountCredit: 42, + originalTransactionKey: '' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy() + }) + }) + test('PayInInstallments', async () => { + await capayable + .payInInstallments(paymentPayload) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy() + }) + }) +}) + +const paymentPayload = { + clientIP: '127.0.0.0', + description: 'fdsfsdfdsf', + amountDebit: 32, + customerType: RecipientCategory.COMPANY, + invoiceDate: '22-01-2018', + customer: { + gender: Gender.FEMALE, + culture: 'nl-NL', + initials: 'J.S.', + lastName: 'Aflever', + birthDate: '1990-01-01' + }, + company: { + companyName: 'My Company B.V.', + chamberOfCommerce: '123456' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '2', + houseNumberSuffix: 'a', + zipcode: '8441EE', + city: 'Heerenveen', + country: 'NL' + }, + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678' + }, + articles: [ + { + identifier: '64381664f2f8b', + price: 10, + quantity: 1, + description: 'Blue Toy Car' + } + ], + subtotals: [ + { + name: 'Verzendkosten', + value: 2 + } + ] +} diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index ff393cb4..858e223c 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,7 +1,5 @@ -require('../BuckarooClient.test') -import KBC from '../../src/PaymentMethods/KBC' - -const method = new KBC() +import buckarooClientTest from '../BuckarooClient.test' +const method = buckarooClientTest.method('KBCPaymentButton') describe('Testing KBC methods', () => { test('Pay', async () => { @@ -9,18 +7,20 @@ describe('Testing KBC methods', () => { .pay({ amountDebit: 10 }) + .request() .then((response) => { - expect(response.data).toBeDefined() + expect(response.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { method .refund({ - amountCredit: 0, + amountCredit: 10, originalTransactionKey: 'B5675356904444F3965C33D280591C74' }) + .request() .then((response) => { - expect(response.data).toBeDefined() + expect(response.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index c49b500c..8e98978b 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -1,23 +1,22 @@ +import buckarooClientTest from '../BuckarooClient.test' import { IPay } from '../../src/PaymentMethods/Klarna/Models/Pay' - -require('../BuckarooClient.test') -import Klarna from '../../src/PaymentMethods/Klarna/index' import { uniqid } from '../../src/Utils/Functions' +import RecipientCategory from '../../src/Constants/RecipientCategory' -const klarna = new Klarna() - +const klarna = buckarooClientTest.method('klarna') describe('Testing Klarna methods', () => { test('Pay', async () => { - await klarna.pay(payload).then((res) => { - expect(res).toBeDefined() - }) - }) - test('Refund', async () => { await klarna - .refund({ - amountCredit: 21, - originalTransactionKey: '' + .pay(payload) + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy() }) + }) + test('PayInInstallments', async () => { + await klarna + .payInInstallments(payload) + .request() .then((res) => { expect(res).toBeDefined() }) @@ -25,38 +24,62 @@ describe('Testing Klarna methods', () => { }) let payload: IPay = { - order: uniqid(), amountDebit: 50.3, invoice: uniqid(), - additionalParameters: undefined, - article: [], - billingCustomer: { - city: '', - country: '', - email: '', - firstName: '', - lastName: '', - phone: '', - postalCode: '', - street: '', - streetNumber: '', - streetNumberAdditional: '' + order: uniqid(), + billing: { + recipient: { + category: RecipientCategory.PERSON, + gender: 'female', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.COMPANY, + gender: 'male', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + }, + email: 'test@buckaroo.nl' }, - clientIP: undefined, - culture: '', - currency: '', - customParameters: undefined, - description: '', - originalTransactionKey: '', - originalTransactionReference: '', - pushURL: '', - pushURLFailure: '', - returnURL: '', - returnURLCancel: '', - returnURLError: '', - returnURLReject: '', - servicesExcludedForClient: '', - servicesSelectableByClient: '', - shippingCustomer: undefined, - startRecurrent: false + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1 + } + ] } diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index b23a20dc..9c3b6232 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,11 +1,88 @@ -require('../BuckarooClient.test') -import KlarnaKp from '../../src/PaymentMethods/KlarnaKP' -const klarnaKp = new KlarnaKp() -describe('KlarnaKp', () => { - test('reserve', async () => { +import buckarooClientTest from '../BuckarooClient.test' +import gender from '../../src/Constants/Gender' +const klarnaKp = buckarooClientTest.method('klarnakp') - await klarnaKp.reserve({}).then((info) => { - expect(info).toBeDefined() - }) +describe('KlarnaKp', () => { + test('Pay', async () => { + await klarnaKp + .pay({ + amountDebit: 50.3, + reservationNumber: '2377577452' + }) + .request() + .then((info) => { + expect(info.isFailed()).toBeTruthy() + }) + }) + test('Reserve', async () => { + await klarnaKp + .reserve({ + gender: gender.MALE, + operatingCountry: 'NL', + pno: '01011990', + billing: { + recipient: { + firstName: 'John', + lastName: 'Do' + }, + address: { + street: 'Neherkade', + houseNumber: '1', + zipcode: '2521VA', + city: 'Gravenhage', + country: 'NL' + }, + phone: { + mobile: '0612345678' + }, + email: 'youremail@example.nl' + }, + shipping: { + recipient: { + firstName: 'John', + lastName: 'Do' + }, + address: { + street: 'Rosenburglaan', + houseNumber: '216', + zipcode: '4385 JM', + city: 'Vlissingen', + country: 'NL' + }, + email: 'test@buckaroo.nl' + }, + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1 + } + ], + additionalParameters: { + initiated_by_magento: '1', + service_action: 'something' + } + }) + .request() + .then((info) => { + expect(info.isPendingProcessing()).toBeTruthy() + }) + }) + test('Cancel', async () => { + await klarnaKp + .cancel({}) + .request() + .then((info) => { + expect(info).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index c2e79a66..08e378c1 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,6 +1,6 @@ require('../BuckarooClient.test') -import Marketplaces from '../../src/PaymentMethods/Marketplaces/index' -import Ideal from '../../src/PaymentMethods/Ideal/index' +import Marketplaces from '../../src/PaymentMethods/Marketplaces' +import Ideal from '../../src/PaymentMethods/Ideal' const marketplaces = new Marketplaces() const ideal = new Ideal() diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 3da31577..cb9dce33 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -1,5 +1,5 @@ -import Gender from "../../src/Constants/Gender"; -import PayPerEmail from '../../src/PaymentMethods/PayPerEmail/index' +import Gender from '../../src/Constants/Gender' +import PayPerEmail from '../../src/PaymentMethods/PayPerEmail' require('../BuckarooClient.test') diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index d4e5b48a..eb1f074b 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import Payconiq from '../../src/PaymentMethods/Payconiq/index' +import Payconiq from '../../src/PaymentMethods/Payconiq' const payconiq = new Payconiq() @@ -25,11 +25,13 @@ describe('Payconiq', () => { }) }) test('InstantRefund', async () => { - await payconiq.instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', - }).then((data) => { - expect(data).toBeDefined() - }) + await payconiq + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }) + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 97e33ef0..36d5e035 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,9 +1,9 @@ require('../BuckarooClient.test') -import PaymentInitiation from '../../src/PaymentMethods/PaymentInitiation' +import PayByBank from '../../src/PaymentMethods/PayByBank' -const paymentInitiation = new PaymentInitiation() +const paymentInitiation = new PayByBank('PayByBank') -describe('PaymentInitiation methods', () => { +describe('PayByBank methods', () => { test('Pay', async () => { await paymentInitiation .pay({ @@ -12,6 +12,7 @@ describe('PaymentInitiation methods', () => { issuer: 'INGBNL2A', countryCode: 'NL' }) + .request() .then((info) => { expect(info.data).toBeDefined() }) @@ -22,6 +23,7 @@ describe('PaymentInitiation methods', () => { amountCredit: 50.3, originalTransactionKey: '123456' }) + .request() .then((info) => { expect(info.data).toBeDefined() }) diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 3ac78130..83ebfd03 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,7 +1,9 @@ +import buckarooClientTest from '../BuckarooClient.test' + require('../BuckarooClient.test') -import Paypal from '../../src/PaymentMethods/Paypal/index' +import Paypal from '../../src/PaymentMethods/Paypal' -const method = new Paypal() +const method = new Paypal('paypal') describe('Paypal', () => { test('Pay', async () => { @@ -9,6 +11,7 @@ describe('Paypal', () => { .pay({ amountDebit: 50.3 }) + .request() .then((info) => { expect(info.data).toBeDefined() }) @@ -19,27 +22,30 @@ describe('Paypal', () => { amountCredit: 50.3, originalTransactionKey: '123456' }) + .request() .then((info) => { expect(info.data).toBeDefined() }) }) test('ExtraInfo', async () => { + buckarooClientTest.method('subscriptions').createCombined({}) await method .extraInfo({ amountDebit: 50.3, address: { - city: 're', - country: 'rw', - state: 'fsd', - street: 'dsf', - street2: 'dsf', - zipcode: 'sdf' + street: 'Hoofstraat 90', + street2: 'Street 2', + city: 'Heerenveen', + state: 'Friesland', + zipcode: '8441AB', + country: 'NL' }, addressOverride: false, - costumer: { name: 'ers' }, - noShipping: 0, - phone: { mobile: '534' } + costumer: { name: 'John' }, + noShipping: '0', + phone: { mobile: '0612345678' } }) + .request() .then((info) => { expect(info.data).toBeDefined() }) diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index 113ff994..46dca2bb 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -1,13 +1,12 @@ -require("../BuckarooClient.test"); -import PiM from "../../src/PaymentMethods/PiM"; +require('../BuckarooClient.test') +import PiM from '../../src/PaymentMethods/PiM' -const pim = new PiM(); +const pim = new PiM() -describe("PiM", () => { - - test("generate", async () => { - await pim.generate().then((info) => { - expect(info).toBeDefined(); - }); - }); -}) \ No newline at end of file +describe('PiM', () => { + test('generate', async () => { + await pim.generate().then((info) => { + expect(info).toBeDefined() + }) + }) +}) diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 8ccbb97e..653405a2 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,21 +1,22 @@ require('../BuckarooClient.test') -import Przelewy24 from '../../src/PaymentMethods/Przelewy24/index' +import Przelewy24 from '../../src/PaymentMethods/Przelewy24' -const method = new Przelewy24() +const method = new Przelewy24('Przelewy24') describe('Przelewy24', () => { test('Pay', async () => { - await method + method .pay({ - customerLastName: "", - additionalParameters: undefined, - amountDebit: 0, - customerEmail: "", - customerFirstName: "", - email: "", + amountDebit: 50.3, + customer: { + firstName: 'test', + lastName: 'test' + }, + email: 'test@hotmail.com' }) - .then((info) => { - expect(info).toBeDefined() + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { @@ -24,6 +25,7 @@ describe('Przelewy24', () => { amountCredit: 50.3, originalTransactionKey: '123456' }) + .request() .then((info) => { expect(info.data).toBeDefined() }) diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index 9652e532..6bed227d 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import SEPA from '../../src/PaymentMethods/SEPA/index' +import SEPA from '../../src/PaymentMethods/SEPA' const method = new SEPA() diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index 9d039f9a..0424c4c6 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -25,11 +25,13 @@ describe('Sofort', () => { }) test('InstantRefund', async () => { - await method.instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', - }).then((data) => { - expect(data).toBeDefined() - }) + await method + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }) + .then((data) => { + expect(data).toBeDefined() + }) }) }) diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 4193aad2..ffac707b 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,44 +1,47 @@ -import Subscriptions from '../../src/PaymentMethods/Subscriptions/index' -import Ideal from '../../src/PaymentMethods/Ideal/index' +import buckarooClientTest from '../BuckarooClient.test' -require('../BuckarooClient.test') - -const subscription = new Subscriptions() -const ideal = new Ideal() +const subscription = buckarooClientTest.method('subscriptions') test('Create', async () => { subscription .create({ - ratePlan: { - update: { + additionalParameters: { + signature: '123213' + }, + ratePlans: { + add: { startDate: '2024-07-23', - ratePlanGuid: '' + ratePlanCode: 'zfv59mmy' } }, - ratePlanCharge: { + ratePlanCharges: { add: { ratePlanChargeCode: 'test' } }, configurationCode: 'gfyh9fe4', - addConfiguration: { + configuration: { name: 'owiejr' }, debtor: { code: 'johnsmith4' } }) + .request() + .then((data) => { + expect(data.hasError()).toBeTruthy() + }) .catch((e) => { - expect(e.response.data).toBeDefined() + expect(e).toBeDefined() }) .catch((e) => { - expect(e.response.data).toBeDefined() + expect(e).toBeDefined() }) }) test('Update', async () => { subscription .update({ - email: { email: 'test@buckaroo.nl' }, + email: 'test@buckaroo.nl', subscriptionGuid: 'FC512FC9CC3A485D8CF3D1804FF6xxxx', configurationCode: '9wqe32ew', ratePlan: { @@ -49,60 +52,70 @@ test('Update', async () => { } } }) + .request() .then((data) => { expect(data).toBeDefined() }) }) test('Combined Subscription', async () => { - const combinable = subscription.createCombined({ - address: undefined, - allowedServices: '', - b2b: '', - bankAccount: { accountName: '', bic: '', iban: '' }, - billingTiming: 0, - // company: undefined, - configuration: undefined, - configurationCode: '', - customerAccountName: '', - customerBIC: '', - customerIBAN: '', - debtor: { code: '' }, - email: { email: '' }, - includeTransaction: false, - mandateReference: '', - person: undefined, - phone: undefined, - ratePlan: undefined, - ratePlanCharge: undefined, - subscriptionGuid: '', - termStartDay: 0, - termStartMonth: 0, - termStartWeek: '', - transactionVatPercentage: 0 - }) - ideal - .combine(combinable) + const combinable = subscription + .createCombined({ + pushURL: 'https://buckaroo.dev/push', + includeTransaction: false, + transactionVatPercentage: 5, + configurationCode: 'gfyh9fe4', + email: 'test@buckaroo.nl', + ratePlans: { + add: { + startDate: '2033-01-01', + ratePlanCode: '9863hdcj' + } + }, + phone: { + mobile: '0612345678' + }, + debtor: { + code: 'johnsmith4' + }, + company: { + culture: 'nl-NL', + companyName: 'My Company Coporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '90', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL' + } + }) + .combine('ideal') .pay({ issuer: 'ABNANL2A', amountDebit: 10, startRecurrent: true }) + .request() .then((res) => { expect(res).toBeDefined() }) }) test('Update Combined Subscription', async () => { - const combinable = subscription.updateCombined({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - ideal - .combine(combinable) + const combinable = subscription + .updateCombined({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }) + .combine('ideal') .pay({ issuer: 'ABNANL2A', amountDebit: 10 }) + .request() .then((res) => { expect(res).toBeDefined() }) @@ -125,8 +138,9 @@ test('Delete Subscription Config', async () => { .deletePaymentConfig({ subscriptionGuid: '515461997AD34C50881D74157E38A64D' }) + .request() .then((res) => { - expect(res.status === 200).toBeTruthy() + expect(res.httpResponse.statusCode === 200).toBeTruthy() }) }) test('Subscription Pause', async () => { diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 0efad202..0ed4b594 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import SurePay from '../../src/PaymentMethods/Surepay/index' +import SurePay from '../../src/PaymentMethods/Surepay' const method = new SurePay() @@ -7,7 +7,7 @@ describe('Sofort', () => { test('Verify', async () => { await method .verify({ - customeraccountname: "string" + customeraccountname: 'string' }) .then((info) => { expect(info).toBeDefined() diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index e3f329eb..c2e760bb 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -1,28 +1,28 @@ require('../BuckarooClient.test') -import Thunes from "../../src/PaymentMethods/Thunes"; +import Thunes from '../../src/PaymentMethods/Thunes' const thunes = new Thunes() describe('Thunes methods', () => { - test('authorize', async () => { - thunes.authorize({ amountDebit: 0 }).then((res)=>{ - expect(res.data).toBeDefined() + test('authorize', async () => { + thunes.authorize({ amountDebit: 0 }).then((res) => { + expect(res.data).toBeDefined() + }) }) - }) - test('capture', async () => { - thunes.capture({ amountDebit: 0 ,originalTransactionKey:'1'}).then((res)=>{ - expect(res.data).toBeDefined() + test('capture', async () => { + thunes.capture({ amountDebit: 0, originalTransactionKey: '1' }).then((res) => { + expect(res.data).toBeDefined() + }) }) - }) - test('getStatus', async () => { - thunes.getStatus({originalTransactionKey:'111111111111'}).then((res)=>{ - expect(res.data).toBeDefined() + test('getStatus', async () => { + thunes.getStatus({ originalTransactionKey: '111111111111' }).then((res) => { + expect(res.data).toBeDefined() + }) }) - }) - test('cancel', async () => { - thunes.cancel({originalTransactionKey:'111111111111'}).then((res)=>{ - expect(res.data).toBeDefined() + test('cancel', async () => { + thunes.cancel({ originalTransactionKey: '111111111111' }).then((res) => { + expect(res.data).toBeDefined() + }) }) - }) -}) \ No newline at end of file +}) diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 3613a782..e40a2a2a 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import Tinka from '../../src/PaymentMethods/Tinka/index' +import Tinka from '../../src/PaymentMethods/Tinka' const method = new Tinka() diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index cd57104b..cd8e93c6 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import Trustly from '../../src/PaymentMethods/Trustly/index' +import Trustly from '../../src/PaymentMethods/Trustly' const method = new Trustly() diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index b80a7020..47e8e9b9 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,5 +1,5 @@ require('../BuckarooClient.test') -import WechatPay from '../../src/PaymentMethods/WeChatPay/index' +import WechatPay from '../../src/PaymentMethods/WeChatPay' const method = new WechatPay() diff --git a/tsconfig.json b/tsconfig.json index f3c0dec6..adf32238 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,13 +8,11 @@ "skipLibCheck": false /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, "declaration": true, - "outDir": "./dist", - "rootDir": "./src", - "experimentalDecorators": true, + "declarationDir": "dist/types", "moduleResolution": "node", "noImplicitAny": false, - "typeRoots": ["./node_modules/@types"], - "resolveJsonModule": true, + "resolveJsonModule": true }, "include": ["src/**/*.ts"], + "exclude": ["tests/**/*.ts"] } From 178991eecf8e42aea33d958293b13f38b404edf0 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:43:57 +0200 Subject: [PATCH 05/52] V1.0 --- .prettierignore | 2 +- example/buckarooClient.ts | 3 +- example/response/push.ts | 2 +- .../creditCard.ts | 1 + example/{Transaction => transaction}/ideal.ts | 1 - package.json | 5 +- src/PaymentMethods/Alipay/index.ts | 10 +-- src/PaymentMethods/Billink/Models/Article.ts | 1 + src/PaymentMethods/EPS/index.ts | 5 -- src/PaymentMethods/Marketplaces/index.ts | 2 +- src/PaymentMethods/PayPerEmail/index.ts | 1 + src/PaymentMethods/Surepay/index.ts | 5 +- src/PaymentMethods/Tinka/Models/Address.ts | 19 +++-- src/PaymentMethods/Tinka/Models/Article.ts | 27 +++---- src/PaymentMethods/Tinka/Models/Pay.ts | 63 +++++++++++---- src/PaymentMethods/Tinka/Models/Person.ts | 18 +++++ src/PaymentMethods/Tinka/Models/Phone.ts | 7 ++ src/PaymentMethods/Tinka/Models/Recipient.ts | 19 +++++ src/PaymentMethods/Tinka/index.ts | 8 +- src/PaymentMethods/Trustly/Models/Customer.ts | 10 +++ src/PaymentMethods/Trustly/Models/Pay.ts | 16 +++- src/PaymentMethods/Trustly/index.ts | 4 +- src/PaymentMethods/WeChatPay/Models/Pay.ts | 11 +++ src/PaymentMethods/WeChatPay/index.ts | 8 +- src/Request/Headers.ts | 9 +-- src/Request/HttpsClient.ts | 19 ++--- src/index.ts | 25 +++--- tests/BuckarooClient.test.ts | 6 +- tests/Client.test.ts | 44 +++------- tests/Models/index.ts | 18 ++--- tests/PaymentMethods/AfterPay.test.ts | 4 +- tests/PaymentMethods/Alipay.test.ts | 10 +-- tests/PaymentMethods/Belfius.test.ts | 2 +- tests/PaymentMethods/EPS.test.ts | 25 ++++++ tests/PaymentMethods/Ideal.test.ts | 24 +++--- tests/PaymentMethods/Tinka.test.ts | 80 ++++++++++--------- tests/PaymentMethods/WechatPay.test.ts | 13 ++- tsconfig.json | 6 +- 38 files changed, 311 insertions(+), 222 deletions(-) rename example/{Transaction => transaction}/creditCard.ts (92%) rename example/{Transaction => transaction}/ideal.ts (99%) create mode 100644 src/PaymentMethods/Tinka/Models/Person.ts create mode 100644 src/PaymentMethods/Tinka/Models/Phone.ts create mode 100644 src/PaymentMethods/Tinka/Models/Recipient.ts create mode 100644 src/PaymentMethods/Trustly/Models/Customer.ts create mode 100644 src/PaymentMethods/WeChatPay/Models/Pay.ts create mode 100644 tests/PaymentMethods/EPS.test.ts diff --git a/.prettierignore b/.prettierignore index 53c37a16..1521c8b7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1 @@ -dist \ No newline at end of file +dist diff --git a/example/buckarooClient.ts b/example/buckarooClient.ts index 27f34ebb..a26ba4db 100644 --- a/example/buckarooClient.ts +++ b/example/buckarooClient.ts @@ -1,9 +1,10 @@ -import Buckaroo from '../src' +import Buckaroo from "@buckaroo/buckaroo_sdk"; const buckaroo = Buckaroo.InitializeClient({ secretKey: 'secret', websiteKey: 'website' }) + buckaroo.config = { mode: 'TEST', currency: 'EUR', diff --git a/example/response/push.ts b/example/response/push.ts index a8e02cb1..afb5ca51 100644 --- a/example/response/push.ts +++ b/example/response/push.ts @@ -35,7 +35,7 @@ reply_handler.isValid() // Return either true or false const auth_header = 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572' post_data = - '{"Transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"Transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}' + '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}' const uri = 'https://buckaroo.dev/push' reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri) diff --git a/example/Transaction/creditCard.ts b/example/transaction/creditCard.ts similarity index 92% rename from example/Transaction/creditCard.ts rename to example/transaction/creditCard.ts index ecfb57c6..09c1b92e 100644 --- a/example/Transaction/creditCard.ts +++ b/example/transaction/creditCard.ts @@ -9,6 +9,7 @@ const paymentMethod = new CreditCard('nexi') invoice: 'test1', amountDebit: 12 }) + console.log(info) } catch (error) { console.warn(error) } diff --git a/example/Transaction/ideal.ts b/example/transaction/ideal.ts similarity index 99% rename from example/Transaction/ideal.ts rename to example/transaction/ideal.ts index 6ab2a4b1..5b84b78e 100644 --- a/example/Transaction/ideal.ts +++ b/example/transaction/ideal.ts @@ -10,7 +10,6 @@ ideal description: 'Ideal Payment' }) .request() - //Refund ideal .refund({ diff --git a/package.json b/package.json index 650e2349..267613ec 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "@buckaroo/buckaroo_sdk", - "version": "0.9.0", + "version": "1.0.0", "description": "Buckaroo payment SDK", "main": "dist/index.js", + "types": "dist/index.d.ts", "engines": { "node": ">=6.14" }, @@ -45,6 +46,6 @@ }, "homepage": "https://github.com/buckaroo-it/BuckarooSDK_Node#readme", "files": [ - "dist/**/*" + "dist" ] } diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 982896df..049c58fb 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,14 +1,14 @@ import PayablePaymentMethod from '../PayablePaymentMethod' import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' -import { Parameter } from '../../Models/IParameters' +import {ServiceParameter} from "../../Models/ServiceParameters"; export default class Alipay extends PayablePaymentMethod { protected _paymentName = 'Alipay' - pay(payload: { useMobileView: boolean } & IPaymentRequest) { - return super.pay(payload, [ - new Parameter({ name: 'useMobileView', value: payload.useMobileView }) - ]) + pay(payload: { useMobileView?: boolean } & IPaymentRequest) { + const serviceParameters = new ServiceParameter() + .set('useMobileView', payload.useMobileView) + return super.pay(payload, serviceParameters) } refund(payload: IRefundRequest) { return super.refund(payload) diff --git a/src/PaymentMethods/Billink/Models/Article.ts b/src/PaymentMethods/Billink/Models/Article.ts index 16e25891..03eeef37 100644 --- a/src/PaymentMethods/Billink/Models/Article.ts +++ b/src/PaymentMethods/Billink/Models/Article.ts @@ -10,3 +10,4 @@ export class Article extends ArticleClass { this.set('grossUnitPriceIncl', price) } } + diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 24f5c444..c0952ed6 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,10 +1,5 @@ import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' export default class EPS extends PayablePaymentMethod { protected _paymentName = 'EPS' - - refund(payload: IRefundRequest) { - return super.refund(payload) - } } diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index c074954b..1c50f2f2 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,6 +1,6 @@ import PaymentMethod from '../PaymentMethod' import { ISplit, ITransfer } from './Models/ISplit' - +//ToDO Add the service parameter models export default class Marketplaces extends PaymentMethod { protected _paymentName = 'Marketplaces' split(payload: ISplit) { diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 0709bb8d..abdfaeca 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -2,6 +2,7 @@ import PaymentMethod from '../PaymentMethod' import { IInvitation } from './Models/invitation' import { uniqid } from '../../Utils/Functions' +//ToDO Add the service parameter models export default class PayPerEmail extends PaymentMethod { protected _paymentName = 'PayPerEmail' paymentInvitation(payload: IInvitation) { diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 4d649707..0242da50 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,12 +1,13 @@ import PaymentMethod from '../PaymentMethod' import { IVerify } from './Models/Verify' -import { ServiceParameter } from '../../Models/ServiceParameters' +import {Parameter} from "../../Models/IParameters"; export default class Surepay extends PaymentMethod { protected _paymentName = 'Surepay' verify(payload: IVerify) { + const serviceParameter = new Parameter({name: 'customeraccountname', value: payload.customeraccountname}) this.setServiceList( 'Verify', - new ServiceParameter().set('customeraccountname', payload.customeraccountname) + [serviceParameter] ) return this.dataRequest(payload) } diff --git a/src/PaymentMethods/Tinka/Models/Address.ts b/src/PaymentMethods/Tinka/Models/Address.ts index 000207a7..ab268f40 100644 --- a/src/PaymentMethods/Tinka/Models/Address.ts +++ b/src/PaymentMethods/Tinka/Models/Address.ts @@ -1,8 +1,13 @@ -export type ITinkaAddress = { - street: string - streetNumber: string - streetNumberAdditional?: string - postalCode: string - city: string - country?: string +import {Address} from "../../../Models/Interfaces/IAddress"; + +export class TinkaAddress extends Address { + set houseNumber(value: string) { + this.set('streetNumber', value) + } + set houseNumberAdditional(value: string) { + this.set('streetNumberAdditional', value) + } + set zipcode(value: string) { + this.set('postalCode', value) + } } diff --git a/src/PaymentMethods/Tinka/Models/Article.ts b/src/PaymentMethods/Tinka/Models/Article.ts index e3aaa304..b6b75d05 100644 --- a/src/PaymentMethods/Tinka/Models/Article.ts +++ b/src/PaymentMethods/Tinka/Models/Article.ts @@ -1,18 +1,17 @@ -export enum ArticleType { - Unknown = 0, - Article = 1, - GiftCard = 2, - Discount = 3 -} +import IArticle, {Article} from "../../../Models/Interfaces/IArticle"; -export type ITinkaArticle = { - type?: ArticleType - quantity: number - unitCode: string - description: string - brand?: string - manufacturer?: string - unitGrossPrice: number +export interface ITinkaArticle extends IArticle { color?: string size?: string } +export class TinkaArticle extends Article { + set color(value: string) { + this.set('color', value) + } + set price(value: number) { + this.set('unitGrossPrice', value) + } + set size(value: string) { + this.set('size', value) + } +} diff --git a/src/PaymentMethods/Tinka/Models/Pay.ts b/src/PaymentMethods/Tinka/Models/Pay.ts index f24d0c46..fcdd7bde 100644 --- a/src/PaymentMethods/Tinka/Models/Pay.ts +++ b/src/PaymentMethods/Tinka/Models/Pay.ts @@ -1,23 +1,52 @@ import { IPaymentRequest } from '../../../Models/IRequest' -import { ITinkaArticle } from './Article' -import { ITinkaAddress } from './Address' -import Gender from '../../../Constants/Gender' +import {ITinkaArticle, TinkaArticle} from './Article' +import {ServiceParameter} from "../../../Models/ServiceParameters"; +import {ICustomer} from "../../../Models/Interfaces/ICustomer"; +import {ITinkaPerson, TinkaPerson} from "./Person"; +import {Recipient} from "./Recipient"; export interface IPay extends IPaymentRequest { paymentMethod: string deliveryMethod: string deliveryDate?: string - article: ITinkaArticle[] - billingCustomer: { - email: string - phone?: string - prefixLastName?: string - } & ITinkaAddress - shippingCustomer?: { - externalName: false - } & ITinkaAddress - dateOfBirth?: string - firstName?: string - gender?: Gender - initials?: string - lastName?: string + articles: Partial[] + customer: ITinkaPerson + shipping?:ICustomer + billing:ICustomer +} +export class Pay extends ServiceParameter { + protected getGroups(){ + return super.getGroups({ + 'Articles':'Article', + 'Shipping':'ShippingCustomer', + 'Billing':'BillingCustomer', + }); + } + protected getCountable() { + return super.getCountable(['Articles']); + } + + set paymentMethod(value: string) { + this.set('paymentMethod', value) + } + set deliveryMethod(value: string) { + this.set('deliveryMethod', value) + } + set deliveryDate(value: string) { + this.set('deliveryDate', value) + } + set articles(value: ITinkaArticle[]) { + this.set('articles', value.map(article => new TinkaArticle(article))) + } + set customer(value: ITinkaPerson) { + this.set('customer', new TinkaPerson(value)) + } + set shipping(value: ICustomer) { + this.set('shipping', new Recipient(value)) + } + set billing(value: ICustomer) { + this.set('billing', new Recipient(value)) + if (this.shipping === undefined) { + this.shipping = value + } + } } diff --git a/src/PaymentMethods/Tinka/Models/Person.ts b/src/PaymentMethods/Tinka/Models/Person.ts new file mode 100644 index 00000000..c5880576 --- /dev/null +++ b/src/PaymentMethods/Tinka/Models/Person.ts @@ -0,0 +1,18 @@ +import {Person} from "../../../Models/Interfaces/IRecipient"; +import Gender from "../../../Constants/Gender"; + +export interface ITinkaPerson { + gender : Gender, + firstName: string, + lastName : string, + initials : string, + birthDate : string, +} +export class TinkaPerson extends Person { + set lastNamePrefix(value: string) { + this.set('prefixLastName', value) + } + set birthDate(value: string) { + this.set('dateOfBirth', value) + } +} diff --git a/src/PaymentMethods/Tinka/Models/Phone.ts b/src/PaymentMethods/Tinka/Models/Phone.ts new file mode 100644 index 00000000..8fe46c5b --- /dev/null +++ b/src/PaymentMethods/Tinka/Models/Phone.ts @@ -0,0 +1,7 @@ +import {Phone} from "../../../Models/Interfaces/IPhone"; + +export class TinkaPhone extends Phone { + set mobile(value: string) { + this.set('phone', value) + } +} diff --git a/src/PaymentMethods/Tinka/Models/Recipient.ts b/src/PaymentMethods/Tinka/Models/Recipient.ts new file mode 100644 index 00000000..dab47a4f --- /dev/null +++ b/src/PaymentMethods/Tinka/Models/Recipient.ts @@ -0,0 +1,19 @@ +import {Customer} from "../../../Models/Interfaces/ICustomer"; +import IAddress from "../../../Models/Interfaces/IAddress"; +import {TinkaAddress} from "./Address"; +import IPhone from "../../../Models/Interfaces/IPhone"; +import {TinkaPhone} from "./Phone"; +import {TinkaPerson} from "./Person"; +import {IPerson} from "../../../Models/Interfaces/IRecipient"; + +export class Recipient extends Customer { + set address(value: IAddress) { + this.set('address', new TinkaAddress(value)) + } + set phone(value: IPhone) { + this.set('phone', new TinkaPhone(value)) + } + set recipient(value: IPerson) { + this.set('recipient', new TinkaPerson(value)) + } +} diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index 37061180..818a8847 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,15 +1,11 @@ import PayablePaymentMethod from '../PayablePaymentMethod' import { IRefundRequest } from '../../Models/IRequest' -import { IPay } from './Models/Pay' +import {IPay, Pay} from './Models/Pay' export default class Tinka extends PayablePaymentMethod { protected _paymentName = 'Tinka' pay(payload: IPay) { - if (payload.billingCustomer) { - // @ts-ignore - payload.shippingCustomer = payload.shippingCustomer || payload.billingCustomer - } - return super.pay(payload) + return super.pay(payload,new Pay(payload)) } refund(payload: IRefundRequest) { return super.refund(payload) diff --git a/src/PaymentMethods/Trustly/Models/Customer.ts b/src/PaymentMethods/Trustly/Models/Customer.ts new file mode 100644 index 00000000..e9ed2a09 --- /dev/null +++ b/src/PaymentMethods/Trustly/Models/Customer.ts @@ -0,0 +1,10 @@ +import {Model} from "../../../Models/Model"; + +export class Customer extends Model { + set firstName(value: string) { + this.set('CustomerFirstName', value) + } + set lastName(value: string) { + this.set('customerLastName', value) + } +} diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index a84c98f6..cc674f30 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -1,7 +1,17 @@ import { IPaymentRequest } from '../../../Models/IRequest' +import {ServiceParameter} from "../../../Models/ServiceParameters"; +import {IPerson} from "../../../Models/Interfaces/IRecipient"; +import {Customer} from "./Customer"; export interface IPay extends IPaymentRequest { - customerCountryCode: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB' - customerFirstName: string - customerLastName: string + customer:Partial + country?:'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB' +} +export class Pay extends ServiceParameter { + set customer(value: Partial) { + this.set('customer', new Customer(value)) + } + set country(value: string) { + this.set('country', value) + } } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 28d7b5f9..c36bb403 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,11 +1,11 @@ import PayablePaymentMethod from '../PayablePaymentMethod' import { IRefundRequest } from '../../Models/IRequest' -import { IPay } from './Models/Pay' +import {IPay, Pay} from './Models/Pay' export default class Trustly extends PayablePaymentMethod { protected _paymentName = 'Trustly' pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload,new Pay(payload)) } refund(payload: IRefundRequest) { return super.refund(payload) diff --git a/src/PaymentMethods/WeChatPay/Models/Pay.ts b/src/PaymentMethods/WeChatPay/Models/Pay.ts new file mode 100644 index 00000000..a24c6917 --- /dev/null +++ b/src/PaymentMethods/WeChatPay/Models/Pay.ts @@ -0,0 +1,11 @@ +import {IPaymentRequest} from "../../../Models/IRequest"; +import {ServiceParameter} from "../../../Models/ServiceParameters"; + +export interface IPay extends IPaymentRequest { + locale?: string +} +export class Pay extends ServiceParameter { + set locale(value: string) { + this.set('locale', value) + } +} diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 7559578e..05f700a8 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,13 +1,11 @@ import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest, IPaymentRequest } from '../../Models/IRequest' +import { IRefundRequest } from '../../Models/IRequest' +import {IPay, Pay} from "./Models/Pay"; -interface IPay extends IPaymentRequest { - locale: 'en-US' | 'zh-CN' | 'zh-TW' -} export default class WeChatPay extends PayablePaymentMethod { protected _paymentName = 'WeChatPay' pay(payload: IPay) { - return super.pay(payload) + return super.pay(payload,new Pay(payload)) } refund(payload: IRefundRequest) { return super.refund(payload) diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index 2c26ed1d..f35a96fb 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -19,18 +19,17 @@ export default class Headers { Accept: 'application/json', Culture: 'nl-NL', Authorization: '', - Channel: 'Web', - Software: JSON.stringify({ + Channel:'Web', + Software: JSON.stringify({ PlatformName: 'Node SDK', PlatformVersion: '1.0', ModuleSupplier: 'Buckaroo', ModuleName: 'BuckarooPayments', - ModuleVersion: '1.0' + ModuleVersion: '1.0', }) } } - setSoftwareHeader( - value: { + setSoftwareHeader(value: { platformName?: string platformVersion?: string moduleSupplier?: string diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index a45196f0..78dba1ca 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,9 +1,8 @@ import { Agent, RequestOptions } from 'https' import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse' -import { ReplyHandler } from '../Handlers/Reply/ReplyHandler' -import Buckaroo from '../index' -const https = require('https') -const defaultAgent = new https.Agent({ +import * as https from "https"; + +const defaultAgent = new Agent({ keepAlive: true, keepAliveMsecs: 10000 }) @@ -13,6 +12,7 @@ export default class HttpsClient { this._options.timeout = 10000 this._options.agent = agent || defaultAgent this._options.sessionTimeout = 30000 + } public sendRequest( url: URL, @@ -38,22 +38,13 @@ export default class HttpsClient { }) res.on('end', () => { try { - let data = Buffer.concat(response).toString() - new ReplyHandler( - Buckaroo.Client.credentials, - data, - res.headers['authorization'], - url.toString(), - options.method - ).validate() - resolve(new responseClass(res, data) as InstanceType) + resolve(new responseClass(res, Buffer.concat(response).toString()) as InstanceType) } catch (e) { try { reject(Buffer.concat(response).toString()) } catch (e) { reject(e) } - reject(e) } }) }) diff --git a/src/index.ts b/src/index.ts index aafcb6fc..78f1a730 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,13 @@ -import { IConfig, ICredentials } from './Utils/Types' +import {IConfig, ICredentials} from './Utils/Types' import HttpsClient from './Request/HttpsClient' -import { Agent } from 'https' -import getMethod, { MethodFromServiceCode, ServiceCode } from './Utils/MethodTypes' +import {Agent} from 'https' +import getMethod, {MethodFromServiceCode, ServiceCode} from './Utils/MethodTypes' import Request from './Request/Request' import NoService from './PaymentMethods/NoService' import TransactionService from './Services/TransactionService' -import { Credentials } from './Handlers/Credentials' +import {Credentials} from './Handlers/Credentials' +import {RequestTypes} from "./Constants/Endpoints"; + export default class Buckaroo { private readonly _credentials: Credentials private _config: IConfig @@ -16,15 +18,11 @@ export default class Buckaroo { this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) } this._httpClient = new HttpsClient(agent) } - static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent) { - this._client = new this(credentials, config, agent) - return this.Client + static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent):Buckaroo { + return this._client = new this(credentials, config, agent) } static get Client(): Buckaroo { - if (this._client) { - return this._client - } - throw new Error('Buckaroo client not initialized') + return this._client } get credentials(): ICredentials { return this._credentials @@ -44,7 +42,10 @@ export default class Buckaroo { transaction(key: string) { return new TransactionService(key) } - get batch() { + batch(type:RequestTypes.BatchData | RequestTypes.BatchTransaction = RequestTypes.BatchTransaction) { + if (type === RequestTypes.BatchData) { + return Request.BatchDataRequest + } return Request.BatchTransaction } method(): NoService diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index 0b4d7c1c..b6bbbd81 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,7 +1,8 @@ import Buckaroo from '../src' + require('dotenv').config() -const buckarooClientTest = Buckaroo.InitializeClient( +const BuckarooClient = Buckaroo.InitializeClient( { secretKey: process.env.BPE_SECRET_KEY || '', websiteKey: process.env.BPE_WEBSITE_KEY || '' @@ -14,5 +15,4 @@ const buckarooClientTest = Buckaroo.InitializeClient( pushURL: process.env.BPE_PUSH_URL || '' } ) - -export default buckarooClientTest +export default BuckarooClient diff --git a/tests/Client.test.ts b/tests/Client.test.ts index a1879a5b..cfeaf6f2 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -1,37 +1,19 @@ -import Buckaroo from '../src' +import client from './BuckarooClient.test' import { TransactionData } from '../src/Request/DataModels' import { TransactionResponse } from '../src/Models/Response/TransactionResponse' import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse' import { uniqid } from '../src/Utils/Functions' -import {creditManagementTestInvoice} from "./PaymentMethods/CreditManagment.test"; +import { creditManagementTestInvoice } from "./PaymentMethods/CreditManagment.test"; -require('dotenv').config() - -const client = Buckaroo.InitializeClient( - { - secretKey: process.env.BPE_SECRET_KEY || '', - websiteKey: process.env.BPE_WEBSITE_KEY || '' - }, - { - mode: process.env.BPE_MODE === 'LIVE' ? 'LIVE' : 'TEST', - currency: process.env.BPE_CURRENCY_CODE || 'EUR', - returnURL: process.env.BPE_RETURN_URL || '', - returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', - pushURL: process.env.BPE_PUSH_URL || '' - } -) describe('Testing Buckaroo Client', () => { - test('Credentials', async () => { - await client + test('Credentials', () => { + return client .confirmCredentials() .then((response) => { expect(response).toBeTruthy() }) - .catch((err) => { - expect(err).toBeUndefined() - }) }) - test('Batch Transaction', async () => { + test('Batch transaction', async () => { const transactionData: TransactionData[] = [] for (let i = 0; i < 3; i++) { let invoice = client @@ -49,8 +31,8 @@ describe('Testing Buckaroo Client', () => { customer: { name: 'John Smith' } - }).data - transactionData.push(invoice) + }) + transactionData.push(invoice.data) } await client @@ -65,7 +47,7 @@ describe('Testing Buckaroo Client', () => { }) describe('Transaction', () => { const transactionService = client.transaction('39F3EC520A3F4A25B0A1899D4FF0E1CB') - test('Transaction Status', async () => { + test('transaction Status', async () => { await transactionService .status() .then((res) => { @@ -75,26 +57,20 @@ describe('Testing Buckaroo Client', () => { expect(err).toBeUndefined() }) }) - test('Transaction Cancel Info', async () => { + test('transaction Cancel Info', async () => { await transactionService .cancelInfo() .then((res) => { expect(res instanceof HttpClientResponse).toBeTruthy() }) - .catch((err) => { - expect(err).toBeUndefined() - }) }) - test('Transaction Refund Info', async () => { + test('transaction Refund Info', async () => { await transactionService .refundInfo() .then((res) => { expect(res instanceof HttpClientResponse).toBeTruthy() }) - .catch((err) => { - expect(err).toBeUndefined() - }) }) }) }) diff --git a/tests/Models/index.ts b/tests/Models/index.ts index 3a924b37..c94f262d 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -1,8 +1,8 @@ import { ICompany, IPerson } from '../../src/Models/Interfaces/IRecipient' -import { Address } from '../../src/Models/Interfaces/IAddress' +import IAddress from '../../src/Models/Interfaces/IAddress' import IArticle from '../../src/Models/Interfaces/IArticle' -import { Phone } from '../../src/Models/Interfaces/IPhone' -import { BankAccount } from '../../src/Models/Interfaces/IBankAccount' +import IPhone from '../../src/Models/Interfaces/IPhone' +import IBankAccount from '../../src/Models/Interfaces/IBankAccount' import RecipientCategory from '../../src/Constants/RecipientCategory' import { getIPAddress } from '../../src/Utils/Functions' @@ -27,7 +27,7 @@ export const TestCompany: ICompany = { vatApplicable: false, vatNumber: '321' } -export const TestAddress = new Address({ +export const TestAddress:IAddress = { city: 'city', country: 'NL', houseNumber: '2313432', @@ -35,7 +35,7 @@ export const TestAddress = new Address({ state: 'state', street: 'street', zipcode: '32323' -}) +} export const TestArticle: IArticle = { description: 'test', identifier: 'identifier', @@ -47,17 +47,17 @@ export const TestArticle: IArticle = { vatPercentage: 1 } -export const TestPhone = new Phone({ +export const TestPhone:IPhone = { fax: '23232', landline: '323123', mobile: '21312332' -}) +} export const TestEmail = 'test@hotmail.com' -export const TestBankAccount = new BankAccount({ +export const TestBankAccount:IBankAccount = { accountName: 'accountName', bic: 'bic', iban: 'iban' -}) +} export const TestBilling = { recipient: TestPerson, address: TestAddress, diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index b7701f11..6f76e793 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -5,8 +5,8 @@ import RecipientCategory from '../../src/Constants/RecipientCategory' const method = buckarooClientTest.method('afterpay') describe('AfterPay methods', () => { - test('Pay', async () => { - await method + test('Pay', () => { + return method .pay(paymentPayload) .request() .then((data) => { diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index 0077dcec..f449f0a5 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -22,15 +22,7 @@ describe('Alipay methods', () => { }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) - test('Specifications', async () => { - await alipay - .specification() - .request() - .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index c5c4f511..8775b83e 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -10,7 +10,7 @@ describe('testing methods', () => { }) .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts new file mode 100644 index 00000000..42cc1ec5 --- /dev/null +++ b/tests/PaymentMethods/EPS.test.ts @@ -0,0 +1,25 @@ +import buckarooClientTest from '../BuckarooClient.test' +const method = buckarooClientTest.method('eps') +describe('Testing Eps methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 10.1 + }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy() + }) + }) + test('Refund', async () => { + method + .refund({ + amountCredit: 10.1, + originalTransactionKey: '1234567890' + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy() + }) + }) +}) diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index 5c3f0d54..fd365b07 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,14 +1,14 @@ -import { uniqid } from '../../src/Utils/Functions' +import {getIPAddress, uniqid} from '../../src/Utils/Functions' import buckarooClientTest from '../BuckarooClient.test' const ideal = buckarooClientTest.method('ideal') describe('testing Ideal methods', () => { - test('Issuers', async () => { - await ideal.issuers().then((response) => { + test('Issuers', () => { + return ideal.issuers().then((response) => { expect(Array.isArray(response)).toBeTruthy() }) }) - test('Pay Simple Payload', async () => { - await ideal + test('Pay Simple Payload', () => { + return ideal .pay({ amountDebit: 10.1, issuer: 'ABNANL2A', @@ -23,14 +23,14 @@ describe('testing Ideal methods', () => { expect(data.isPendingProcessing()).toBeTruthy() }) }) - test('Refund', async () => { - await ideal + test('Refund',() => { + return ideal .refund({ order: uniqid(), invoice: uniqid(), originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', amountCredit: 4.23, - clientIP: '123.456.789.123', + clientIP: getIPAddress(), additionalParameters: { initiated_by_magento: '1', service_action: 'something' @@ -38,18 +38,18 @@ describe('testing Ideal methods', () => { }) .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) - test('InstantRefund', async () => { - await ideal + test('InstantRefund', () => { + return ideal .instantRefund({ amountCredit: 4.23, originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' }) .request() .then((data) => { - expect(data).toBeDefined() + expect(data.isFailed()).toBeTruthy() }) }) }) diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index e40a2a2a..818455da 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,42 +1,54 @@ -require('../BuckarooClient.test') -import Tinka from '../../src/PaymentMethods/Tinka' - -const method = new Tinka() - +import Gender from "../../src/Constants/Gender"; +import buckarooClientTest from "../BuckarooClient.test"; +const method = buckarooClientTest.method('tinka') describe('Tinka', () => { test('Pay', async () => { await method .pay({ + billing: { + recipient: { + lastNamePrefix: "the" + }, + email: "billingcustomer@buckaroo.nl", + phone: { + mobile: "0109876543" + }, + address: { + street: "Hoofdstraat", + houseNumber: "80", + houseNumberAdditional: "A", + zipcode: "8441EE", + city: "Heerenveen", + country: "NL" + } + }, + customer: { + gender : Gender.MALE, + firstName: 'Buck', + lastName : 'Aroo', + initials :'BA', + birthDate : '1990-01-01', + }, amountDebit: 3.5, - article: [ + articles: [ { - description: 'ewf', + type: '1', + description: "Blue Toy Car", + brand: "Ford Focus", + manufacturer: "Ford", + color: "Red", + size: "Small", quantity: 1, - unitCode: '', - unitGrossPrice: 3.5 + price: 3.5, + unitCode: "test" } ], - billingCustomer: { - city: 'wef', - country: 'rfew', - email: 'few@hotmail.com', - phone: '3161234567', - postalCode: '345445', - prefixLastName: 'fsd', - street: 'ds', - streetNumber: '32', - streetNumberAdditional: 'descs' - }, - dateOfBirth: '', - deliveryDate: '', + deliveryDate: '09-07-2020', deliveryMethod: 'CompanyStore', - firstName: '323', - initials: '', - lastName: '54', paymentMethod: 'Credit' - }) - .then((info) => { - expect(info.data).toBeDefined() + }).request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy() }) }) test('Refund', async () => { @@ -44,15 +56,9 @@ describe('Tinka', () => { .refund({ amountCredit: 3.5, originalTransactionKey: '1234567890' + }).request() + .then((res) => { + expect(res.isFailed()).toBeTruthy() }) - .then((info) => { - expect(info).toBeDefined() - }) - }) - - test('Specifications', async () => { - await method.specification().then((info) => { - expect(info).toBeDefined() - }) }) }) diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 47e8e9b9..98fb6a83 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,17 +1,14 @@ -require('../BuckarooClient.test') -import WechatPay from '../../src/PaymentMethods/WeChatPay' - -const method = new WechatPay() - +import buckarooClientTest from "../BuckarooClient.test"; +const method = buckarooClientTest.method('wechatpay') describe('WechatPay', () => { test('Pay', async () => { await method .pay({ amountDebit: 3.5, locale: 'en-US' - }) + }).request() .then((response) => { - expect(response.data).toBeDefined() + expect(response.isPendingProcessing()).toBeDefined() }) }) test('Refund', async () => { @@ -19,7 +16,7 @@ describe('WechatPay', () => { .refund({ amountCredit: 3.5, originalTransactionKey: '1234567890' - }) + }).request() .then((response) => { expect(response.data).toBeDefined() }) diff --git a/tsconfig.json b/tsconfig.json index adf32238..39f52037 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,14 +5,14 @@ "lib": ["ES2021", "dom"], "strict": true, "esModuleInterop": true, - "skipLibCheck": false /* Skip type checking of declaration files. */, + "skipLibCheck": true /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, "declaration": true, - "declarationDir": "dist/types", + "sourceMap": true, "moduleResolution": "node", "noImplicitAny": false, + "outDir": "dist", "resolveJsonModule": true }, "include": ["src/**/*.ts"], - "exclude": ["tests/**/*.ts"] } From 35074bcc2d90cf5462ca0530a0db865b016eeb60 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Tue, 10 Oct 2023 13:58:33 +0200 Subject: [PATCH 06/52] Readme update regarding usage outside of node --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index deb280d4..43af0186 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,13 @@ buckarooClient().cancelInfo(transactionKey) // Retrieve cancellation info Find our full documentation online on [docs.buckaroo.io](https://docs.buckaroo.io/docs/node-sdk). +### Regarding Usage Outside of Node.js +This library is written in JavaScript, a versatile programming language with broad applicability. While it's technically possible to integrate this library into a website or mobile application, it's strongly advised against doing so. + +In the standard configuration, you make requests to the Buckaroo API using one of our provided libraries, typically from your server (such as a Node.js server). Your secret key is securely stored on this server, inaccessible to external entities. + +However, if you incorporate this library directly into a website or app, your secret key will be exposed to users. This could enable users to take actions on your behalf using that key. + #### Need more examples? More examples can be found in the [examples folder](https://github.com/buckaroo-it/BuckarooSDK_Node/tree/master/example) From 7d943cde2ac8f1432729f4a092c5dcbf0340f2ff Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Fri, 13 Oct 2023 14:15:32 +0200 Subject: [PATCH 07/52] Rollup --- .babelrc | 14 ++++++++++++++ package.json | 8 +++++--- src/index.ts | 3 +++ tsconfig-declarations.json | 9 +++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .babelrc create mode 100644 tsconfig-declarations.json diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..d4e2cf80 --- /dev/null +++ b/.babelrc @@ -0,0 +1,14 @@ +{ + "plugins": ["@babel/plugin-proposal-class-properties"], + "presets": [ + "@babel/preset-typescript", + [ + "@babel/preset-env", + { + "targets": { + "node": "6.9" + } + } + ] + ] +} diff --git a/package.json b/package.json index 267613ec..7d774ede 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,16 @@ "name": "@buckaroo/buckaroo_sdk", "version": "1.0.0", "description": "Buckaroo payment SDK", - "main": "dist/index.js", + "main": "dist/buckaroo.cjs.js", + "module": "dist/buckaroo.esm.js", "types": "dist/index.d.ts", "engines": { "node": ">=6.14" }, "scripts": { - "prepare": "npm run build", - "build": "tsc", + "build": "yarn build:library && yarn build:declarations", + "build:library": "rollup --config rollup.config.js", + "build:declarations": "tsc --project tsconfig-declarations.json", "test": "jest", "prettier": "prettier --write ." }, diff --git a/src/index.ts b/src/index.ts index 78f1a730..eaa205fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,3 +57,6 @@ export default class Buckaroo { return getMethod(name) } } + + +export { Buckaroo }; \ No newline at end of file diff --git a/tsconfig-declarations.json b/tsconfig-declarations.json new file mode 100644 index 00000000..9b72f9ce --- /dev/null +++ b/tsconfig-declarations.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "files": [], + "compilerOptions": { + "emitDeclarationOnly": true, + "declaration": true, + "declarationDir": "dist/types" + } +} \ No newline at end of file From b01e384ab3b462a7a40dc0810ca98a2fd356312f Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Fri, 13 Oct 2023 14:28:42 +0200 Subject: [PATCH 08/52] Git ignored update and rollup config --- .gitignore | 1 - .../additional_services/creditManagment.js | 63 +++++ example/additional_services/subscription.js | 36 +++ example/buckarooClient.js | 12 + example/response/push.js | 39 +++ example/transaction/creditCard.js | 15 + example/transaction/ideal.js | 20 ++ rollup.config.js | 40 +++ tests/BuckarooClient.test.js | 13 + tests/Client.test.js | 72 +++++ tests/Models/index.js | 60 ++++ tests/PaymentMethods/AfterPay.test.js | 122 ++++++++ .../PaymentMethods/AfterPayDigiAccept.test.js | 114 ++++++++ tests/PaymentMethods/Alipay.test.js | 26 ++ tests/PaymentMethods/ApplePay.test.js | 50 ++++ tests/PaymentMethods/Bancontact.test.js | 86 ++++++ tests/PaymentMethods/BankTransfer.test.js | 23 ++ tests/PaymentMethods/Belfius.test.js | 33 +++ tests/PaymentMethods/Billink.test.js | 127 +++++++++ tests/PaymentMethods/BuckarooVoucher.test.js | 59 ++++ tests/PaymentMethods/BuckarooWallet.test.js | 115 ++++++++ tests/PaymentMethods/CreditCard.test.js | 119 ++++++++ tests/PaymentMethods/CreditClick.test.js | 32 +++ tests/PaymentMethods/CreditManagment.test.js | 265 ++++++++++++++++++ tests/PaymentMethods/EPS.test.js | 25 ++ tests/PaymentMethods/Emandate.test.js | 56 ++++ tests/PaymentMethods/Giftcard.test.js | 37 +++ tests/PaymentMethods/GiroPay.test.js | 28 ++ tests/PaymentMethods/Ideal.test.js | 55 ++++ tests/PaymentMethods/IdealQR.test.js | 31 ++ tests/PaymentMethods/In3.test.js | 105 +++++++ tests/PaymentMethods/In3Old.test.js | 77 +++++ tests/PaymentMethods/KBC.test.js | 25 ++ tests/PaymentMethods/Klarna.test.js | 82 ++++++ tests/PaymentMethods/KlarnaKp.test.js | 87 ++++++ tests/PaymentMethods/Marketplaces.test.js | 51 ++++ tests/PaymentMethods/PayPerEmail.test.js | 44 +++ tests/PaymentMethods/Payconiq.test.js | 34 +++ .../PaymentMethods/PaymentInitiation.test.js | 29 ++ tests/PaymentMethods/Paypal.test.js | 50 ++++ tests/PaymentMethods/PiM.test.js | 10 + tests/PaymentMethods/Przelewy24.test.js | 31 ++ tests/PaymentMethods/SEPA.test.js | 128 +++++++++ tests/PaymentMethods/Sofort.test.js | 35 +++ tests/PaymentMethods/Subscriptions.test.js | 154 ++++++++++ tests/PaymentMethods/SurePay.test.js | 14 + tests/PaymentMethods/Thunes.test.js | 25 ++ tests/PaymentMethods/Tinka.test.js | 64 +++++ tests/PaymentMethods/Trustly.test.js | 17 ++ tests/PaymentMethods/WechatPay.test.js | 24 ++ 50 files changed, 2859 insertions(+), 1 deletion(-) create mode 100644 example/additional_services/creditManagment.js create mode 100644 example/additional_services/subscription.js create mode 100644 example/buckarooClient.js create mode 100644 example/response/push.js create mode 100644 example/transaction/creditCard.js create mode 100644 example/transaction/ideal.js create mode 100644 rollup.config.js create mode 100644 tests/BuckarooClient.test.js create mode 100644 tests/Client.test.js create mode 100644 tests/Models/index.js create mode 100644 tests/PaymentMethods/AfterPay.test.js create mode 100644 tests/PaymentMethods/AfterPayDigiAccept.test.js create mode 100644 tests/PaymentMethods/Alipay.test.js create mode 100644 tests/PaymentMethods/ApplePay.test.js create mode 100644 tests/PaymentMethods/Bancontact.test.js create mode 100644 tests/PaymentMethods/BankTransfer.test.js create mode 100644 tests/PaymentMethods/Belfius.test.js create mode 100644 tests/PaymentMethods/Billink.test.js create mode 100644 tests/PaymentMethods/BuckarooVoucher.test.js create mode 100644 tests/PaymentMethods/BuckarooWallet.test.js create mode 100644 tests/PaymentMethods/CreditCard.test.js create mode 100644 tests/PaymentMethods/CreditClick.test.js create mode 100644 tests/PaymentMethods/CreditManagment.test.js create mode 100644 tests/PaymentMethods/EPS.test.js create mode 100644 tests/PaymentMethods/Emandate.test.js create mode 100644 tests/PaymentMethods/Giftcard.test.js create mode 100644 tests/PaymentMethods/GiroPay.test.js create mode 100644 tests/PaymentMethods/Ideal.test.js create mode 100644 tests/PaymentMethods/IdealQR.test.js create mode 100644 tests/PaymentMethods/In3.test.js create mode 100644 tests/PaymentMethods/In3Old.test.js create mode 100644 tests/PaymentMethods/KBC.test.js create mode 100644 tests/PaymentMethods/Klarna.test.js create mode 100644 tests/PaymentMethods/KlarnaKp.test.js create mode 100644 tests/PaymentMethods/Marketplaces.test.js create mode 100644 tests/PaymentMethods/PayPerEmail.test.js create mode 100644 tests/PaymentMethods/Payconiq.test.js create mode 100644 tests/PaymentMethods/PaymentInitiation.test.js create mode 100644 tests/PaymentMethods/Paypal.test.js create mode 100644 tests/PaymentMethods/PiM.test.js create mode 100644 tests/PaymentMethods/Przelewy24.test.js create mode 100644 tests/PaymentMethods/SEPA.test.js create mode 100644 tests/PaymentMethods/Sofort.test.js create mode 100644 tests/PaymentMethods/Subscriptions.test.js create mode 100644 tests/PaymentMethods/SurePay.test.js create mode 100644 tests/PaymentMethods/Thunes.test.js create mode 100644 tests/PaymentMethods/Tinka.test.js create mode 100644 tests/PaymentMethods/Trustly.test.js create mode 100644 tests/PaymentMethods/WechatPay.test.js diff --git a/.gitignore b/.gitignore index 071aebbc..22fd4251 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ dist/ *.lock *.cache package-lock.json -*.js *.map *.d.ts .idea/ diff --git a/example/additional_services/creditManagment.js b/example/additional_services/creditManagment.js new file mode 100644 index 00000000..28f87470 --- /dev/null +++ b/example/additional_services/creditManagment.js @@ -0,0 +1,63 @@ +import buckaroo from '../buckarooClient'; +const creditManagement = buckaroo.method('CreditManagement3'); +// Sometimes we need to combine multiple payments. +// By calling "combine" it will combine the payload of the method with the next method or a given payload. +const invoice = creditManagement.createCombinedInvoice({ + invoice: '', + applyStartRecurrent: false, + invoiceAmount: 10, + invoiceAmountVAT: 1, + invoiceDate: '', + dueDate: '', + schemeKey: '2amq34', + maxStepIndex: 1, + allowedServices: 'ideal,mastercard', + debtor: { + code: 'johnsmith4' + }, + email: 'youremail@example.nl', + phone: { + mobile: '06198765432' + }, + person: { + culture: 'nl-NL', + title: 'Msc', + initials: 'JS', + firstName: 'Test', + lastNamePrefix: 'Jones', + lastName: 'Aflever', + gender: 'male' + }, + company: { + culture: 'nl-NL', + name: 'My Company Corporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741' + }, + address: { + street: 'Hoofdtraat', + houseNumber: '90', + houseNumberAdditional: 'A', + zipcode: '8441ER', + city: 'Heerenveen', + state: 'Friesland', + country: 'NL' + } +}); +const sepadirectdebit = buckaroo.method('sepadirectdebit'); +sepadirectdebit + .combine(invoice.data) + .pay({ + invoice: '', + amountDebit: 10.1, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + collectdate: '2022-06-03', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + customer: { + name: 'John Smith' + } +}) + .request(); diff --git a/example/additional_services/subscription.js b/example/additional_services/subscription.js new file mode 100644 index 00000000..2b84c343 --- /dev/null +++ b/example/additional_services/subscription.js @@ -0,0 +1,36 @@ +require('../buckarooClient'); +import Subscriptions from '../../src/PaymentMethods/Subscriptions'; +import Ideal from '../../src/PaymentMethods/Ideal'; +const subscription = new Subscriptions().createCombined({ + address: undefined, + allowedServices: '', + b2b: '', + bankAccount: { accountName: '', bic: '', iban: '' }, + billingTiming: 0, + company: undefined, + configuration: undefined, + configurationCode: '', + customerAccountName: '', + customerBIC: '', + customerIBAN: '', + debtor: { code: '' }, + email: '345345345', + includeTransaction: false, + mandateReference: '', + subscriptionGuid: '', + termStartDay: 0, + termStartMonth: 0, + termStartWeek: '', + transactionVatPercentage: 0 +}); +(async () => { + const combinedPayment = await new Ideal() + .pay({ + amountDebit: 1, + currency: 'EUR', + description: 'test' + }) + .combine('subscriptions') + .create({}); + console.log(combinedPayment); +})(); diff --git a/example/buckarooClient.js b/example/buckarooClient.js new file mode 100644 index 00000000..112e489e --- /dev/null +++ b/example/buckarooClient.js @@ -0,0 +1,12 @@ +import Buckaroo from "@buckaroo/buckaroo_sdk"; +const buckaroo = Buckaroo.InitializeClient({ + secretKey: 'secret', + websiteKey: 'website' +}); +buckaroo.config = { + mode: 'TEST', + currency: 'EUR', + returnURL: 'https://example.com/return', + pushURL: 'https://example.com/push' +}; +export default buckaroo; diff --git a/example/response/push.js b/example/response/push.js new file mode 100644 index 00000000..8047966e --- /dev/null +++ b/example/response/push.js @@ -0,0 +1,39 @@ +import buckaroo from '../buckarooClient'; +import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler'; +//START HTTP POST PUSH +let post_data = `{ + "brq_amount": "10.10", + "brq_currency": "EUR", + "brq_customer_name": "J. de Tèster", + "brq_invoicenumber": "SDKDevelopment.com_INVOICE_NO_628c6d032af90", + "brq_ordernumber": "SDKDevelopment.com_ORDER_NO_628c6d032af95", + "brq_payer_hash": "2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da", + "brq_payment": "D44ACDD0F99D4A1C811D2CD3EFDB05BA", + "brq_payment_method": "ideal", + "brq_SERVICE_ideal_consumerBIC": "RABONL2U", + "brq_SERVICE_ideal_consumerIBAN": "NL44RABO0123456789", + "brq_SERVICE_ideal_consumerIssuer": "ABN AMRO", + "brq_SERVICE_ideal_consumerName": "J. de Tèster", + "brq_SERVICE_ideal_transactionId": "0000000000000001", + "brq_statuscode": "190", + "brq_statuscode_detail": "S001", + "brq_statusmessage": "Transaction successfully processed", + "brq_test": "true", + "brq_timestamp": "2022-05-24 07:29:09", + "brq_transactions": "4C1BE53E2C42412AB32A799D9316E7DD", + "brq_websitekey": "IBjihN7Fhp", + "brq_signature": "bf7a62c830da2d2e004199919a8fe0d53b0668f5", +}`; +let reply_handler = new ReplyHandler(buckaroo.credentials, post_data); +reply_handler.validate(); +reply_handler.isValid(); // Return either true or false +//END HTTP POST PUSH +//START JSON PUSH +const auth_header = 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572'; +post_data = + '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}'; +const uri = 'https://buckaroo.dev/push'; +reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri); +reply_handler.validate(); +reply_handler.isValid(); // Return either true or false +//END JSON PUSH diff --git a/example/transaction/creditCard.js b/example/transaction/creditCard.js new file mode 100644 index 00000000..03b9c67d --- /dev/null +++ b/example/transaction/creditCard.js @@ -0,0 +1,15 @@ +require('../buckarooClient'); +import CreditCard from '../../src/PaymentMethods/CreditCard'; +const paymentMethod = new CreditCard('nexi'); +(async () => { + try { + const info = await paymentMethod.pay({ + invoice: 'test1', + amountDebit: 12 + }); + console.log(info); + } + catch (error) { + console.warn(error); + } +})(); diff --git a/example/transaction/ideal.js b/example/transaction/ideal.js new file mode 100644 index 00000000..a44f74a6 --- /dev/null +++ b/example/transaction/ideal.js @@ -0,0 +1,20 @@ +import buckarooClient from '../buckarooClient'; +const ideal = buckarooClient.method('ideal'); +//Pay +ideal + .pay({ + amountDebit: 10.1, + issuer: 'ABNANL2A', + description: 'Ideal Payment' +}) + .request(); +//Refund +ideal + .refund({ + originalTransactionKey: '', + amountCredit: 10.1, + invoice: '' +}) + .request(); +//Issuers +ideal.issuers(); diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..a8a1f249 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,40 @@ +const { join } = require('path'); +const json = require('rollup-plugin-json'); +const resolve = require('rollup-plugin-node-resolve'); +const babel = require('rollup-plugin-babel'); + +module.exports = { + input: join('src', 'index.ts'), + external: [ + // These Node.js internals are external to our bundles… + 'crypto', 'https', 'querystring', 'url', 'util', + // …as are the dependencies listed in our package.json. + ...Object.keys(require('./package.json').dependencies), + ], + output: [{ file: join('dist', 'buckaroo.cjs.js'), format: 'cjs' }, { file: join('dist', 'buckaroo.esm.js'), format: 'es' }], + plugins: [ + json(), + resolve({ + extensions: ['.ts'], + customResolveOptions: { + moduleDirectory: 'src', + }, + preferBuiltins: true, + }), + babel({ + extensions: ['.ts'], + }), + { + name: 'cert', + transform(code, id) { + if (id.endsWith('.pem') == false) { + return null; + } + return { + code: `export default ${JSON.stringify(code)}`, + map: { mappings: '' } + }; + } + } + ], +}; diff --git a/tests/BuckarooClient.test.js b/tests/BuckarooClient.test.js new file mode 100644 index 00000000..0c11eb77 --- /dev/null +++ b/tests/BuckarooClient.test.js @@ -0,0 +1,13 @@ +import Buckaroo from '../src'; +require('dotenv').config(); +const BuckarooClient = Buckaroo.InitializeClient({ + secretKey: process.env.BPE_SECRET_KEY || '', + websiteKey: process.env.BPE_WEBSITE_KEY || '' +}, { + mode: process.env.BPE_MODE === 'LIVE' ? 'LIVE' : 'TEST', + currency: process.env.BPE_CURRENCY_CODE || 'EUR', + returnURL: process.env.BPE_RETURN_URL || '', + returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', + pushURL: process.env.BPE_PUSH_URL || '' +}); +export default BuckarooClient; diff --git a/tests/Client.test.js b/tests/Client.test.js new file mode 100644 index 00000000..fe724816 --- /dev/null +++ b/tests/Client.test.js @@ -0,0 +1,72 @@ +import client from './BuckarooClient.test'; +import { TransactionResponse } from '../src/Models/Response/TransactionResponse'; +import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse'; +import { uniqid } from '../src/Utils/Functions'; +import { creditManagementTestInvoice } from "./PaymentMethods/CreditManagment.test"; +describe('Testing Buckaroo Client', () => { + test('Credentials', () => { + return client + .confirmCredentials() + .then((response) => { + expect(response).toBeTruthy(); + }); + }); + test('Batch transaction', async () => { + const transactionData = []; + for (let i = 0; i < 3; i++) { + let invoice = client + .method('CreditManagement3') + .createCombinedInvoice(creditManagementTestInvoice()) + .combine('sepadirectdebit') + .pay({ + invoice: uniqid(), + amountDebit: 10.1, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + collectdate: '2024-07-03', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + customer: { + name: 'John Smith' + } + }); + transactionData.push(invoice.data); + } + await client + .batch(transactionData) + .request() + .then((response) => { + expect(response).toBeTruthy(); + }) + .catch((err) => { + expect(err).toBeUndefined(); + }); + }); + describe('Transaction', () => { + const transactionService = client.transaction('39F3EC520A3F4A25B0A1899D4FF0E1CB'); + test('transaction Status', async () => { + await transactionService + .status() + .then((res) => { + expect(res instanceof TransactionResponse).toBeTruthy(); + }) + .catch((err) => { + expect(err).toBeUndefined(); + }); + }); + test('transaction Cancel Info', async () => { + await transactionService + .cancelInfo() + .then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy(); + }); + }); + test('transaction Refund Info', async () => { + await transactionService + .refundInfo() + .then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy(); + }); + }); + }); +}); diff --git a/tests/Models/index.js b/tests/Models/index.js new file mode 100644 index 00000000..b8a9fbe0 --- /dev/null +++ b/tests/Models/index.js @@ -0,0 +1,60 @@ +import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { getIPAddress } from '../../src/Utils/Functions'; +export const TestPerson = { + birthDate: '1990-01-01', + category: RecipientCategory.PERSON, + culture: '321', + firstName: 'John', + gender: 'male', + initials: 'R.T', + lastName: 'Do', + lastNamePrefix: 'testlastprefix', + placeOfBirth: 't', + title: 'title' +}; +export const TestCompany = { + category: RecipientCategory.COMPANY, + careOf: 'test', + chamberOfCommerce: 'test', + companyName: 'testCompany', + culture: 'culture', + vatApplicable: false, + vatNumber: '321' +}; +export const TestAddress = { + city: 'city', + country: 'NL', + houseNumber: '2313432', + houseNumberAdditional: '324', + state: 'state', + street: 'street', + zipcode: '32323' +}; +export const TestArticle = { + description: 'test', + identifier: 'identifier', + price: 10, + quantity: 2, + type: 'PhysicalArticle', + unitCode: '23', + vatCategory: '323', + vatPercentage: 1 +}; +export const TestPhone = { + fax: '23232', + landline: '323123', + mobile: '21312332' +}; +export const TestEmail = 'test@hotmail.com'; +export const TestBankAccount = { + accountName: 'accountName', + bic: 'bic', + iban: 'iban' +}; +export const TestBilling = { + recipient: TestPerson, + address: TestAddress, + phone: TestPhone, + email: TestEmail +}; +export const TestIp = getIPAddress(); diff --git a/tests/PaymentMethods/AfterPay.test.js b/tests/PaymentMethods/AfterPay.test.js new file mode 100644 index 00000000..5e1780c9 --- /dev/null +++ b/tests/PaymentMethods/AfterPay.test.js @@ -0,0 +1,122 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { RequestTypes } from '../../src/Constants/Endpoints'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +const method = buckarooClientTest.method('afterpay'); +describe('AfterPay methods', () => { + test('Pay', () => { + return method + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + invoice: 'testinvoice 123', + originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', + amountCredit: 1.23 + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Authorize', async () => { + await method + .authorize(paymentPayload) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('CancelAuthorize', async () => { + await method + .cancelAuthorize({ + invoice: 'testinvoice 123', + originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', + amountCredit: 1.23 + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Capture', async () => { + await method + .capture({ + ...paymentPayload, + originalTransactionKey: '123456789' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('PayRemainder', async () => { + await method + .payRemainder({}) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('AuthorizeRemainder', async () => { + await method + .authorizeRemainder({}) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Spercifications', async () => { + return method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); +const paymentPayload = { + clientIP: '127.0.0.1', + amountDebit: 40, + billing: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01', + companyName: 'buckarooTest', + conversationLanguage: 'NL', + identificationNumber: 'IdNumber12345', + customerNumber: 'customerNumber12345' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678', + landline: '0513123456' + } + }, + articles: [ + { + vatPercentage: 21, + price: 10, + description: 'Test', + quantity: 4, + identifier: 'test' + } + ], + description: 'Test', + merchantImageUrl: 'https://www.buckaroo.nl/Themes/Buckaroo/Content/images/logo.png' +}; diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.js b/tests/PaymentMethods/AfterPayDigiAccept.test.js new file mode 100644 index 00000000..c415788a --- /dev/null +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.js @@ -0,0 +1,114 @@ +import { RequestTypes } from '../../src/Constants/Endpoints'; +import { TestBilling } from '../Models'; +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import Gender from '../../src/Constants/Gender'; +const method = buckarooClientTest.method('afterpaydigiaccept'); +describe('AfterPayDigiAccept methods', () => { + test('Authorize', async () => { + await method + .authorize({ + amountDebit: 0, + articles: [], + bankAccount: '', + bankCode: '', + billing: TestBilling, + clientIP: '', + merchantImageUrl: '', + ourReference: '', + summaryImageUrl: '', + yourReference: '' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Pay', async () => { + await method + .pay({ ...paymentPayload, clientIP: '127.0.0.1' }) + .request() + .then((data) => { + expect(data.data).toBeDefined(); + }); + }); + test('Specification', async () => { + await method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); +const paymentPayload = { + amountDebit: 40.5, + b2b: true, + addressesDiffer: true, + customerIPAddress: '0.0.0.0', + shippingCosts: 0.5, + costCentre: 'Test', + department: 'Test', + establishmentNumber: 123456, + billing: { + recipient: { + gender: Gender.FEMALE, + initials: 'AB', + lastName: 'Do', + birthDate: '1990-01-01', + culture: 'NL' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + culture: 'NL', + gender: Gender.MALE, + initials: 'YJ', + lastName: 'Jansen', + companyName: 'Buckaroo B.V.', + birthDate: '1990-01-01', + chamberOfCommerce: '12345678', + vatNumber: 'NL12345678' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + articles: [ + { + identifier: uniqid(), + description: 'Blue Toy Car', + price: 10.0, + quantity: 2, + vatCategory: '1' + }, + { + identifier: uniqid(), + description: 'Red Toy Car', + price: 10.0, + quantity: 2, + vatCategory: '1' + } + ] +}; diff --git a/tests/PaymentMethods/Alipay.test.js b/tests/PaymentMethods/Alipay.test.js new file mode 100644 index 00000000..21b692b1 --- /dev/null +++ b/tests/PaymentMethods/Alipay.test.js @@ -0,0 +1,26 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const alipay = buckarooClientTest.method('alipay'); +describe('Alipay methods', () => { + test('Pay Simple Payload', async () => { + await alipay + .pay({ + amountDebit: 10, + useMobileView: false + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await alipay + .refund({ + amountCredit: 5, + originalTransactionKey: 'F397777A251645F8BDD81547B5005B4B' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/ApplePay.test.js b/tests/PaymentMethods/ApplePay.test.js new file mode 100644 index 00000000..20566d83 --- /dev/null +++ b/tests/PaymentMethods/ApplePay.test.js @@ -0,0 +1,50 @@ +import { uniqid } from '../../src/Utils/Functions'; +require('../BuckarooClient.test'); +import ApplePay from '../../src/PaymentMethods/ApplePay'; +const method = new ApplePay(); +describe('Applepay methods', () => { + test('Pay Simple Payload', async () => { + await method + .pay({ + amountDebit: 10, + paymentData: 'sad', + customerCardName: '87y7y8' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Pay Redirect Payload', async () => { + await method + .payRedirect({ + amountDebit: 10, + invoice: uniqid(), + servicesSelectableByClient: 'applepay', + continueOnIncomplete: true + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Specifications', async () => { + await method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Bancontact.test.js b/tests/PaymentMethods/Bancontact.test.js new file mode 100644 index 00000000..c617fed3 --- /dev/null +++ b/tests/PaymentMethods/Bancontact.test.js @@ -0,0 +1,86 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('bancontactmrcash'); +describe('BanContact methods', () => { + test('Pay Simple Payload', async () => { + await method + .pay({ + amountDebit: 10, + saveToken: true + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Authenticate', async () => { + await method + .authenticate({ amountDebit: 10 }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeDefined(); + }); + }); + test('PayOneClick', async () => { + await method + .payOneClick({ + originalTransactionKey: 'dsad', + amountDebit: 12 + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('CompletePayment', async () => { + await method + .completePayment({ + originalTransactionKey: 'dsad', + encryptedCardData: 'sUIB' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('PayEncrypted', async () => { + await method + .payEncrypted({ + amountDebit: 10, + encryptedCardData: 'yrtgdd' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('PayRecurring', async () => { + await method + .payRecurring({ + amountDebit: 10, + originalTransactionKey: 'sadas' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Specifications', () => { + method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/BankTransfer.test.js b/tests/PaymentMethods/BankTransfer.test.js new file mode 100644 index 00000000..599c31d4 --- /dev/null +++ b/tests/PaymentMethods/BankTransfer.test.js @@ -0,0 +1,23 @@ +import Gender from '../../src/Constants/Gender'; +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('transfer'); +describe('Transfer methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 10, + customer: { + firstName: 'John', + lastName: 'Doe', + gender: Gender.MALE + }, + email: 'test@hotmail.com', + sendMail: true, + dateDue: '2024-10-10' + }) + .request() + .then((res) => { + expect(res.isAwaitingConsumer()).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Belfius.test.js b/tests/PaymentMethods/Belfius.test.js new file mode 100644 index 00000000..83ddc881 --- /dev/null +++ b/tests/PaymentMethods/Belfius.test.js @@ -0,0 +1,33 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('belfius'); +describe('testing methods', () => { + test('Pay Simple Payload', async () => { + await method + .pay({ + amountDebit: 10 + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: '86CFE2CB5901463EADE061633BDB9EC8' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Specifications', async () => { + await method + .specification() + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Billink.test.js b/tests/PaymentMethods/Billink.test.js new file mode 100644 index 00000000..4cdeae3d --- /dev/null +++ b/tests/PaymentMethods/Billink.test.js @@ -0,0 +1,127 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +require('../BuckarooClient.test'); +const method = buckarooClientTest.method('billink'); +describe('Billink methods', () => { + test('Pay', async () => { + await method + .pay(payload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 12, + originalTransactionKey: 'ytgty' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Authorize', async () => { + await method + .authorize(payload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('CancelAuthorize', async () => { + await method + .cancelAuthorize({ + originalTransactionKey: 'ytgty', + amountCredit: 10, + invoice: 'sdsa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Capture', async () => { + await method + .capture({ + originalTransactionKey: 'ytgty', + invoice: "'dsa", + amountDebit: 123, + articles: payload.articles + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); +const payload = { + amountDebit: 50.3, + order: '', + invoice: '', + trackAndTrace: 'TR0F123456789', + vATNumber: '2', + billing: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + title: 'Female', + initials: 'JD', + firstName: 'John', + lastName: 'Do', + birthDate: '01-01-1990', + chamberOfCommerce: 'TEST' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433', + landline: '0109876543' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'John Smith', + title: 'Male', + initials: 'JD', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + } + }, + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1, + priceExcl: 5 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1, + priceExcl: 5 + } + ] +}; diff --git a/tests/PaymentMethods/BuckarooVoucher.test.js b/tests/PaymentMethods/BuckarooVoucher.test.js new file mode 100644 index 00000000..40986071 --- /dev/null +++ b/tests/PaymentMethods/BuckarooVoucher.test.js @@ -0,0 +1,59 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('buckaroovoucher'); +describe('testing methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 12, + voucherCode: '' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 12, + originalTransactionKey: '' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('GetBalance', async () => { + await method + .getBalance({ + voucherCode: 'WP6W-XXXX-XXXX-56T7' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('CreateApplication', async () => { + await method + .create({ + creationBalance: 12, + usageType: 1, + validFrom: '2021-01-01', + validUntil: '2024-01-01' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('DeactivateVoucher', async () => { + await method + .deactivate({ + voucherCode: '' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/BuckarooWallet.test.js b/tests/PaymentMethods/BuckarooWallet.test.js new file mode 100644 index 00000000..209621b7 --- /dev/null +++ b/tests/PaymentMethods/BuckarooWallet.test.js @@ -0,0 +1,115 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +const method = buckarooClientTest.method('BuckarooWalletCollecting'); +describe('BuckarooWallet methods', () => { + test('Pay', async () => { + await method + .pay({ + invoice: 'string', + amountDebit: 12, + walletId: '2' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + invoice: 'string', + amountCredit: 12, + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('CancelReservation', async () => { + await method + .cancel({ + invoice: 'BuckarooWalletInvoiceId', + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', + amountDebit: 1, + walletMutationGuid: '49B018248ECE4346AC20B902' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('deposit', async () => { + await method + .deposit({ + invoice: 'string', + walletId: '', + amountCredit: 12, + originalTransactionKey: '' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Update', async () => { + await method + .update({ + walletId: '10', + status: 'Disabled', + email: 'test@buckaroo.nl', + customer: { + firstName: 'John', + lastName: 'string' + }, + bankAccount: { + iban: 'NL13TEST0123456789' + } + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Withdrawal', async () => { + await method + .withdrawal({ + invoice: 'BuckarooWalletInvoiceId', + walletId: '10', + amountDebit: 10, + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('Create Wallet', async () => { + await method + .create({ + walletId: uniqid(), + email: 'test@buckaroo.nl', + customer: { + firstName: 'John', + lastName: 'string' + }, + bankAccount: { + iban: 'NL13TEST0123456789' + } + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('GetInfo', async () => { + await method + .getInfo({ + walletId: '10' + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditCard.test.js b/tests/PaymentMethods/CreditCard.test.js new file mode 100644 index 00000000..82c261ff --- /dev/null +++ b/tests/PaymentMethods/CreditCard.test.js @@ -0,0 +1,119 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('visa'); +describe('testing methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 10 + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Authorize', async () => { + await method + .authorize({ + amountDebit: 10 + }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); + test('PayEncrypted', async () => { + await method + .payEncrypted({ + amountDebit: 10, + name: 'Visa', + encryptedCardData: '' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('PayWithSecurityCode', async () => { + await method + .payWithSecurityCode({ + amountDebit: 10, + encryptedSecurityCode: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('AuthorizeWithSecurityCode', async () => { + await method + .authorizeWithSecurityCode({ + amountDebit: 10, + encryptedSecurityCode: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('AuthorizeEncrypted', async () => { + await method + .authorizeEncrypted({ + amountDebit: 10, + encryptedCardData: 'sad', + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('CancelAuthorize', async () => { + await method + .cancelAuthorize({ + originalTransactionKey: 'sad', + amountCredit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Capture', async () => { + await method + .capture({ + originalTransactionKey: 'sad', + amountDebit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('PayRecurrent', async () => { + await method + .payRecurrent({ + originalTransactionKey: 'sad', + amountDebit: 10, + name: 'Visa' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditClick.test.js b/tests/PaymentMethods/CreditClick.test.js new file mode 100644 index 00000000..82994ff4 --- /dev/null +++ b/tests/PaymentMethods/CreditClick.test.js @@ -0,0 +1,32 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('creditclick'); +describe('Testing CreditClick methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 31, + person: { + firstName: 'test', + lastName: 'test' + }, + email: 't.tester@test.nl' + }) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 31, + originalTransactionKey: 'C85BABFCCA2D4921B9CFBA0EBDF82C70', + description: 'test', + refundReason: 'Fraudulent' + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditManagment.test.js b/tests/PaymentMethods/CreditManagment.test.js new file mode 100644 index 00000000..86a196ba --- /dev/null +++ b/tests/PaymentMethods/CreditManagment.test.js @@ -0,0 +1,265 @@ +import Gender from '../../src/Constants/Gender'; +import CreditManagementInstallmentInterval from '../../src/Constants/CreditManagementInstallmentInterval'; +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +const creditManagement = buckarooClientTest.method('CreditManagement3'); +describe('Testing Credit Management', () => { + test('CreateInvoice', async () => { + await creditManagement + .createInvoice(creditManagementTestInvoice()) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('CreateInvoice With Articles', async () => { + await creditManagement + .createInvoice(creditManagementTestInvoice({ + invoice: 'Billingtest101', + description: 'buckaroo_schema_test_PDF', + invoiceAmount: 217.8, + invoiceDate: '2022-01-01', + dueDate: '1990-01-01', + schemeKey: '2amq34', + poNumber: 'PO-12345', + debtor: { + code: 'johnsmith4' + }, + articles: [ + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 1, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123 + }, + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 2, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123 + } + ] + })) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('Pause Invoice', async () => { + await creditManagement + .pauseInvoice({ invoice: 'Testinvoice184915' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('UnPause Invoice', async () => { + await creditManagement + .unpauseInvoice({ invoice: 'Testinvoice184915' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('Invoice Info', async () => { + await creditManagement + .invoiceInfo({ + invoice: 'INV001', + invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }] + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('Debtor Info', async () => { + await creditManagement + .debtorInfo({ + debtor: { + code: 'TestDebtor123123' + } + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('AddOrUpdateProductLines', async () => { + await creditManagement + .addOrUpdateProductLines({ + invoiceKey: 'd42', + articles: [ + { + type: 'Regular', + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + totalVat: 12, + totalAmount: 123, + quantity: 2, + price: 20.1 + }, + { + type: 'Regular', + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + totalVat: 12, + totalAmount: 123, + quantity: 1, + price: 10.1 + } + ] + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('resumeDebtorFile', async () => { + await creditManagement + .resumeDebtorFile({ debtorFileGuid: 'd42' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('pauseDebtorFile', async () => { + await creditManagement + .pauseDebtorFile({ debtorFileGuid: 'd42' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('addOrUpdateDebtor', async () => { + await creditManagement + .addOrUpdateDebtor(creditManagementTestInvoice({ + addressUnreachable: false, + emailUnreachable: false, + mobileUnreachable: false + })) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('CreateCombinedInvoice', async () => { + const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); + buckarooClientTest + .method('sepadirectdebit') + .combine(combinedInvoice.data) + .pay({ + iban: 'NL39RABO0300065264', + bic: 'RABONL2U', + mandateReference: 'TestMandateReference', + mandateDate: '2020-01-01', + collectDate: '2020-07-03', + amountDebit: 10.1, + customer: { + name: 'John Smith' + }, + invoice: uniqid('TestInvoice') + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('CreatePaymentPlan', async () => { + await creditManagement + .createPaymentPlan({ + description: 'Payment in two intstallments', + includedInvoiceKey: '20D09973FB5C4DBC9A33DB0F4F707xxx', + dossierNumber: 'PaymentplanJohnsmith123', + installmentCount: 2, + initialAmount: 100, + startDate: '2030-01-01', + interval: CreditManagementInstallmentInterval.MONTH, + paymentPlanCostAmount: 3.5, + paymentPlanCostAmountVat: 1.2, + recipientEmail: 'test@buckaroo.nl' + }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); + test('pauseInvoice', async () => { + await creditManagement + .pauseInvoice({ + invoice: 'd42' + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); +export const creditManagementTestInvoice = (append = {}) => { + return { + applyStartRecurrent: false, + invoiceAmount: 10, + invoiceAmountVAT: 1, + invoiceDate: '2022-01-01', + dueDate: '2030-01-01', + schemeKey: '2amq34', + maxStepIndex: 1, + allowedServices: 'ideal,mastercard', + debtor: { + code: 'johnsmith4' + }, + email: 'youremail@example.nl', + phone: { + mobile: '06198765432' + }, + person: { + culture: 'nl-NL', + title: 'Msc', + initials: 'JS', + firstName: 'Test', + lastNamePrefix: 'Jones', + lastName: 'Aflever', + gender: Gender.MALE + }, + company: { + culture: 'nl-NL', + name: 'My Company Corporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741' + }, + address: { + street: 'Hoofdtraat', + houseNumber: '90', + houseNumberAdditional: 'A', + zipcode: '8441ER', + city: 'Heerenveen', + state: 'Friesland', + country: 'NL' + }, + ...append + }; +}; diff --git a/tests/PaymentMethods/EPS.test.js b/tests/PaymentMethods/EPS.test.js new file mode 100644 index 00000000..b8d1c150 --- /dev/null +++ b/tests/PaymentMethods/EPS.test.js @@ -0,0 +1,25 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('eps'); +describe('Testing Eps methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 10.1 + }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + method + .refund({ + amountCredit: 10.1, + originalTransactionKey: '1234567890' + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Emandate.test.js b/tests/PaymentMethods/Emandate.test.js new file mode 100644 index 00000000..019ebebc --- /dev/null +++ b/tests/PaymentMethods/Emandate.test.js @@ -0,0 +1,56 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('emandate'); +describe('Testing Emandates methods', () => { + test('GetIssuerList', async () => { + await method + .issuerList() + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); + }); + test('CreateMandate', async () => { + method + .createMandate({ + debtorReference: 'klant1234', + language: 'nl', + continueOnIncomplete: true, + purchaseId: 'purchaseid1234', + sequenceType: 0 + }) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); + test('GetStatus', async () => { + method + .status({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC' }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); + }); + test('ModifyMandate', async () => { + method + .modifyMandate({ + originalMandateId: '1DC014098EC5C1F40AD803B83A425153BBC', + continueOnIncomplete: true + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); + test('CancelMandate', async () => { + method + .cancelMandate({ + mandateId: '1DC014098EC5C1F40AD803B83A425153BBC', + purchaseId: 'purchaseid1234' + }) + .request() + .then((response) => { + expect(response.isValidationFailure()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Giftcard.test.js b/tests/PaymentMethods/Giftcard.test.js new file mode 100644 index 00000000..d05c2d33 --- /dev/null +++ b/tests/PaymentMethods/Giftcard.test.js @@ -0,0 +1,37 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('boekenbon'); +describe('GiftCard methods', () => { + test('Pay', async () => { + const responsePay = await method + .pay({ + amountDebit: 10, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '500' + }) + .request(); + expect(responsePay.isSuccess()).toBeTruthy(); + const responseRemainderPay = await buckarooClientTest + .method('ideal') + .payRemainder({ + amountDebit: 10.1, + issuer: 'ABNANL2A', + invoice: responsePay.data.invoice, + originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey + }) + .request(); + expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 5, + originalTransactionKey: '9F99B530DA5449EB919D27351D28BDF2', + email: '', + lastName: '' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/GiroPay.test.js b/tests/PaymentMethods/GiroPay.test.js new file mode 100644 index 00000000..8fb80d49 --- /dev/null +++ b/tests/PaymentMethods/GiroPay.test.js @@ -0,0 +1,28 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +const method = buckarooClientTest.method('giropay'); +describe('Testing Giropay methods', () => { + test('Pay', async () => { + await method + .pay({ + bic: 'GENODETT488', + amountDebit: 10.1 + }) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 10, + invoice: uniqid(), + originalTransactionKey: '2D04704995B74D679AACC59F87XXXXXX' + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Ideal.test.js b/tests/PaymentMethods/Ideal.test.js new file mode 100644 index 00000000..4842f589 --- /dev/null +++ b/tests/PaymentMethods/Ideal.test.js @@ -0,0 +1,55 @@ +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import buckarooClientTest from '../BuckarooClient.test'; +const ideal = buckarooClientTest.method('ideal'); +describe('testing Ideal methods', () => { + test('Issuers', () => { + return ideal.issuers().then((response) => { + expect(Array.isArray(response)).toBeTruthy(); + }); + }); + test('Pay Simple Payload', () => { + return ideal + .pay({ + amountDebit: 10.1, + issuer: 'ABNANL2A', + continueOnIncomplete: false, + additionalParameters: { + initiated_by_magento: 1, + service_action: 'something' + } + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', () => { + return ideal + .refund({ + order: uniqid(), + invoice: uniqid(), + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', + amountCredit: 4.23, + clientIP: getIPAddress(), + additionalParameters: { + initiated_by_magento: '1', + service_action: 'something' + } + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('InstantRefund', () => { + return ideal + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/IdealQR.test.js b/tests/PaymentMethods/IdealQR.test.js new file mode 100644 index 00000000..db67b992 --- /dev/null +++ b/tests/PaymentMethods/IdealQR.test.js @@ -0,0 +1,31 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('idealqr'); +describe('Testing IdealQR methods', () => { + test('Pay', async () => { + await method + .generate({ + description: 'Test purchase', + returnURL: 'https://buckaroo.dev/return', + returnURLCancel: 'https://buckaroo.dev/cancel', + returnURLError: 'https://buckaroo.dev/error', + returnURLReject: 'https://buckaroo.dev/reject', + minAmount: 0.1, + maxAmount: 10.0, + imageSize: 2000, + purchaseId: 'Testpurchase123', + isOneOff: false, + amount: 1.0, + amountIsChangeable: true, + expiration: '2030-09-30', + isProcessing: false, + additionalParameters: { + initiated_by_magento: '1', + service_action: 'something' + } + }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/In3.test.js b/tests/PaymentMethods/In3.test.js new file mode 100644 index 00000000..3c17c00c --- /dev/null +++ b/tests/PaymentMethods/In3.test.js @@ -0,0 +1,105 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +const in3 = buckarooClientTest.method('In3'); +describe('Testing In3 methods', () => { + test('Pay', async () => { + await in3 + .pay(payload) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await in3 + .refund({ + amountCredit: 42, + originalTransactionKey: '', + merchantImageUrl: '', + summaryImageUrl: '', + articles: [] + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeFalsy(); + }); + }); +}); +const payload = { + amountDebit: 52.3, + description: 'in3 pay', + order: uniqid(), + invoice: uniqid(), + clientIP: '127.0.0.1', + billing: { + recipient: { + category: RecipientCategory.PERSON, + initials: 'J', + firstName: 'John', + lastName: 'Dona', + birthDate: '1990-01-01', + customerNumber: '12345', + companyName: 'Buckaroo', + chamberOfCommerce: '123456' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.PERSON, + careOf: 'J', + firstName: 'John', + lastName: 'Dona', + chamberOfCommerce: '123456' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + } + }, + articles: [ + { + identifier: 'Articlenumber1', + type: 'Physical', + description: 'Blue Toy Car', + category: 'test product', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + type: 'Physical', + description: 'Red Toy Car', + category: 'test product', + vatPercentage: 21, + quantity: 1, + price: 10.1 + }, + { + identifier: 'USPShippingID', + type: 'Physical', + description: 'UPS', + category: 'test product', + vatPercentage: 21, + quantity: 1, + price: 2 + } + ] +}; diff --git a/tests/PaymentMethods/In3Old.test.js b/tests/PaymentMethods/In3Old.test.js new file mode 100644 index 00000000..2100e257 --- /dev/null +++ b/tests/PaymentMethods/In3Old.test.js @@ -0,0 +1,77 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import Gender from '../../src/Constants/Gender'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +const capayable = buckarooClientTest.method('capayable'); +describe('Testing capayable methods', () => { + test('Pay', async () => { + await capayable + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await capayable + .refund({ + amountCredit: 42, + originalTransactionKey: '' + }) + .request() + .then((data) => { + expect(data.isFailed()).toBeTruthy(); + }); + }); + test('PayInInstallments', async () => { + await capayable + .payInInstallments(paymentPayload) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); +}); +const paymentPayload = { + clientIP: '127.0.0.0', + description: 'fdsfsdfdsf', + amountDebit: 32, + customerType: RecipientCategory.COMPANY, + invoiceDate: '22-01-2018', + customer: { + gender: Gender.FEMALE, + culture: 'nl-NL', + initials: 'J.S.', + lastName: 'Aflever', + birthDate: '1990-01-01' + }, + company: { + companyName: 'My Company B.V.', + chamberOfCommerce: '123456' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '2', + houseNumberSuffix: 'a', + zipcode: '8441EE', + city: 'Heerenveen', + country: 'NL' + }, + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678' + }, + articles: [ + { + identifier: '64381664f2f8b', + price: 10, + quantity: 1, + description: 'Blue Toy Car' + } + ], + subtotals: [ + { + name: 'Verzendkosten', + value: 2 + } + ] +}; diff --git a/tests/PaymentMethods/KBC.test.js b/tests/PaymentMethods/KBC.test.js new file mode 100644 index 00000000..dac67ae6 --- /dev/null +++ b/tests/PaymentMethods/KBC.test.js @@ -0,0 +1,25 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('KBCPaymentButton'); +describe('Testing KBC methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 10 + }) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + method + .refund({ + amountCredit: 10, + originalTransactionKey: 'B5675356904444F3965C33D280591C74' + }) + .request() + .then((response) => { + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Klarna.test.js b/tests/PaymentMethods/Klarna.test.js new file mode 100644 index 00000000..45e9bd2c --- /dev/null +++ b/tests/PaymentMethods/Klarna.test.js @@ -0,0 +1,82 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +const klarna = buckarooClientTest.method('klarna'); +describe('Testing Klarna methods', () => { + test('Pay', async () => { + await klarna + .pay(payload) + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); + test('PayInInstallments', async () => { + await klarna + .payInInstallments(payload) + .request() + .then((res) => { + expect(res).toBeDefined(); + }); + }); +}); +let payload = { + amountDebit: 50.3, + invoice: uniqid(), + order: uniqid(), + billing: { + recipient: { + category: RecipientCategory.PERSON, + gender: 'female', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '13', + houseNumberAdditional: 'a', + zipcode: '1234AB', + city: 'Heerenveen', + country: 'NL' + }, + phone: { + mobile: '0698765433' + }, + email: 'test@buckaroo.nl' + }, + shipping: { + recipient: { + category: RecipientCategory.COMPANY, + gender: 'male', + firstName: 'John', + lastName: 'Do', + birthDate: '1990-01-01' + }, + address: { + street: 'Kalverstraat', + houseNumber: '13', + houseNumberAdditional: 'b', + zipcode: '4321EB', + city: 'Amsterdam', + country: 'NL' + }, + email: 'test@buckaroo.nl' + }, + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1 + } + ] +}; diff --git a/tests/PaymentMethods/KlarnaKp.test.js b/tests/PaymentMethods/KlarnaKp.test.js new file mode 100644 index 00000000..30022eae --- /dev/null +++ b/tests/PaymentMethods/KlarnaKp.test.js @@ -0,0 +1,87 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import gender from '../../src/Constants/Gender'; +const klarnaKp = buckarooClientTest.method('klarnakp'); +describe('KlarnaKp', () => { + test('Pay', async () => { + await klarnaKp + .pay({ + amountDebit: 50.3, + reservationNumber: '2377577452' + }) + .request() + .then((info) => { + expect(info.isFailed()).toBeTruthy(); + }); + }); + test('Reserve', async () => { + await klarnaKp + .reserve({ + gender: gender.MALE, + operatingCountry: 'NL', + pno: '01011990', + billing: { + recipient: { + firstName: 'John', + lastName: 'Do' + }, + address: { + street: 'Neherkade', + houseNumber: '1', + zipcode: '2521VA', + city: 'Gravenhage', + country: 'NL' + }, + phone: { + mobile: '0612345678' + }, + email: 'youremail@example.nl' + }, + shipping: { + recipient: { + firstName: 'John', + lastName: 'Do' + }, + address: { + street: 'Rosenburglaan', + houseNumber: '216', + zipcode: '4385 JM', + city: 'Vlissingen', + country: 'NL' + }, + email: 'test@buckaroo.nl' + }, + articles: [ + { + identifier: 'Articlenumber1', + description: 'Blue Toy Car', + vatPercentage: 21, + quantity: 2, + price: 20.1 + }, + { + identifier: 'Articlenumber2', + description: 'Red Toy Car', + vatPercentage: 21, + quantity: 1, + price: 10.1 + } + ], + additionalParameters: { + initiated_by_magento: '1', + service_action: 'something' + } + }) + .request() + .then((info) => { + expect(info.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Cancel', async () => { + await klarnaKp + .cancel({}) + .request() + .then((info) => { + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Marketplaces.test.js b/tests/PaymentMethods/Marketplaces.test.js new file mode 100644 index 00000000..16d27038 --- /dev/null +++ b/tests/PaymentMethods/Marketplaces.test.js @@ -0,0 +1,51 @@ +require('../BuckarooClient.test'); +import Marketplaces from '../../src/PaymentMethods/Marketplaces'; +import Ideal from '../../src/PaymentMethods/Ideal'; +const marketplaces = new Marketplaces(); +const ideal = new Ideal(); +describe('Testing Marketplaces methods', () => { + test('Split', async () => { + marketplaces.split({ + daysUntilTransfer: 2, + marketplace: { + amount: 10, + description: '' + }, + seller: [ + { + accountId: '789C60F316D24B088ACD471', + amount: 50, + description: '' + }, + { + accountId: '369C60F316D24B088ACD238', + amount: 35, + description: '' + } + ] + }); + ideal + .combine(marketplaces) + .pay({ + issuer: 'ABNANL2A', + amountDebit: 95.0 + }) + .then((response) => { + expect(response.data).toBeDefined(); + }); + }); + test('transfer', async () => { + marketplaces.transfer({ originalTransactionKey: 'fwcafgdhgf' }).then((response) => { + expect(response.data).toBeDefined(); + }); + }); + test('refundSupplementary', async () => { + const market = marketplaces.refundSupplementary(); + ideal + .combine(market) + .refund({ originalTransactionKey: 'dasda', amountCredit: 10 }) + .then((response) => { + expect(response.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/PayPerEmail.test.js b/tests/PaymentMethods/PayPerEmail.test.js new file mode 100644 index 00000000..829588c6 --- /dev/null +++ b/tests/PaymentMethods/PayPerEmail.test.js @@ -0,0 +1,44 @@ +import Gender from '../../src/Constants/Gender'; +import PayPerEmail from '../../src/PaymentMethods/PayPerEmail'; +require('../BuckarooClient.test'); +const method = new PayPerEmail(); +describe('PayPerEmail methods', () => { + test('paymentInvitation', async () => { + await method + .paymentInvitation({ + invoice: '123456', + amountDebit: 10, + currency: 'EUR', + attachment: '', + additionalParameters: undefined, + clientIP: undefined, + continueOnIncomplete: 1, + culture: '', + customParameters: undefined, + customerEmail: '', + customerFirstName: '', + customerGender: Gender.NOT_APPLICABLE, + customerLastName: '', + description: '', + order: '', + originalTransactionKey: '', + originalTransactionReference: '', + pushURL: '', + pushURLFailure: '', + returnURL: '', + returnURLCancel: '', + returnURLError: '', + returnURLReject: '', + servicesExcludedForClient: '', + servicesSelectableByClient: '', + startRecurrent: false, + email: 's', + expirationDate: '', + merchantSendsEmail: false, + paymentMethodsAllowed: 'ideal' + }) + .then((response) => { + expect(response).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Payconiq.test.js b/tests/PaymentMethods/Payconiq.test.js new file mode 100644 index 00000000..8f12e1ef --- /dev/null +++ b/tests/PaymentMethods/Payconiq.test.js @@ -0,0 +1,34 @@ +import buckarooClientTest from "../BuckarooClient.test"; +const payconiq = buckarooClientTest.method("payconiq"); +describe('Payconiq', () => { + test('Pay', async () => { + await payconiq + .pay({ + amountDebit: 50.3, + order: '123456' + }).request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); + test('Refund', async () => { + await payconiq + .refund({ + amountCredit: 50.3, + originalTransactionKey: '123456' + }).request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); + test('InstantRefund', async () => { + await payconiq + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }).request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/PaymentInitiation.test.js b/tests/PaymentMethods/PaymentInitiation.test.js new file mode 100644 index 00000000..0bdae1d6 --- /dev/null +++ b/tests/PaymentMethods/PaymentInitiation.test.js @@ -0,0 +1,29 @@ +require('../BuckarooClient.test'); +import PayByBank from '../../src/PaymentMethods/PayByBank'; +const paymentInitiation = new PayByBank('PayByBank'); +describe('PayByBank methods', () => { + test('Pay', async () => { + await paymentInitiation + .pay({ + amountDebit: 50.3, + order: '123456', + issuer: 'INGBNL2A', + countryCode: 'NL' + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); + test('Refund', async () => { + await paymentInitiation + .refund({ + amountCredit: 50.3, + originalTransactionKey: '123456' + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Paypal.test.js b/tests/PaymentMethods/Paypal.test.js new file mode 100644 index 00000000..d548718a --- /dev/null +++ b/tests/PaymentMethods/Paypal.test.js @@ -0,0 +1,50 @@ +import buckarooClientTest from '../BuckarooClient.test'; +require('../BuckarooClient.test'); +import Paypal from '../../src/PaymentMethods/Paypal'; +const method = new Paypal('paypal'); +describe('Paypal', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 50.3 + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 50.3, + originalTransactionKey: '123456' + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); + test('ExtraInfo', async () => { + buckarooClientTest.method('subscriptions').createCombined({}); + await method + .extraInfo({ + amountDebit: 50.3, + address: { + street: 'Hoofstraat 90', + street2: 'Street 2', + city: 'Heerenveen', + state: 'Friesland', + zipcode: '8441AB', + country: 'NL' + }, + addressOverride: false, + costumer: { name: 'John' }, + noShipping: '0', + phone: { mobile: '0612345678' } + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/PiM.test.js b/tests/PaymentMethods/PiM.test.js new file mode 100644 index 00000000..ddf1750c --- /dev/null +++ b/tests/PaymentMethods/PiM.test.js @@ -0,0 +1,10 @@ +require('../BuckarooClient.test'); +import PiM from '../../src/PaymentMethods/PiM'; +const pim = new PiM(); +describe('PiM', () => { + test('generate', async () => { + await pim.generate().then((info) => { + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Przelewy24.test.js b/tests/PaymentMethods/Przelewy24.test.js new file mode 100644 index 00000000..bebf63b3 --- /dev/null +++ b/tests/PaymentMethods/Przelewy24.test.js @@ -0,0 +1,31 @@ +require('../BuckarooClient.test'); +import Przelewy24 from '../../src/PaymentMethods/Przelewy24'; +const method = new Przelewy24('Przelewy24'); +describe('Przelewy24', () => { + test('Pay', async () => { + method + .pay({ + amountDebit: 50.3, + customer: { + firstName: 'test', + lastName: 'test' + }, + email: 'test@hotmail.com' + }) + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 50.3, + originalTransactionKey: '123456' + }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/SEPA.test.js b/tests/PaymentMethods/SEPA.test.js new file mode 100644 index 00000000..4d5e74de --- /dev/null +++ b/tests/PaymentMethods/SEPA.test.js @@ -0,0 +1,128 @@ +require('../BuckarooClient.test'); +import SEPA from '../../src/PaymentMethods/SEPA'; +const method = new SEPA(); +describe('SEPA', () => { + test('Pay', async () => { + await method + .pay({ + additionalParameters: undefined, + amountDebit: 0, + clientIP: undefined, + collectDate: '', + continueOnIncomplete: 0, + culture: '', + currency: '', + customParameters: undefined, + customerBIC: '', + customerIBAN: '', + customeraccountname: '', + description: '', + invoice: '', + mandateDate: '', + mandateReference: '', + order: '', + originalTransactionKey: '', + originalTransactionReference: '', + pushURL: '', + pushURLFailure: '', + returnURL: '', + returnURLCancel: '', + returnURLError: '', + returnURLReject: '', + servicesExcludedForClient: '', + servicesSelectableByClient: '', + startRecurrent: false + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 50.3, + originalTransactionKey: '' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('Authorize', async () => { + await method + .authorize({ + amountDebit: 0, + collectDate: '', + customerIBAN: '', + customeraccountname: '' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('PayRecurrent', async () => { + await method + .payRecurrent({ + collectDate: '', + amountDebit: 50.3, + originalTransactionKey: '' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('ExtraInfo', async () => { + await method + .extraInfo({ + additionalParameters: undefined, + amountDebit: 0, + city: '', + clientIP: undefined, + collectDate: '', + contractID: '', + country: '', + culture: '', + currency: '', + customParameters: undefined, + customerBIC: '', + customerCode: '', + customerIBAN: '', + customerName: '', + customerReferencePartyCode: '', + customerReferencePartyName: '', + customeraccountname: '', + description: '', + houseNumber: '', + houseNumberSuffix: '', + invoice: '', + mandateDate: '', + mandateReference: '', + order: '', + originalTransactionKey: '', + originalTransactionReference: '', + pushURL: '', + pushURLFailure: '', + returnURL: '', + returnURLCancel: '', + returnURLError: '', + returnURLReject: '', + servicesExcludedForClient: '', + servicesSelectableByClient: '', + startRecurrent: false, + street: '', + zipcode: '' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('Emandates', async () => { + await method + .payWithEmandate({ + mandateReference: '', + amountDebit: 50.3 + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Sofort.test.js b/tests/PaymentMethods/Sofort.test.js new file mode 100644 index 00000000..8663717a --- /dev/null +++ b/tests/PaymentMethods/Sofort.test.js @@ -0,0 +1,35 @@ +require('../BuckarooClient.test'); +import Sofort from '../../src/PaymentMethods/Sofort'; +const method = new Sofort(); +describe('Sofort', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 50.3, + order: '123456' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 50.3, + originalTransactionKey: '123456' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); + test('InstantRefund', async () => { + await method + .instantRefund({ + amountCredit: 4.23, + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + }) + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Subscriptions.test.js b/tests/PaymentMethods/Subscriptions.test.js new file mode 100644 index 00000000..c4baa95f --- /dev/null +++ b/tests/PaymentMethods/Subscriptions.test.js @@ -0,0 +1,154 @@ +import buckarooClientTest from '../BuckarooClient.test'; +const subscription = buckarooClientTest.method('subscriptions'); +test('Create', async () => { + subscription + .create({ + additionalParameters: { + signature: '123213' + }, + ratePlans: { + add: { + startDate: '2024-07-23', + ratePlanCode: 'zfv59mmy' + } + }, + ratePlanCharges: { + add: { + ratePlanChargeCode: 'test' + } + }, + configurationCode: 'gfyh9fe4', + configuration: { + name: 'owiejr' + }, + debtor: { + code: 'johnsmith4' + } + }) + .request() + .then((data) => { + expect(data.hasError()).toBeTruthy(); + }) + .catch((e) => { + expect(e).toBeDefined(); + }) + .catch((e) => { + expect(e).toBeDefined(); + }); +}); +test('Update', async () => { + subscription + .update({ + email: 'test@buckaroo.nl', + subscriptionGuid: 'FC512FC9CC3A485D8CF3D1804FF6xxxx', + configurationCode: '9wqe32ew', + ratePlan: { + update: { + ratePlanGuid: 'F075470B1BB24B9291943A888A2Fxxxx', + startDate: '2022-01-01', + endDate: '2030-01-01' + } + } + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); +}); +test('Combined Subscription', async () => { + const combinable = subscription + .createCombined({ + pushURL: 'https://buckaroo.dev/push', + includeTransaction: false, + transactionVatPercentage: 5, + configurationCode: 'gfyh9fe4', + email: 'test@buckaroo.nl', + ratePlans: { + add: { + startDate: '2033-01-01', + ratePlanCode: '9863hdcj' + } + }, + phone: { + mobile: '0612345678' + }, + debtor: { + code: 'johnsmith4' + }, + company: { + culture: 'nl-NL', + companyName: 'My Company Coporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741' + }, + address: { + street: 'Hoofdstraat', + houseNumber: '90', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL' + } + }) + .combine('ideal') + .pay({ + issuer: 'ABNANL2A', + amountDebit: 10, + startRecurrent: true + }) + .request() + .then((res) => { + expect(res).toBeDefined(); + }); +}); +test('Update Combined Subscription', async () => { + const combinable = subscription + .updateCombined({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }) + .combine('ideal') + .pay({ + issuer: 'ABNANL2A', + amountDebit: 10 + }) + .request() + .then((res) => { + expect(res).toBeDefined(); + }); +}); +test('Stop Subscription', async () => { + const stop = await subscription.stop({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }); + expect(stop).toBeDefined(); +}); +test('Subscription Info', async () => { + const info = await subscription.info({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }); + expect(info).toBeDefined(); +}); +test('Delete Subscription Config', async () => { + await subscription + .deletePaymentConfig({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }) + .request() + .then((res) => { + expect(res.httpResponse.statusCode === 200).toBeTruthy(); + }); +}); +test('Subscription Pause', async () => { + const pause = await subscription.pause({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + resumeDate: '2030-01-01' + }); + expect(pause).toBeDefined(); +}); +test('Subscription Resume', async () => { + const resume = await subscription.resume({ + resumeDate: '2030-01-01', + subscriptionGuid: '515461997AD34C50881D74157E38A64D' + }); + expect(resume).toBeDefined(); +}); diff --git a/tests/PaymentMethods/SurePay.test.js b/tests/PaymentMethods/SurePay.test.js new file mode 100644 index 00000000..01319efb --- /dev/null +++ b/tests/PaymentMethods/SurePay.test.js @@ -0,0 +1,14 @@ +require('../BuckarooClient.test'); +import SurePay from '../../src/PaymentMethods/Surepay'; +const method = new SurePay(); +describe('Sofort', () => { + test('Verify', async () => { + await method + .verify({ + customeraccountname: 'string' + }) + .then((info) => { + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Thunes.test.js b/tests/PaymentMethods/Thunes.test.js new file mode 100644 index 00000000..d02b5a7f --- /dev/null +++ b/tests/PaymentMethods/Thunes.test.js @@ -0,0 +1,25 @@ +require('../BuckarooClient.test'); +import Thunes from '../../src/PaymentMethods/Thunes'; +const thunes = new Thunes(); +describe('Thunes methods', () => { + test('authorize', async () => { + thunes.authorize({ amountDebit: 0 }).then((res) => { + expect(res.data).toBeDefined(); + }); + }); + test('capture', async () => { + thunes.capture({ amountDebit: 0, originalTransactionKey: '1' }).then((res) => { + expect(res.data).toBeDefined(); + }); + }); + test('getStatus', async () => { + thunes.getStatus({ originalTransactionKey: '111111111111' }).then((res) => { + expect(res.data).toBeDefined(); + }); + }); + test('cancel', async () => { + thunes.cancel({ originalTransactionKey: '111111111111' }).then((res) => { + expect(res.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Tinka.test.js b/tests/PaymentMethods/Tinka.test.js new file mode 100644 index 00000000..e939962a --- /dev/null +++ b/tests/PaymentMethods/Tinka.test.js @@ -0,0 +1,64 @@ +import Gender from "../../src/Constants/Gender"; +import buckarooClientTest from "../BuckarooClient.test"; +const method = buckarooClientTest.method('tinka'); +describe('Tinka', () => { + test('Pay', async () => { + await method + .pay({ + billing: { + recipient: { + lastNamePrefix: "the" + }, + email: "billingcustomer@buckaroo.nl", + phone: { + mobile: "0109876543" + }, + address: { + street: "Hoofdstraat", + houseNumber: "80", + houseNumberAdditional: "A", + zipcode: "8441EE", + city: "Heerenveen", + country: "NL" + } + }, + customer: { + gender: Gender.MALE, + firstName: 'Buck', + lastName: 'Aroo', + initials: 'BA', + birthDate: '1990-01-01', + }, + amountDebit: 3.5, + articles: [ + { + type: '1', + description: "Blue Toy Car", + brand: "Ford Focus", + manufacturer: "Ford", + color: "Red", + size: "Small", + quantity: 1, + price: 3.5, + unitCode: "test" + } + ], + deliveryDate: '09-07-2020', + deliveryMethod: 'CompanyStore', + paymentMethod: 'Credit' + }).request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 3.5, + originalTransactionKey: '1234567890' + }).request() + .then((res) => { + expect(res.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Trustly.test.js b/tests/PaymentMethods/Trustly.test.js new file mode 100644 index 00000000..a226eca6 --- /dev/null +++ b/tests/PaymentMethods/Trustly.test.js @@ -0,0 +1,17 @@ +require('../BuckarooClient.test'); +import Trustly from '../../src/PaymentMethods/Trustly'; +const method = new Trustly(); +describe('Trustly', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 12, + customerCountryCode: 'DE', + customerFirstName: 'da', + customerLastName: '34' + }) + .then((response) => { + expect(response).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/WechatPay.test.js b/tests/PaymentMethods/WechatPay.test.js new file mode 100644 index 00000000..10c0f9a6 --- /dev/null +++ b/tests/PaymentMethods/WechatPay.test.js @@ -0,0 +1,24 @@ +import buckarooClientTest from "../BuckarooClient.test"; +const method = buckarooClientTest.method('wechatpay'); +describe('WechatPay', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 3.5, + locale: 'en-US' + }).request() + .then((response) => { + expect(response.isPendingProcessing()).toBeDefined(); + }); + }); + test('Refund', async () => { + await method + .refund({ + amountCredit: 3.5, + originalTransactionKey: '1234567890' + }).request() + .then((response) => { + expect(response.data).toBeDefined(); + }); + }); +}); From 9a949d2561b8bdf16aa09db959e39e67a6891469 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:48:37 +0200 Subject: [PATCH 09/52] add multibanco,mbway,.etc --- .editorconfig | 25 ++ .prettierrc.json | 8 +- README.md | 22 +- .../additional_services/creditManagment.ts | 26 +- example/additional_services/subscription.ts | 26 +- example/buckarooClient.ts | 12 +- example/response/push.ts | 25 +- example/transaction/creditCard.ts | 18 +- example/transaction/ideal.ts | 14 +- jest.config.js | 4 +- .../CreditManagementInstallmentInterval.ts | 4 +- src/Constants/Endpoints.ts | 6 +- src/Constants/Gender.ts | 4 +- src/Constants/HttpMethods.ts | 4 +- src/Constants/IPProtocolVersion.ts | 22 +- src/Constants/RecipientCategory.ts | 4 +- src/Constants/ResponseStatus.ts | 4 +- src/Handlers/Credentials.ts | 22 +- src/Handlers/Reply/ReplyHandler.ts | 92 +++--- src/Models/IParameters.ts | 36 +-- src/Models/IRequest.ts | 66 ++-- src/Models/IServiceList.ts | 36 +-- src/Models/Interfaces/IAddress.ts | 30 +- src/Models/Interfaces/IArticle.ts | 42 +-- src/Models/Interfaces/IBankAccount.ts | 14 +- src/Models/Interfaces/ICustomer.ts | 28 +- src/Models/Interfaces/IDebtor.ts | 6 +- src/Models/Interfaces/IEmail.ts | 10 +- src/Models/Interfaces/IPhone.ts | 14 +- src/Models/Interfaces/IRecipient.ts | 96 +++--- src/Models/Model.ts | 93 +++--- src/Models/Response/BatchRequestResponse.ts | 12 +- src/Models/Response/HttpClientResponse.ts | 42 +-- .../Response/SpecificationRequestResponse.ts | 92 +++--- src/Models/Response/TransactionResponse.ts | 240 +++++++------- src/Models/ServiceParameters.ts | 23 +- src/PaymentMethods/Afterpay/Model/Address.ts | 14 +- src/PaymentMethods/Afterpay/Model/Article.ts | 26 +- src/PaymentMethods/Afterpay/Model/Customer.ts | 28 +- src/PaymentMethods/Afterpay/Model/Pay.ts | 54 ++-- src/PaymentMethods/Afterpay/Model/Phone.ts | 10 +- .../Afterpay/Model/Recipient.ts | 20 +- src/PaymentMethods/Afterpay/Model/Refund.ts | 16 +- src/PaymentMethods/Afterpay/index.ts | 34 +- .../AfterpayDigiAccept/Model/Article.ts | 22 +- .../AfterpayDigiAccept/Model/Customer.ts | 24 +- .../AfterpayDigiAccept/Model/Pay.ts | 64 ++-- .../AfterpayDigiAccept/Services/Address.ts | 24 +- .../AfterpayDigiAccept/Services/Phone.ts | 4 +- .../AfterpayDigiAccept/index.ts | 36 +-- src/PaymentMethods/Alipay/index.ts | 15 +- src/PaymentMethods/ApplePay/Models/Pay.ts | 12 +- src/PaymentMethods/ApplePay/index.ts | 16 +- src/PaymentMethods/Bancontact/Models/Pay.ts | 20 +- src/PaymentMethods/Bancontact/index.ts | 32 +- src/PaymentMethods/BankTransfer/Models/Pay.ts | 30 +- src/PaymentMethods/BankTransfer/index.ts | 12 +- src/PaymentMethods/Belfius/index.ts | 10 +- src/PaymentMethods/Billink/Models/Address.ts | 8 +- src/PaymentMethods/Billink/Models/Article.ts | 9 +- src/PaymentMethods/Billink/Models/Capture.ts | 14 +- src/PaymentMethods/Billink/Models/Customer.ts | 32 +- src/PaymentMethods/Billink/Models/Pay.ts | 42 +-- src/PaymentMethods/Billink/Models/Phone.ts | 8 +- src/PaymentMethods/Billink/Models/Refund.ts | 8 +- src/PaymentMethods/Billink/index.ts | 32 +- .../BuckarooVoucher/Models/Create.ts | 24 +- .../BuckarooVoucher/Models/Pay.ts | 8 +- src/PaymentMethods/BuckarooVoucher/index.ts | 24 +- .../BuckarooWallet/Models/BankAccount.ts | 4 +- .../BuckarooWallet/Models/Customer.ts | 8 +- .../BuckarooWallet/Models/Wallet.ts | 36 +-- src/PaymentMethods/BuckarooWallet/index.ts | 56 ++-- .../CreditCard/Models/CardData.ts | 8 +- .../CreditCard/Models/SecurityCode.ts | 8 +- src/PaymentMethods/CreditCard/index.ts | 62 ++-- src/PaymentMethods/CreditClick/Models/Pay.ts | 14 +- .../CreditClick/Models/Refund.ts | 17 +- src/PaymentMethods/CreditClick/index.ts | 12 +- .../Models/AddOrUpdateProductLines.ts | 20 +- .../CreditManagement/Models/Address.ts | 4 +- .../CreditManagement/Models/Article.ts | 48 +-- .../CreditManagement/Models/CreditNote.ts | 24 +- .../CreditManagement/Models/Debtor.ts | 22 +- .../CreditManagement/Models/DebtorInfo.ts | 16 +- .../CreditManagement/Models/Invoice.ts | 94 +++--- .../CreditManagement/Models/PaymentPlan.ts | 46 +-- .../Models/multiInfoInvoice.ts | 12 +- src/PaymentMethods/CreditManagement/index.ts | 82 ++--- src/PaymentMethods/EPS/index.ts | 4 +- .../Emandates/Models/Mandate.ts | 40 +-- src/PaymentMethods/Emandates/index.ts | 30 +- src/PaymentMethods/GiftCard/Models/Pay.ts | 46 +-- src/PaymentMethods/GiftCard/Models/Refund.ts | 12 +- src/PaymentMethods/GiftCard/index.ts | 12 +- src/PaymentMethods/Giropay/Models/Pay.ts | 12 +- src/PaymentMethods/Giropay/index.ts | 8 +- src/PaymentMethods/Ideal/Models/Pay.ts | 8 +- src/PaymentMethods/Ideal/index.ts | 27 +- .../IdealQR/Models/IGenerate.ts | 44 +-- src/PaymentMethods/IdealQR/index.ts | 10 +- src/PaymentMethods/Idin/index.ts | 12 +- src/PaymentMethods/In3/Models/Article.ts | 18 +- src/PaymentMethods/In3/Models/Pay.ts | 38 +-- src/PaymentMethods/In3/Models/Phone.ts | 8 +- src/PaymentMethods/In3/Models/Recipient.ts | 84 ++--- src/PaymentMethods/In3/Models/Refund.ts | 20 +- src/PaymentMethods/In3/index.ts | 14 +- src/PaymentMethods/In3Old/Models/Address.ts | 4 +- src/PaymentMethods/In3Old/Models/Article.ts | 6 +- src/PaymentMethods/In3Old/Models/Company.ts | 4 +- src/PaymentMethods/In3Old/Models/Pay.ts | 70 ++-- src/PaymentMethods/In3Old/Models/Phone.ts | 4 +- src/PaymentMethods/In3Old/Models/Subtotal.ts | 10 +- src/PaymentMethods/In3Old/index.ts | 14 +- src/PaymentMethods/KBC/index.ts | 8 +- src/PaymentMethods/Klarna/Models/Article.ts | 6 +- src/PaymentMethods/Klarna/Models/Pay.ts | 32 +- src/PaymentMethods/Klarna/Models/Recipient.ts | 26 +- .../Klarna/Services/KlarnaAddress.ts | 14 +- .../Klarna/Services/KlarnaPhone.ts | 6 +- src/PaymentMethods/Klarna/index.ts | 14 +- src/PaymentMethods/KlarnaKP/Models/IPay.ts | 8 +- .../KlarnaKP/Models/IReserve.ts | 42 +-- src/PaymentMethods/KlarnaKP/index.ts | 34 +- .../Marketplaces/Models/ISplit.ts | 22 -- .../Marketplaces/Models/Marketplace.ts | 14 + .../Marketplaces/Models/Seller.ts | 18 ++ .../Marketplaces/Models/Split.ts | 33 ++ .../Marketplaces/Models/Transfer.ts | 9 + src/PaymentMethods/Marketplaces/index.ts | 22 +- src/PaymentMethods/Multibanco/index.ts | 5 + src/PaymentMethods/NoService/index.ts | 10 +- src/PaymentMethods/PayByBank/Models/IPay.ts | 12 +- src/PaymentMethods/PayByBank/index.ts | 20 +- .../PayPerEmail/Models/Attachments.ts | 9 + .../PayPerEmail/Models/Invitation.ts | 54 ++++ .../PayPerEmail/Models/invitation.ts | 14 - src/PaymentMethods/PayPerEmail/index.ts | 13 +- src/PaymentMethods/PayablePaymentMethod.ts | 41 ++- src/PaymentMethods/Payconiq/index.ts | 10 +- src/PaymentMethods/PaymentMethod.ts | 122 ++++--- src/PaymentMethods/Paypal/Models/Address.ts | 24 +- src/PaymentMethods/Paypal/Models/ExtraInfo.ts | 32 +- src/PaymentMethods/Paypal/Models/Pay.ts | 24 +- src/PaymentMethods/Paypal/Models/Phone.ts | 4 +- src/PaymentMethods/Paypal/index.ts | 26 +- src/PaymentMethods/PiM/index.ts | 10 +- src/PaymentMethods/PointOfSale/index.ts | 4 +- src/PaymentMethods/Przelewy24/Models/Pay.ts | 18 +- src/PaymentMethods/Przelewy24/index.ts | 12 +- src/PaymentMethods/SEPA/Models/Emandate.ts | 6 +- src/PaymentMethods/SEPA/Models/ExtraInfo.ts | 26 +- src/PaymentMethods/SEPA/Models/Pay.ts | 42 +-- src/PaymentMethods/SEPA/index.ts | 42 +-- src/PaymentMethods/Sofort/index.ts | 14 +- .../Subscriptions/Models/Company.ts | 4 +- .../Subscriptions/Models/Configuration.ts | 36 +-- .../Subscriptions/Models/ISubscription.ts | 130 ++++---- .../Subscriptions/Models/RatePlan.ts | 80 ++--- .../Subscriptions/Models/RatePlanCharge.ts | 56 ++-- .../Models/ResumeSubscription.ts | 4 +- src/PaymentMethods/Subscriptions/index.ts | 61 ++-- src/PaymentMethods/Surepay/Models/Verify.ts | 4 +- src/PaymentMethods/Surepay/index.ts | 17 +- src/PaymentMethods/Thunes/index.ts | 24 +- src/PaymentMethods/Tinka/Models/Address.ts | 8 +- src/PaymentMethods/Tinka/Models/Article.ts | 12 +- src/PaymentMethods/Tinka/Models/Pay.ts | 53 ++-- src/PaymentMethods/Tinka/Models/Person.ts | 18 +- src/PaymentMethods/Tinka/Models/Phone.ts | 4 +- src/PaymentMethods/Tinka/Models/Recipient.ts | 20 +- src/PaymentMethods/Tinka/index.ts | 12 +- src/PaymentMethods/Trustly/Models/Customer.ts | 6 +- src/PaymentMethods/Trustly/Models/Pay.ts | 16 +- src/PaymentMethods/Trustly/index.ts | 12 +- src/PaymentMethods/WeChatPay/Models/Pay.ts | 8 +- src/PaymentMethods/WeChatPay/index.ts | 12 +- src/Request/DataModels.ts | 94 +++--- src/Request/Headers.ts | 57 ++-- src/Request/Hmac.ts | 99 +++--- src/Request/HttpsClient.ts | 62 ++-- src/Request/Request.ts | 151 ++++----- src/Services/TransactionService.ts | 29 +- src/Utils/Functions.ts | 79 ++--- src/Utils/MethodTypes.ts | 148 ++++----- src/Utils/Types.ts | 28 +- src/index.ts | 67 ++-- tests/BuckarooClient.test.ts | 12 +- tests/Client.test.ts | 91 +++--- tests/Models/index.ts | 52 +-- tests/PaymentMethods/AfterPay.test.ts | 85 +++-- .../PaymentMethods/AfterPayDigiAccept.test.ts | 62 ++-- tests/PaymentMethods/Alipay.test.ts | 22 +- tests/PaymentMethods/ApplePay.test.ts | 40 +-- tests/PaymentMethods/Bancontact.test.ts | 66 ++-- tests/PaymentMethods/BankTransfer.test.ts | 18 +- tests/PaymentMethods/Belfius.test.ts | 28 +- tests/PaymentMethods/Billink.test.ts | 72 ++--- tests/PaymentMethods/BuckarooVoucher.test.ts | 46 +-- tests/PaymentMethods/BuckarooWallet.test.ts | 80 ++--- tests/PaymentMethods/CreditCard.test.ts | 86 ++--- tests/PaymentMethods/CreditClick.test.ts | 24 +- tests/PaymentMethods/CreditManagment.test.ts | 146 +++++---- tests/PaymentMethods/EPS.test.ts | 22 +- tests/PaymentMethods/Emandate.test.ts | 42 +-- tests/PaymentMethods/Giftcard.test.ts | 29 +- tests/PaymentMethods/GiroPay.test.ts | 24 +- tests/PaymentMethods/Ideal.test.ts | 56 ++-- tests/PaymentMethods/IdealQR.test.ts | 16 +- tests/PaymentMethods/In3.test.ts | 52 +-- tests/PaymentMethods/In3Old.test.ts | 50 +-- tests/PaymentMethods/KBC.test.ts | 22 +- tests/PaymentMethods/Klarna.test.ts | 48 +-- tests/PaymentMethods/KlarnaKp.test.ts | 52 +-- tests/PaymentMethods/Marketplaces.test.ts | 82 +++-- tests/PaymentMethods/Mbway.test.ts | 13 + tests/PaymentMethods/Multibanco.test.ts | 15 + tests/PaymentMethods/PayPerEmail.test.ts | 58 ++-- tests/PaymentMethods/Payconiq.test.ts | 39 +-- .../PaymentMethods/PaymentInitiation.test.ts | 24 +- tests/PaymentMethods/Paypal.test.ts | 38 +-- tests/PaymentMethods/PiM.test.ts | 14 +- tests/PaymentMethods/Przelewy24.test.ts | 26 +- tests/PaymentMethods/SEPA.test.ts | 56 ++-- tests/PaymentMethods/Sofort.test.ts | 32 +- tests/PaymentMethods/Subscriptions.test.ts | 298 +++++++++--------- tests/PaymentMethods/SurePay.test.ts | 16 +- tests/PaymentMethods/Thunes.test.ts | 32 +- tests/PaymentMethods/Tinka.test.ts | 72 +++-- tests/PaymentMethods/Trustly.test.ts | 16 +- tests/PaymentMethods/WechatPay.test.ts | 28 +- tsconfig.json | 2 +- 233 files changed, 3803 insertions(+), 3820 deletions(-) create mode 100644 .editorconfig delete mode 100644 src/PaymentMethods/Marketplaces/Models/ISplit.ts create mode 100644 src/PaymentMethods/Marketplaces/Models/Marketplace.ts create mode 100644 src/PaymentMethods/Marketplaces/Models/Seller.ts create mode 100644 src/PaymentMethods/Marketplaces/Models/Split.ts create mode 100644 src/PaymentMethods/Marketplaces/Models/Transfer.ts create mode 100644 src/PaymentMethods/Multibanco/index.ts create mode 100644 src/PaymentMethods/PayPerEmail/Models/Attachments.ts create mode 100644 src/PaymentMethods/PayPerEmail/Models/Invitation.ts delete mode 100644 src/PaymentMethods/PayPerEmail/Models/invitation.ts create mode 100644 tests/PaymentMethods/Mbway.test.ts create mode 100644 tests/PaymentMethods/Multibanco.test.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..1eb3fe00 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +[*] +charset = utf-8 +end_of_line = crlf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 200 +tab_width = 4 +trim_trailing_whitespace = true +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = none +ij_wrap_on_typing = false + +[*.{ts,js}] +indent_size = 4 +ij_vue_indent_children_of_top_level = template +ij_vue_interpolation_new_line_after_start_delimiter = true +ij_vue_interpolation_new_line_before_end_delimiter = true +ij_vue_interpolation_wrap = off +ij_vue_keep_indents_on_empty_lines = false +ij_vue_spaces_within_interpolation_expressions = true diff --git a/.prettierrc.json b/.prettierrc.json index 216efb86..0eb852f9 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,8 +1,8 @@ { - "printWidth": 100, + "trailingComma": "es5", "tabWidth": 4, "singleQuote": true, - "bracketSameLine": true, - "trailingComma": "none", - "semi": false + "singleAttributePerLine": true, + "htmlWhitespaceSensitivity": "ignore", + "bracketSameLine": false } diff --git a/README.md b/README.md index deb280d4..0f6a69c6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ ### About -Buckaroo is the the Payment Service Provider for all your online payments with more than 15,000 companies relying on Buckaroo's platform to securely process their payments, subscriptions and unpaid invoices. Buckaroo developed their own Node SDK. The SDK is a modern, open-source Node.js library that makes it easy to integrate your Javascript application with Buckaroo's services. Start accepting payments today with Buckaroo. +Buckaroo is the Payment Service Provider for all your online payments with more than 15,000 companies relying on Buckaroo's platform to securely process their payments, subscriptions and unpaid invoices. Buckaroo developed their own Node SDK. The SDK is a modern, open-source Node.js library that makes it easy to integrate your Javascript application with Buckaroo's services. Start accepting payments today with Buckaroo. ### Requirements @@ -46,32 +46,32 @@ npm install @buckaroo/buckaroo_sdk Initiate the buckaroo client with your website key and secret key. The keys can be retrieved from your [Buckaroo account](https://plaza.buckaroo.nl/Login). ```javascript -import { initializeBuckarooClient } from './BuckarooClient' -initializeBuckarooClient({ websiteKey: 'KEY', secretKey: 'SECRET' }) +import { initializeBuckarooClient } from './BuckarooClient'; +initializeBuckarooClient({ websiteKey: 'KEY', secretKey: 'SECRET' }); ``` Create a payment with all the available payment methods. In this example, we show how to create a credit card payment. Each payment has a slightly different payload. ```javascript -import creditCard from './PaymentMethods/CreditCard' +import creditCard from './PaymentMethods/CreditCard'; const payment = await creditCard().pay({ amountDebit: 10, name: 'Mastercard', - invoice: 'UNIQUE-INVOICE-NO' -}) + invoice: 'UNIQUE-INVOICE-NO', +}); ``` After you create a transaction, you can retrieve several transaction information on demand. ```javascript -const transactionKey = payment.Key +const transactionKey = payment.Key; -import { buckarooClient } from './BuckarooClient' +import { buckarooClient } from './BuckarooClient'; -buckarooClient().status(transactionKey) // Retrieve transaction status -buckarooClient().refundInfo(transactionKey) // Retrieve refund info -buckarooClient().cancelInfo(transactionKey) // Retrieve cancellation info +buckarooClient().status(transactionKey); // Retrieve transaction status +buckarooClient().refundInfo(transactionKey); // Retrieve refund info +buckarooClient().cancelInfo(transactionKey); // Retrieve cancellation info ``` Find our full documentation online on [docs.buckaroo.io](https://docs.buckaroo.io/docs/node-sdk). diff --git a/example/additional_services/creditManagment.ts b/example/additional_services/creditManagment.ts index 14018b96..c6237873 100644 --- a/example/additional_services/creditManagment.ts +++ b/example/additional_services/creditManagment.ts @@ -1,6 +1,6 @@ -import buckaroo from '../buckarooClient' +import buckaroo from '../buckarooClient'; -const creditManagement = buckaroo.method('CreditManagement3') +const creditManagement = buckaroo.method('CreditManagement3'); // Sometimes we need to combine multiple payments. // By calling "combine" it will combine the payload of the method with the next method or a given payload. @@ -16,11 +16,11 @@ const invoice = creditManagement.createCombinedInvoice({ maxStepIndex: 1, allowedServices: 'ideal,mastercard', debtor: { - code: 'johnsmith4' + code: 'johnsmith4', }, email: 'youremail@example.nl', phone: { - mobile: '06198765432' + mobile: '06198765432', }, person: { culture: 'nl-NL', @@ -29,14 +29,14 @@ const invoice = creditManagement.createCombinedInvoice({ firstName: 'Test', lastNamePrefix: 'Jones', lastName: 'Aflever', - gender: 'male' + gender: 'male', }, company: { culture: 'nl-NL', name: 'My Company Corporation', vatApplicable: true, vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741' + chamberOfCommerce: '20091741', }, address: { street: 'Hoofdtraat', @@ -45,11 +45,11 @@ const invoice = creditManagement.createCombinedInvoice({ zipcode: '8441ER', city: 'Heerenveen', state: 'Friesland', - country: 'NL' - } -}) + country: 'NL', + }, +}); -const sepadirectdebit = buckaroo.method('sepadirectdebit') +const sepadirectdebit = buckaroo.method('sepadirectdebit'); sepadirectdebit .combine(invoice.data) .pay({ @@ -61,7 +61,7 @@ sepadirectdebit mandateReference: '1DCtestreference', mandateDate: '2022-07-03', customer: { - name: 'John Smith' - } + name: 'John Smith', + }, }) - .request() + .request(); diff --git a/example/additional_services/subscription.ts b/example/additional_services/subscription.ts index d6077b52..844c7573 100644 --- a/example/additional_services/subscription.ts +++ b/example/additional_services/subscription.ts @@ -1,8 +1,9 @@ -require('../buckarooClient') -import Subscriptions from '../../src/PaymentMethods/Subscriptions' -import Ideal from '../../src/PaymentMethods/Ideal' +require('../buckarooClient'); +import Subscriptions from '../../src/PaymentMethods/Subscriptions'; +import Ideal from '../../src/PaymentMethods/Ideal'; -const subscription = new Subscriptions().createCombined({ +const subscription = new Subscriptions() +subscription.createCombined({ address: undefined, allowedServices: '', b2b: '', @@ -22,17 +23,16 @@ const subscription = new Subscriptions().createCombined({ termStartDay: 0, termStartMonth: 0, termStartWeek: '', - transactionVatPercentage: 0 -}) + transactionVatPercentage: 0, +}); -;(async () => { +(async () => { const combinedPayment = await new Ideal() + .combine(subscription) .pay({ amountDebit: 1, currency: 'EUR', - description: 'test' - }) - .combine('subscriptions') - .create({}) - console.log(combinedPayment) -})() + description: 'test', + }).request() + console.log(combinedPayment); +})(); diff --git a/example/buckarooClient.ts b/example/buckarooClient.ts index a26ba4db..b8e9e243 100644 --- a/example/buckarooClient.ts +++ b/example/buckarooClient.ts @@ -1,14 +1,14 @@ -import Buckaroo from "@buckaroo/buckaroo_sdk"; +import Buckaroo from '@buckaroo/buckaroo_sdk'; const buckaroo = Buckaroo.InitializeClient({ secretKey: 'secret', - websiteKey: 'website' -}) + websiteKey: 'website', +}); buckaroo.config = { mode: 'TEST', currency: 'EUR', returnURL: 'https://example.com/return', - pushURL: 'https://example.com/push' -} -export default buckaroo + pushURL: 'https://example.com/push', +}; +export default buckaroo; diff --git a/example/response/push.ts b/example/response/push.ts index afb5ca51..17c9b2f5 100644 --- a/example/response/push.ts +++ b/example/response/push.ts @@ -1,5 +1,5 @@ -import buckaroo from '../buckarooClient' -import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler' +import buckaroo from '../buckarooClient'; +import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler'; //START HTTP POST PUSH let post_data = `{ @@ -24,21 +24,20 @@ let post_data = `{ "brq_transactions": "4C1BE53E2C42412AB32A799D9316E7DD", "brq_websitekey": "IBjihN7Fhp", "brq_signature": "bf7a62c830da2d2e004199919a8fe0d53b0668f5", -}` +}`; -let reply_handler = new ReplyHandler(buckaroo.credentials, post_data) -reply_handler.validate() -reply_handler.isValid() // Return either true or false +let reply_handler = new ReplyHandler(buckaroo.credentials, post_data); +reply_handler.validate(); +reply_handler.isValid(); // Return either true or false //END HTTP POST PUSH //START JSON PUSH -const auth_header = - 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572' +const auth_header = 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572'; post_data = - '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}' -const uri = 'https://buckaroo.dev/push' + '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}'; +const uri = 'https://buckaroo.dev/push'; -reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri) -reply_handler.validate() -reply_handler.isValid() // Return either true or false +reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri); +reply_handler.validate(); +reply_handler.isValid(); // Return either true or false //END JSON PUSH diff --git a/example/transaction/creditCard.ts b/example/transaction/creditCard.ts index 09c1b92e..a3cb0a17 100644 --- a/example/transaction/creditCard.ts +++ b/example/transaction/creditCard.ts @@ -1,16 +1,16 @@ -require('../buckarooClient') -import CreditCard from '../../src/PaymentMethods/CreditCard' +require('../buckarooClient'); +import CreditCard from '../../src/PaymentMethods/CreditCard'; -const paymentMethod = new CreditCard('nexi') +const paymentMethod = new CreditCard('nexi'); -;(async () => { +(async () => { try { const info = await paymentMethod.pay({ invoice: 'test1', - amountDebit: 12 - }) - console.log(info) + amountDebit: 12, + }); + console.log(info); } catch (error) { - console.warn(error) + console.warn(error); } -})() +})(); diff --git a/example/transaction/ideal.ts b/example/transaction/ideal.ts index 5b84b78e..b61ac5c9 100644 --- a/example/transaction/ideal.ts +++ b/example/transaction/ideal.ts @@ -1,23 +1,23 @@ -import buckarooClient from '../buckarooClient' +import buckarooClient from '../buckarooClient'; -const ideal = buckarooClient.method('ideal') +const ideal = buckarooClient.method('ideal'); //Pay ideal .pay({ amountDebit: 10.1, issuer: 'ABNANL2A', - description: 'Ideal Payment' + description: 'Ideal Payment', }) - .request() + .request(); //Refund ideal .refund({ originalTransactionKey: '', amountCredit: 10.1, - invoice: '' + invoice: '', }) - .request() + .request(); //Issuers -ideal.issuers() +ideal.issuers(); diff --git a/jest.config.js b/jest.config.js index 9d1dd1c9..ab7459e0 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,5 +3,5 @@ module.exports = { testEnvironment: 'node', testRegex: '/tests/.*.test.(ts|tsx)$', modulePathIgnorePatterns: ['/tests/.*(.d.ts)'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] -} + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], +}; diff --git a/src/Constants/CreditManagementInstallmentInterval.ts b/src/Constants/CreditManagementInstallmentInterval.ts index 245163cc..2902e8af 100644 --- a/src/Constants/CreditManagementInstallmentInterval.ts +++ b/src/Constants/CreditManagementInstallmentInterval.ts @@ -8,7 +8,7 @@ enum CreditManagementInstallmentInterval { TWOMONTHS = 'TwoMonths', QUARTERYEAR = 'QuarterYear', HALFYEAR = 'HalfYear', - YEAR = 'Year' + YEAR = 'Year', } -export default CreditManagementInstallmentInterval +export default CreditManagementInstallmentInterval; diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index 67f4e11a..d3a9449a 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -1,11 +1,11 @@ enum Endpoints { LIVE = 'https://checkout.buckaroo.nl', - TEST = 'https://testcheckout.buckaroo.nl' + TEST = 'https://testcheckout.buckaroo.nl', } export enum RequestTypes { Data = '/json/DataRequest', Transaction = '/json/Transaction', BatchData = '/json/batch/DataRequests', - BatchTransaction = '/json/batch/Transactions' + BatchTransaction = '/json/batch/Transactions', } -export default Endpoints +export default Endpoints; diff --git a/src/Constants/Gender.ts b/src/Constants/Gender.ts index dda7de2b..0253e8db 100644 --- a/src/Constants/Gender.ts +++ b/src/Constants/Gender.ts @@ -2,6 +2,6 @@ enum Gender { UNKNOWN = 0, MALE = 1, FEMALE = 2, - NOT_APPLICABLE = 9 + NOT_APPLICABLE = 9, } -export default Gender +export default Gender; diff --git a/src/Constants/HttpMethods.ts b/src/Constants/HttpMethods.ts index 2903572c..8f7a9c52 100644 --- a/src/Constants/HttpMethods.ts +++ b/src/Constants/HttpMethods.ts @@ -1,5 +1,5 @@ enum HttpMethods { GET = 'GET', - POST = 'POST' + POST = 'POST', } -export default HttpMethods +export default HttpMethods; diff --git a/src/Constants/IPProtocolVersion.ts b/src/Constants/IPProtocolVersion.ts index 3438aea0..3bdd8ebd 100644 --- a/src/Constants/IPProtocolVersion.ts +++ b/src/Constants/IPProtocolVersion.ts @@ -1,26 +1,26 @@ -import * as IpAddress from 'ip-address' +import * as IpAddress from 'ip-address'; -import { getIPAddress } from '../Utils/Functions' +import { getIPAddress } from '../Utils/Functions'; export class IPProtocolVersion { - public static readonly IPV4: number = 0 - public static readonly IPV6: number = 1 + public static readonly IPV4: number = 0; + public static readonly IPV6: number = 1; public static getVersion(ipAddress: string = '0.0.0.0'): number { if (IpAddress.Address4.isValid(ipAddress)) { - return IPProtocolVersion.IPV4 + return IPProtocolVersion.IPV4; } if (IpAddress.Address6.isValid(ipAddress)) { - return IPProtocolVersion.IPV6 + return IPProtocolVersion.IPV6; } - throw new Error(`Invalid IP address: ${ipAddress}`) + throw new Error(`Invalid IP address: ${ipAddress}`); } } export class ClientIP { - type: IPProtocolVersion - address: string + type: IPProtocolVersion; + address: string; constructor(ipAddress: string = getIPAddress()) { - this.type = IPProtocolVersion.getVersion(ipAddress) - this.address = ipAddress + this.type = IPProtocolVersion.getVersion(ipAddress); + this.address = ipAddress; } } diff --git a/src/Constants/RecipientCategory.ts b/src/Constants/RecipientCategory.ts index 6c40fae5..5649e99b 100644 --- a/src/Constants/RecipientCategory.ts +++ b/src/Constants/RecipientCategory.ts @@ -1,5 +1,5 @@ enum RecipientCategory { PERSON = 'PERSON', - COMPANY = 'COMPANY' + COMPANY = 'COMPANY', } -export default RecipientCategory +export default RecipientCategory; diff --git a/src/Constants/ResponseStatus.ts b/src/Constants/ResponseStatus.ts index cb768207..6af8ffd8 100644 --- a/src/Constants/ResponseStatus.ts +++ b/src/Constants/ResponseStatus.ts @@ -12,6 +12,6 @@ enum ResponseStatus { BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT = '891', BUCKAROO_AUTHORIZE_TYPE_CANCEL = 'I014', BUCKAROO_AUTHORIZE_TYPE_ACCEPT = 'I013', - BUCKAROO_AUTHORIZE_TYPE_GROUP_TRANSACTION = 'I150' + BUCKAROO_AUTHORIZE_TYPE_GROUP_TRANSACTION = 'I150', } -export default ResponseStatus +export default ResponseStatus; diff --git a/src/Handlers/Credentials.ts b/src/Handlers/Credentials.ts index c3dec222..938b5d4c 100644 --- a/src/Handlers/Credentials.ts +++ b/src/Handlers/Credentials.ts @@ -1,25 +1,25 @@ -import { ICredentials } from '../Utils/Types' -import Request from '../Request/Request' -import { RequestTypes } from '../Constants/Endpoints' +import { ICredentials } from '../Utils/Types'; +import Request from '../Request/Request'; +import { RequestTypes } from '../Constants/Endpoints'; export class Credentials implements ICredentials { - secretKey: string - websiteKey: string + secretKey: string; + websiteKey: string; constructor(secretKey: string, websiteKey: string) { - this.secretKey = secretKey - this.websiteKey = websiteKey + this.secretKey = secretKey; + this.websiteKey = websiteKey; } confirm() { return Request.Specification(RequestTypes.Transaction, { name: 'ideal', - version: 2 + version: 2, }) .request() .then((response) => { - return response.httpResponse.statusCode === 200 + return response.httpResponse.statusCode === 200; }) .catch(() => { - return false - }) + return false; + }); } } diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 96e3e83b..8e15faee 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -1,80 +1,64 @@ -import crypto from 'crypto' -import { ICredentials } from '../../Utils/Types' -import { Hmac } from '../../Request/Hmac' -import HttpMethods from '../../Constants/HttpMethods' +import crypto from 'crypto'; +import { ICredentials } from '../../Utils/Types'; +import { Hmac } from '../../Request/Hmac'; +import HttpMethods from '../../Constants/HttpMethods'; export class ReplyHandler { - private readonly _data: object - private readonly uri?: string - private readonly auth_header?: string - private readonly credentials: ICredentials - private _isValid: boolean = false - private strategy: 'JSON' | 'HTTP' = 'JSON' - private method?: string - constructor( - credentials: ICredentials, - data: string, - auth_header?: string, - uri?: string, - httpMethod?: string - ) { - this._data = this.formatStringData(data) - this.credentials = credentials - this.uri = uri - this.auth_header = auth_header - this.method = httpMethod + private readonly _data: object; + private readonly uri?: string; + private readonly auth_header?: string; + private readonly credentials: ICredentials; + private _isValid: boolean = false; + private strategy: 'JSON' | 'HTTP' = 'JSON'; + private method?: string; + constructor(credentials: ICredentials, data: string, auth_header?: string, uri?: string, httpMethod?: string) { + this._data = this.formatStringData(data); + this.credentials = credentials; + this.uri = uri; + this.auth_header = auth_header; + this.method = httpMethod; } isValid(): boolean { - return this._isValid + return this._isValid; } private formatStringData(value: string) { try { - let data = JSON.parse(value) - this.strategy = 'JSON' - return data + let data = JSON.parse(value); + this.strategy = 'JSON'; + return data; } catch (e) { - let objData = {} + let objData = {}; new URLSearchParams(value).forEach((value, name) => { - objData[name] = value - }) - this.strategy = 'HTTP' - return objData + objData[name] = value; + }); + this.strategy = 'HTTP'; + return objData; } } validate() { if (this.strategy === 'HTTP') { - let { brq_signature, BRQ_SIGNATURE, ...data } = this._data as any - this._isValid = this.validateHttp(data, brq_signature || BRQ_SIGNATURE) - return this + let { brq_signature, BRQ_SIGNATURE, ...data } = this._data as any; + this._isValid = this.validateHttp(data, brq_signature || BRQ_SIGNATURE); + return this; } if (this.strategy === 'JSON' && this.auth_header && this.uri) { - this._isValid = this.validateJson( - this.auth_header, - this.uri, - JSON.stringify(this._data) - ) - return this + this._isValid = this.validateJson(this.auth_header, this.uri, JSON.stringify(this._data)); + return this; } - throw new Error('Invalid response data') + throw new Error('Invalid response data'); } private validateJson(auth_header: string, url: string, data: string) { - return new Hmac().validate( - this.credentials, - auth_header, - url, - data, - this.method || HttpMethods.POST - ) + return new Hmac().validate(this.credentials, auth_header, url, data, this.method || HttpMethods.POST); } private validateHttp(data: object, signature: string) { - let stringData = '' + let stringData = ''; for (const key in data) { - stringData += key + '=' + data[key] + stringData += key + '=' + data[key]; } - stringData = stringData + this.credentials.websiteKey + stringData = stringData + this.credentials.websiteKey; - let hash = crypto.createHash('sha1').update(stringData).digest('hex') + let hash = crypto.createHash('sha1').update(stringData).digest('hex'); - return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)) + return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)); } } diff --git a/src/Models/IParameters.ts b/src/Models/IParameters.ts index 09c968b8..5158994e 100644 --- a/src/Models/IParameters.ts +++ b/src/Models/IParameters.ts @@ -1,43 +1,43 @@ -import { Model } from './Model' -import { Str } from '../Utils/Functions' +import { Model } from './Model'; +import { Str } from '../Utils/Functions'; export interface IParameter { - name: string - value: string | number | boolean - groupType?: string - groupID?: number + name: string; + value: string | number | boolean; + groupType?: string; + groupID?: number; } export class Parameter extends Model implements IParameter { set name(value: string) { - this.set('name', Str.ucfirst(value)) + this.set('name', Str.ucfirst(value)); } set value(value: ParameterTypes) { - this.set('value', value) + this.set('value', value); } set groupType(value: string) { - this.set('groupType', value) + this.set('groupType', value); } set groupID(value: number) { - this.set('groupID', value) + this.set('groupID', value); } } -export type ParameterTypes = string | number | boolean +export type ParameterTypes = string | number | boolean; export declare type IAdditionalParameters = { - [name: string]: ParameterTypes -} -export declare type ServiceParameterTypes = ParameterTypes | ParameterTypes[] | IServiceParameters + [name: string]: ParameterTypes; +}; +export declare type ServiceParameterTypes = ParameterTypes | ParameterTypes[] | IServiceParameters; export declare interface IServiceParameters { - [name: keyof any]: ServiceParameterTypes | undefined + [name: keyof any]: ServiceParameterTypes | undefined; } export type IFormattedParameter = { - name: string - value: string | number | boolean -} + name: string; + value: string | number | boolean; +}; diff --git a/src/Models/IRequest.ts b/src/Models/IRequest.ts index d8215430..7e4882c3 100644 --- a/src/Models/IRequest.ts +++ b/src/Models/IRequest.ts @@ -1,41 +1,41 @@ -import { ServiceCode } from '../Utils/MethodTypes' -import { IAdditionalParameters } from './IParameters' +import { ServiceCode } from '../Utils/MethodTypes'; +import { IAdditionalParameters } from './IParameters'; export default interface IRequest { - clientIP?: string - currency?: string - clientUserAgent?: string - returnURL?: string - returnURLError?: string - returnURLCancel?: string - returnURLReject?: string - pushURL?: string - pushURLFailure?: string - invoice?: string - order?: string - amountDebit?: number - amountCredit?: number - description?: string - originalTransactionKey?: string + clientIP?: string; + currency?: string; + clientUserAgent?: string; + returnURL?: string; + returnURLError?: string; + returnURLCancel?: string; + returnURLReject?: string; + pushURL?: string; + pushURLFailure?: string; + invoice?: string; + order?: string; + amountDebit?: number; + amountCredit?: number; + description?: string; + originalTransactionKey?: string; originalTransactionReference?: { - type: string - reference: string - } - culture?: string - startRecurrent?: boolean - continueOnIncomplete?: boolean - servicesSelectableByClient?: ServiceCode[] | string - servicesExcludedForClient?: ServiceCode[] | string - customParameters?: IAdditionalParameters - additionalParameters?: IAdditionalParameters - [key: string]: any + type: string; + reference: string; + }; + culture?: string; + startRecurrent?: boolean; + continueOnIncomplete?: boolean; + servicesSelectableByClient?: ServiceCode[] | string; + servicesExcludedForClient?: ServiceCode[] | string; + customParameters?: IAdditionalParameters; + additionalParameters?: IAdditionalParameters; + [key: string]: any; } export declare interface IPaymentRequest extends IRequest { - amountDebit: number - amountCredit?: never + amountDebit: number; + amountCredit?: never; } export declare interface IRefundRequest extends IRequest { - amountCredit: number - amountDebit?: never - originalTransactionKey: string + amountCredit: number; + amountDebit?: never; + originalTransactionKey: string; } diff --git a/src/Models/IServiceList.ts b/src/Models/IServiceList.ts index dc471d63..c8ec7aea 100644 --- a/src/Models/IServiceList.ts +++ b/src/Models/IServiceList.ts @@ -1,52 +1,52 @@ -import { Model } from './Model' -import { IParameter, Parameter } from './IParameters' +import { Model } from './Model'; +import { IParameter, Parameter } from './IParameters'; export interface IService { - name: string - action?: string - version?: number - parameters?: IParameter[] + name: string; + action?: string; + version?: number; + parameters?: IParameter[]; } export class Service extends Model implements IService { constructor(data: IService) { - super(data) + super(data); } set action(value: string) { - this.set('action', value) + this.set('action', value); } set name(value: string) { - this.set('name', value) + this.set('name', value); } set version(value: number) { - this.set('version', value) + this.set('version', value); } set parameters(value: IParameter[]) { this.set( 'parameters', value.map((parameter) => new Parameter(parameter)) - ) + ); } } export class ServiceList extends Model { constructor(...list: IService[]) { - super({ list: list }) + super({ list: list }); } get list(): Service[] { - return this.get('serviceList') + return this.get('serviceList'); } set list(services: IService[]) { this.set( 'serviceList', services.map((service) => new Service(service)) - ) + ); } addService(service: IService) { if (this.getService(service.name)) { - throw new Error(`Service ${service.name} already exists`) - } - this.list.push(new Service(service)) + this.list[this.list.findIndex((s) => s.name === service.name)] = new Service(service); + }else + this.list.push(new Service(service)); } getService(name: string) { - return this.list.find((service) => service.name.toLowerCase() === name.toLowerCase()) + return this.list.find((service) => service.name.toLowerCase() === name.toLowerCase()); } } diff --git a/src/Models/Interfaces/IAddress.ts b/src/Models/Interfaces/IAddress.ts index ccfa2703..5412ca4a 100644 --- a/src/Models/Interfaces/IAddress.ts +++ b/src/Models/Interfaces/IAddress.ts @@ -1,34 +1,34 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IAddress { - street: string - houseNumber: string - houseNumberAdditional: string - zipcode: string - city: string - state?: string - country: string + street: string; + houseNumber: string; + houseNumberAdditional: string; + zipcode: string; + city: string; + state?: string; + country: string; } export class Address extends Model implements IAddress { set street(street: string) { - this.set('street', street) + this.set('street', street); } set houseNumber(houseNumber: string) { - this.set('houseNumber', houseNumber) + this.set('houseNumber', houseNumber); } set houseNumberAdditional(houseNumberAdditional: string) { - this.set('houseNumberAdditional', houseNumberAdditional) + this.set('houseNumberAdditional', houseNumberAdditional); } set zipcode(zipcode: string) { - this.set('zipcode', zipcode) + this.set('zipcode', zipcode); } set city(city: string) { - this.set('city', city) + this.set('city', city); } set state(state: string) { - this.set('state', state) + this.set('state', state); } set country(country: string) { - this.set('country', country) + this.set('country', country); } } diff --git a/src/Models/Interfaces/IArticle.ts b/src/Models/Interfaces/IArticle.ts index 5f373995..bfb45b7a 100644 --- a/src/Models/Interfaces/IArticle.ts +++ b/src/Models/Interfaces/IArticle.ts @@ -1,46 +1,46 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IArticle { - identifier: string - type: string - brand?: string - manufacturer?: string - unitCode: string - price: number - quantity: number - vatPercentage: number - vatCategory: string - description: string + identifier: string; + type: string; + brand?: string; + manufacturer?: string; + unitCode: string; + price: number; + quantity: number; + vatPercentage: number; + vatCategory: string; + description: string; } export class Article extends Model implements IArticle { set identifier(identifier: string) { - this.set('identifier', identifier) + this.set('identifier', identifier); } set type(type: string) { - this.set('type', type) + this.set('type', type); } set brand(brand: string) { - this.set('brand', brand) + this.set('brand', brand); } set manufacturer(manufacturer: string) { - this.set('manufacturer', manufacturer) + this.set('manufacturer', manufacturer); } set unitCode(unitCode: string) { - this.set('unitCode', unitCode) + this.set('unitCode', unitCode); } set price(price: number) { - this.set('price', price) + this.set('price', price); } set quantity(quantity: number) { - this.set('quantity', quantity) + this.set('quantity', quantity); } set vatPercentage(vatPercentage: number) { - this.set('vatPercentage', vatPercentage) + this.set('vatPercentage', vatPercentage); } set vatCategory(vatCategory: string) { - this.set('vatCategory', vatCategory) + this.set('vatCategory', vatCategory); } set description(description: string) { - this.set('description', description) + this.set('description', description); } } diff --git a/src/Models/Interfaces/IBankAccount.ts b/src/Models/Interfaces/IBankAccount.ts index fbdc771b..d41fe272 100644 --- a/src/Models/Interfaces/IBankAccount.ts +++ b/src/Models/Interfaces/IBankAccount.ts @@ -1,18 +1,18 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IBankAccount { - iban: string - bic: string - accountName: string + iban: string; + bic: string; + accountName: string; } export class BankAccount extends Model implements IBankAccount { set accountName(accountName: string) { - this.set('accountName', accountName) + this.set('accountName', accountName); } set bic(bic: string) { - this.set('bic', bic) + this.set('bic', bic); } set iban(iban: string) { - this.set('iban', iban) + this.set('iban', iban); } } diff --git a/src/Models/Interfaces/ICustomer.ts b/src/Models/Interfaces/ICustomer.ts index 44c91bdf..43fa43c0 100644 --- a/src/Models/Interfaces/ICustomer.ts +++ b/src/Models/Interfaces/ICustomer.ts @@ -1,30 +1,30 @@ -import IAddress, { Address } from './IAddress' -import IPhone, { Phone } from './IPhone' -import { Company, ICompany, IPerson, Person } from './IRecipient' -import { Model } from '../Model' -import recipientCategory from '../../Constants/RecipientCategory' +import IAddress, { Address } from './IAddress'; +import IPhone, { Phone } from './IPhone'; +import { Company, ICompany, IPerson, Person } from './IRecipient'; +import { Model } from '../Model'; +import recipientCategory from '../../Constants/RecipientCategory'; export interface ICustomer { - phone?: Partial - email?: string - recipient?: Partial - address?: Partial + phone?: Partial; + email?: string; + recipient?: Partial; + address?: Partial; } export class Customer extends Model { set address(address: Partial) { - this.set('address', new Address(address)) + this.set('address', new Address(address)); } set email(email: string) { - this.set('email', email) + this.set('email', email); } set phone(phone: Partial) { - this.set('phone', new Phone(phone)) + this.set('phone', new Phone(phone)); } set recipient(recipient: IPerson | ICompany) { if (recipient.category === recipientCategory.PERSON) { - this.set('recipient', new Person(recipient)) + this.set('recipient', new Person(recipient)); } else if (recipient.category === recipientCategory.COMPANY) { - this.set('recipient', new Company(recipient)) + this.set('recipient', new Company(recipient)); } } } diff --git a/src/Models/Interfaces/IDebtor.ts b/src/Models/Interfaces/IDebtor.ts index 53db4cf6..6fc2a66b 100644 --- a/src/Models/Interfaces/IDebtor.ts +++ b/src/Models/Interfaces/IDebtor.ts @@ -1,10 +1,10 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IDebtor { - code: string + code: string; } export class Debtor extends Model { set code(value: string) { - this.set('code', value) + this.set('code', value); } } diff --git a/src/Models/Interfaces/IEmail.ts b/src/Models/Interfaces/IEmail.ts index eb9ffdd9..663c7dc7 100644 --- a/src/Models/Interfaces/IEmail.ts +++ b/src/Models/Interfaces/IEmail.ts @@ -1,16 +1,16 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IEmail { - email: string + email: string; } export class Email extends Model implements IEmail { constructor(data: IEmail) { - super(data) + super(data); } get email() { - return '' + return ''; } set email(email: string) { - this.set('email', email) + this.set('email', email); } } diff --git a/src/Models/Interfaces/IPhone.ts b/src/Models/Interfaces/IPhone.ts index 2bfef7f3..530eb475 100644 --- a/src/Models/Interfaces/IPhone.ts +++ b/src/Models/Interfaces/IPhone.ts @@ -1,19 +1,19 @@ -import { Model } from '../Model' +import { Model } from '../Model'; export default interface IPhone { - landline?: string - mobile?: string - fax?: string + landline?: string; + mobile?: string; + fax?: string; } export class Phone extends Model implements IPhone { set landline(landline: string) { - this.set('landline', landline) + this.set('landline', landline); } set mobile(mobile: string) { - this.set('mobile', mobile) + this.set('mobile', mobile); } set fax(fax: string) { - this.set('fax', fax) + this.set('fax', fax); } } diff --git a/src/Models/Interfaces/IRecipient.ts b/src/Models/Interfaces/IRecipient.ts index d273766d..f175fb8b 100644 --- a/src/Models/Interfaces/IRecipient.ts +++ b/src/Models/Interfaces/IRecipient.ts @@ -1,90 +1,94 @@ -import RecipientCategory from '../../Constants/RecipientCategory' -import { Model } from '../Model' -import Gender from '../../Constants/Gender' +import RecipientCategory from '../../Constants/RecipientCategory'; +import { Model } from '../Model'; +import Gender from '../../Constants/Gender'; export interface IRecipient { - [key: string]: any + [key: string]: any; } export interface IPerson extends IRecipient { - category: RecipientCategory.PERSON - gender: string | Gender - culture: string - careOf?: string - title?: string - initials?: string - firstName: string - lastName?: string - lastNamePrefix?: string - birthDate: string - placeOfBirth: string + category: RecipientCategory.PERSON; + gender: string | Gender; + culture: string; + careOf?: string; + title?: string; + initials?: string; + firstName: string; + lastName?: string; + lastNamePrefix?: string; + birthDate: string; + placeOfBirth: string; } export interface ICompany extends IRecipient { - category: RecipientCategory.COMPANY - companyName: string - culture: string - vatApplicable: boolean - vatNumber: string - chamberOfCommerce: string + category: RecipientCategory.COMPANY; + companyName: string; + culture: string; + vatApplicable: boolean; + vatNumber: string; + chamberOfCommerce: string; } -export class Person extends Model implements IPerson { - constructor(data: Partial) { - super(data) - } +export class Recipient extends Model implements IRecipient { set birthDate(value: string) { - this.set('birthDate', value) + this.set('birthDate', value); } set careOf(value: string) { - this.set('careOf', value) + this.set('careOf', value); } - set category(value: RecipientCategory.PERSON) { - this.set('category', value) + set category(value: RecipientCategory) { + this.set('category', value); } set culture(value: string) { - this.set('culture', value) + this.set('culture', value); } set firstName(value: string) { - this.set('firstName', value) + this.set('firstName', value); } set gender(value: string) { - this.set('gender', value) + this.set('gender', value); } set initials(value: string) { - this.set('initials', value) + this.set('initials', value); } set lastName(value: string) { - this.set('lastName', value) + this.set('lastName', value); } set lastNamePrefix(value: string) { - this.set('lastNamePrefix', value) + this.set('lastNamePrefix', value); } set placeOfBirth(value: string) { - this.set('placeOfBirth', value) + this.set('placeOfBirth', value); } set title(value: string) { - this.set('title', value) + this.set('title', value); + } +} +export class Person extends Recipient implements IPerson { + constructor(data: Partial) { + super(data); + } + set category(value: RecipientCategory.PERSON) { + this.set('category', value); } } -export class Company extends Person implements ICompany { +export class Company extends Recipient implements ICompany { constructor(data: Partial) { - super(data as any) + super(data as any); } - // @ts-ignore set category(value: RecipientCategory.COMPANY) { - this.set('category', value) + this.set('category', value); } set chamberOfCommerce(value: string) { - this.set('chamberOfCommerce', value) + this.set('chamberOfCommerce', value); } set companyName(value: string) { - this.set('companyName', value) + this.set('companyName', value); } set culture(value: string) { - this.set('culture', value) + this.set('culture', value); } set vatApplicable(value: boolean) { - this.set('vatApplicable', value) + this.set('vatApplicable', value); } set vatNumber(value: string) { - this.set('vatNumber', value) + this.set('vatNumber', value); } } diff --git a/src/Models/Model.ts b/src/Models/Model.ts index 95779244..c98808d4 100644 --- a/src/Models/Model.ts +++ b/src/Models/Model.ts @@ -1,124 +1,115 @@ -import { Str } from '../Utils/Functions' +import { Str } from '../Utils/Functions'; export class Model { - [key: keyof any]: any + [key: keyof any]: any; constructor(...args: any[]) { - this.initialize(...args) + this.initialize(...args); } initialize(data?: any) { if (data instanceof Object && !Array.isArray(data)) { if (data.constructor === this.constructor) { - this.setDataProperties(data) - } else this.setOwnProperties(data) + this.setDataProperties(data); + } else this.setOwnProperties(data); } + return this; } - protected setOwnProperties( - data: object = {}, - properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors() - ) { + protected setOwnProperties(data: object = {}, properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors()) { for (const key in properties) { if (properties[key].set) { - let value = data[key] ?? properties[key].get?.call(this) - if (value !== undefined) this[key] = value + let value = data[key] ?? properties[key].get?.call(this); + if (value !== undefined) this[key] = value; } } - return this + return this; } protected setDataProperties(data: object = {}) { for (const dataKey in data) { - if (data.hasOwnProperty(dataKey) && data[dataKey] !== undefined) - this.set(dataKey, data[dataKey]) + if (data.hasOwnProperty(dataKey) && data[dataKey] !== undefined) this.set(dataKey, data[dataKey]); } - return this + return this; } protected privateName(name: string): string { - return Str.ucfirst(name) + return Str.ucfirst(name); } protected publicName(name: string): string { - return Str.lcfirst(name) + return Str.lcfirst(name); } - protected getAllPropertyDescriptors( - descriptors = {}, - root = Model.prototype - ): { [p: string]: PropertyDescriptor } { + protected getAllPropertyDescriptors(descriptors = {}, root = Model.prototype): { [p: string]: PropertyDescriptor } { // Loop through the prototype chain - let currentObj = Object.getPrototypeOf(this) + let currentObj = Object.getPrototypeOf(this); while (currentObj !== root) { - const currentDescriptors = Object.getOwnPropertyDescriptors(currentObj) + const currentDescriptors = Object.getOwnPropertyDescriptors(currentObj); // Merge the descriptors into the result - descriptors = { ...currentDescriptors, ...descriptors } + descriptors = { ...currentDescriptors, ...descriptors }; // Move up the prototype chain - currentObj = Object.getPrototypeOf(currentObj) + currentObj = Object.getPrototypeOf(currentObj); } - return descriptors + return descriptors; } protected defineProperty(name: string, value: any, hidden: boolean = false) { - let privateName = this.privateName(name) + let privateName = this.privateName(name); Object.defineProperty(this, privateName, { value, writable: true, enumerable: !hidden, - configurable: true - }) - let publicName = this.publicName(name) + configurable: true, + }); + let publicName = this.publicName(name); Object.defineProperty(this, publicName, { get: () => value, set: this.has(publicName)?.set ?? ((value) => this.set(publicName, value, hidden)), enumerable: false, - configurable: true - }) + configurable: true, + }); } set(name: string, value: any, hidden: boolean = false): this { - this.defineProperty(name, value, hidden) - return this + this.defineProperty(name, value, hidden); + return this; } get(prop: string): any { - return this.has(prop)?.get?.call(this) + return this.has(prop)?.get?.call(this); } has(prop: string, model = this): PropertyDescriptor | undefined { - return getObjectProperty(model, prop, Model.prototype) + return getObjectProperty(model, prop, Model.prototype); } getData(callBack?: ((this: any, key: string, value: any) => any) | undefined): { - [key: string]: any + [key: string]: any; } { - return JSON.parse(JSON.stringify(this), callBack) + return JSON.parse(JSON.stringify(this), callBack); } } export class JsonModel extends Model { constructor(data: object) { - super(data) + super(data); } initialize(data?: any) { - this.setDataProperties(data) + return this.setDataProperties(data); } set(key: string, value: any) { Object.defineProperty(this, Str.lcfirst(key), { get: this.get.bind(this, value), - enumerable: true - }) - return this + enumerable: true, + }); + return this; } get(value: any) { if (Array.isArray(value)) { - return value.map((v) => new JsonModel(v)) + return value.map((v) => new JsonModel(v)); } if (value instanceof Object) { - return new JsonModel(value) + return new JsonModel(value); } if (value === null) { - return undefined + return undefined; } - return value + return value; } } export function getObjectProperty(object: object, property: string, root: any = null) { if (object !== root) { - return ( - Object.getOwnPropertyDescriptor(object, property) ?? - getObjectProperty(Object.getPrototypeOf(object), property, root) - ) + return Object.getOwnPropertyDescriptor(object, property) ?? getObjectProperty(Object.getPrototypeOf(object), property, root); } } diff --git a/src/Models/Response/BatchRequestResponse.ts b/src/Models/Response/BatchRequestResponse.ts index db4a4bf5..c569125e 100644 --- a/src/Models/Response/BatchRequestResponse.ts +++ b/src/Models/Response/BatchRequestResponse.ts @@ -1,14 +1,14 @@ -import { HttpClientResponse } from './HttpClientResponse' +import { HttpClientResponse } from './HttpClientResponse'; export class BatchRequestResponse extends HttpClientResponse { get data(): BatchResponseData { - return this._data as any + return this._data as any; } } export interface BatchResponseData { - message: string + message: string; errors?: { - reference: string - message: string - }[] + reference: string; + message: string; + }[]; } diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts index 1e709203..b2f37d27 100644 --- a/src/Models/Response/HttpClientResponse.ts +++ b/src/Models/Response/HttpClientResponse.ts @@ -1,43 +1,35 @@ -import { IncomingMessage } from 'http' -import { JsonModel } from '../Model' -import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler' -import { ICredentials } from '../../Utils/Types' +import { IncomingMessage } from 'http'; +import { JsonModel } from '../Model'; +import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler'; +import { ICredentials } from '../../Utils/Types'; export interface HttpResponseConstructor { - new (httpResponse: IncomingMessage, data: string): IHttpClientResponse + new (httpResponse: IncomingMessage, data: string): IHttpClientResponse; } export interface IHttpClientResponse { - httpResponse: IncomingMessage - data: object + httpResponse: IncomingMessage; + data: object; } export class HttpClientResponse implements IHttpClientResponse { - protected readonly _httpResponse: IncomingMessage - protected readonly _data: object - protected readonly _rawData: string + protected readonly _httpResponse: IncomingMessage; + protected readonly _data: object; + protected readonly _rawData: string; constructor(httpResponse: IncomingMessage, data: string) { - this._httpResponse = httpResponse - this._rawData = data - this._data = new JsonModel(JSON.parse(data)) + this._httpResponse = httpResponse; + this._rawData = data; + this._data = new JsonModel(JSON.parse(data)); } get httpResponse(): IncomingMessage { - return this._httpResponse + return this._httpResponse; } get rawData(): string { - return this._rawData + return this._rawData; } get data() { - return this._data + return this._data; } validateResponse(credentials: ICredentials) { - return new ReplyHandler( - credentials, - this._rawData, - this.httpResponse.headers['authorization'], - this.httpResponse.url, - this.httpResponse.method - ) - .validate() - .isValid() + return new ReplyHandler(credentials, this._rawData, this.httpResponse.headers['authorization'], this.httpResponse.url, this.httpResponse.method).validate().isValid(); } } diff --git a/src/Models/Response/SpecificationRequestResponse.ts b/src/Models/Response/SpecificationRequestResponse.ts index 44b76aab..faa33acf 100644 --- a/src/Models/Response/SpecificationRequestResponse.ts +++ b/src/Models/Response/SpecificationRequestResponse.ts @@ -1,66 +1,66 @@ -import { Str } from '../../Utils/Functions' -import { HttpClientResponse } from './HttpClientResponse' +import { Str } from '../../Utils/Functions'; +import { HttpClientResponse } from './HttpClientResponse'; export class SpecificationRequestResponse extends HttpClientResponse { get data(): ISpecificationRequestResponse { - return this._data as any + return this._data as any; } getActionRequestParameters(actionName: string): RequestParameter[] | undefined { let actions = this.data.actions?.find((action) => { if (Str.ciEquals(action.name, actionName)) { - return action + return action; } - })?.requestParameters + })?.requestParameters; if (actions) { - actions.sort((a, b) => a.name.localeCompare(b.name)) + actions.sort((a, b) => a.name.localeCompare(b.name)); } - return actions + return actions; } } type ListItemDescription = { - value: string - description: string - groupName: string -} + value: string; + description: string; + groupName: string; +}; type SupportedCurrency = { - isoNumber: number - code: string - name: string -} + isoNumber: number; + code: string; + name: string; +}; type Action = { - name: string - type: number - default: boolean - description: string - requestParameters: RequestParameter[] - responseParameters: RequestParameter[] -} + name: string; + type: number; + default: boolean; + description: string; + requestParameters: RequestParameter[]; + responseParameters: RequestParameter[]; +}; export type RequestParameter = { - listItemDescriptions?: ListItemDescription[] - isRequestParameter: boolean - name: string - dataType: number - maxLength: number - maxOccurs: number - required: boolean - global: boolean - group?: string - description: string - explanationHTML: string - displayName: string - inputPattern: string - autoCompleteType: string -} + listItemDescriptions?: ListItemDescription[]; + isRequestParameter: boolean; + name: string; + dataType: number; + maxLength: number; + maxOccurs: number; + required: boolean; + global: boolean; + group?: string; + description: string; + explanationHTML: string; + displayName: string; + inputPattern: string; + autoCompleteType: string; +}; export interface ISpecificationRequestResponse { - name: string - version: number - description: string - actions?: Action[] - supportedCurrencies?: SupportedCurrency[] + name: string; + version: number; + description: string; + actions?: Action[]; + supportedCurrencies?: SupportedCurrency[]; customParameters?: { - description: 'sample string 1' - dataType: 0 - name: 'sample string 2' - }[] + description: string; + dataType: number; + name: string; + }[]; } diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index e8d0230d..9e6c9065 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -1,86 +1,76 @@ -import ResponseStatus from '../../Constants/ResponseStatus' -import { DataFormatter } from '../../Utils/Functions' -import { HttpClientResponse } from './HttpClientResponse' +import ResponseStatus from '../../Constants/ResponseStatus'; +import { DataFormatter } from '../../Utils/Functions'; +import { HttpClientResponse } from './HttpClientResponse'; -import { IFormattedParameter } from '../IParameters' +import { IFormattedParameter } from '../IParameters'; export class TransactionResponse extends HttpClientResponse { get data(): ITransactionResponse { - return this._data as any + return this._data as any; } getStatusCode() { - return this.data.status.code.code.toString() + return this.data.status.code.code.toString(); } getSubStatusCode() { - return this.data.status.subCode.code.toString() + return this.data.status.subCode.code.toString(); } isSuccess() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS; } isFailed() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED; } isCanceled() { - return ( - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT - ) + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT; } isAwaitingConsumer() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER; } isPendingProcessing() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING; } isWaitingOnUserInput() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT; } isRejected() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED; } isValidationFailure() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE + return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE; } hasRedirect() { - return ( - this.data.requiredAction?.redirectURL.length > 0 && - this.data.requiredAction?.name === 'Redirect' - ) + return this.data.requiredAction?.redirectURL.length > 0 && this.data.requiredAction?.name === 'Redirect'; } getRedirectUrl() { - if (this.hasRedirect()) return this.data.requiredAction?.redirectURL - return '' + if (this.hasRedirect()) return this.data.requiredAction?.redirectURL; + return ''; } getServices() { - return this.data.services + return this.data.services; } getMethod() { - return this.data.services?.[0].name + return this.data.services?.[0].name; } getServiceAction() { - return this.data.services?.[0].action + return this.data.services?.[0].action; } getCustomParameters() { - return DataFormatter.parametersReverseMap(this.data.customParameters?.list ?? []) + return DataFormatter.parametersReverseMap(this.data.customParameters?.list ?? []); } getAdditionalParameters() { - return DataFormatter.parametersReverseMap( - this.data.additionalParameters?.additionalParameter ?? - this.data.additionalParameters?.['list'] ?? - [] - ) + return DataFormatter.parametersReverseMap(this.data.additionalParameters?.additionalParameter ?? this.data.additionalParameters?.['list'] ?? []); } getTransactionKey() { - return this.data.key + return this.data.key; } getPaymentKey() { - return this.data.paymentKey + return this.data.paymentKey; } getAmountDebit() { - return this.data.amountDebit + return this.data.amountDebit; } getAmountCredit() { - return this.data.amountCredit + return this.data.amountCredit; } hasError() { return ( @@ -91,115 +81,115 @@ export class TransactionResponse extends HttpClientResponse { this.data.requestErrors.actionErrors.length > 0 || this.data.requestErrors.parameterErrors.length > 0 || this.data.requestErrors.customParameterErrors.length > 0) - ) + ); } getErrorMessage() { - return this.data.status.code.description + return this.data.status.code.description; } } export declare interface ITransactionResponse { - key: string - name: string - version: number - description: string + key: string; + name: string; + version: number; + description: string; status: { code: { - code: number | string - description: string - } + code: number | string; + description: string; + }; subCode: { - code: number | string - description: string - } - dateTime: string - } + code: number | string; + description: string; + }; + dateTime: string; + }; requiredAction: { - redirectURL: string + redirectURL: string; requestedInformation: { - name: string - dataType: number - maxLength: number - required: boolean - description: string - }[] + name: string; + dataType: number; + maxLength: number; + required: boolean; + description: string; + }[]; payRemainderDetails: { - remainderAmount: number - currency: string - groupTransaction: string - } - name: string - typeDeprecated: number - } + remainderAmount: number; + currency: string; + groupTransaction: string; + }; + name: string; + typeDeprecated: number; + }; services: { - action: string - name: string - value: string - versionAsProperty: number - parameters: IFormattedParameter[] - }[] + action: string; + name: string; + value: string; + versionAsProperty: number; + parameters: IFormattedParameter[]; + }[]; customParameters?: { - list: IFormattedParameter[] - } + list: IFormattedParameter[]; + }; additionalParameters?: { - additionalParameter: IFormattedParameter[] - } + additionalParameter: IFormattedParameter[]; + }; requestErrors: { channelErrors: { - service: string - action: string - name: string - error: string - errorMessage: string - }[] + service: string; + action: string; + name: string; + error: string; + errorMessage: string; + }[]; serviceErrors: { - name: string - error: string - errorMessage: string - }[] + name: string; + error: string; + errorMessage: string; + }[]; actionErrors: { - service: string - name: string - error: string - errorMessage: string - }[] + service: string; + name: string; + error: string; + errorMessage: string; + }[]; parameterErrors: { - service: string - action: string - name: string - error: string - errorMessage: string - }[] + service: string; + action: string; + name: string; + error: string; + errorMessage: string; + }[]; customParameterErrors: { - name: string - error: string - errorMessage: string - }[] - } - invoice: string - serviceCode: string - isTest: boolean - currency: string - amountDebit: number - amountCredit: number - transactionType: string - mutationType: number + name: string; + error: string; + errorMessage: string; + }[]; + }; + invoice: string; + serviceCode: string; + isTest: boolean; + currency: string; + amountDebit: number; + amountCredit: number; + transactionType: string; + mutationType: number; relatedTransactions: { - relationType: string - relatedTransactionKey: string - }[] + relationType: string; + relatedTransactionKey: string; + }[]; consumerMessage: { - mustRead: boolean - cultureName: string - title: string - plainText: string - htmlText: string - } - order: string - issuingCountry: string - startRecurrent: boolean - recurring: boolean - customerName: string - payerHash: string - paymentKey: string + mustRead: boolean; + cultureName: string; + title: string; + plainText: string; + htmlText: string; + }; + order: string; + issuingCountry: string; + startRecurrent: boolean; + recurring: boolean; + customerName: string; + payerHash: string; + paymentKey: string; } diff --git a/src/Models/ServiceParameters.ts b/src/Models/ServiceParameters.ts index 3ff64125..bcb4185e 100644 --- a/src/Models/ServiceParameters.ts +++ b/src/Models/ServiceParameters.ts @@ -1,25 +1,18 @@ -import { Model } from './Model' -import { DataFormatter } from '../Utils/Functions' -import { IParameter } from './IParameters' +import { Model } from './Model'; +import { DataFormatter } from '../Utils/Functions'; +import { IParameter } from './IParameters'; export class ServiceParameter extends Model { protected getGroups(groups: { [key: Capitalize]: Capitalize } = {}) { - return groups + return groups; } protected getCountable(countable: Capitalize[] = []) { - return countable + return countable; } - protected getAllPropertyDescriptors( - descriptors = {}, - root: Model = ServiceParameter.prototype - ): { [p: string]: PropertyDescriptor } { - return super.getAllPropertyDescriptors(descriptors, root) + protected getAllPropertyDescriptors(descriptors = {}, root: Model = ServiceParameter.prototype): { [p: string]: PropertyDescriptor } { + return super.getAllPropertyDescriptors(descriptors, root); } toParameterList(): IParameter[] { - return DataFormatter.serviceParametersMap( - this.getData(), - this.getGroups(), - this.getCountable() - ) + return DataFormatter.serviceParametersMap(this.getData(), this.getGroups(), this.getCountable()); } } diff --git a/src/PaymentMethods/Afterpay/Model/Address.ts b/src/PaymentMethods/Afterpay/Model/Address.ts index 846e3d4d..37fcef40 100644 --- a/src/PaymentMethods/Afterpay/Model/Address.ts +++ b/src/PaymentMethods/Afterpay/Model/Address.ts @@ -1,27 +1,27 @@ -import { Address as IAddress } from '../../../Models/Interfaces/IAddress' +import { Address as IAddress } from '../../../Models/Interfaces/IAddress'; export default class Address extends IAddress { get houseNumber(): string { - return this.get('streetNumber') + return this.get('streetNumber'); } set houseNumber(phone: string) { - this.set('streetNumber', phone) + this.set('streetNumber', phone); } get houseNumberAdditional(): string { - return this.get('streetNumberAdditional') + return this.get('streetNumberAdditional'); } set houseNumberAdditional(phone: string) { - this.set('streetNumberAdditional', phone) + this.set('streetNumberAdditional', phone); } get zipcode(): string { - return this.get('postalCode') + return this.get('postalCode'); } set zipcode(phone: string) { - this.set('postalCode', phone) + this.set('postalCode', phone); } } diff --git a/src/PaymentMethods/Afterpay/Model/Article.ts b/src/PaymentMethods/Afterpay/Model/Article.ts index 3a0e64a1..95420745 100644 --- a/src/PaymentMethods/Afterpay/Model/Article.ts +++ b/src/PaymentMethods/Afterpay/Model/Article.ts @@ -1,32 +1,32 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle' +import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; export interface IAfterPayArticle extends Partial { - type?: string - imageUrl?: string - url?: string - refundType?: 'Refund' | 'Return' - marketPlaceSellerId?: string + type?: string; + imageUrl?: string; + url?: string; + refundType?: 'Refund' | 'Return'; + marketPlaceSellerId?: string; } export class AfterPayArticle extends Article { constructor(article: Interface) { - super(article) + super(article); } get price(): number { - return this.get('grossUnitPrice') + return this.get('grossUnitPrice'); } set price(price: number) { - this.set('grossUnitPrice', price) + this.set('grossUnitPrice', price); } set imageUrl(imageUrl: string) { - this.set('imageUrl', imageUrl) + this.set('imageUrl', imageUrl); } set url(url: string) { - this.set('url', url) + this.set('url', url); } set refundType(refundType: string) { - this.set('refundType', refundType) + this.set('refundType', refundType); } set marketPlaceSellerId(marketPlaceSellerId: string) { - this.set('marketPlaceSellerId', marketPlaceSellerId) + this.set('marketPlaceSellerId', marketPlaceSellerId); } } diff --git a/src/PaymentMethods/Afterpay/Model/Customer.ts b/src/PaymentMethods/Afterpay/Model/Customer.ts index 85db1f5f..7c1885c9 100644 --- a/src/PaymentMethods/Afterpay/Model/Customer.ts +++ b/src/PaymentMethods/Afterpay/Model/Customer.ts @@ -1,28 +1,28 @@ -import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient' -import IAddress from '../../../Models/Interfaces/IAddress' -import IPhone from '../../../Models/Interfaces/IPhone' -import { Model } from '../../../Models/Model' -import RecipientCategory from '../../../Constants/RecipientCategory' -import Phone from './Phone' -import Address from './Address' -import { AfterPayCompany, AfterPayPerson } from './Recipient' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient'; +import IAddress from '../../../Models/Interfaces/IAddress'; +import IPhone from '../../../Models/Interfaces/IPhone'; +import { Model } from '../../../Models/Model'; +import RecipientCategory from '../../../Constants/RecipientCategory'; +import Phone from './Phone'; +import Address from './Address'; +import { AfterPayCompany, AfterPayPerson } from './Recipient'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export default class Customer extends Model implements ICustomer { set recipient(recipient: IPerson | ICompany) { if (recipient.category === RecipientCategory.PERSON) { - this.set('recipient', new AfterPayPerson(recipient)) + this.set('recipient', new AfterPayPerson(recipient)); } else if (recipient.category === RecipientCategory.COMPANY) { - this.set('recipient', new AfterPayCompany(recipient)) + this.set('recipient', new AfterPayCompany(recipient)); } } set address(address: IAddress) { - this.set('address', new Address(address)) + this.set('address', new Address(address)); } set email(email: string) { - this.set('email', email) + this.set('email', email); } set phone(phone: IPhone) { - this.set('phone', new Phone(phone)) + this.set('phone', new Phone(phone)); } } diff --git a/src/PaymentMethods/Afterpay/Model/Pay.ts b/src/PaymentMethods/Afterpay/Model/Pay.ts index 97528023..721e8b25 100644 --- a/src/PaymentMethods/Afterpay/Model/Pay.ts +++ b/src/PaymentMethods/Afterpay/Model/Pay.ts @@ -1,61 +1,61 @@ -import { AfterPayArticle, IAfterPayArticle } from './Article' -import Customer from './Customer' -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { AfterPayArticle, IAfterPayArticle } from './Article'; +import Customer from './Customer'; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IPay extends IPaymentRequest { - clientIP: string - billing: ICustomer - shipping?: ICustomer - articles: IAfterPayArticle[] - bankAccount?: string - bankCode?: string - merchantImageUrl?: string - summaryImageUrl?: string - yourReference?: string - ourReference?: string + clientIP: string; + billing: ICustomer; + shipping?: ICustomer; + articles: IAfterPayArticle[]; + bankAccount?: string; + bankCode?: string; + merchantImageUrl?: string; + summaryImageUrl?: string; + yourReference?: string; + ourReference?: string; } export class Pay extends ServiceParameter { protected getGroups() { return super.getGroups({ Billing: 'BillingCustomer', Shipping: 'ShippingCustomer', - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set shipping(shipping: ICustomer) { - this.set('shipping', new Customer(shipping)) + this.set('shipping', new Customer(shipping)); } set billing(billing: ICustomer) { - this.set('billing', new Customer(billing)) + this.set('billing', new Customer(billing)); if (this.get('shipping') === undefined) { - this.shipping = billing + this.shipping = billing; } } set articles(articles: IAfterPayArticle[]) { this.set( 'articles', articles.map((article) => new AfterPayArticle(article)) - ) + ); } set bankAccount(bankAccount: string) { - this.set('bankAccount', bankAccount) + this.set('bankAccount', bankAccount); } set bankCode(bankCode: string) { - this.set('bankCode', bankCode) + this.set('bankCode', bankCode); } set merchantImageUrl(merchantImageUrl: string) { - this.set('merchantImageUrl', merchantImageUrl) + this.set('merchantImageUrl', merchantImageUrl); } set summaryImageUrl(summaryImageUrl: string) { - this.set('summaryImageUrl', summaryImageUrl) + this.set('summaryImageUrl', summaryImageUrl); } set ourReference(ourReference: string) { - this.set('ourReference', ourReference) + this.set('ourReference', ourReference); } } diff --git a/src/PaymentMethods/Afterpay/Model/Phone.ts b/src/PaymentMethods/Afterpay/Model/Phone.ts index 1d3d1502..4d90cdc3 100644 --- a/src/PaymentMethods/Afterpay/Model/Phone.ts +++ b/src/PaymentMethods/Afterpay/Model/Phone.ts @@ -1,18 +1,18 @@ -import { Phone as IPhone } from '../../../Models/Interfaces/IPhone' +import { Phone as IPhone } from '../../../Models/Interfaces/IPhone'; export default class Phone extends IPhone { get mobile(): string { - return this.get('mobilePhone') + return this.get('mobilePhone'); } set mobile(phone: string) { - this.set('mobilePhone', phone) + this.set('mobilePhone', phone); } get landline(): string { - return this.get('phone') + return this.get('phone'); } set landline(phone: string) { - this.set('phone', phone) + this.set('phone', phone); } } diff --git a/src/PaymentMethods/Afterpay/Model/Recipient.ts b/src/PaymentMethods/Afterpay/Model/Recipient.ts index 6c15518a..447215b7 100644 --- a/src/PaymentMethods/Afterpay/Model/Recipient.ts +++ b/src/PaymentMethods/Afterpay/Model/Recipient.ts @@ -1,29 +1,29 @@ -import { Company, IPerson, Person } from '../../../Models/Interfaces/IRecipient' +import { Company, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; export class AfterPayCompany extends Company { set title(title: string) { - this.set('salutation', title) + this.set('salutation', title); } set chamberOfCommerce(chamberOfCommerce: string) { - this.set('identificationNumber', chamberOfCommerce) + this.set('identificationNumber', chamberOfCommerce); } } export interface IAfterPayPerson extends IPerson { - customerNumber?: string - identificationNumber?: string - conversationLanguage?: string + customerNumber?: string; + identificationNumber?: string; + conversationLanguage?: string; } export class AfterPayPerson extends Person { constructor(data: IAfterPayPerson) { - super(data) + super(data); } set customerNumber(customerNumber: string) { - this.set('customerNumber', customerNumber) + this.set('customerNumber', customerNumber); } set identificationNumber(identificationNumber: string) { - this.set('identificationNumber', identificationNumber) + this.set('identificationNumber', identificationNumber); } set conversationLanguage(conversationLanguage: string) { - this.set('conversationLanguage', conversationLanguage) + this.set('conversationLanguage', conversationLanguage); } } diff --git a/src/PaymentMethods/Afterpay/Model/Refund.ts b/src/PaymentMethods/Afterpay/Model/Refund.ts index cf7a7a89..b781c37a 100644 --- a/src/PaymentMethods/Afterpay/Model/Refund.ts +++ b/src/PaymentMethods/Afterpay/Model/Refund.ts @@ -1,23 +1,23 @@ -import { IRefundRequest } from '../../../Models/IRequest' -import { AfterPayArticle, IAfterPayArticle } from './Article' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IRefundRequest } from '../../../Models/IRequest'; +import { AfterPayArticle, IAfterPayArticle } from './Article'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IRefund extends IRefundRequest { - articles?: IAfterPayArticle[] + articles?: IAfterPayArticle[]; } export class Refund extends ServiceParameter { protected getGroups() { return super.getGroups({ - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set articles(articles: IAfterPayArticle[]) { this.set( 'articles', articles.map((article) => new AfterPayArticle(article)) - ) + ); } } diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index a7e9bfb3..7c806c93 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -1,34 +1,34 @@ -import { IPay, Pay } from './Model/Pay' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefund, Refund } from './Model/Refund' +import { IPay, Pay } from './Model/Pay'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefund, Refund } from './Model/Refund'; export default class Afterpay extends PayablePaymentMethod { - protected _paymentName = 'Afterpay' - protected _serviceVersion = 1 + protected _paymentName = 'Afterpay'; + protected _serviceVersion = 1; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefund) { - return super.refund(payload, new Refund(payload)) + return super.refund(payload, new Refund(payload)); } authorize(payload: IPay) { - this.setServiceList('Authorize', new Pay(payload)) - return this.transactionRequest(payload) + this.setServiceList('Authorize', new Pay(payload)); + return this.transactionRequest(payload); } cancelAuthorize(payload: IRefundRequest) { - this.setServiceList('CancelAuthorize') - return super.transactionRequest(payload) + this.setServiceList('CancelAuthorize'); + return super.transactionRequest(payload); } capture(payload: IPaymentRequest) { - this.setServiceList('Capture', new Pay(payload)) - return super.transactionRequest(payload) + this.setServiceList('Capture', new Pay(payload)); + return super.transactionRequest(payload); } payRemainder(payload: IPay) { - return super.payRemainder(payload, new Pay(payload)) + return super.payRemainder(payload, new Pay(payload)); } authorizeRemainder(payload: IPay) { - this.setServiceList('AuthorizeRemainder', new Pay(payload)) - return super.transactionRequest(payload) + this.setServiceList('AuthorizeRemainder', new Pay(payload)); + return super.transactionRequest(payload); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts index f7fbfdf6..5d8f2aa6 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts @@ -1,34 +1,34 @@ -import { Article as ArticleClass } from '../../../Models/Interfaces/IArticle' +import { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; export default class Article extends ArticleClass { get identifier(): string { - return this.get('articleId') + return this.get('articleId'); } set identifier(identifier: string) { - this.set('articleId', identifier) + this.set('articleId', identifier); } get quantity(): number { - return this.get('articleQuantity') + return this.get('articleQuantity'); } set quantity(quantity: number) { - this.set('articleQuantity', quantity) + this.set('articleQuantity', quantity); } get price(): number { - return this.get('articleUnitprice') + return this.get('articleUnitprice'); } set price(price: number) { - this.set('articleUnitprice', price) + this.set('articleUnitprice', price); } get vatCategory(): string { - return this.get('articleVatcategory') + return this.get('articleVatcategory'); } set vatCategory(vatCategory: string) { - this.set('articleVatcategory', vatCategory) + this.set('articleVatcategory', vatCategory); } get description(): string { - return this.get('articleDescription') + return this.get('articleDescription'); } set description(description: string) { - this.set('articleDescription', description) + this.set('articleDescription', description); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts index 30d77b35..369d0c1c 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts @@ -1,29 +1,29 @@ -import { Address } from '../Services/Address' -import { Model } from '../../../Models/Model' -import { Phone } from '../Services/Phone' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { Address } from '../Services/Address'; +import { Model } from '../../../Models/Model'; +import { Phone } from '../Services/Phone'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export class Customer extends Model implements ICustomer { constructor(data?: ICustomer, prefix?: string) { - super(data, prefix) + super(data, prefix); } get prefix() { - return '' + return ''; } initialize(data?: any, prefix: string = '') { - this.set('prefix', prefix, true) - super.initialize(data) + this.set('prefix', prefix, true); + return super.initialize(data); } set recipient(recipient: ICustomer['recipient']) { - this.set('recipient', recipient) + this.set('recipient', recipient); } set address(address: ICustomer['address']) { - this.set('address', new Address(address, this.prefix)) + this.set('address', new Address(address, this.prefix)); } set email(email: ICustomer['email']) { - this.set(this.prefix + 'Email', email) + this.set(this.prefix + 'Email', email); } set phone(phone: ICustomer['phone']) { - this.set('phone', new Phone(phone)) + this.set('phone', new Phone(phone)); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts index 8ee3faa6..c1f29bc8 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -1,67 +1,67 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import Article from './Article' -import IArticle from '../../../Models/Interfaces/IArticle' -import { Customer } from './Customer' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import Article from './Article'; +import IArticle from '../../../Models/Interfaces/IArticle'; +import { Customer } from './Customer'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IPay extends IPaymentRequest { - b2b: boolean - addressesDiffer: boolean - customerIPAddress: string - shippingCosts: number - costCentre: string - department: string - establishmentNumber: number - billing: ICustomer - shipping?: ICustomer - articles: Partial[] + b2b: boolean; + addressesDiffer: boolean; + customerIPAddress: string; + shippingCosts: number; + costCentre: string; + department: string; + establishmentNumber: number; + billing: ICustomer; + shipping?: ICustomer; + articles: Partial[]; } export class Pay extends ServiceParameter implements Omit { protected getGroups() { return super.getGroups({ - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set addressesDiffer(value: boolean) { - this.set('addressesDiffer', value) + this.set('addressesDiffer', value); } set articles(articles: IArticle[]) { this.set( 'articles', articles.map((article) => new Article(article)) - ) + ); } set b2b(value: boolean) { - this.set('b2b', value) + this.set('b2b', value); } set billing(billing: ICustomer) { - this.set('billing', new Customer(billing, 'Billing')) + this.set('billing', new Customer(billing, 'Billing')); if (this.get('shipping') === undefined) { - this.shipping = billing + this.shipping = billing; } } set shipping(shipping: ICustomer) { - this.addressesDiffer = true - this.set('shipping', new Customer(shipping, 'Shipping')) + this.addressesDiffer = true; + this.set('shipping', new Customer(shipping, 'Shipping')); } set costCentre(value: string) { - this.set('costCentre', value) + this.set('costCentre', value); } set customerIPAddress(value: string) { - this.set('customerIPAddress', value) + this.set('customerIPAddress', value); } set department(value: string) { - this.set('department', value) + this.set('department', value); } set establishmentNumber(value: number) { - this.set('establishmentNumber', value) + this.set('establishmentNumber', value); } set shippingCosts(value: number) { - this.set('shippingCosts', value) + this.set('shippingCosts', value); } - protected accept: boolean = true + protected accept: boolean = true; } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts index 82a0d66e..013522f6 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts @@ -1,34 +1,34 @@ -import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; export class Address extends AddressClass { private get prefix() { - return '' + return ''; } private set prefix(value: string) { - this.set('prefix', value) + this.set('prefix', value); } initialize(data?: any, prefix: string = '') { - this.set('prefix', prefix, true) - super.initialize(data) + this.set('prefix', prefix, true); + return super.initialize(data); } protected privateName(name: string): string { - return super.privateName(name) + return super.privateName(name); } get houseNumberAdditional() { - return this.get('houseNumberSuffix') + return this.get('houseNumberSuffix'); } set houseNumberAdditional(value: string) { - this.set('houseNumberSuffix', value) + this.set('houseNumberSuffix', value); } get zipcode() { - return this.get('postalCode') + return this.get('postalCode'); } set zipcode(value: string) { - this.set('postalCode', value) + this.set('postalCode', value); } set country(value: string) { if (this.prefix === 'Shipping' && value === 'NL') { - this.set('countryCode', value) - } else this.set('country', value) + this.set('countryCode', value); + } else this.set('country', value); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts index 11bef31c..3d906054 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts @@ -1,6 +1,6 @@ -import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; export class Phone extends PhoneClass { set mobile(value: string) { - this.set('phoneNumber', value) + this.set('phoneNumber', value); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 4a8b1ed9..d3c406b6 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -1,35 +1,35 @@ -import { IPay } from '../Afterpay/Model/Pay' -import IRequest, { IRefundRequest } from '../../Models/IRequest' -import PayablePaymentMethod from '../PayablePaymentMethod' -import { Pay } from './Model/Pay' +import { IPay } from '../Afterpay/Model/Pay'; +import IRequest, { IRefundRequest } from '../../Models/IRequest'; +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { Pay } from './Model/Pay'; export default class AfterpayDigiAccept extends PayablePaymentMethod { - protected _paymentName = 'AfterpayDigiAccept' - protected _serviceVersion = 2 + protected _paymentName = 'AfterpayDigiAccept'; + protected _serviceVersion = 2; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } authorize(payload: IPay) { - this.setServiceList('Authorize', new Pay(payload)) - return super.transactionRequest(payload) + this.setServiceList('Authorize', new Pay(payload)); + return super.transactionRequest(payload); } cancelAuthorize(payload: IRefundRequest) { - this.setServiceList('CancelAuthorize') - return super.transactionRequest(payload) + this.setServiceList('CancelAuthorize'); + return super.transactionRequest(payload); } capture(payload: IRequest) { - this.setServiceList('Capture') - return super.transactionRequest(payload) + this.setServiceList('Capture'); + return super.transactionRequest(payload); } payRemainder(payload: IPay) { - this.setServiceList('PayRemainder') - return super.transactionRequest(payload) + this.setServiceList('PayRemainder'); + return super.transactionRequest(payload); } authorizeRemainder(payload: IPay) { - this.setServiceList('AuthorizeRemainder') - return super.transactionRequest(payload) + this.setServiceList('AuthorizeRemainder'); + return super.transactionRequest(payload); } } diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 049c58fb..e542b3dd 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,16 +1,15 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' -import {ServiceParameter} from "../../Models/ServiceParameters"; +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { ServiceParameter } from '../../Models/ServiceParameters'; export default class Alipay extends PayablePaymentMethod { - protected _paymentName = 'Alipay' + protected _paymentName = 'Alipay'; pay(payload: { useMobileView?: boolean } & IPaymentRequest) { - const serviceParameters = new ServiceParameter() - .set('useMobileView', payload.useMobileView) - return super.pay(payload, serviceParameters) + const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); + return super.pay(payload, serviceParameters); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/ApplePay/Models/Pay.ts b/src/PaymentMethods/ApplePay/Models/Pay.ts index d38a973e..3125e3e8 100644 --- a/src/PaymentMethods/ApplePay/Models/Pay.ts +++ b/src/PaymentMethods/ApplePay/Models/Pay.ts @@ -1,15 +1,15 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - paymentData: string - customerCardName: string + paymentData: string; + customerCardName: string; } export class Pay extends ServiceParameter { set paymentData(value: string) { - this.set('paymentData', value) + this.set('paymentData', value); } set customerCardName(value: string) { - this.set('customerCardName', value) + this.set('customerCardName', value); } } diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 8f09dab7..eeea17c3 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -1,17 +1,17 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class ApplePay extends PayablePaymentMethod { - protected _paymentName = 'ApplePay' + protected _paymentName = 'ApplePay'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } payRedirect(payload: IPaymentRequest) { - this.setPayPayload(payload) - return this.transactionRequest() + this.setPayPayload(payload); + return this.transactionRequest(); } } diff --git a/src/PaymentMethods/Bancontact/Models/Pay.ts b/src/PaymentMethods/Bancontact/Models/Pay.ts index a1928025..3ba0d1eb 100644 --- a/src/PaymentMethods/Bancontact/Models/Pay.ts +++ b/src/PaymentMethods/Bancontact/Models/Pay.ts @@ -1,26 +1,26 @@ -import IRequest, { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest, { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - saveToken?: boolean + saveToken?: boolean; } export interface IPayEncrypted extends IPaymentRequest { - encryptedCardData: string + encryptedCardData: string; } export interface IPayComplete extends IRequest { - encryptedCardData: string - originalTransactionKey: string + encryptedCardData: string; + originalTransactionKey: string; } export interface IPayOneClick extends IRequest { - originalTransactionKey: string - amountDebit: number + originalTransactionKey: string; + amountDebit: number; } export class Pay extends ServiceParameter { set encryptedCardData(value: string) { - this.set('encryptedCardData', value) + this.set('encryptedCardData', value); } set saveToken(value: boolean) { - this.set('saveToken', value) + this.set('saveToken', value); } } diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 9c747d6e..b5bfaa3b 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -1,33 +1,33 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay' -import { IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; +import { IRefundRequest } from '../../Models/IRequest'; export default class Bancontact extends PayablePaymentMethod { - protected _paymentName = 'Bancontact' + protected _paymentName = 'Bancontact'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } authenticate(payload: IPay) { - this.setServiceList('Authenticate', new Pay(payload)) - return this.transactionRequest(payload) + this.setServiceList('Authenticate', new Pay(payload)); + return this.transactionRequest(payload); } payOneClick(payload: IPayOneClick) { - this.setServiceList('PayOneClick', new Pay(payload)) - return this.transactionRequest(payload) + this.setServiceList('PayOneClick', new Pay(payload)); + return this.transactionRequest(payload); } payEncrypted(payload: IPayEncrypted) { - this.setServiceList('PayEncrypted', new Pay(payload)) - return this.transactionRequest(payload) + this.setServiceList('PayEncrypted', new Pay(payload)); + return this.transactionRequest(payload); } completePayment(payload: IPayComplete) { - this.setServiceList('CompletePayment', new Pay(payload)) - return this.dataRequest(payload) + this.setServiceList('CompletePayment', new Pay(payload)); + return this.dataRequest(payload); } payRecurring(payload: IPayOneClick) { - this.setServiceList('PayRecurring', new Pay(payload)) - return this.transactionRequest(payload) + this.setServiceList('PayRecurring', new Pay(payload)); + return this.transactionRequest(payload); } } diff --git a/src/PaymentMethods/BankTransfer/Models/Pay.ts b/src/PaymentMethods/BankTransfer/Models/Pay.ts index c9a51a5e..b4dc31ce 100644 --- a/src/PaymentMethods/BankTransfer/Models/Pay.ts +++ b/src/PaymentMethods/BankTransfer/Models/Pay.ts @@ -1,38 +1,38 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - customer: Partial - sendMail?: boolean - dateDue?: string - customerCountry?: string + customer: Partial; + sendMail?: boolean; + dateDue?: string; + customerCountry?: string; } class BankTransferPerson extends Person { set firstName(value: string) { - this.set('customerFirstName', value) + this.set('customerFirstName', value); } set lastName(value: string) { - this.set('customerLastName', value) + this.set('customerLastName', value); } set gender(value: string) { - this.set('customerGender', value) + this.set('customerGender', value); } } export class Pay extends ServiceParameter { set sendMail(sendMail: boolean) { - this.set('sendMail', sendMail) + this.set('sendMail', sendMail); } set dateDue(dateDue: string) { - this.set('dateDue', dateDue) + this.set('dateDue', dateDue); } set country(country: string) { - this.set('customerCountry', country) + this.set('customerCountry', country); } set customer(person: IPerson) { - this.set('customer', new BankTransferPerson(person)) + this.set('customer', new BankTransferPerson(person)); } set email(email: string) { - this.set('customerEmail', email) + this.set('customerEmail', email); } } diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 5d556df9..34e2faf9 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -1,14 +1,14 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import { IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import { IRefundRequest } from '../../Models/IRequest'; export default class BankTransfer extends PayablePaymentMethod { - protected _paymentName = 'BankTransfer' + protected _paymentName = 'BankTransfer'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index adec001c..a77723c9 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,12 +1,12 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Belfius extends PayablePaymentMethod { - protected _paymentName = 'Belfius' + protected _paymentName = 'Belfius'; pay(payload: IPaymentRequest) { - return super.pay(payload) + return super.pay(payload); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/Billink/Models/Address.ts b/src/PaymentMethods/Billink/Models/Address.ts index e62fe2a2..57d259d9 100644 --- a/src/PaymentMethods/Billink/Models/Address.ts +++ b/src/PaymentMethods/Billink/Models/Address.ts @@ -1,12 +1,12 @@ -import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; export class Address extends AddressClass { set houseNumber(houseNumber: string) { - this.set('streetNumber', houseNumber) + this.set('streetNumber', houseNumber); } set houseNumberAdditional(houseNumberAdditional: string) { - this.set('streetNumberAdditional', houseNumberAdditional) + this.set('streetNumberAdditional', houseNumberAdditional); } set zipcode(zipcode: string) { - this.set('postalCode', zipcode) + this.set('postalCode', zipcode); } } diff --git a/src/PaymentMethods/Billink/Models/Article.ts b/src/PaymentMethods/Billink/Models/Article.ts index 03eeef37..0de0e503 100644 --- a/src/PaymentMethods/Billink/Models/Article.ts +++ b/src/PaymentMethods/Billink/Models/Article.ts @@ -1,13 +1,12 @@ -import IArticle, { Article as ArticleClass } from '../../../Models/Interfaces/IArticle' +import IArticle, { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; export interface IBillinkArticle extends Partial { - priceExcl: number + priceExcl: number; } export class Article extends ArticleClass { set priceExcl(priceExcl: number) { - this.set('grossUnitPriceExcl', priceExcl) + this.set('grossUnitPriceExcl', priceExcl); } set price(price: number) { - this.set('grossUnitPriceIncl', price) + this.set('grossUnitPriceIncl', price); } } - diff --git a/src/PaymentMethods/Billink/Models/Capture.ts b/src/PaymentMethods/Billink/Models/Capture.ts index 17ac16d0..53fb86d0 100644 --- a/src/PaymentMethods/Billink/Models/Capture.ts +++ b/src/PaymentMethods/Billink/Models/Capture.ts @@ -1,20 +1,20 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { Article, IBillinkArticle } from './Article' -import { IPaymentRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Article, IBillinkArticle } from './Article'; +import { IPaymentRequest } from '../../../Models/IRequest'; export interface ICapture extends IPaymentRequest { - articles?: IBillinkArticle[] + articles?: IBillinkArticle[]; } export class Capture extends ServiceParameter { protected getGroups() { return super.getGroups({ - Articles: 'Article' - }) + Articles: 'Article', + }); } set articles(articels: IBillinkArticle[]) { this.set( 'articles', articels.map((article) => new Article(article)) - ) + ); } } diff --git a/src/PaymentMethods/Billink/Models/Customer.ts b/src/PaymentMethods/Billink/Models/Customer.ts index acf943c2..80f03cc0 100644 --- a/src/PaymentMethods/Billink/Models/Customer.ts +++ b/src/PaymentMethods/Billink/Models/Customer.ts @@ -1,40 +1,40 @@ -import IPhone from '../../../Models/Interfaces/IPhone' -import { Phone } from './Phone' -import IAddress from '../../../Models/Interfaces/IAddress' -import { Address } from './Address' -import { Customer } from '../../../Models/Interfaces/ICustomer' -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import recipientCategory from '../../../Constants/RecipientCategory' +import IPhone from '../../../Models/Interfaces/IPhone'; +import { Phone } from './Phone'; +import IAddress from '../../../Models/Interfaces/IAddress'; +import { Address } from './Address'; +import { Customer } from '../../../Models/Interfaces/ICustomer'; +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import recipientCategory from '../../../Constants/RecipientCategory'; export class BillinkCustomer extends Customer { set address(address: IAddress) { - this.set('address', new Address(address)) + this.set('address', new Address(address)); } set phone(phone: IPhone) { - this.set('phone', new Phone(phone)) + this.set('phone', new Phone(phone)); } set recipient(recipient: IPerson | ICompany) { if (recipient.category === recipientCategory.PERSON) { - this.set('recipient', new BillinkPerson(recipient)) + this.set('recipient', new BillinkPerson(recipient)); } else if (recipient.category === recipientCategory.COMPANY) { - this.set('recipient', new BillinkCompany(recipient)) - } else throw new Error('Invalid recipient category') + this.set('recipient', new BillinkCompany(recipient)); + } else throw new Error('Invalid recipient category'); } } export class BillinkPerson extends Person { set category(category: recipientCategory.PERSON) { - this.set('category', 'B2C') + this.set('category', 'B2C'); } set title(title: string) { - this.set('salutation', title) + this.set('salutation', title); } } export class BillinkCompany extends Company { set category(category: recipientCategory.COMPANY) { - this.set('category', 'B2B') + this.set('category', 'B2B'); } set title(title: string) { - this.set('salutation', title) + this.set('salutation', title); } } diff --git a/src/PaymentMethods/Billink/Models/Pay.ts b/src/PaymentMethods/Billink/Models/Pay.ts index 45b948c9..860b0872 100644 --- a/src/PaymentMethods/Billink/Models/Pay.ts +++ b/src/PaymentMethods/Billink/Models/Pay.ts @@ -1,50 +1,50 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { Article, IBillinkArticle } from './Article' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' -import { BillinkCustomer } from './Customer' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { Article, IBillinkArticle } from './Article'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { BillinkCustomer } from './Customer'; export interface IPay extends IPaymentRequest { - billing: ICustomer - shipping?: ICustomer - articles: IBillinkArticle[] - trackandtrace?: string - VATNumber?: string - summaryImageUrl?: string + billing: ICustomer; + shipping?: ICustomer; + articles: IBillinkArticle[]; + trackandtrace?: string; + VATNumber?: string; + summaryImageUrl?: string; } export class Pay extends ServiceParameter { protected getGroups() { return super.getGroups({ Billing: 'BillingCustomer', Shipping: 'ShippingCustomer', - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable(countable: Capitalize[] = []): Capitalize[] { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set billing(billing: ICustomer) { - this.set('billing', new BillinkCustomer(billing)) + this.set('billing', new BillinkCustomer(billing)); if (this.get('shipping') === undefined) { - this.shipping = billing + this.shipping = billing; } } set shipping(shipping: ICustomer) { - this.set('shipping', new BillinkCustomer(shipping)) + this.set('shipping', new BillinkCustomer(shipping)); } set articles(articles: IBillinkArticle[]) { this.set( 'articles', articles.map((article) => new Article(article)) - ) + ); } set trackandtrace(trackandtrace: string) { - this.set('trackandtrace', trackandtrace) + this.set('trackandtrace', trackandtrace); } set VATNumber(VATNumber: string) { - this.set('VATNumber', VATNumber) + this.set('VATNumber', VATNumber); } set summaryImageUrl(summaryImageUrl: string) { - this.set('summaryImageUrl', summaryImageUrl) + this.set('summaryImageUrl', summaryImageUrl); } } diff --git a/src/PaymentMethods/Billink/Models/Phone.ts b/src/PaymentMethods/Billink/Models/Phone.ts index 4b0e2763..dc51b0f6 100644 --- a/src/PaymentMethods/Billink/Models/Phone.ts +++ b/src/PaymentMethods/Billink/Models/Phone.ts @@ -1,12 +1,12 @@ -import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; export class Phone extends PhoneClass { set fax(fax: string) { - this.set('mobilePhone', fax) + this.set('mobilePhone', fax); } set landline(landline: string) { - this.set('mobilePhone', landline) + this.set('mobilePhone', landline); } set mobile(mobile: string) { - this.set('mobilePhone', mobile) + this.set('mobilePhone', mobile); } } diff --git a/src/PaymentMethods/Billink/Models/Refund.ts b/src/PaymentMethods/Billink/Models/Refund.ts index 699608b9..cd2a59d6 100644 --- a/src/PaymentMethods/Billink/Models/Refund.ts +++ b/src/PaymentMethods/Billink/Models/Refund.ts @@ -1,11 +1,11 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { IRefundRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRefundRequest } from '../../../Models/IRequest'; export interface IRefund extends IRefundRequest { - refundReason?: string + refundReason?: string; } export class Refund extends ServiceParameter { set refundReason(value: string) { - this.set('refundreason', value) + this.set('refundreason', value); } } diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 64570950..666397a4 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -1,28 +1,28 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import { IRefund, Refund } from './Models/Refund' -import { Capture, ICapture } from './Models/Capture' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import { IRefund, Refund } from './Models/Refund'; +import { Capture, ICapture } from './Models/Capture'; export default class Billink extends PayablePaymentMethod { - protected _paymentName = 'Billink' + protected _paymentName = 'Billink'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefund) { - return super.refund(payload, new Refund(payload)) + return super.refund(payload, new Refund(payload)); } authorize(payload: IPay) { - this.setPayPayload(payload) - this.setServiceList('Authorize', new Pay(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Authorize', new Pay(payload)); + return super.transactionRequest(); } cancelAuthorize(payload: IRefund) { - this.setPayload(payload) - this.setServiceList('CancelAuthorize', new Refund(payload)) - return super.transactionRequest() + this.setPayload(payload); + this.setServiceList('CancelAuthorize', new Refund(payload)); + return super.transactionRequest(); } capture(payload: ICapture) { - this.setPayPayload(payload) - this.setServiceList('Capture', new Capture(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Capture', new Capture(payload)); + return super.transactionRequest(); } } diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts index 319bf55f..4f079442 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts @@ -1,32 +1,32 @@ -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ICreate extends IRequest { - groupReference?: string + groupReference?: string; /** * 1 = Single * 2 = Multiple */ - usageType: 1 | 2 - validFrom: string - validUntil?: string - creationBalance: number + usageType: 1 | 2; + validFrom: string; + validUntil?: string; + creationBalance: number; } export class Create extends ServiceParameter { set groupReference(value: string) { - this.set('groupReference', value) + this.set('groupReference', value); } set usageType(value: 1 | 2) { - this.set('usageType', value) + this.set('usageType', value); } set validFrom(value: string) { - this.set('validFrom', value) + this.set('validFrom', value); } set validUntil(value: string) { - this.set('validUntil', value) + this.set('validUntil', value); } set creationBalance(value: number) { - this.set('creationBalance', value) + this.set('creationBalance', value); } } diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts index 3a73ae24..1b266f9d 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts @@ -1,11 +1,11 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - voucherCode: string + voucherCode: string; } export class Pay extends ServiceParameter { set voucherCode(voucherCode: string) { - this.set('voucherCode', voucherCode) + this.set('voucherCode', voucherCode); } } diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index e6ba9509..663c4dee 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -1,23 +1,23 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import IRequest from '../../Models/IRequest' -import { Create, ICreate } from './Models/Create' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import IRequest from '../../Models/IRequest'; +import { Create, ICreate } from './Models/Create'; export default class BuckarooVoucher extends PayablePaymentMethod { - protected _paymentName = 'BuckarooVoucher' + protected _paymentName = 'BuckarooVoucher'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } getBalance(payload: IRequest & Pick) { - this.setServiceList('GetBalance', new Pay(payload)) - return this.dataRequest(payload) + this.setServiceList('GetBalance', new Pay(payload)); + return this.dataRequest(payload); } create(payload: IRequest & ICreate) { - this.setServiceList('CreateApplication', new Create(payload)) - return this.dataRequest(payload) + this.setServiceList('CreateApplication', new Create(payload)); + return this.dataRequest(payload); } deactivate(payload: IRequest & Pick) { - this.setServiceList('DeactivateVoucher', new Pay(payload)) - return this.dataRequest(payload) + this.setServiceList('DeactivateVoucher', new Pay(payload)); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts index c1d7f376..3f2c7f6f 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts @@ -1,7 +1,7 @@ -import { BankAccount as BankAccountClass } from '../../../Models/Interfaces/IBankAccount' +import { BankAccount as BankAccountClass } from '../../../Models/Interfaces/IBankAccount'; export class BankAccount extends BankAccountClass { set iban(value: string) { - this.set('consumerIban', value) + this.set('consumerIban', value); } } diff --git a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts index 4c9d9366..86bc02dd 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts @@ -1,12 +1,12 @@ -import { Person } from '../../../Models/Interfaces/IRecipient' -import RecipientCategory from '../../../Constants/RecipientCategory' +import { Person } from '../../../Models/Interfaces/IRecipient'; +import RecipientCategory from '../../../Constants/RecipientCategory'; export class Customer extends Person { set category(value: RecipientCategory.PERSON) {} set firstName(value: string) { - this.set('consumerFirstName', value) + this.set('consumerFirstName', value); } set lastName(value: string) { - this.set('consumerLastName', value) + this.set('consumerLastName', value); } } diff --git a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts index 4a498fc7..6d3f8877 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts @@ -1,36 +1,36 @@ -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { IPerson } from '../../../Models/Interfaces/IRecipient' -import { Customer } from './Customer' -import IBankAccount from '../../../Models/Interfaces/IBankAccount' -import { BankAccount } from './BankAccount' +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { Customer } from './Customer'; +import IBankAccount from '../../../Models/Interfaces/IBankAccount'; +import { BankAccount } from './BankAccount'; export interface IWallet extends IRequest { - invoice?: string - walletId?: string - customer?: Partial - bankAccount?: Partial - walletMutationGuid?: string - status?: string + invoice?: string; + walletId?: string; + customer?: Partial; + bankAccount?: Partial; + walletMutationGuid?: string; + status?: string; } export class Wallet extends ServiceParameter { set walletId(value: string) { - this.set('walletId', value) + this.set('walletId', value); } set customer(value: Partial) { - this.set('customer', new Customer(value)) + this.set('customer', new Customer(value)); } set email(value: string) { - this.set('consumerEmail', value) + this.set('consumerEmail', value); } set status(value: string) { - this.set('status', value) + this.set('status', value); } set walletMutationGuid(value: string) { - this.set('walletMutationGuid', value) + this.set('walletMutationGuid', value); } set bankAccount(value: IBankAccount) { - this.set('bankAccount', new BankAccount(value)) + this.set('bankAccount', new BankAccount(value)); } } diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 2dc5e883..d6b634c5 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -1,51 +1,51 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IWallet, Wallet } from './Models/Wallet' -import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IWallet, Wallet } from './Models/Wallet'; +import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class BuckarooWallet extends PayablePaymentMethod { - protected _paymentName = 'BuckarooWallet' + protected _paymentName = 'BuckarooWallet'; pay(payload: IWallet & IPaymentRequest) { - return super.pay(payload, new Wallet(payload)) + return super.pay(payload, new Wallet(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } create(payload: IWallet & IRequest) { - this._requiredFields = ['currency'] - this.setPayload(payload) - this.setServiceList('Create', new Wallet(payload)) - return this.dataRequest() + this._requiredFields = ['currency']; + this.setPayload(payload); + this.setServiceList('Create', new Wallet(payload)); + return this.dataRequest(); } deposit(payload: IWallet & IRefundRequest) { - this.setPayload(payload) - this.setServiceList('Deposit', new Wallet(payload)) - return super.transactionRequest() + this.setPayload(payload); + this.setServiceList('Deposit', new Wallet(payload)); + return super.transactionRequest(); } reserve(payload: IWallet & IRefundRequest) { - this.setPayload(payload) - this.setServiceList('Reserve', new Wallet(payload)) - return super.transactionRequest() + this.setPayload(payload); + this.setServiceList('Reserve', new Wallet(payload)); + return super.transactionRequest(); } withdrawal(payload: IWallet & IPaymentRequest) { - this.setPayPayload(payload) - this.setServiceList('Withdrawal', new Wallet(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Withdrawal', new Wallet(payload)); + return super.transactionRequest(); } cancel(payload: IPaymentRequest & { walletMutationGuid: string }) { - this.setPayPayload(payload) - this.setServiceList('Withdrawal', new Wallet(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Withdrawal', new Wallet(payload)); + return super.transactionRequest(); } update(payload: IWallet) { - this.setServiceList('Update', new Wallet(payload)) - return this.dataRequest(payload) + this.setServiceList('Update', new Wallet(payload)); + return this.dataRequest(payload); } getInfo(payload: IWallet) { - this.setServiceList('GetInfo', new Wallet(payload)) - return this.dataRequest(payload) + this.setServiceList('GetInfo', new Wallet(payload)); + return this.dataRequest(payload); } release(payload: IWallet & IRefundRequest) { - this.setServiceList('Release', new Wallet(payload)) - return this.dataRequest(payload) + this.setServiceList('Release', new Wallet(payload)); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/CreditCard/Models/CardData.ts b/src/PaymentMethods/CreditCard/Models/CardData.ts index 2533d088..5934fca8 100644 --- a/src/PaymentMethods/CreditCard/Models/CardData.ts +++ b/src/PaymentMethods/CreditCard/Models/CardData.ts @@ -1,11 +1,11 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ICardData extends IPaymentRequest { - encryptedCardData: string + encryptedCardData: string; } export class CardData extends ServiceParameter { set encryptedCardData(value: string) { - this.set('encryptedCardData', value) + this.set('encryptedCardData', value); } } diff --git a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts index 119d401c..347610bf 100644 --- a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts +++ b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts @@ -1,11 +1,11 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ISecurityCode extends IPaymentRequest { - encryptedSecurityCode: string + encryptedSecurityCode: string; } export class SecurityCode extends ServiceParameter { set encryptedSecurityCode(value: string) { - this.set('encryptedSecurityCode', value) + this.set('encryptedSecurityCode', value); } } diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 8227b72d..be773707 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -1,52 +1,52 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' -import { CardData, ICardData } from './Models/CardData' -import { ISecurityCode, SecurityCode } from './Models/SecurityCode' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { CardData, ICardData } from './Models/CardData'; +import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; export default class CreditCard extends PayablePaymentMethod { - protected _paymentName = 'CreditCard' + protected _paymentName = 'CreditCard'; payEncrypted(payload: ICardData) { - this.setPayPayload(payload) - this.setServiceList('PayEncrypted', new CardData(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayEncrypted', new CardData(payload)); + return super.transactionRequest(); } payWithSecurityCode(payload: ISecurityCode) { - this.setPayPayload(payload) - this.setServiceList('PayWithSecurityCode', new SecurityCode(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayWithSecurityCode', new SecurityCode(payload)); + return super.transactionRequest(); } authorize(payload: IPaymentRequest) { - this.setPayPayload(payload) - this.setServiceList('Authorize') - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Authorize'); + return super.transactionRequest(); } authorizeWithSecurityCode(payload: ISecurityCode) { - this.setPayPayload(payload) - this.setServiceList('AuthorizeWithSecurityCode', new SecurityCode(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('AuthorizeWithSecurityCode', new SecurityCode(payload)); + return super.transactionRequest(); } authorizeEncrypted(payload: ICardData) { - this.setPayPayload(payload) - this.setServiceList('AuthorizeEncrypted', new CardData(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('AuthorizeEncrypted', new CardData(payload)); + return super.transactionRequest(); } cancelAuthorize(payload: IRefundRequest) { - this.setServiceList('CancelAuthorize') - return super.transactionRequest(payload) + this.setServiceList('CancelAuthorize'); + return super.transactionRequest(payload); } capture(payload: IRequest) { - this.setPayPayload(payload) - this.setServiceList('Capture') - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Capture'); + return super.transactionRequest(); } payRecurrent(payload: IRequest) { - this.setPayPayload(payload) - this.setServiceList('PayRecurrent') - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayRecurrent'); + return super.transactionRequest(); } payRemainderEncrypted(payload: ICardData) { - this.setPayPayload(payload) - this.setServiceList('PayRemainderEncrypted', new CardData(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayRemainderEncrypted', new CardData(payload)); + return super.transactionRequest(); } } diff --git a/src/PaymentMethods/CreditClick/Models/Pay.ts b/src/PaymentMethods/CreditClick/Models/Pay.ts index 6d7b76a1..66a98c6a 100644 --- a/src/PaymentMethods/CreditClick/Models/Pay.ts +++ b/src/PaymentMethods/CreditClick/Models/Pay.ts @@ -1,16 +1,16 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { IPerson } from '../../../Models/Interfaces/IRecipient' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - person: Partial - email?: string + person: Partial; + email?: string; } export class Pay extends ServiceParameter { set person(value: Partial) { - this.set('person', value) + this.set('person', value); } set email(value: string) { - this.set('email', value) + this.set('email', value); } } diff --git a/src/PaymentMethods/CreditClick/Models/Refund.ts b/src/PaymentMethods/CreditClick/Models/Refund.ts index 2f78a778..3f972b6d 100644 --- a/src/PaymentMethods/CreditClick/Models/Refund.ts +++ b/src/PaymentMethods/CreditClick/Models/Refund.ts @@ -1,21 +1,16 @@ -import { IRefundRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IRefundRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IRefund extends IRefundRequest { - description: string - refundReason: - | 'Duplicate' - | 'Fraudulent' - | 'GoodsNotDelivered' - | 'RequestedByCustomer' - | 'TechnicalError' + description: string; + refundReason: 'Duplicate' | 'Fraudulent' | 'GoodsNotDelivered' | 'RequestedByCustomer' | 'TechnicalError'; } export class Refund extends ServiceParameter { set description(value: string) { - this.set('description', value) + this.set('description', value); } set refundReason(value: IRefund['refundReason']) { - this.set('refundreason', value) + this.set('refundreason', value); } } diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 9014b328..c5635a52 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import { IRefund, Refund } from './Models/Refund' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import { IRefund, Refund } from './Models/Refund'; export default class CreditClick extends PayablePaymentMethod { - protected _paymentName = 'CreditClick' + protected _paymentName = 'CreditClick'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefund) { - return super.refund(payload, new Refund(payload)) + return super.refund(payload, new Refund(payload)); } } diff --git a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts index d15958a2..1331b7fc 100644 --- a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts +++ b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts @@ -1,27 +1,27 @@ -import { CreditArticle, ICreditArticle } from './Article' -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { CreditArticle, ICreditArticle } from './Article'; +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IAddOrUpdateProductLines extends IRequest { - invoiceKey: string - articles: ICreditArticle[] + invoiceKey: string; + articles: ICreditArticle[]; } export class AddOrUpdateProductLines extends ServiceParameter { protected getGroups() { return super.getGroups({ - Articles: 'ProductLine' - }) + Articles: 'ProductLine', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set invoiceKey(value: string) { - this.set('invoiceKey', value) + this.set('invoiceKey', value); } set articles(value: ICreditArticle[]) { this.set( 'articles', value.map((article) => new CreditArticle(article)) - ) + ); } } diff --git a/src/PaymentMethods/CreditManagement/Models/Address.ts b/src/PaymentMethods/CreditManagement/Models/Address.ts index 699381b2..c578bc57 100644 --- a/src/PaymentMethods/CreditManagement/Models/Address.ts +++ b/src/PaymentMethods/CreditManagement/Models/Address.ts @@ -1,6 +1,6 @@ -import { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; export class Address extends AddressClass { set houseNumberAdditional(value: string) { - this.set('houseNumberSuffix', value) + this.set('houseNumberSuffix', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/Article.ts b/src/PaymentMethods/CreditManagement/Models/Article.ts index 89a13e6a..3f0880e1 100644 --- a/src/PaymentMethods/CreditManagement/Models/Article.ts +++ b/src/PaymentMethods/CreditManagement/Models/Article.ts @@ -1,54 +1,54 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle' +import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; export interface ICreditArticle extends Partial { - totalVat: number - productLine?: string - productGroupName?: string - productGroupOrderIndex?: number - productOrderIndex?: number - unitOfMeasurement?: string - discountPercentage?: number - totalDiscount?: number - totalAmountExVat?: number - totalAmount?: number + totalVat: number; + productLine?: string; + productGroupName?: string; + productGroupOrderIndex?: number; + productOrderIndex?: number; + unitOfMeasurement?: string; + discountPercentage?: number; + totalDiscount?: number; + totalAmountExVat?: number; + totalAmount?: number; } export class CreditArticle extends Article implements ICreditArticle { set identifier(value: string) { - this.set('productId', value) + this.set('productId', value); } set description(value: string) { - this.set('productName', value) + this.set('productName', value); } set price(value: number) { - this.set('pricePerUnit', value) + this.set('pricePerUnit', value); } set productLine(value: string) { - this.set('productLine', value) + this.set('productLine', value); } set productGroupName(value: string) { - this.set('productGroupName', value) + this.set('productGroupName', value); } set productGroupOrderIndex(value: number) { - this.set('productGroupOrderIndex', value) + this.set('productGroupOrderIndex', value); } set productOrderIndex(value: number) { - this.set('productOrderIndex', value) + this.set('productOrderIndex', value); } set unitOfMeasurement(value: string) { - this.set('unitOfMeasurement', value) + this.set('unitOfMeasurement', value); } set discountPercentage(value: number) { - this.set('discountPercentage', value) + this.set('discountPercentage', value); } set totalDiscount(value: number) { - this.set('totalDiscount', value) + this.set('totalDiscount', value); } set totalVat(value: number) { - this.set('totalVat', value) + this.set('totalVat', value); } set totalAmountExVat(value: number) { - this.set('totalAmountExVat', value) + this.set('totalAmountExVat', value); } set totalAmount(value: number) { - this.set('totalAmount', value) + this.set('totalAmount', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts index 9e0cd019..f430087e 100644 --- a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts +++ b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts @@ -1,27 +1,27 @@ -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ICreditNote extends IRequest { - originalInvoiceNumber: string - invoiceDate: string - invoiceAmount: string - invoiceAmountVAT: string - sendCreditNoteMessage: string + originalInvoiceNumber: string; + invoiceDate: string; + invoiceAmount: string; + invoiceAmountVAT: string; + sendCreditNoteMessage: string; } export class CreditNote extends ServiceParameter implements ICreditNote { set originalInvoiceNumber(value: string) { - this.set('originalInvoiceNumber', value) + this.set('originalInvoiceNumber', value); } set invoiceDate(value: string) { - this.set('invoiceDate', value) + this.set('invoiceDate', value); } set invoiceAmount(value: string) { - this.set('invoiceAmount', value) + this.set('invoiceAmount', value); } set invoiceAmountVAT(value: string) { - this.set('invoiceAmountVAT', value) + this.set('invoiceAmountVAT', value); } set sendCreditNoteMessage(value: string) { - this.set('sendCreditNoteMessage', value) + this.set('sendCreditNoteMessage', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/Debtor.ts b/src/PaymentMethods/CreditManagement/Models/Debtor.ts index b7791247..52ba497d 100644 --- a/src/PaymentMethods/CreditManagement/Models/Debtor.ts +++ b/src/PaymentMethods/CreditManagement/Models/Debtor.ts @@ -1,30 +1,30 @@ -import { IInvoice, Invoice } from './Invoice' +import { IInvoice, Invoice } from './Invoice'; export interface IDebtor extends IInvoice { - addressUnreachable?: boolean + addressUnreachable?: boolean; - emailUnreachable?: boolean + emailUnreachable?: boolean; - mobileUnreachable?: boolean + mobileUnreachable?: boolean; - landlineUnreachable?: boolean + landlineUnreachable?: boolean; - faxUnreachable?: boolean + faxUnreachable?: boolean; } export class Debtor extends Invoice { set addressUnreachable(value: boolean) { - this.set('addressUnreachable', value) + this.set('addressUnreachable', value); } set emailUnreachable(value: boolean) { - this.set('emailUnreachable', value) + this.set('emailUnreachable', value); } set mobileUnreachable(value: boolean) { - this.set('mobileUnreachable', value) + this.set('mobileUnreachable', value); } set landlineUnreachable(value: boolean) { - this.set('landlineUnreachable', value) + this.set('landlineUnreachable', value); } set faxUnreachable(value: boolean) { - this.set('faxUnreachable', value) + this.set('faxUnreachable', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts index b5618073..9d3f28f4 100644 --- a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts +++ b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts @@ -1,21 +1,21 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import IDebtor, { Debtor as DebtorClass } from '../../../Models/Interfaces/IDebtor' -import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import IDebtor, { Debtor as DebtorClass } from '../../../Models/Interfaces/IDebtor'; +import IRequest from '../../../Models/IRequest'; export interface IDebtorInfo extends IRequest { - debtor: IDebtor + debtor: IDebtor; } export class DebtorInfo extends ServiceParameter { protected getGroups() { return super.getGroups({ - Debtor: 'Debtor' - }) + Debtor: 'Debtor', + }); } set debtor(debtor: IDebtor) { - this.set('debtor', new Debtor(debtor)) + this.set('debtor', new Debtor(debtor)); } } class Debtor extends DebtorClass { set code(value: string) { - this.set('DebtorCode', value) + this.set('DebtorCode', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/Invoice.ts b/src/PaymentMethods/CreditManagement/Models/Invoice.ts index 99483890..21df35a4 100644 --- a/src/PaymentMethods/CreditManagement/Models/Invoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/Invoice.ts @@ -1,31 +1,31 @@ -import IPhone from '../../../Models/Interfaces/IPhone' -import IAddress from '../../../Models/Interfaces/IAddress' -import { CreditArticle, ICreditArticle } from './Article' -import IRequest from '../../../Models/IRequest' -import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient' -import IDebtor from '../../../Models/Interfaces/IDebtor' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { Address } from './Address' +import IPhone from '../../../Models/Interfaces/IPhone'; +import IAddress from '../../../Models/Interfaces/IAddress'; +import { CreditArticle, ICreditArticle } from './Article'; +import IRequest from '../../../Models/IRequest'; +import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient'; +import IDebtor from '../../../Models/Interfaces/IDebtor'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Address } from './Address'; export interface IInvoice extends IRequest { - invoiceAmount: number - invoiceAmountVAT?: number - invoiceDate: string - dueDate: string - schemeKey?: string - maxStepIndex?: number - allowedServices?: string - allowedServicesAfterDueDate?: string - code?: string - person: Partial - company: Partial - address: Partial - debtor: IDebtor - email?: string - phone: IPhone - articles?: ICreditArticle[] - invoiceNumber?: string - applyStartRecurrent?: boolean + invoiceAmount: number; + invoiceAmountVAT?: number; + invoiceDate: string; + dueDate: string; + schemeKey?: string; + maxStepIndex?: number; + allowedServices?: string; + allowedServicesAfterDueDate?: string; + code?: string; + person: Partial; + company: Partial; + address: Partial; + debtor: IDebtor; + email?: string; + phone: IPhone; + articles?: ICreditArticle[]; + invoiceNumber?: string; + applyStartRecurrent?: boolean; } export class Invoice extends ServiceParameter implements IInvoice { protected getGroups() { @@ -36,68 +36,68 @@ export class Invoice extends ServiceParameter implements IInvoice { Person: 'Person', Debtor: 'Debtor', Email: 'Email', - Phone: 'Phone' - }) + Phone: 'Phone', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set invoiceAmount(value: number) { - this.set('invoiceAmount', value) + this.set('invoiceAmount', value); } set invoiceAmountVAT(value: number) { - this.set('invoiceAmountVAT', value) + this.set('invoiceAmountVAT', value); } set invoiceDate(value: string) { - this.set('invoiceDate', value) + this.set('invoiceDate', value); } set dueDate(value: string) { - this.set('dueDate', value) + this.set('dueDate', value); } set schemeKey(value: string) { - this.set('schemeKey', value) + this.set('schemeKey', value); } set maxStepIndex(value: number) { - this.set('maxStepIndex', value) + this.set('maxStepIndex', value); } set allowedServices(value: string) { - this.set('allowedServices', value) + this.set('allowedServices', value); } set allowedServicesAfterDueDate(value: string) { - this.set('allowedServicesAfterDueDate', value) + this.set('allowedServicesAfterDueDate', value); } set code(value: string) { - this.set('code', value) + this.set('code', value); } set person(value: Partial) { - this.set('person', value) + this.set('person', value); } set company(value: Partial) { - this.set('company', value) + this.set('company', value); } set address(value: Partial) { - this.set('address', new Address(value)) + this.set('address', new Address(value)); } set debtor(value: IDebtor) { - this.set('debtor', value) + this.set('debtor', value); } set email(value: string) { - this.set('email', value) + this.set('email', value); } set phone(value: IPhone) { - this.set('phone', value) + this.set('phone', value); } set articles(value: ICreditArticle[]) { this.set( 'articles', value.map((article) => new CreditArticle(article)) - ) + ); } set invoiceNumber(value: string) { - this.set('invoiceNumber', value) + this.set('invoiceNumber', value); } set applyStartRecurrent(value: boolean) { - this.set('applyStartRecurrent', value) + this.set('applyStartRecurrent', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts index 19565eaa..19eb8a44 100644 --- a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts +++ b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts @@ -1,48 +1,48 @@ -import IRequest from '../../../Models/IRequest' -import CreditManagementInstallmentInterval from '../../../Constants/CreditManagementInstallmentInterval' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest'; +import CreditManagementInstallmentInterval from '../../../Constants/CreditManagementInstallmentInterval'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPaymentPlan extends IRequest { - includedInvoiceKey?: string - dossierNumber?: string - installmentCount?: number - installmentAmount?: number - initialAmount?: number - startDate?: string - interval?: CreditManagementInstallmentInterval - paymentPlanCostAmount?: number - paymentPlanCostAmountVat?: number - recipientEmail?: string + includedInvoiceKey?: string; + dossierNumber?: string; + installmentCount?: number; + installmentAmount?: number; + initialAmount?: number; + startDate?: string; + interval?: CreditManagementInstallmentInterval; + paymentPlanCostAmount?: number; + paymentPlanCostAmountVat?: number; + recipientEmail?: string; } export class PaymentPlan extends ServiceParameter implements IPaymentPlan { set includedInvoiceKey(value: string) { - this.set('includedInvoiceKey', value) + this.set('includedInvoiceKey', value); } set dossierNumber(value: string) { - this.set('dossierNumber', value) + this.set('dossierNumber', value); } set installmentCount(value: number) { - this.set('installmentCount', value) + this.set('installmentCount', value); } set installmentAmount(value: number) { - this.set('installmentAmount', value) + this.set('installmentAmount', value); } set initialAmount(value: number) { - this.set('initialAmount', value) + this.set('initialAmount', value); } set startDate(value: string) { - this.set('startDate', value) + this.set('startDate', value); } set interval(value: CreditManagementInstallmentInterval) { - this.set('interval', value) + this.set('interval', value); } set paymentPlanCostAmount(value: number) { - this.set('paymentPlanCostAmount', value) + this.set('paymentPlanCostAmount', value); } set paymentPlanCostAmountVat(value: number) { - this.set('paymentPlanCostAmountVat', value) + this.set('paymentPlanCostAmountVat', value); } set recipientEmail(value: string) { - this.set('recipientEmail', value) + this.set('recipientEmail', value); } } diff --git a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts index f57e9402..17a1c17f 100644 --- a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts @@ -1,15 +1,15 @@ -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IMultiInfoInvoice extends IRequest { - invoice: string - invoices?: { invoiceNumber: string }[] + invoice: string; + invoices?: { invoiceNumber: string }[]; } export class MultiInfoInvoice extends ServiceParameter { protected getCountable() { - return super.getCountable(['Invoices']) + return super.getCountable(['Invoices']); } set invoices(value: { invoiceNumber: string }[]) { - this.set('invoices', value) + this.set('invoices', value); } } diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 8371d6db..65fc0f9d 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -1,72 +1,72 @@ -import PaymentMethod from '../PaymentMethod' -import { IInvoice, Invoice } from './Models/Invoice' -import { CreditNote, ICreditNote } from './Models/CreditNote' -import { Debtor, IDebtor } from './Models/Debtor' -import { IPaymentPlan, PaymentPlan } from './Models/PaymentPlan' -import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice' -import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines' -import IRequest from '../../Models/IRequest' -import { IDebtorInfo, DebtorInfo } from './Models/DebtorInfo' -import { ServiceParameter } from '../../Models/ServiceParameters' +import PaymentMethod from '../PaymentMethod'; +import { IInvoice, Invoice } from './Models/Invoice'; +import { CreditNote, ICreditNote } from './Models/CreditNote'; +import { Debtor, IDebtor } from './Models/Debtor'; +import { IPaymentPlan, PaymentPlan } from './Models/PaymentPlan'; +import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice'; +import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines'; +import IRequest from '../../Models/IRequest'; +import { IDebtorInfo, DebtorInfo } from './Models/DebtorInfo'; +import { ServiceParameter } from '../../Models/ServiceParameters'; export default class CreditManagement extends PaymentMethod { - protected _paymentName = 'CreditManagement' - protected _serviceVersion = 1 - protected _requiredFields = ['currency'] + protected _paymentName = 'CreditManagement'; + protected _serviceVersion = 1; + protected _requiredFields = ['currency']; createInvoice(payload: IInvoice) { - this.setServiceList('CreateInvoice', new Invoice(payload)) - return this.dataRequest(payload) + this.setServiceList('CreateInvoice', new Invoice(payload)); + return this.dataRequest(payload); } createCombinedInvoice(payload: IInvoice) { - this.setServiceList('CreateCombinedInvoice', new Invoice(payload)) - return this.transactionRequest(payload) + this.setServiceList('CreateCombinedInvoice', new Invoice(payload)); + return this.transactionRequest(payload); } createCreditNote(payload: ICreditNote) { - this.setServiceList('CreateCreditNote', new CreditNote(payload)) - return this.dataRequest(payload) + this.setServiceList('CreateCreditNote', new CreditNote(payload)); + return this.dataRequest(payload); } addOrUpdateDebtor(payload: IDebtor) { - this.setServiceList('AddOrUpdateDebtor', new Debtor(payload)) - return this.dataRequest(payload) + this.setServiceList('AddOrUpdateDebtor', new Debtor(payload)); + return this.dataRequest(payload); } createPaymentPlan(payload: IPaymentPlan) { - this.setServiceList('CreatePaymentPlan', new PaymentPlan(payload)) - return this.dataRequest(payload) + this.setServiceList('CreatePaymentPlan', new PaymentPlan(payload)); + return this.dataRequest(payload); } terminatePaymentPlan(payload: Required>) { - this.setServiceList('TerminatePaymentPlan', new PaymentPlan(payload)) - return this.dataRequest(payload) + this.setServiceList('TerminatePaymentPlan', new PaymentPlan(payload)); + return this.dataRequest(payload); } pauseInvoice(payload: Required>) { - this.setServiceList('PauseInvoice') - return this.dataRequest(payload) + this.setServiceList('PauseInvoice'); + return this.dataRequest(payload); } unpauseInvoice(payload: Required>) { - this.setServiceList('UnpauseInvoice') - return this.dataRequest(payload) + this.setServiceList('UnpauseInvoice'); + return this.dataRequest(payload); } invoiceInfo(payload: IMultiInfoInvoice) { - this.setServiceList('InvoiceInfo', new MultiInfoInvoice(payload)) - return this.dataRequest(payload) + this.setServiceList('InvoiceInfo', new MultiInfoInvoice(payload)); + return this.dataRequest(payload); } debtorInfo(payload: IDebtorInfo) { - this.setServiceList('DebtorInfo', new DebtorInfo(payload)) - return this.dataRequest(payload) + this.setServiceList('DebtorInfo', new DebtorInfo(payload)); + return this.dataRequest(payload); } addOrUpdateProductLines(payload: IAddOrUpdateProductLines) { - this.setServiceList('AddOrUpdateProductLines', new AddOrUpdateProductLines(payload)) - return this.dataRequest(payload) + this.setServiceList('AddOrUpdateProductLines', new AddOrUpdateProductLines(payload)); + return this.dataRequest(payload); } resumeDebtorFile(payload: { debtorFileGuid: string }) { - let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid) - this.setServiceList('ResumeDebtorFile', debtorFile) - return this.dataRequest(payload) + let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid); + this.setServiceList('ResumeDebtorFile', debtorFile); + return this.dataRequest(payload); } pauseDebtorFile(payload: { debtorFileGuid: string }) { - let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid) - this.setServiceList('PauseDebtorFile', debtorFile) - return this.dataRequest(payload) + let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid); + this.setServiceList('PauseDebtorFile', debtorFile); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index c0952ed6..1b87f1bb 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' +import PayablePaymentMethod from '../PayablePaymentMethod'; export default class EPS extends PayablePaymentMethod { - protected _paymentName = 'EPS' + protected _paymentName = 'EPS'; } diff --git a/src/PaymentMethods/Emandates/Models/Mandate.ts b/src/PaymentMethods/Emandates/Models/Mandate.ts index a4cfffb1..e9bfe23d 100644 --- a/src/PaymentMethods/Emandates/Models/Mandate.ts +++ b/src/PaymentMethods/Emandates/Models/Mandate.ts @@ -1,44 +1,44 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import IRequest from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import IRequest from '../../../Models/IRequest'; export interface IMandate extends IRequest { - mandateId?: string - debtorBankId?: string - debtorReference?: string - sequenceType?: 0 | 1 - purchaseId?: string - language?: string - emandateReason?: string - maxAmount?: number - originalMandateId?: string + mandateId?: string; + debtorBankId?: string; + debtorReference?: string; + sequenceType?: 0 | 1; + purchaseId?: string; + language?: string; + emandateReason?: string; + maxAmount?: number; + originalMandateId?: string; } export class Mandate extends ServiceParameter { set debtorBankId(value: string) { - this.set('debtorBankId', value) + this.set('debtorBankId', value); } set debtorReference(value: string) { - this.set('debtorReference', value) + this.set('debtorReference', value); } set sequenceType(value: number) { - this.set('sequenceType', value) + this.set('sequenceType', value); } set purchaseId(value: string) { - this.set('purchaseId', value) + this.set('purchaseId', value); } set mandateId(value: string) { - this.set('mandateId', value) + this.set('mandateId', value); } set language(value: string) { - this.set('language', value) + this.set('language', value); } set emandateReason(value: string) { - this.set('emandateReason', value) + this.set('emandateReason', value); } set maxAmount(value: number) { - this.set('maxAmount', value) + this.set('maxAmount', value); } set originalMandateId(value: string) { - this.set('originalMandateId', value) + this.set('originalMandateId', value); } } diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 7e902a39..9a589058 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -1,28 +1,28 @@ -import PaymentMethod from '../PaymentMethod' -import { IConfig } from '../../Utils/Types' -import { IMandate, Mandate } from './Models/Mandate' +import PaymentMethod from '../PaymentMethod'; +import { IConfig } from '../../Utils/Types'; +import { IMandate, Mandate } from './Models/Mandate'; export default class Emandates extends PaymentMethod { - protected _paymentName = 'Emandates' - _requiredFields: Array = ['currency'] + protected _paymentName = 'Emandates'; + _requiredFields: Array = ['currency']; issuerList() { - this.setServiceList('GetIssuerList') - return this.dataRequest() + this.setServiceList('GetIssuerList'); + return this.dataRequest(); } createMandate(payload: IMandate) { - this.setServiceList('CreateMandate', new Mandate(payload)) - return this.dataRequest(payload) + this.setServiceList('CreateMandate', new Mandate(payload)); + return this.dataRequest(payload); } status(payload: IMandate) { - this.setServiceList('GetStatus', new Mandate(payload)) - return this.dataRequest(payload) + this.setServiceList('GetStatus', new Mandate(payload)); + return this.dataRequest(payload); } modifyMandate(payload: IMandate) { - this.setServiceList('ModifyMandate', new Mandate(payload)) - return this.dataRequest(payload) + this.setServiceList('ModifyMandate', new Mandate(payload)); + return this.dataRequest(payload); } cancelMandate(payload: IMandate) { - this.setServiceList('CancelMandate', new Mandate(payload)) - return this.dataRequest(payload) + this.setServiceList('CancelMandate', new Mandate(payload)); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/GiftCard/Models/Pay.ts b/src/PaymentMethods/GiftCard/Models/Pay.ts index f14f5a9e..6f1942c0 100644 --- a/src/PaymentMethods/GiftCard/Models/Pay.ts +++ b/src/PaymentMethods/GiftCard/Models/Pay.ts @@ -1,50 +1,50 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export default interface IPay extends IPaymentRequest { - fashionChequeCardNumber?: string - fashionChequePin?: string - intersolveCardnumber?: string - intersolvePIN?: string - tcsCardnumber?: string - tcsValidationCode?: string - lastName?: string - email?: string - cardNumber?: string - pin?: string + fashionChequeCardNumber?: string; + fashionChequePin?: string; + intersolveCardnumber?: string; + intersolvePIN?: string; + tcsCardnumber?: string; + tcsValidationCode?: string; + lastName?: string; + email?: string; + cardNumber?: string; + pin?: string; } export class Pay extends ServiceParameter { set fashionChequeCardNumber(value: string) { - this.set('fashionChequeCardNumber', value) + this.set('fashionChequeCardNumber', value); } set fashionChequePin(value: string) { - this.set('fashionChequePin', value) + this.set('fashionChequePin', value); } set intersolveCardnumber(value: string) { - this.set('intersolveCardnumber', value) + this.set('intersolveCardnumber', value); } set intersolvePIN(value: string) { - this.set('intersolvePIN', value) + this.set('intersolvePIN', value); } set tcsCardnumber(value: string) { - this.set('tcsCardnumber', value) + this.set('tcsCardnumber', value); } set tcsValidationCode(value: string) { - this.set('tcsValidationCode', value) + this.set('tcsValidationCode', value); } set lastName(value: string) { - this.set('lastName', value) + this.set('lastName', value); } set email(value: string) { - this.set('email', value) + this.set('email', value); } set cardNumber(value: string) { - this.set('cardNumber', value) + this.set('cardNumber', value); } set pin(value: string) { - this.set('pin', value) + this.set('pin', value); } set issuer(value: string) { - this.set('issuer', value) + this.set('issuer', value); } } diff --git a/src/PaymentMethods/GiftCard/Models/Refund.ts b/src/PaymentMethods/GiftCard/Models/Refund.ts index d2b1c8c6..96803981 100644 --- a/src/PaymentMethods/GiftCard/Models/Refund.ts +++ b/src/PaymentMethods/GiftCard/Models/Refund.ts @@ -1,16 +1,16 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { IRefundRequest } from '../../../Models/IRequest' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRefundRequest } from '../../../Models/IRequest'; export interface IRefund extends IRefundRequest { - email?: string - lastName?: string + email?: string; + lastName?: string; } export class Refund extends ServiceParameter { set email(value: string) { - this.set('amount', value) + this.set('amount', value); } set lastName(value: string) { - this.set('lastName', value) + this.set('lastName', value); } } diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 247b897c..3cda781c 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -1,14 +1,14 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import IPay, { Pay } from './Models/Pay' -import { IRefund, Refund } from './Models/Refund' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import IPay, { Pay } from './Models/Pay'; +import { IRefund, Refund } from './Models/Refund'; export default class GiftCard extends PayablePaymentMethod { - protected _paymentName = 'GiftCard' + protected _paymentName = 'GiftCard'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefund) { - return super.refund(payload, new Refund(payload)) + return super.refund(payload, new Refund(payload)); } } diff --git a/src/PaymentMethods/Giropay/Models/Pay.ts b/src/PaymentMethods/Giropay/Models/Pay.ts index 483bb6f7..66a0fe43 100644 --- a/src/PaymentMethods/Giropay/Models/Pay.ts +++ b/src/PaymentMethods/Giropay/Models/Pay.ts @@ -1,15 +1,15 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - bic?: string - costumerIBAN?: string + bic?: string; + costumerIBAN?: string; } export class Pay extends ServiceParameter { set bic(value: string) { - this.set('bic', value) + this.set('bic', value); } set costumerIBAN(value: string) { - this.set('costumerIBAN', value) + this.set('costumerIBAN', value); } } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 3698ca28..6f5d3131 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,9 +1,9 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; export default class Giropay extends PayablePaymentMethod { - protected _paymentName = 'Giropay' + protected _paymentName = 'Giropay'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } } diff --git a/src/PaymentMethods/Ideal/Models/Pay.ts b/src/PaymentMethods/Ideal/Models/Pay.ts index dcc69b00..17555ec6 100644 --- a/src/PaymentMethods/Ideal/Models/Pay.ts +++ b/src/PaymentMethods/Ideal/Models/Pay.ts @@ -1,10 +1,10 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - issuer?: string + issuer?: string; } export class Pay extends ServiceParameter { set issuer(value: string) { - this.set('issuer', value) + this.set('issuer', value); } } diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index 4499cb5f..a62140e1 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -1,16 +1,19 @@ -import { Pay, IPay } from './Models/Pay' -import PayablePaymentMethod from '../PayablePaymentMethod' -import { RequestTypes } from '../../Constants/Endpoints' -import { IRefundRequest } from '../../Models/IRequest' +import { Pay, IPay } from './Models/Pay'; +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { RequestTypes } from '../../Constants/Endpoints'; +import { IRefundRequest } from '../../Models/IRequest'; export default class Ideal extends PayablePaymentMethod { - protected _paymentName = 'Ideal' - protected _serviceVersion = 2 + protected _paymentName = 'Ideal'; + protected _serviceVersion = 2; + constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { + super(serviceCode); + } pay(data: IPay) { - return super.pay(data, new Pay(data)) + return super.pay(data, new Pay(data)); } payRemainder(payload: IPay) { - return super.payRemainder(payload, new Pay(payload)) + return super.payRemainder(payload, new Pay(payload)); } issuers() { return this.specification(RequestTypes.Transaction) @@ -20,11 +23,11 @@ export default class Ideal extends PayablePaymentMethod { .getActionRequestParameters('Pay') ?.find((item) => item.name === 'issuer') ?.listItemDescriptions?.map((item) => { - return { [item.value]: item.description } - }) - }) + return { [item.value]: item.description }; + }); + }); } instantRefund(data: IRefundRequest) { - return super.refund(data) + return super.refund(data); } } diff --git a/src/PaymentMethods/IdealQR/Models/IGenerate.ts b/src/PaymentMethods/IdealQR/Models/IGenerate.ts index 7819e7c2..74f99f8f 100644 --- a/src/PaymentMethods/IdealQR/Models/IGenerate.ts +++ b/src/PaymentMethods/IdealQR/Models/IGenerate.ts @@ -1,47 +1,47 @@ -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IGenerate extends IRequest { - amount: number - amountIsChangeable: boolean - purchaseId: string - description: string - isOneOff: boolean - expiration: string - isProcessing?: boolean - minAmount: number - maxAmount: number - imageSize: number + amount: number; + amountIsChangeable: boolean; + purchaseId: string; + description: string; + isOneOff: boolean; + expiration: string; + isProcessing?: boolean; + minAmount: number; + maxAmount: number; + imageSize: number; } export class Generate extends ServiceParameter implements IGenerate { set amount(value: number) { - this.set('amount', value) + this.set('amount', value); } set amountIsChangeable(value: boolean) { - this.set('amountIsChangeable', value) + this.set('amountIsChangeable', value); } set purchaseId(value: string) { - this.set('purchaseId', value) + this.set('purchaseId', value); } set description(value: string) { - this.set('description', value) + this.set('description', value); } set isOneOff(value: boolean) { - this.set('isOneOff', value) + this.set('isOneOff', value); } set expiration(value: string) { - this.set('expiration', value) + this.set('expiration', value); } set isProcessing(value: boolean) { - this.set('isProcessing', value) + this.set('isProcessing', value); } set minAmount(value: number) { - this.set('minAmount', value) + this.set('minAmount', value); } set maxAmount(value: number) { - this.set('maxAmount', value) + this.set('maxAmount', value); } set imageSize(value: number) { - this.set('imageSize', value) + this.set('imageSize', value); } } diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 02967a21..bc6831a3 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,10 +1,10 @@ -import { Generate, IGenerate } from './Models/IGenerate' -import PaymentMethod from '../PaymentMethod' +import { Generate, IGenerate } from './Models/IGenerate'; +import PaymentMethod from '../PaymentMethod'; export default class IdealQR extends PaymentMethod { - protected _paymentName = 'IdealQR' + protected _paymentName = 'IdealQR'; generate(payload: IGenerate) { - this.setServiceList('Generate', new Generate(payload)) - return this.dataRequest() + this.setServiceList('Generate', new Generate(payload)); + return this.dataRequest(); } } diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 34b3b3e7..f2cc1eeb 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,15 +1,15 @@ -import PaymentMethod from '../PaymentMethod' -import { IPay } from '../Ideal/Models/Pay' +import PaymentMethod from '../PaymentMethod'; +import { IPay } from '../Ideal/Models/Pay'; export default class Idin extends PaymentMethod { - protected _paymentName = 'Idin' + protected _paymentName = 'Idin'; identify(payload: IPay) { - return this.dataRequest(payload) + return this.dataRequest(payload); } verify(payload: IPay) { - return this.dataRequest(payload) + return this.dataRequest(payload); } login(payload: IPay) { - return this.dataRequest(payload) + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/In3/Models/Article.ts b/src/PaymentMethods/In3/Models/Article.ts index a03565e1..57815ea5 100644 --- a/src/PaymentMethods/In3/Models/Article.ts +++ b/src/PaymentMethods/In3/Models/Article.ts @@ -1,24 +1,24 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle' +import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; export interface IIn3Article extends IArticle { - category?: string - url?: string - quantityDescription?: string + category?: string; + url?: string; + quantityDescription?: string; } export class In3Article extends Article implements In3Article { set category(value: string) { - this.set('category', value) + this.set('category', value); } get price() { - return this.get('grossUnitPrice') + return this.get('grossUnitPrice'); } set price(value: number) { - this.set('grossUnitPrice', value) + this.set('grossUnitPrice', value); } set url(value: string) { - this.set('url', value) + this.set('url', value); } set quantityDescription(value: string) { - this.set('quantityDescription', value) + this.set('quantityDescription', value); } } diff --git a/src/PaymentMethods/In3/Models/Pay.ts b/src/PaymentMethods/In3/Models/Pay.ts index dae1acc5..ea3367b3 100644 --- a/src/PaymentMethods/In3/Models/Pay.ts +++ b/src/PaymentMethods/In3/Models/Pay.ts @@ -1,48 +1,48 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { IPaymentRequest } from '../../../Models/IRequest' -import { IIn3Article, In3Article } from './Article' -import { IIn3Recipient, In3Recipient } from './Recipient' +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { IIn3Article, In3Article } from './Article'; +import { IIn3Recipient, In3Recipient } from './Recipient'; export interface IPay extends IPaymentRequest { - invoiceDate?: string - invoiceUrl?: string - billing?: IIn3Recipient - shipping?: Partial - articles?: Partial[] + invoiceDate?: string; + invoiceUrl?: string; + billing?: IIn3Recipient; + shipping?: Partial; + articles?: Partial[]; } export default class Pay extends ServiceParameter { protected getGroups(): {} { return super.getGroups({ Billing: 'BillingCustomer', Shipping: 'ShippingCustomer', - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set invoiceDate(value: string) { - this.set('invoiceDate', value) + this.set('invoiceDate', value); } set invoiceUrl(value: string) { - this.set('invoiceUrl', value) + this.set('invoiceUrl', value); } get billing() { - return new In3Recipient() + return new In3Recipient(); } set billing(billing: IIn3Recipient) { - this.set('billing', new In3Recipient(billing)) + this.set('billing', new In3Recipient(billing)); if (this.get('shipping') === undefined) { - this.shipping = billing + this.shipping = billing; } } set shipping(shipping: IIn3Recipient) { - this.set('shipping', new In3Recipient(shipping)) + this.set('shipping', new In3Recipient(shipping)); } set articles(articles: In3Article[]) { this.set( 'articles', articles.map((article) => new In3Article(article)) - ) + ); } } diff --git a/src/PaymentMethods/In3/Models/Phone.ts b/src/PaymentMethods/In3/Models/Phone.ts index 7715f4b3..3c14a9e0 100644 --- a/src/PaymentMethods/In3/Models/Phone.ts +++ b/src/PaymentMethods/In3/Models/Phone.ts @@ -1,13 +1,13 @@ -import { Phone } from '../../../Models/Interfaces/IPhone' +import { Phone } from '../../../Models/Interfaces/IPhone'; export class In3Phone extends Phone { set landline(value: string) { - this.set('phone', value) + this.set('phone', value); } set mobile(value: string) { - this.set('phone', value) + this.set('phone', value); } set fax(value: string) { - this.set('phone', value) + this.set('phone', value); } } diff --git a/src/PaymentMethods/In3/Models/Recipient.ts b/src/PaymentMethods/In3/Models/Recipient.ts index 478f76be..82d88134 100644 --- a/src/PaymentMethods/In3/Models/Recipient.ts +++ b/src/PaymentMethods/In3/Models/Recipient.ts @@ -1,112 +1,112 @@ -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import IAddress, { Address } from '../../../Models/Interfaces/IAddress' -import IPhone from '../../../Models/Interfaces/IPhone' -import { In3Phone } from './Phone' -import RecipientCategory from '../../../Constants/RecipientCategory' -import { Model } from '../../../Models/Model' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; +import IPhone from '../../../Models/Interfaces/IPhone'; +import { In3Phone } from './Phone'; +import RecipientCategory from '../../../Constants/RecipientCategory'; +import { Model } from '../../../Models/Model'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IIn3Recipient extends ICustomer { - recipient: Partial - phone: IPhone + recipient: Partial; + phone: IPhone; } export class In3Recipient extends Model implements In3Recipient { get recipient(): In3Company | IIn3Person { - return new In3Person({}) + return new In3Person({}); } set recipient(value: In3Company | IIn3Person) { if (value.category === RecipientCategory.COMPANY) { - this.set('recipient', new In3Company(value)) + this.set('recipient', new In3Company(value)); } else if (value.category === RecipientCategory.PERSON) { - this.set('recipient', new In3Person(value)) - } else throw new Error('Invalid recipient category') + this.set('recipient', new In3Person(value)); + } else throw new Error('Invalid recipient category'); } get address(): IAddress { - return new In3Address() + return new In3Address(); } set address(value: IAddress) { - this.set('address', new In3Address(value)) + this.set('address', new In3Address(value)); } get email(): string { - return '' + return ''; } set email(value: string) { - this.set('email', value) + this.set('email', value); } get phone(): IPhone { - return new In3Phone() + return new In3Phone(); } set phone(value: IPhone) { - this.set('phone', new In3Phone(value)) + this.set('phone', new In3Phone(value)); } } export interface IIn3Person extends IPerson { - customerNumber: string - identificationNumber: string - conversationLanguage: string - lastName: string + customerNumber: string; + identificationNumber: string; + conversationLanguage: string; + lastName: string; } export interface IIn3Company extends ICompany { - customerNumber: string + customerNumber: string; } export class In3Person extends Person implements IIn3Person { set category(value: RecipientCategory.PERSON) { - this.set('category', 'B2C') + this.set('category', 'B2C'); } set customerNumber(value: string) { - this.set('customerNumber', value) + this.set('customerNumber', value); } set identificationNumber(value: string) { - this.set('identificationNumber', value) + this.set('identificationNumber', value); } set conversationLanguage(value: string) { - this.set('conversationLanguage', value) + this.set('conversationLanguage', value); } } export class In3Company extends Company implements IIn3Company { set category(value: RecipientCategory.COMPANY) { - this.set('category', 'B2B') + this.set('category', 'B2B'); } set customerNumber(value: string) { - this.set('customerNumber', value) + this.set('customerNumber', value); } get title() { - return this.get('salutation') + return this.get('salutation'); } set title(value: string) { - this.set('salutation', value) + this.set('salutation', value); } get chamberOfCommerce() { - return this.get('cocNumber') + return this.get('cocNumber'); } set chamberOfCommerce(value: string) { - this.set('cocNumber', value) + this.set('cocNumber', value); } } export class In3Address extends Address { get houseNumber() { - return this.get('streetNumber') + return this.get('streetNumber'); } set houseNumber(value: string) { - this.set('streetNumber', value) + this.set('streetNumber', value); } get houseNumberAdditional() { - return this.get('streetNumberSuffix') + return this.get('streetNumberSuffix'); } set houseNumberAdditional(value: string) { - this.set('streetNumberSuffix', value) + this.set('streetNumberSuffix', value); } get zipcode() { - return this.get('postalCode') + return this.get('postalCode'); } set zipcode(value: string) { - this.set('postalCode', value) + this.set('postalCode', value); } get country() { - return this.get('countryCode') + return this.get('countryCode'); } set country(value: string) { - this.set('countryCode', value) + this.set('countryCode', value); } } diff --git a/src/PaymentMethods/In3/Models/Refund.ts b/src/PaymentMethods/In3/Models/Refund.ts index 5d0d4987..62e8eb61 100644 --- a/src/PaymentMethods/In3/Models/Refund.ts +++ b/src/PaymentMethods/In3/Models/Refund.ts @@ -1,21 +1,21 @@ -import { IIn3Article } from './Article' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { IRefundRequest } from '../../../Models/IRequest' +import { IIn3Article } from './Article'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRefundRequest } from '../../../Models/IRequest'; export interface IRefund extends IRefundRequest { - merchantImageUrl: string - summaryImageUrl: string - articles: IIn3Article[] + merchantImageUrl: string; + summaryImageUrl: string; + articles: IIn3Article[]; } export class Refund extends ServiceParameter { - protected _countable: string[] = ['articles'] + protected _countable: string[] = ['articles']; set merchantImageUrl(value: string) { - this.set('merchantImageUrl', value) + this.set('merchantImageUrl', value); } set summaryImageUrl(value: string) { - this.set('summaryImageUrl', value) + this.set('summaryImageUrl', value); } set articles(value: IIn3Article[]) { - this.set('article', value) + this.set('article', value); } } diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index 6040276e..f8aa8dcf 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -1,14 +1,14 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPaymentRequest } from '../../Models/IRequest' -import Pay from './Models/Pay' -import { IRefund, Refund } from './Models/Refund' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPaymentRequest } from '../../Models/IRequest'; +import Pay from './Models/Pay'; +import { IRefund, Refund } from './Models/Refund'; export default class In3 extends PayablePaymentMethod { - protected _paymentName = 'In3' + protected _paymentName = 'In3'; pay(payload: IPaymentRequest) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefund) { - return super.refund(payload, new Refund(payload)) + return super.refund(payload, new Refund(payload)); } } diff --git a/src/PaymentMethods/In3Old/Models/Address.ts b/src/PaymentMethods/In3Old/Models/Address.ts index acae33e5..3b2a0618 100644 --- a/src/PaymentMethods/In3Old/Models/Address.ts +++ b/src/PaymentMethods/In3Old/Models/Address.ts @@ -1,7 +1,7 @@ -import { Address } from '../../../Models/Interfaces/IAddress' +import { Address } from '../../../Models/Interfaces/IAddress'; export class In3OldAddress extends Address { set houseNumberAddition(houseNumberAddition: string) { - this.set('houseNumberSuffix', houseNumberAddition) + this.set('houseNumberSuffix', houseNumberAddition); } } diff --git a/src/PaymentMethods/In3Old/Models/Article.ts b/src/PaymentMethods/In3Old/Models/Article.ts index 56c15263..9f4e408c 100644 --- a/src/PaymentMethods/In3Old/Models/Article.ts +++ b/src/PaymentMethods/In3Old/Models/Article.ts @@ -1,10 +1,10 @@ -import { Article } from '../../../Models/Interfaces/IArticle' +import { Article } from '../../../Models/Interfaces/IArticle'; export class In3OldArticle extends Article { set identifier(identifier: string) { - this.set('code', identifier) + this.set('code', identifier); } set description(description: string) { - this.set('name', description) + this.set('name', description); } } diff --git a/src/PaymentMethods/In3Old/Models/Company.ts b/src/PaymentMethods/In3Old/Models/Company.ts index 1d347318..71375ecc 100644 --- a/src/PaymentMethods/In3Old/Models/Company.ts +++ b/src/PaymentMethods/In3Old/Models/Company.ts @@ -1,7 +1,7 @@ -import { Company } from '../../../Models/Interfaces/IRecipient' +import { Company } from '../../../Models/Interfaces/IRecipient'; export class In3OldCompany extends Company { set companyName(companyName: string) { - this.set('name', companyName) + this.set('name', companyName); } } diff --git a/src/PaymentMethods/In3Old/Models/Pay.ts b/src/PaymentMethods/In3Old/Models/Pay.ts index e455d560..183a4c1b 100644 --- a/src/PaymentMethods/In3Old/Models/Pay.ts +++ b/src/PaymentMethods/In3Old/Models/Pay.ts @@ -1,28 +1,28 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import RecipientCategory from '../../../Constants/RecipientCategory' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import IArticle from '../../../Models/Interfaces/IArticle' -import { In3OldArticle } from './Article' -import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import IAddress from '../../../Models/Interfaces/IAddress' -import IPhone from '../../../Models/Interfaces/IPhone' -import { ISubtotal, Subtotal } from './Subtotal' -import { In3OldCompany } from './Company' -import { In3OldAddress } from './Address' -import { In3OldPhone } from './Phone' +import { IPaymentRequest } from '../../../Models/IRequest'; +import RecipientCategory from '../../../Constants/RecipientCategory'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import IArticle from '../../../Models/Interfaces/IArticle'; +import { In3OldArticle } from './Article'; +import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import IAddress from '../../../Models/Interfaces/IAddress'; +import IPhone from '../../../Models/Interfaces/IPhone'; +import { ISubtotal, Subtotal } from './Subtotal'; +import { In3OldCompany } from './Company'; +import { In3OldAddress } from './Address'; +import { In3OldPhone } from './Phone'; export interface IPay extends IPaymentRequest { - description: string - clientIP: string - customerType: RecipientCategory.PERSON | RecipientCategory.COMPANY - invoiceDate: string - email: string - phone: Partial - company: Partial - customer: Partial - address: Partial - articles: Partial[] - subtotals: ISubtotal[] + description: string; + clientIP: string; + customerType: RecipientCategory.PERSON | RecipientCategory.COMPANY; + invoiceDate: string; + email: string; + phone: Partial; + company: Partial; + customer: Partial; + address: Partial; + articles: Partial[]; + subtotals: ISubtotal[]; } export class Pay extends ServiceParameter { protected getGroups() { @@ -33,43 +33,43 @@ export class Pay extends ServiceParameter { Customer: 'Person', Company: 'Company', Phone: 'Phone', - Email: 'Email' - }) + Email: 'Email', + }); } protected getCountable() { - return super.getCountable(['Articles', 'Subtotals']) + return super.getCountable(['Articles', 'Subtotals']); } set customerType(value: RecipientCategory) { - this.set('customerType', value) + this.set('customerType', value); } set invoiceDate(value: string) { - this.set('invoiceDate', value) + this.set('invoiceDate', value); } set email(value: string) { - this.set('email', value) + this.set('email', value); } set phone(value: Partial) { - this.set('phone', new In3OldPhone(value)) + this.set('phone', new In3OldPhone(value)); } set company(value: Partial) { - this.set('company', new In3OldCompany(value)) + this.set('company', new In3OldCompany(value)); } set customer(value: Partial) { - this.set('customer', new Person(value)) + this.set('customer', new Person(value)); } set address(value: Partial) { - this.set('address', new In3OldAddress(value)) + this.set('address', new In3OldAddress(value)); } set articles(value: Partial[]) { this.set( 'articles', value.map((article) => new In3OldArticle(article)) - ) + ); } set subtotals(value: ISubtotal[]) { this.set( 'subtotals', value.map((subtotal) => new Subtotal(subtotal)) - ) + ); } } diff --git a/src/PaymentMethods/In3Old/Models/Phone.ts b/src/PaymentMethods/In3Old/Models/Phone.ts index e909243e..2411f1e7 100644 --- a/src/PaymentMethods/In3Old/Models/Phone.ts +++ b/src/PaymentMethods/In3Old/Models/Phone.ts @@ -1,7 +1,7 @@ -import { Phone } from '../../../Models/Interfaces/IPhone' +import { Phone } from '../../../Models/Interfaces/IPhone'; export class In3OldPhone extends Phone { set mobile(number) { - this.set('phone', number) + this.set('phone', number); } } diff --git a/src/PaymentMethods/In3Old/Models/Subtotal.ts b/src/PaymentMethods/In3Old/Models/Subtotal.ts index 99bdd531..85d70540 100644 --- a/src/PaymentMethods/In3Old/Models/Subtotal.ts +++ b/src/PaymentMethods/In3Old/Models/Subtotal.ts @@ -1,14 +1,14 @@ -import { Model } from '../../../Models/Model' +import { Model } from '../../../Models/Model'; export interface ISubtotal { - name: string - value: number + name: string; + value: number; } export class Subtotal extends Model implements ISubtotal { set name(name: string) { - this.set('name', name) + this.set('name', name); } set value(value: number) { - this.set('value', value) + this.set('value', value); } } diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 5ec61b94..8c2ec8f3 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; export default class In3Old extends PayablePaymentMethod { - protected _paymentName = 'In3Old' + protected _paymentName = 'In3Old'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } payInInstallments(payload: IPay) { - this.setPayPayload(payload) - this.setServiceList('PayInInstallments', new Pay(payload)) - return super.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayInInstallments', new Pay(payload)); + return super.transactionRequest(); } } diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 538f952e..ec1943b8 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,10 +1,10 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; export default class KBC extends PayablePaymentMethod { - protected _paymentName = 'KBC' + protected _paymentName = 'KBC'; refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/Klarna/Models/Article.ts b/src/PaymentMethods/Klarna/Models/Article.ts index 4a0da68f..f09cbd84 100644 --- a/src/PaymentMethods/Klarna/Models/Article.ts +++ b/src/PaymentMethods/Klarna/Models/Article.ts @@ -1,9 +1,9 @@ -import { Article } from '../../../Models/Interfaces/IArticle' +import { Article } from '../../../Models/Interfaces/IArticle'; export class KlarnaArticle extends Article { get price() { - return this.get('grossUnitPrice') + return this.get('grossUnitPrice'); } set price(price: number) { - this.set('grossUnitPrice', price) + this.set('grossUnitPrice', price); } } diff --git a/src/PaymentMethods/Klarna/Models/Pay.ts b/src/PaymentMethods/Klarna/Models/Pay.ts index 187de119..2426c893 100644 --- a/src/PaymentMethods/Klarna/Models/Pay.ts +++ b/src/PaymentMethods/Klarna/Models/Pay.ts @@ -1,39 +1,39 @@ -import { KlarnaRecipient } from './Recipient' -import IArticle, { Article } from '../../../Models/Interfaces/IArticle' -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { KlarnaArticle } from './Article' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import { KlarnaRecipient } from './Recipient'; +import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { KlarnaArticle } from './Article'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IPay extends IPaymentRequest { - billing: ICustomer - shipping?: ICustomer - articles: Partial[] + billing: ICustomer; + shipping?: ICustomer; + articles: Partial[]; } export class Pay extends ServiceParameter { protected getGroups() { return super.getGroups({ Billing: 'BillingCustomer', Shipping: 'ShippingCustomer', - Articles: 'Article' - }) + Articles: 'Article', + }); } protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set billing(billing: ICustomer) { - this.set('billing', new KlarnaRecipient(billing)) + this.set('billing', new KlarnaRecipient(billing)); if (this.get('shipping') === undefined) { - this.shipping = billing + this.shipping = billing; } } set shipping(shipping: ICustomer) { - this.set('shipping', new KlarnaRecipient(shipping)) + this.set('shipping', new KlarnaRecipient(shipping)); } set articles(articles: IArticle[]) { this.set( 'articles', articles.map((article) => new KlarnaArticle(article)) - ) + ); } } diff --git a/src/PaymentMethods/Klarna/Models/Recipient.ts b/src/PaymentMethods/Klarna/Models/Recipient.ts index 5a4296f8..d35fbd92 100644 --- a/src/PaymentMethods/Klarna/Models/Recipient.ts +++ b/src/PaymentMethods/Klarna/Models/Recipient.ts @@ -1,29 +1,29 @@ -import IAddress from '../../../Models/Interfaces/IAddress' -import IPhone from '../../../Models/Interfaces/IPhone' -import { Model } from '../../../Models/Model' -import { KlarnaAddress } from '../Services/KlarnaAddress' -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import { KlarnaPhone } from '../Services/KlarnaPhone' -import RecipientCategory from '../../../Constants/RecipientCategory' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' +import IAddress from '../../../Models/Interfaces/IAddress'; +import IPhone from '../../../Models/Interfaces/IPhone'; +import { Model } from '../../../Models/Model'; +import { KlarnaAddress } from '../Services/KlarnaAddress'; +import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { KlarnaPhone } from '../Services/KlarnaPhone'; +import RecipientCategory from '../../../Constants/RecipientCategory'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export class KlarnaRecipient extends Model implements ICustomer { set email(email: string) { - this.set('email', email) + this.set('email', email); } set address(address: IAddress) { - this.set('address', new KlarnaAddress(address)) + this.set('address', new KlarnaAddress(address)); } set recipient(recipient: Partial) { if (recipient.category === RecipientCategory.PERSON) { // @ts-ignore - this.set('recipient', new Person({ ...recipient, category: 'B2C' })) + this.set('recipient', new Person({ ...recipient, category: 'B2C' })); } else if (recipient.category === RecipientCategory.COMPANY) { // @ts-ignore - this.set('recipient', new Company({ ...recipient, category: 'B2B' })) + this.set('recipient', new Company({ ...recipient, category: 'B2B' })); } } set phone(phone: IPhone) { - this.set('phone', new KlarnaPhone(phone)) + this.set('phone', new KlarnaPhone(phone)); } } diff --git a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts index 58c41cb4..a1c94c57 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts @@ -1,21 +1,21 @@ -import IAddress, { Address } from '../../../Models/Interfaces/IAddress' +import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; export class KlarnaAddress extends Address implements IAddress { get houseNumber(): string { - return this.get('streetNumber') + return this.get('streetNumber'); } set houseNumber(houseNumber: string) { - this.set('streetNumber', houseNumber) + this.set('streetNumber', houseNumber); } get houseNumberAdditional(): string { - return this.get('streetNumberAdditional') + return this.get('streetNumberAdditional'); } set houseNumberAdditional(houseNumberAdditional: string) { - this.set('streetNumberAdditional', houseNumberAdditional) + this.set('streetNumberAdditional', houseNumberAdditional); } get zipcode(): string { - return this.get('postalCode') + return this.get('postalCode'); } set zipcode(zipcode: string) { - this.set('postalCode', zipcode) + this.set('postalCode', zipcode); } } diff --git a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts index 87d2368c..ae578493 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts @@ -1,10 +1,10 @@ -import { Phone } from '../../../Models/Interfaces/IPhone' +import { Phone } from '../../../Models/Interfaces/IPhone'; export class KlarnaPhone extends Phone { get mobile(): string { - return this.get('phone') + return this.get('phone'); } set mobile(mobile: string) { - this.set('phone', mobile) + this.set('phone', mobile); } } diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index e25ee5e3..57c384cf 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,16 +1,16 @@ -import { IPay, Pay } from './Models/Pay' -import PayablePaymentMethod from '../PayablePaymentMethod' +import { IPay, Pay } from './Models/Pay'; +import PayablePaymentMethod from '../PayablePaymentMethod'; export default class Klarna extends PayablePaymentMethod { - protected _paymentName = 'Klarna' + protected _paymentName = 'Klarna'; pay(data: IPay) { - return super.pay(data, new Pay(data)) + return super.pay(data, new Pay(data)); } payInInstallments(data: IPay) { - this.setServiceList('PayInInstallments', new Pay(data)) - return super.pay(data) + this.setServiceList('PayInInstallments', new Pay(data)); + return super.pay(data); } payRemainder(payload: IPay) { - return super.payRemainder(payload, new Pay(payload)) + return super.payRemainder(payload, new Pay(payload)); } } diff --git a/src/PaymentMethods/KlarnaKP/Models/IPay.ts b/src/PaymentMethods/KlarnaKP/Models/IPay.ts index cb5431b8..0b520759 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IPay.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IPay.ts @@ -1,11 +1,11 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - reservationNumber?: string + reservationNumber?: string; } export class Pay extends ServiceParameter { set reservationNumber(value: string) { - this.set('reservationNumber', value) + this.set('reservationNumber', value); } } diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts index 0dca1eac..4a04df3f 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -1,42 +1,42 @@ -import Gender from '../../../Constants/Gender' -import IRequest from '../../../Models/IRequest' -import { ICustomer } from '../../../Models/Interfaces/ICustomer' -import IArticle from '../../../Models/Interfaces/IArticle' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import Gender from '../../../Constants/Gender'; +import IRequest from '../../../Models/IRequest'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import IArticle from '../../../Models/Interfaces/IArticle'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IReserve extends IRequest { - gender?: Gender.MALE | Gender.FEMALE - billing?: ICustomer - shipping?: ICustomer - articles?: Partial[] - operatingCountry?: string - reservationNumber?: string - shippingSameAsBilling?: boolean - pno?: string + gender?: Gender.MALE | Gender.FEMALE; + billing?: ICustomer; + shipping?: ICustomer; + articles?: Partial[]; + operatingCountry?: string; + reservationNumber?: string; + shippingSameAsBilling?: boolean; + pno?: string; } export class Reserve extends ServiceParameter implements IReserve { protected getCountable() { - return super.getCountable(['Articles']) + return super.getCountable(['Articles']); } set reservationNumber(value: string) { - this.set('reservationNumber', value) + this.set('reservationNumber', value); } set gender(value: Gender.MALE | Gender.FEMALE) { - this.set('gender', value) + this.set('gender', value); } set operatingCountry(value: string) { - this.set('operatingCountry', value) + this.set('operatingCountry', value); } set pno(value: string) { - this.set('pno', value) + this.set('pno', value); } set billing(value: ICustomer) { - this.set('billing', value) + this.set('billing', value); } set shipping(value: ICustomer) { - this.set('shipping', value) + this.set('shipping', value); } set articles(value: IArticle[]) { - this.set('articles', value) + this.set('articles', value); } } diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 9c8a07a5..54e6c84d 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -1,32 +1,32 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/IPay' -import IRequest from '../../Models/IRequest' -import { IReserve, Reserve } from './Models/IReserve' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/IPay'; +import IRequest from '../../Models/IRequest'; +import { IReserve, Reserve } from './Models/IReserve'; export default class KlarnaKP extends PayablePaymentMethod { - protected _paymentName = 'KlarnaKP' - protected _serviceVersion = 1 + protected _paymentName = 'KlarnaKP'; + protected _serviceVersion = 1; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } reserve(payload: IReserve) { - this.setServiceList('Reserve', new Reserve(payload)) - return this.dataRequest(payload) + this.setServiceList('Reserve', new Reserve(payload)); + return this.dataRequest(payload); } cancel(payload: IRequest) { - this.setServiceList('CancelReservation') - return this.dataRequest(payload) + this.setServiceList('CancelReservation'); + return this.dataRequest(payload); } update(payload: IRequest) { - this.setServiceList('UpdateReservation') - return this.dataRequest(payload) + this.setServiceList('UpdateReservation'); + return this.dataRequest(payload); } extend(payload: IRequest) { - this.setServiceList('ExtendReservation') - return this.dataRequest(payload) + this.setServiceList('ExtendReservation'); + return this.dataRequest(payload); } addShippingInfo(payload: IRequest) { - this.setServiceList('AddShippingInfo') - return this.dataRequest(payload) + this.setServiceList('AddShippingInfo'); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/Marketplaces/Models/ISplit.ts b/src/PaymentMethods/Marketplaces/Models/ISplit.ts deleted file mode 100644 index 416d65c5..00000000 --- a/src/PaymentMethods/Marketplaces/Models/ISplit.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IPaymentRequest } from '../../../Models/IRequest' - -type Seller = { - accountId?: string - amount?: number - description?: string -} -type Marketplace = { - amount?: number - description?: string -} -export interface ISplit extends IPaymentRequest { - seller?: Seller[] - marketplace?: Marketplace - daysUntilTransfer?: number -} -export interface ITransfer extends IPaymentRequest { - seller?: Seller[] - marketplace?: Marketplace - daysUntilTransfer?: number - originalTransactionKey: string -} diff --git a/src/PaymentMethods/Marketplaces/Models/Marketplace.ts b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts new file mode 100644 index 00000000..6018c57b --- /dev/null +++ b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts @@ -0,0 +1,14 @@ +import { Model } from '../../../Models/Model'; + +export interface IMarketplace { + amount: number; + description: string; +} +export class Marketplace extends Model implements IMarketplace { + set amount(value: number) { + this.set('amount', value); + } + set description(value: string) { + this.set('description', value); + } +} diff --git a/src/PaymentMethods/Marketplaces/Models/Seller.ts b/src/PaymentMethods/Marketplaces/Models/Seller.ts new file mode 100644 index 00000000..4a329ebc --- /dev/null +++ b/src/PaymentMethods/Marketplaces/Models/Seller.ts @@ -0,0 +1,18 @@ +import { Model } from '../../../Models/Model'; + +export interface ISeller { + accountId?: string; + amount?: number; + description?: string; +} +export class Seller extends Model implements ISeller { + set accountId(value: string) { + this.set('accountId', value); + } + set amount(value: number) { + this.set('amount', value); + } + set description(value: string) { + this.set('description', value); + } +} diff --git a/src/PaymentMethods/Marketplaces/Models/Split.ts b/src/PaymentMethods/Marketplaces/Models/Split.ts new file mode 100644 index 00000000..ea803db3 --- /dev/null +++ b/src/PaymentMethods/Marketplaces/Models/Split.ts @@ -0,0 +1,33 @@ +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IMarketplace, Marketplace } from './Marketplace'; +import { ISeller, Seller } from './Seller'; + +export interface ISplit extends IRequest { + sellers?: ISeller[]; + marketplace?: IMarketplace; + daysUntilTransfer?: number; +} +export class Split extends ServiceParameter { + protected getCountable() { + return super.getCountable(['Sellers']); + } + protected getGroups() { + return super.getGroups({ + Sellers: 'Seller', + Marketplace: 'Marketplace', + }); + } + set seller(value: ISeller[]) { + this.set( + 'sellers', + value.map((seller: ISeller) => new Seller(seller)) + ); + } + set marketplace(value: IMarketplace) { + this.set('marketplace', new Marketplace(value)); + } + set daysUntilTransfer(value: number) { + this.set('daysUntilTransfer', value); + } +} diff --git a/src/PaymentMethods/Marketplaces/Models/Transfer.ts b/src/PaymentMethods/Marketplaces/Models/Transfer.ts new file mode 100644 index 00000000..83a82890 --- /dev/null +++ b/src/PaymentMethods/Marketplaces/Models/Transfer.ts @@ -0,0 +1,9 @@ +import IRequest from '../../../Models/IRequest'; +import { ISeller } from './Seller'; +import { IMarketplace } from './Marketplace'; + +export interface ITransfer extends IRequest { + seller?: ISeller[]; + marketplace?: IMarketplace; + originalTransactionKey: string; +} diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 1c50f2f2..5b795c93 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,18 +1,20 @@ -import PaymentMethod from '../PaymentMethod' -import { ISplit, ITransfer } from './Models/ISplit' -//ToDO Add the service parameter models +import PaymentMethod from '../PaymentMethod'; +import { ISplit, Split } from './Models/Split'; +import { ITransfer } from './Models/Transfer'; export default class Marketplaces extends PaymentMethod { - protected _paymentName = 'Marketplaces' + get paymentName() { + return 'Marketplaces'; + } split(payload: ISplit) { - this.setServiceList('Split') - return this.dataRequest(payload) + this.setServiceList('Split', new Split(payload)); + return this.dataRequest(payload); } transfer(payload: ITransfer) { - this.setServiceList('Transfer') - return this.dataRequest(payload) + this.setServiceList('Transfer', new Split(payload)); + return this.dataRequest(payload); } refundSupplementary(payload: ISplit) { - this.setServiceList('RefundSupplementary') - return this.dataRequest(payload) + this.setServiceList('RefundSupplementary', new Split(payload)); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts new file mode 100644 index 00000000..4f661d23 --- /dev/null +++ b/src/PaymentMethods/Multibanco/index.ts @@ -0,0 +1,5 @@ +import PayablePaymentMethod from '../PayablePaymentMethod'; + +export default class MultiBanco extends PayablePaymentMethod { + protected _paymentName = 'MultiBanco'; +} diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index 3d8b4e55..fd9d4ab2 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,5 +1,11 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' +import PayablePaymentMethod from '../PayablePaymentMethod'; export default class NoService extends PayablePaymentMethod { - protected _paymentName = 'noserivce' + get paymentName() { + return 'NoService'; + } + protected _paymentName = 'noserivce'; + protected setServiceList(): this { + return this; + } } diff --git a/src/PaymentMethods/PayByBank/Models/IPay.ts b/src/PaymentMethods/PayByBank/Models/IPay.ts index 70eae191..e29e8c50 100644 --- a/src/PaymentMethods/PayByBank/Models/IPay.ts +++ b/src/PaymentMethods/PayByBank/Models/IPay.ts @@ -1,15 +1,15 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export default interface IPay extends IPaymentRequest { - issuer: string - countryCode: string + issuer: string; + countryCode: string; } export class Pay extends ServiceParameter { set issuer(value: string) { - this.set('issuer', value) + this.set('issuer', value); } set countryCode(value: string) { - this.set('countryCode', value) + this.set('countryCode', value); } } diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 390eec29..5ecb0f64 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -1,14 +1,14 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' -import IPay, { Pay } from './Models/IPay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; +import IPay, { Pay } from './Models/IPay'; export default class PayByBank extends PayablePaymentMethod { - protected _paymentName = 'PayByBank' + protected _paymentName = 'PayByBank'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } issuers() { return this.specification() @@ -18,11 +18,11 @@ export default class PayByBank extends PayablePaymentMethod { .getActionRequestParameters('Pay') ?.find((item) => item.name === 'issuer') ?.listItemDescriptions!.map((item) => { - return { [item.value]: item.description } - }) + return { [item.value]: item.description }; + }); }) .catch((err) => { - console.log(err) - }) + console.log(err); + }); } } diff --git a/src/PaymentMethods/PayPerEmail/Models/Attachments.ts b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts new file mode 100644 index 00000000..f356a111 --- /dev/null +++ b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts @@ -0,0 +1,9 @@ +import { Model } from '../../../Models/Model'; +export interface IAttachments { + name: string; +} +export class Attachments extends Model implements IAttachments { + set name(value: string) { + this.set('attachment', value); + } +} diff --git a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts new file mode 100644 index 00000000..bfaba57a --- /dev/null +++ b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts @@ -0,0 +1,54 @@ +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Attachments, IAttachments } from './Attachments'; +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; + +export interface IInvitation extends IRequest { + customer: Partial; + email: string; + merchantSendsEmail?: boolean; + expirationDate?: string; + paymentMethodsAllowed?: string; + attachments?: IAttachments[]; + attachment?: string; +} +export class Invitation extends ServiceParameter { + protected getCountable() { + return super.getCountable(['Attachments']); + } + set attachment(value: string) { + this.set('attachment', value); + } + set customer(value: Partial) { + this.set('customer', new Customer(value)); + } + set merchantSendsEmail(value: boolean) { + this.set('merchantSendsEmail', value); + } + set attachments(value: IAttachments[]) { + this.set( + 'attachments', + value.map((attachment: IAttachments) => new Attachments(attachment)) + ); + } + set email(value: string) { + this.set('customerEmail', value); + } + set paymentMethodsAllowed(value: string) { + this.set('paymentMethodsAllowed', value); + } + set expirationDate(value: string) { + this.set('expirationDate', value); + } +} +class Customer extends Person { + set gender(value: string) { + this.set('customergender', value); + } + set firstName(value: string) { + this.set('customerFirstName', value); + } + set lastName(value: string) { + this.set('customerLastName', value); + } +} diff --git a/src/PaymentMethods/PayPerEmail/Models/invitation.ts b/src/PaymentMethods/PayPerEmail/Models/invitation.ts deleted file mode 100644 index 67c5c8a4..00000000 --- a/src/PaymentMethods/PayPerEmail/Models/invitation.ts +++ /dev/null @@ -1,14 +0,0 @@ -import IRequest from '../../../Models/IRequest' -import gender from '../../../Constants/Gender' - -export interface IInvitation extends IRequest { - customerGender: gender - customerFirstName: string - customerLastName: string - customerEmail: string - merchantSendsEmail?: boolean - email: string - expirationDate?: string - paymentMethodsAllowed?: string - attachment?: string -} diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index abdfaeca..261675a6 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,13 +1,10 @@ -import PaymentMethod from '../PaymentMethod' -import { IInvitation } from './Models/invitation' -import { uniqid } from '../../Utils/Functions' +import PaymentMethod from '../PaymentMethod'; +import { IInvitation, Invitation } from './Models/Invitation'; -//ToDO Add the service parameter models export default class PayPerEmail extends PaymentMethod { - protected _paymentName = 'PayPerEmail' + protected _paymentName = 'PayPerEmail'; paymentInvitation(payload: IInvitation) { - payload.invoice = payload.invoice || uniqid() - this.setServiceList('paymentInvitation') - return super.transactionRequest(payload) + this.setServiceList('paymentInvitation', new Invitation(payload)); + return super.transactionRequest(payload); } } diff --git a/src/PaymentMethods/PayablePaymentMethod.ts b/src/PaymentMethods/PayablePaymentMethod.ts index 4620e54c..776f2794 100644 --- a/src/PaymentMethods/PayablePaymentMethod.ts +++ b/src/PaymentMethods/PayablePaymentMethod.ts @@ -1,34 +1,29 @@ -import PaymentMethod from './PaymentMethod' -import IRequest, { IPaymentRequest, IRefundRequest } from '../Models/IRequest' -import { uniqid } from '../Utils/Functions' -import { ServiceParameter } from '../Models/ServiceParameters' -import { IParameter } from '../Models/IParameters' +import PaymentMethod from './PaymentMethod'; +import IRequest, { IPaymentRequest, IRefundRequest } from '../Models/IRequest'; +import { uniqid } from '../Utils/Functions'; +import { ServiceParameter } from '../Models/ServiceParameters'; +import { IParameter } from '../Models/IParameters'; export default abstract class PayablePaymentMethod extends PaymentMethod { - protected _requiredFields: Array = [ - 'currency', - 'returnURL', - 'returnURLCancel', - 'pushURL' - ] + protected _requiredFields: Array = ['currency', 'returnURL', 'returnURLCancel', 'pushURL']; protected setPayPayload(payload: IRequest) { - payload.invoice = payload.invoice || uniqid() - payload.order = payload.order || uniqid() - super.setPayload(payload) + payload.invoice = payload.invoice ?? uniqid(); + payload.order = payload.order ?? uniqid(); + super.setPayload(payload); } pay(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { - this.setPayPayload(payload) - this.setServiceList('Pay', serviceParameters) - return this.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Pay', serviceParameters); + return this.transactionRequest(); } payRemainder(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { - this.setPayPayload(payload) - this.setServiceList('PayRemainder', serviceParameters) - return this.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayRemainder', serviceParameters); + return this.transactionRequest(); } refund(payload: IRefundRequest, serviceParameters?: ServiceParameter | IParameter[]) { - this.setPayload(payload) - this.setServiceList('Refund', serviceParameters) - return this.transactionRequest() + this.setPayload(payload); + this.setServiceList('Refund', serviceParameters); + return this.transactionRequest(); } } diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index 2670ef03..ab4badc2 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,10 +1,10 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; export default class Payconiq extends PayablePaymentMethod { - protected _paymentName = 'Payconiq' + protected _paymentName = 'Payconiq'; instantRefund(payload: IRefundRequest) { - this.setServiceList('InstantRefund') - return this.transactionRequest(payload) + this.setServiceList('InstantRefund'); + return this.transactionRequest(payload); } } diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index a9e824cb..2796da8b 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -1,102 +1,90 @@ -import { RequestTypes } from '../Constants/Endpoints' -import IRequest from '../Models/IRequest' -import Buckaroo from '../index' -import Request from '../Request/Request' -import { ServiceList } from '../Models/IServiceList' -import { ServiceParameter } from '../Models/ServiceParameters' -import { IParameter } from '../Models/IParameters' -import { DataRequestData, TransactionData } from '../Request/DataModels' +import { RequestTypes } from '../Constants/Endpoints'; +import IRequest from '../Models/IRequest'; +import Buckaroo from '../index'; +import Request from '../Request/Request'; +import {IService, ServiceList} from '../Models/IServiceList'; +import { ServiceParameter } from '../Models/ServiceParameters'; +import { IParameter } from '../Models/IParameters'; +import { TransactionData } from '../Request/DataModels'; +import {MethodFromServiceCode, ServiceCode} from "../Utils/MethodTypes"; export default abstract class PaymentMethod { - protected _paymentName: string = '' - protected _serviceCode?: string - protected _serviceVersion: number = 0 - protected _payload: IRequest = {} - protected _serviceList: ServiceList = new ServiceList() + protected _paymentName: string = ''; + protected _serviceCode?: string; + protected _serviceVersion: number = 0; + protected _payload: TransactionData = new TransactionData(); + protected _requiredFields: Array = []; constructor(serviceCode?: string) { - this._serviceCode = serviceCode + this._serviceCode = serviceCode ?? this.paymentName; } get serviceVersion() { - return this._serviceVersion + return this._serviceVersion; } set serviceVersion(value: number) { - this._serviceVersion = value + this._serviceVersion = value; } get serviceCode() { - return this._serviceCode || '' + return this._serviceCode || ''; } get paymentName() { - return this._paymentName + return this._paymentName; } - protected _requiredFields: Array = [] protected setRequiredFields(requiredFields: Array = this._requiredFields) { for (const fieldKey of requiredFields) { - let field = this._payload[fieldKey] ?? Buckaroo.Client.config[fieldKey] + let field = this._payload[fieldKey] ?? Buckaroo.Client.config[fieldKey]; if (field === undefined) { - throw new Error(`Missing required config parameter ${String(fieldKey)}`) + throw new Error(`Missing required config parameter ${String(fieldKey)}`); } - this._payload[fieldKey] = field + this._payload[fieldKey] = field; } - return this + return this; } - protected setPayload(payload: IRequest) { - this.setRequiredFields() - this._payload = { ...this._payload, ...payload } + setPayload(payload?: IRequest) { + this.setRequiredFields(); + this._payload.initialize(payload); } - getPayload() { - return this._payload + getPayload():Record { + return this._payload.getData(); } - protected setServiceList( - action: string, - serviceParameters?: IParameter[] | ServiceParameter, - serviceCode = this.serviceCode, - serviceVersion = this.serviceVersion - ) { - this._serviceList.addService({ + protected setServiceList(action: string, serviceParameters?: IParameter[] | ServiceParameter, serviceCode = this.serviceCode, serviceVersion = this.serviceVersion) { + const service:IService = { name: serviceCode, action: action, version: serviceVersion, - parameters: - serviceParameters instanceof ServiceParameter - ? serviceParameters.toParameterList() - : serviceParameters - }) + parameters: serviceParameters instanceof ServiceParameter ? serviceParameters.toParameterList() : serviceParameters, + }; + if (this.getServiceList() instanceof ServiceList) { + this.getServiceList()!.addService(service); + } else { + this._payload.setServiceList(new ServiceList(service)); + } + return this; } - getServices() { - return this._serviceList.list + getServiceList() { + return this._payload.getServiceList(); } protected transactionRequest(payload?: IRequest) { - let data = new TransactionData({ ...(payload ?? this._payload) }) - if (this._serviceList.list.length > 0) { - data.setServiceList(this._serviceList) - } - return Request.Transaction(data) + this.setPayload(payload); + return Request.Transaction(this._payload); } protected dataRequest(payload?: IRequest) { - let data = new DataRequestData({ ...(payload ?? this._payload) }) - if (this._serviceList.list.length > 0) { - data.setServiceList(this._serviceList) - } - return Request.DataRequest(data) + this.setPayload(payload); + return Request.DataRequest(this._payload); } public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { - return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }) + return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); } - combine(data: Payload): this - combine(method: Method): this + + combine(data: Name): MethodFromServiceCode; + combine(data: Payload): this; + combine(method: Method): this; combine(data): this { - if (data instanceof PaymentMethod) { - data = data.getPayload() - } - let { services, Services, ...payload } = data - for (const key in payload) { - if (payload.hasOwnProperty(key)) { - this._payload[key] = payload[key] - } - } - for (const service of services?.serviceList) { - this.setServiceList(service.action, service.parameters, service.name, service.version) + if(typeof data === "string") { + const method:PaymentMethod = Buckaroo.Client.method(data as any) + method.setPayload(this._payload); + return method as any } - return this + this.setPayload(data instanceof PaymentMethod ? data.getPayload() : data); + return this; } } diff --git a/src/PaymentMethods/Paypal/Models/Address.ts b/src/PaymentMethods/Paypal/Models/Address.ts index aed64475..4f3592e1 100644 --- a/src/PaymentMethods/Paypal/Models/Address.ts +++ b/src/PaymentMethods/Paypal/Models/Address.ts @@ -1,35 +1,35 @@ -import IAddressGlobal, { Address as AddressClass } from '../../../Models/Interfaces/IAddress' +import IAddressGlobal, { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; export interface IAddress extends Partial { - street: string - street2?: string + street: string; + street2?: string; } export class Address extends AddressClass { set street2(value: string) { - this.set('street2', value) + this.set('street2', value); } set street(value: string) { - this.set('street1', value) + this.set('street1', value); } get street() { - return this.get('street1') + return this.get('street1'); } set city(value: string) { - this.set('cityName', value) + this.set('cityName', value); } get city() { - return this.get('cityName') + return this.get('cityName'); } set state(value: string) { - this.set('stateOrProvince', value) + this.set('stateOrProvince', value); } get state() { - return this.get('stateOrProvince') + return this.get('stateOrProvince'); } set zipcode(value: string) { - this.set('postalCode', value) + this.set('postalCode', value); } get zipcode() { - return this.get('postalCode') + return this.get('postalCode'); } } diff --git a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts index 594f69d1..05365590 100644 --- a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts +++ b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts @@ -1,32 +1,32 @@ -import IPhone from '../../../Models/Interfaces/IPhone' -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { Phone } from './Phone' -import { Address, IAddress } from './Address' -import { IPaymentRequest } from '../../../Models/IRequest' +import IPhone from '../../../Models/Interfaces/IPhone'; +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Phone } from './Phone'; +import { Address, IAddress } from './Address'; +import { IPaymentRequest } from '../../../Models/IRequest'; export interface IExtraInfo extends IPaymentRequest { - address?: IAddress - customer?: IPerson - phone?: IPhone - noShipping?: string - addressOverride?: boolean + address?: IAddress; + customer?: IPerson; + phone?: IPhone; + noShipping?: string; + addressOverride?: boolean; } export class ExtraInfo extends ServiceParameter { set address(value: IAddress) { - this.set('address', new Address(value)) + this.set('address', new Address(value)); } set customer(value: IPerson) { - this.set('customer', new Person(value)) + this.set('customer', new Person(value)); } set phone(value: IPhone) { - this.set('phone', new Phone(value)) + this.set('phone', new Phone(value)); } set noShipping(value: string) { - this.set('noShipping', value) + this.set('noShipping', value); } set addressOverride(value: boolean) { - this.set('addressOverride', value) + this.set('addressOverride', value); } } diff --git a/src/PaymentMethods/Paypal/Models/Pay.ts b/src/PaymentMethods/Paypal/Models/Pay.ts index 9c77c877..23f97d1d 100644 --- a/src/PaymentMethods/Paypal/Models/Pay.ts +++ b/src/PaymentMethods/Paypal/Models/Pay.ts @@ -1,28 +1,28 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - buyerEmail?: string - productName?: string - billingAgreementDescription?: string - pageStyle?: string - payPalOrderId?: string + buyerEmail?: string; + productName?: string; + billingAgreementDescription?: string; + pageStyle?: string; + payPalOrderId?: string; } export class Pay extends ServiceParameter { set buyerEmail(value: string) { - this.set('buyerEmail', value) + this.set('buyerEmail', value); } set productName(value: string) { - this.set('productName', value) + this.set('productName', value); } set billingAgreementDescription(value: string) { - this.set('billingAgreementDescription', value) + this.set('billingAgreementDescription', value); } set pageStyle(value: string) { - this.set('pageStyle', value) + this.set('pageStyle', value); } set payPalOrderId(value: string) { - this.set('payPalOrderId', value) + this.set('payPalOrderId', value); } } diff --git a/src/PaymentMethods/Paypal/Models/Phone.ts b/src/PaymentMethods/Paypal/Models/Phone.ts index b6e1c83b..7ea9effb 100644 --- a/src/PaymentMethods/Paypal/Models/Phone.ts +++ b/src/PaymentMethods/Paypal/Models/Phone.ts @@ -1,7 +1,7 @@ -import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone' +import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; export class Phone extends PhoneClass { set mobile(value: string) { - this.set('phone', value) + this.set('phone', value); } } diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 296f7a24..5178dfe0 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -1,25 +1,25 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' -import { IPay, Pay } from './Models/Pay' -import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { IPay, Pay } from './Models/Pay'; +import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; export default class Paypal extends PayablePaymentMethod { - protected _paymentName = 'Paypal' + protected _paymentName = 'Paypal'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } payRecurrent(payload: IPaymentRequest) { - this.setPayPayload(payload) - this.setServiceList('PayRecurring') - return super.transactionRequest(payload) + this.setPayPayload(payload); + this.setServiceList('PayRecurring'); + return super.transactionRequest(payload); } extraInfo(payload: IExtraInfo) { - this.setPayPayload(payload) - this.setServiceList('Pay,ExtraInfo', new ExtraInfo(payload)) - return super.transactionRequest(payload) + this.setPayPayload(payload); + this.setServiceList('Pay,ExtraInfo', new ExtraInfo(payload)); + return super.transactionRequest(payload); } } diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index 098c5755..c932f282 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,9 +1,9 @@ -import PaymentMethod from '../PaymentMethod' +import PaymentMethod from '../PaymentMethod'; export default class PiM extends PaymentMethod { - protected _paymentName = 'PiM' - protected _requiredFields = ['currency'] + protected _paymentName = 'PiM'; + protected _requiredFields = ['currency']; generate() { - this.setServiceList('Generate') - return this.dataRequest() + this.setServiceList('Generate'); + return this.dataRequest(); } } diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index fd9d72d3..1c1afba3 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' +import PayablePaymentMethod from '../PayablePaymentMethod'; export default class PointOfSale extends PayablePaymentMethod { - protected _paymentName = 'PointOfSale' + protected _paymentName = 'PointOfSale'; } diff --git a/src/PaymentMethods/Przelewy24/Models/Pay.ts b/src/PaymentMethods/Przelewy24/Models/Pay.ts index 599cf8f9..107b946d 100644 --- a/src/PaymentMethods/Przelewy24/Models/Pay.ts +++ b/src/PaymentMethods/Przelewy24/Models/Pay.ts @@ -1,23 +1,23 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - email: string - customer: Partial + email: string; + customer: Partial; } export class Pay extends ServiceParameter { set email(email: string) { - this.set('customerEmail', email) + this.set('customerEmail', email); } set customer(customer: Partial) { - this.set('customer', new Customer(customer)) + this.set('customer', new Customer(customer)); } } export class Customer extends Person { set firstName(email: string) { - this.set('customerFirstName', email) + this.set('customerFirstName', email); } set lastName(email: string) { - this.set('customerLastName', email) + this.set('customerLastName', email); } } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 98aa1c7e..1a40340a 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' -import { IPay, Pay } from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; +import { IPay, Pay } from './Models/Pay'; export default class Przelewy24 extends PayablePaymentMethod { - protected _paymentName = 'Przelewy24' + protected _paymentName = 'Przelewy24'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/SEPA/Models/Emandate.ts b/src/PaymentMethods/SEPA/Models/Emandate.ts index 677274a9..22621021 100644 --- a/src/PaymentMethods/SEPA/Models/Emandate.ts +++ b/src/PaymentMethods/SEPA/Models/Emandate.ts @@ -1,6 +1,6 @@ -import { IPaymentRequest } from '../../../Models/IRequest' +import { IPaymentRequest } from '../../../Models/IRequest'; export interface IEmandate extends IPaymentRequest { - mandateReference: string - collectdate?: string + mandateReference: string; + collectdate?: string; } diff --git a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts index 940ad81d..1916cdff 100644 --- a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts +++ b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts @@ -1,16 +1,16 @@ -import { IPaymentRequest } from '../../../Models/IRequest' +import { IPaymentRequest } from '../../../Models/IRequest'; export interface IExtraInfo extends IPaymentRequest { - customeraccountname: string - customerBIC?: string - customerIBAN: string - collectDate: string - mandateReference?: string - mandateDate?: string - customerName?: string - customerCode?: string - customerReferencePartyCode?: string - customerReferencePartyName?: string - houseNumberSuffix: string - contractID: string + customeraccountname: string; + customerBIC?: string; + customerIBAN: string; + collectDate: string; + mandateReference?: string; + mandateDate?: string; + customerName?: string; + customerCode?: string; + customerReferencePartyCode?: string; + customerReferencePartyName?: string; + houseNumberSuffix: string; + contractID: string; } diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index 2f1454d2..f62c28a0 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -1,53 +1,53 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import { ServiceParameter } from '../../../Models/ServiceParameters' +import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - customer?: Partial - bic?: string - iban?: string - collectDate?: string - mandateReference?: string - mandateDate?: string + customer?: Partial; + bic?: string; + iban?: string; + collectDate?: string; + mandateReference?: string; + mandateDate?: string; } export class Pay extends ServiceParameter { get bic(): string { - return this.get('customerbic') + return this.get('customerbic'); } set bic(value: string) { - this.set('customerbic', value) + this.set('customerbic', value); } get iban(): string { - return this.get('customerIBAN') + return this.get('customerIBAN'); } set iban(value: string) { - this.set('customerIBAN', value) + this.set('customerIBAN', value); } set collectDate(value: string) { - this.set('collectDate', value) + this.set('collectDate', value); } set mandateReference(value: string) { - this.set('mandateReference', value) + this.set('mandateReference', value); } set mandateDate(value: string) { - this.set('mandateDate', value) + this.set('mandateDate', value); } set customer(value: Partial) { - this.set('customer', new Customer(value)) + this.set('customer', new Customer(value)); } } export class Customer extends Person { set category(value) {} get name(): string { - return this.get('customeraccountname') + return this.get('customeraccountname'); } set name(value: string) { - this.set('customeraccountname', value) + this.set('customeraccountname', value); } get firstName(): string { - return this.get('customeraccountname') + return this.get('customeraccountname'); } set firstName(value: string) { - this.set('customeraccountname', value) + this.set('customeraccountname', value); } } diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index d2ae3de7..6d944335 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -1,34 +1,34 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPay, Pay } from './Models/Pay' -import { IExtraInfo } from './Models/ExtraInfo' -import { IEmandate } from './Models/Emandate' -import { uniqid } from '../../Utils/Functions' -import { IPaymentRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; +import { IExtraInfo } from './Models/ExtraInfo'; +import { IEmandate } from './Models/Emandate'; +import { uniqid } from '../../Utils/Functions'; +import { IPaymentRequest } from '../../Models/IRequest'; export default class SEPA extends PayablePaymentMethod { - protected _paymentName = 'SEPA' + protected _paymentName = 'SEPA'; pay(payload: IPay) { - return super.pay(payload, new Pay(payload)) + return super.pay(payload, new Pay(payload)); } authorize(payload: IPay) { - this.setPayPayload(payload) - this.setServiceList('Authorize', new Pay(payload)) - return this.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Authorize', new Pay(payload)); + return this.transactionRequest(); } payRecurrent(payload: Pick & IPaymentRequest) { - this.setPayPayload(payload) - this.setServiceList('PayRecurrent', new Pay(payload)) - return this.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('PayRecurrent', new Pay(payload)); + return this.transactionRequest(); } extraInfo(payload: IExtraInfo) { - this.setPayPayload(payload) - this.setServiceList('Pay,ExtraInfo', new Pay(payload)) - return this.transactionRequest() + this.setPayPayload(payload); + this.setServiceList('Pay,ExtraInfo', new Pay(payload)); + return this.transactionRequest(); } payWithEmandate(payload: IEmandate) { - payload.invoice = payload.invoice || uniqid() - this.setPayPayload(payload) - this.setServiceList('PayWithEmandate', new Pay(payload)) - return this.transactionRequest() + payload.invoice = payload.invoice || uniqid(); + this.setPayPayload(payload); + this.setServiceList('PayWithEmandate', new Pay(payload)); + return this.transactionRequest(); } } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 3be20dd9..18b00696 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,17 +1,17 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Sofort extends PayablePaymentMethod { - protected _paymentName = 'Sofort' + protected _paymentName = 'Sofort'; pay(payload: IPaymentRequest) { - return super.pay(payload) + return super.pay(payload); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } instantRefund(payload: IRefundRequest) { - this.setServiceList('InstantRefund') - return this.transactionRequest(payload) + this.setServiceList('InstantRefund'); + return this.transactionRequest(payload); } } diff --git a/src/PaymentMethods/Subscriptions/Models/Company.ts b/src/PaymentMethods/Subscriptions/Models/Company.ts index 31fbef92..eb35983f 100644 --- a/src/PaymentMethods/Subscriptions/Models/Company.ts +++ b/src/PaymentMethods/Subscriptions/Models/Company.ts @@ -1,7 +1,7 @@ -import { Company as CompanyClass } from '../../../Models/Interfaces/IRecipient' +import { Company as CompanyClass } from '../../../Models/Interfaces/IRecipient'; export default class Company extends CompanyClass { set companyName(companyName: string) { - this.set('name', companyName) + this.set('name', companyName); } } diff --git a/src/PaymentMethods/Subscriptions/Models/Configuration.ts b/src/PaymentMethods/Subscriptions/Models/Configuration.ts index 7b20fdda..f5186f33 100644 --- a/src/PaymentMethods/Subscriptions/Models/Configuration.ts +++ b/src/PaymentMethods/Subscriptions/Models/Configuration.ts @@ -1,43 +1,43 @@ -import { Model } from '../../../Models/Model' +import { Model } from '../../../Models/Model'; export type IConfiguration = { - name?: string - schemeKey?: string - invoiceNumberPrefix?: string - invoiceDescriptionFormat?: string - dueDateDays?: number - allowedServices?: string - generateInvoiceSpecification?: boolean - skipPayPerEmail?: boolean -} + name?: string; + schemeKey?: string; + invoiceNumberPrefix?: string; + invoiceDescriptionFormat?: string; + dueDateDays?: number; + allowedServices?: string; + generateInvoiceSpecification?: boolean; + skipPayPerEmail?: boolean; +}; export class Configuration extends Model implements IConfiguration { set name(value: string) { - this.set('name', value) + this.set('name', value); } set schemeKey(value: string) { - this.set('schemeKey', value) + this.set('schemeKey', value); } set invoiceNumberPrefix(value: string) { - this.set('invoiceNumberPrefix', value) + this.set('invoiceNumberPrefix', value); } set invoiceDescriptionFormat(value: string) { - this.set('invoiceDescriptionFormat', value) + this.set('invoiceDescriptionFormat', value); } set dueDateDays(value: number) { - this.set('dueDateDays', value) + this.set('dueDateDays', value); } set allowedServices(value: string) { - this.set('allowedServices', value) + this.set('allowedServices', value); } set generateInvoiceSpecification(value: boolean) { - this.set('generateInvoiceSpecification', value) + this.set('generateInvoiceSpecification', value); } set skipPayPerEmail(value: boolean) { - this.set('skipPayPerEmail', value) + this.set('skipPayPerEmail', value); } } diff --git a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts index 0798db1b..ab50281d 100644 --- a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts @@ -1,40 +1,40 @@ -import IPhone, { Phone } from '../../../Models/Interfaces/IPhone' -import IAddress, { Address } from '../../../Models/Interfaces/IAddress' -import { IRatePlan, IRatePlans, RatePlan } from './RatePlan' -import { IRatePlanCharge, IRatePlanCharges, RatePlanCharge } from './RatePlanCharge' -import { Configuration, IConfiguration } from './Configuration' -import IRequest from '../../../Models/IRequest' -import { ServiceParameter } from '../../../Models/ServiceParameters' -import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient' -import Company from './Company' -import IDebtor from '../../../Models/Interfaces/IDebtor' -import IBankAccount, { BankAccount } from '../../../Models/Interfaces/IBankAccount' +import IPhone, { Phone } from '../../../Models/Interfaces/IPhone'; +import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; +import { IRatePlan, IRatePlans, RatePlan } from './RatePlan'; +import { IRatePlanCharge, IRatePlanCharges, RatePlanCharge } from './RatePlanCharge'; +import { Configuration, IConfiguration } from './Configuration'; +import IRequest from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import Company from './Company'; +import IDebtor from '../../../Models/Interfaces/IDebtor'; +import IBankAccount, { BankAccount } from '../../../Models/Interfaces/IBankAccount'; export interface ISubscription extends IRequest { - address?: Partial - allowedServices?: string - b2b?: string - billingTiming?: number - company?: Partial - configuration?: IConfiguration - configurationCode?: string - customerAccountName?: string - customerBIC?: string - customerIBAN?: string - debtor?: IDebtor - email?: string - includeTransaction?: boolean - mandateReference?: string - person?: Partial - phone?: Partial - subscriptionGuid?: string - termStartDay?: number - termStartMonth?: number - termStartWeek?: string - transactionVatPercentage?: number - ratePlans?: IRatePlans - ratePlanCharges?: IRatePlanCharges - bankAccount?: IBankAccount + address?: Partial; + allowedServices?: string; + b2b?: string; + billingTiming?: number; + company?: Partial; + configuration?: IConfiguration; + configurationCode?: string; + customerAccountName?: string; + customerBIC?: string; + customerIBAN?: string; + debtor?: IDebtor; + email?: string; + includeTransaction?: boolean; + mandateReference?: string; + person?: Partial; + phone?: Partial; + subscriptionGuid?: string; + termStartDay?: number; + termStartMonth?: number; + termStartWeek?: string; + transactionVatPercentage?: number; + ratePlans?: IRatePlans; + ratePlanCharges?: IRatePlanCharges; + bankAccount?: IBankAccount; } export class Subscription extends ServiceParameter implements ISubscription { @@ -50,99 +50,99 @@ export class Subscription extends ServiceParameter implements ISubscription { DisableRatePlan: 'DisableRatePlan', AddRatePlanCharge: 'AddRatePlanCharge', UpdateRatePlanCharge: 'UpdateRatePlanCharge', - DisableRatePlanCharge: 'DisableRatePlanCharge' - }) + DisableRatePlanCharge: 'DisableRatePlanCharge', + }); } set configurationCode(configurationCode: string) { - this.set('configurationCode', configurationCode) + this.set('configurationCode', configurationCode); } set includeTransaction(includeTransaction: boolean) { - this.set('includeTransaction', includeTransaction) + this.set('includeTransaction', includeTransaction); } set transactionVatPercentage(transactionVatPercentage: number) { - this.set('transactionVatPercentage', transactionVatPercentage) + this.set('transactionVatPercentage', transactionVatPercentage); } set subscriptionGuid(value: string) { - this.set('subscriptionGuid', value) + this.set('subscriptionGuid', value); } set termStartDay(value: number) { - this.set('termStartDay', value) + this.set('termStartDay', value); } set termStartMonth(value: number) { - this.set('termStartMonth', value) + this.set('termStartMonth', value); } set billingTiming(value: number) { - this.set('billingTiming', value) + this.set('billingTiming', value); } set termStartWeek(value: string) { - this.set('termStartWeek', value) + this.set('termStartWeek', value); } set b2b(value: string) { - this.set('b2b', value) + this.set('b2b', value); } set mandateReference(value: string) { - this.set('mandateReference', value) + this.set('mandateReference', value); } set allowedServices(value: string) { - this.set('allowedServices', value) + this.set('allowedServices', value); } set debtor(value: IDebtor) { - this.set('debtor', value) + this.set('debtor', value); } set bankAccount(value: IBankAccount) { - this.set('bankAccount', new BankAccount(value)) + this.set('bankAccount', new BankAccount(value)); } set email(value: string) { - this.set('email', value) + this.set('email', value); } set phone(value: IPhone) { - this.set('phone', new Phone(value)) + this.set('phone', new Phone(value)); } set address(value: IAddress) { - this.set('address', new Address(value)) + this.set('address', new Address(value)); } set person(value: IPerson) { - this.set('person', new Person(value)) + this.set('person', new Person(value)); } set company(value: ICompany) { - this.set('company', new Company(value)) + this.set('company', new Company(value)); } set configuration(value: Configuration) { - this.set('configuration', new Configuration(value)) + this.set('configuration', new Configuration(value)); } protected set addRatePlan(value: IRatePlan) { - this.set('addRatePlan', new RatePlan(value)) + this.set('addRatePlan', new RatePlan(value)); } protected set updateRatePlan(value: IRatePlan) { - this.set('updateRatePlan', new RatePlan(value)) + this.set('updateRatePlan', new RatePlan(value)); } protected set disableRatePlan(value: IRatePlan) { - this.set('disableRatePlan', new RatePlan(value)) + this.set('disableRatePlan', new RatePlan(value)); } protected set addRatePlanCharge(value: IRatePlanCharge) { - this.set('addRatePlanCharge', new RatePlanCharge(value)) + this.set('addRatePlanCharge', new RatePlanCharge(value)); } set ratePlans(value: IRatePlans) { for (const key in value) { if (this.has(key + 'RatePlan')) { - this[key + 'RatePlan'] = value[key] + this[key + 'RatePlan'] = value[key]; } } } set ratePlanCharges(value: IRatePlanCharges) { for (const key in value) { if (this.has(key + 'RatePlanCharge')) { - this[key + 'RatePlanCharge'] = value[key] + this[key + 'RatePlanCharge'] = value[key]; } } } set customerIBAN(value: string) { - this.set('customerIBAN', value) + this.set('customerIBAN', value); } set customerAccountName(value: string) { - this.set('customerAccountName', value) + this.set('customerAccountName', value); } set customerBIC(value: string) { - this.set('customerBIC', value) + this.set('customerBIC', value); } } diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts index ad6769c5..75537b2b 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts @@ -1,83 +1,83 @@ -import { Model } from '../../../Models/Model' +import { Model } from '../../../Models/Model'; export interface IRatePlans { - add?: IRatePlan - update?: IRatePlan - disable?: IRatePlan + add?: IRatePlan; + update?: IRatePlan; + disable?: IRatePlan; } export interface IRatePlan { - type?: string - ratePlanGuid?: string - ratePlanCode?: string - startDate?: string - endDate?: string - ratePlanName?: string - ratePlanDescription?: string - currency?: string - billingTiming?: number - automaticTerm?: boolean - billingInterval?: string - customNumberOfDays?: number - termStartDay?: number - termStartWeek?: string - termStartMonth?: string - trialPeriodDays?: number - trialPeriodMonth?: string - inheritPaymentMethod?: boolean + type?: string; + ratePlanGuid?: string; + ratePlanCode?: string; + startDate?: string; + endDate?: string; + ratePlanName?: string; + ratePlanDescription?: string; + currency?: string; + billingTiming?: number; + automaticTerm?: boolean; + billingInterval?: string; + customNumberOfDays?: number; + termStartDay?: number; + termStartWeek?: string; + termStartMonth?: string; + trialPeriodDays?: number; + trialPeriodMonth?: string; + inheritPaymentMethod?: boolean; } export class RatePlan extends Model implements IRatePlan { set type(value: string) { - this.set('type', value) + this.set('type', value); } set ratePlanGuid(value: string) { - this.set('ratePlanGuid', value) + this.set('ratePlanGuid', value); } set ratePlanCode(value: string) { - this.set('ratePlanCode', value) + this.set('ratePlanCode', value); } set startDate(value: string) { - this.set('startDate', value) + this.set('startDate', value); } set endDate(value: string) { - this.set('endDate', value) + this.set('endDate', value); } set ratePlanName(value: string) { - this.set('ratePlanName', value) + this.set('ratePlanName', value); } set ratePlanDescription(value: string) { - this.set('ratePlanDescription', value) + this.set('ratePlanDescription', value); } set currency(value: string) { - this.set('currency', value) + this.set('currency', value); } set billingTiming(value: number) { - this.set('billingTiming', value) + this.set('billingTiming', value); } set automaticTerm(value: boolean) { - this.set('automaticTerm', value) + this.set('automaticTerm', value); } set billingInterval(value: string) { - this.set('billingInterval', value) + this.set('billingInterval', value); } set customNumberOfDays(value: number) { - this.set('customNumberOfDays', value) + this.set('customNumberOfDays', value); } set termStartDay(value: number) { - this.set('termStartDay', value) + this.set('termStartDay', value); } set termStartWeek(value: string) { - this.set('termStartWeek', value) + this.set('termStartWeek', value); } set termStartMonth(value: string) { - this.set('termStartMonth', value) + this.set('termStartMonth', value); } set trialPeriodDays(value: number) { - this.set('trialPeriodDays', value) + this.set('trialPeriodDays', value); } set trialPeriodMonth(value: string) { - this.set('trialPeriodMonth', value) + this.set('trialPeriodMonth', value); } set inheritPaymentMethod(value: boolean) { - this.set('inheritPaymentMethod', value) + this.set('inheritPaymentMethod', value); } } diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts index f822c246..4de58c47 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts @@ -1,59 +1,59 @@ -import { Model } from '../../../Models/Model' +import { Model } from '../../../Models/Model'; export interface IRatePlanCharge { - ratePlanChargeCode?: string - ratePlanChargeName?: string - ratePlanChargeProductId?: string - ratePlanChargeDescription?: string - unitOfMeasure?: string - baseNumberOfUnits?: number - partialBilling?: string - pricePerUnit?: number - priceIncludesVat?: boolean - vatPercentage?: number - b2b?: string - ratePlanChargeType?: string + ratePlanChargeCode?: string; + ratePlanChargeName?: string; + ratePlanChargeProductId?: string; + ratePlanChargeDescription?: string; + unitOfMeasure?: string; + baseNumberOfUnits?: number; + partialBilling?: string; + pricePerUnit?: number; + priceIncludesVat?: boolean; + vatPercentage?: number; + b2b?: string; + ratePlanChargeType?: string; } export interface IRatePlanCharges { - add?: IRatePlanCharge - update?: IRatePlanCharge - disable?: IRatePlanCharge + add?: IRatePlanCharge; + update?: IRatePlanCharge; + disable?: IRatePlanCharge; } export class RatePlanCharge extends Model implements IRatePlanCharge { set ratePlanChargeCode(value: string) { - this.set('ratePlanChargeCode', value) + this.set('ratePlanChargeCode', value); } set ratePlanChargeName(value: string) { - this.set('ratePlanChargeName', value) + this.set('ratePlanChargeName', value); } set ratePlanChargeProductId(value: string) { - this.set('rateplanChargeProductId', value) + this.set('rateplanChargeProductId', value); } set ratePlanChargeDescription(value: string) { - this.set('rateplanChargeDescription', value) + this.set('rateplanChargeDescription', value); } set unitOfMeasure(value: string) { - this.set('unitOfMeasure', value) + this.set('unitOfMeasure', value); } set baseNumberOfUnits(value: number) { - this.set('baseNumberOfUnits', value) + this.set('baseNumberOfUnits', value); } set partialBilling(value: string) { - this.set('partialBilling', value) + this.set('partialBilling', value); } set pricePerUnit(value: number) { - this.set('pricePerUnit', value) + this.set('pricePerUnit', value); } set priceIncludesVat(value: boolean) { - this.set('priceIncludesVat', value) + this.set('priceIncludesVat', value); } set vatPercentage(value: number) { - this.set('vatPercentage', value) + this.set('vatPercentage', value); } set b2b(value: string) { - this.set('b2B', value) + this.set('b2B', value); } set ratePlanChargeType(value: string) { - this.set('ratePlanChargeType', value) + this.set('ratePlanChargeType', value); } } diff --git a/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts b/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts index 5dfcc542..bc348ca7 100644 --- a/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ResumeSubscription.ts @@ -1,7 +1,7 @@ -import { Subscription } from './ISubscription' +import { Subscription } from './ISubscription'; export class ResumeSubscription extends Subscription { set resumeDate(resumeDate: string) { - this.set('resumeDate', resumeDate) + this.set('resumeDate', resumeDate); } } diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index f51c92a8..987da852 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -1,54 +1,51 @@ -import { ISubscription, Subscription } from './Models/ISubscription' -import PaymentMethod from '../PaymentMethod' -import IRequest from '../../Models/IRequest' -import { ResumeSubscription } from './Models/ResumeSubscription' +import { ISubscription, Subscription } from './Models/ISubscription'; +import PaymentMethod from '../PaymentMethod'; +import IRequest from '../../Models/IRequest'; +import { ResumeSubscription } from './Models/ResumeSubscription'; export default class Subscriptions extends PaymentMethod { - protected _paymentName = 'Subscriptions' - protected _serviceVersion = 1 - - protected setRequiredFields(requiredFields: Array = []) { - return super.setRequiredFields(['currency']) - } + protected _paymentName = 'Subscriptions'; + protected _serviceVersion = 1; + protected _requiredFields: Array = ['currency']; create(payload: ISubscription) { - this.setPayload(payload) - this.setServiceList('CreateSubscription', new Subscription(payload)) - return this.dataRequest() + this.setPayload(payload); + this.setServiceList('CreateSubscription', new Subscription(payload)); + return this.dataRequest(); } update(payload: ISubscription) { - this.setPayload(payload) - this.setServiceList('UpdateSubscription', new Subscription(payload)) - return this.dataRequest() + this.setPayload(payload); + this.setServiceList('UpdateSubscription', new Subscription(payload)); + return this.dataRequest(); } createCombined(payload: ISubscription) { - this.setPayload(payload) - this.setServiceList('CreateCombinedSubscription', new Subscription(payload)) - return this.dataRequest() + this.setPayload(payload); + this.setServiceList('CreateCombinedSubscription', new Subscription(payload)); + return this.dataRequest(); } updateCombined(payload: ISubscription) { - this.setPayload(payload) - this.setServiceList('UpdateCombinedSubscription', new Subscription(payload)) - return this.dataRequest() + this.setPayload(payload); + this.setServiceList('UpdateCombinedSubscription', new Subscription(payload)); + return this.dataRequest(); } stop(payload: { subscriptionGuid: string }) { - this.setServiceList('StopSubscription', new Subscription(payload)) - return this.dataRequest() + this.setServiceList('StopSubscription', new Subscription(payload)); + return this.dataRequest(); } info(payload: { subscriptionGuid: string }) { - this.setServiceList('StopSubscription', new Subscription(payload)) - return this.dataRequest() + this.setServiceList('StopSubscription', new Subscription(payload)); + return this.dataRequest(); } deletePaymentConfig(payload: { subscriptionGuid: string }) { - this.setServiceList('DeletePaymentConfiguration', new Subscription(payload)) - return this.dataRequest() + this.setServiceList('DeletePaymentConfiguration', new Subscription(payload)); + return this.dataRequest(); } pause(payload: { subscriptionGuid: string; resumeDate: string }) { - this.setServiceList('PauseSubscription', new ResumeSubscription(payload)) - return this.dataRequest() + this.setServiceList('PauseSubscription', new ResumeSubscription(payload)); + return this.dataRequest(); } resume(payload: { subscriptionGuid: string; resumeDate: string }) { - this.setServiceList('ResumeSubscription', new ResumeSubscription(payload)) - return this.dataRequest() + this.setServiceList('ResumeSubscription', new ResumeSubscription(payload)); + return this.dataRequest(); } } diff --git a/src/PaymentMethods/Surepay/Models/Verify.ts b/src/PaymentMethods/Surepay/Models/Verify.ts index 76c6df9a..60b32e8e 100644 --- a/src/PaymentMethods/Surepay/Models/Verify.ts +++ b/src/PaymentMethods/Surepay/Models/Verify.ts @@ -1,5 +1,5 @@ -import { IPaymentRequest } from '../../../Models/IRequest' +import { IPaymentRequest } from '../../../Models/IRequest'; export interface IVerify extends IPaymentRequest { - customeraccountname: string + customeraccountname: string; } diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 0242da50..8cf863d4 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,14 +1,11 @@ -import PaymentMethod from '../PaymentMethod' -import { IVerify } from './Models/Verify' -import {Parameter} from "../../Models/IParameters"; +import PaymentMethod from '../PaymentMethod'; +import { IVerify } from './Models/Verify'; +import { Parameter } from '../../Models/IParameters'; export default class Surepay extends PaymentMethod { - protected _paymentName = 'Surepay' + protected _paymentName = 'Surepay'; verify(payload: IVerify) { - const serviceParameter = new Parameter({name: 'customeraccountname', value: payload.customeraccountname}) - this.setServiceList( - 'Verify', - [serviceParameter] - ) - return this.dataRequest(payload) + const serviceParameter = new Parameter({ name: 'customeraccountname', value: payload.customeraccountname }); + this.setServiceList('Verify', [serviceParameter]); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 93cb09f4..1d6c7873 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -1,23 +1,23 @@ -import PaymentMethod from '../PaymentMethod' -import IRequest from '../../Models/IRequest' +import PaymentMethod from '../PaymentMethod'; +import IRequest from '../../Models/IRequest'; -type key = Required> +type key = Required>; export default class Thunes extends PaymentMethod { - protected _paymentName = 'Thunes' + protected _paymentName = 'Thunes'; getStatus(payload: key) { - this.setServiceList('getStatus') - return this.dataRequest(payload) + this.setServiceList('getStatus'); + return this.dataRequest(payload); } capture(payload: IRequest & key) { - this.setServiceList('Capture') - return this.transactionRequest(payload) + this.setServiceList('Capture'); + return this.transactionRequest(payload); } authorize(payload: IRequest) { - this.setServiceList('Authorize') - return this.dataRequest(payload) + this.setServiceList('Authorize'); + return this.dataRequest(payload); } cancel(payload: key) { - this.setServiceList('Cancel') - return this.dataRequest(payload) + this.setServiceList('Cancel'); + return this.dataRequest(payload); } } diff --git a/src/PaymentMethods/Tinka/Models/Address.ts b/src/PaymentMethods/Tinka/Models/Address.ts index ab268f40..b2d1eac5 100644 --- a/src/PaymentMethods/Tinka/Models/Address.ts +++ b/src/PaymentMethods/Tinka/Models/Address.ts @@ -1,13 +1,13 @@ -import {Address} from "../../../Models/Interfaces/IAddress"; +import { Address } from '../../../Models/Interfaces/IAddress'; export class TinkaAddress extends Address { set houseNumber(value: string) { - this.set('streetNumber', value) + this.set('streetNumber', value); } set houseNumberAdditional(value: string) { - this.set('streetNumberAdditional', value) + this.set('streetNumberAdditional', value); } set zipcode(value: string) { - this.set('postalCode', value) + this.set('postalCode', value); } } diff --git a/src/PaymentMethods/Tinka/Models/Article.ts b/src/PaymentMethods/Tinka/Models/Article.ts index b6b75d05..6a2e1a73 100644 --- a/src/PaymentMethods/Tinka/Models/Article.ts +++ b/src/PaymentMethods/Tinka/Models/Article.ts @@ -1,17 +1,17 @@ -import IArticle, {Article} from "../../../Models/Interfaces/IArticle"; +import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; export interface ITinkaArticle extends IArticle { - color?: string - size?: string + color?: string; + size?: string; } export class TinkaArticle extends Article { set color(value: string) { - this.set('color', value) + this.set('color', value); } set price(value: number) { - this.set('unitGrossPrice', value) + this.set('unitGrossPrice', value); } set size(value: string) { - this.set('size', value) + this.set('size', value); } } diff --git a/src/PaymentMethods/Tinka/Models/Pay.ts b/src/PaymentMethods/Tinka/Models/Pay.ts index fcdd7bde..91fedf53 100644 --- a/src/PaymentMethods/Tinka/Models/Pay.ts +++ b/src/PaymentMethods/Tinka/Models/Pay.ts @@ -1,24 +1,24 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import {ITinkaArticle, TinkaArticle} from './Article' -import {ServiceParameter} from "../../../Models/ServiceParameters"; -import {ICustomer} from "../../../Models/Interfaces/ICustomer"; -import {ITinkaPerson, TinkaPerson} from "./Person"; -import {Recipient} from "./Recipient"; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ITinkaArticle, TinkaArticle } from './Article'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { ITinkaPerson, TinkaPerson } from './Person'; +import { Recipient } from './Recipient'; export interface IPay extends IPaymentRequest { - paymentMethod: string - deliveryMethod: string - deliveryDate?: string - articles: Partial[] - customer: ITinkaPerson - shipping?:ICustomer - billing:ICustomer + paymentMethod: string; + deliveryMethod: string; + deliveryDate?: string; + articles: Partial[]; + customer: ITinkaPerson; + shipping?: ICustomer; + billing: ICustomer; } export class Pay extends ServiceParameter { - protected getGroups(){ + protected getGroups() { return super.getGroups({ - 'Articles':'Article', - 'Shipping':'ShippingCustomer', - 'Billing':'BillingCustomer', + Articles: 'Article', + Shipping: 'ShippingCustomer', + Billing: 'BillingCustomer', }); } protected getCountable() { @@ -26,27 +26,30 @@ export class Pay extends ServiceParameter { } set paymentMethod(value: string) { - this.set('paymentMethod', value) + this.set('paymentMethod', value); } set deliveryMethod(value: string) { - this.set('deliveryMethod', value) + this.set('deliveryMethod', value); } set deliveryDate(value: string) { - this.set('deliveryDate', value) + this.set('deliveryDate', value); } set articles(value: ITinkaArticle[]) { - this.set('articles', value.map(article => new TinkaArticle(article))) + this.set( + 'articles', + value.map((article) => new TinkaArticle(article)) + ); } set customer(value: ITinkaPerson) { - this.set('customer', new TinkaPerson(value)) + this.set('customer', new TinkaPerson(value)); } set shipping(value: ICustomer) { - this.set('shipping', new Recipient(value)) + this.set('shipping', new Recipient(value)); } set billing(value: ICustomer) { - this.set('billing', new Recipient(value)) + this.set('billing', new Recipient(value)); if (this.shipping === undefined) { - this.shipping = value + this.shipping = value; } } } diff --git a/src/PaymentMethods/Tinka/Models/Person.ts b/src/PaymentMethods/Tinka/Models/Person.ts index c5880576..3dd65653 100644 --- a/src/PaymentMethods/Tinka/Models/Person.ts +++ b/src/PaymentMethods/Tinka/Models/Person.ts @@ -1,18 +1,18 @@ -import {Person} from "../../../Models/Interfaces/IRecipient"; -import Gender from "../../../Constants/Gender"; +import { Person } from '../../../Models/Interfaces/IRecipient'; +import Gender from '../../../Constants/Gender'; export interface ITinkaPerson { - gender : Gender, - firstName: string, - lastName : string, - initials : string, - birthDate : string, + gender: Gender; + firstName: string; + lastName: string; + initials: string; + birthDate: string; } export class TinkaPerson extends Person { set lastNamePrefix(value: string) { - this.set('prefixLastName', value) + this.set('prefixLastName', value); } set birthDate(value: string) { - this.set('dateOfBirth', value) + this.set('dateOfBirth', value); } } diff --git a/src/PaymentMethods/Tinka/Models/Phone.ts b/src/PaymentMethods/Tinka/Models/Phone.ts index 8fe46c5b..ada84db2 100644 --- a/src/PaymentMethods/Tinka/Models/Phone.ts +++ b/src/PaymentMethods/Tinka/Models/Phone.ts @@ -1,7 +1,7 @@ -import {Phone} from "../../../Models/Interfaces/IPhone"; +import { Phone } from '../../../Models/Interfaces/IPhone'; export class TinkaPhone extends Phone { set mobile(value: string) { - this.set('phone', value) + this.set('phone', value); } } diff --git a/src/PaymentMethods/Tinka/Models/Recipient.ts b/src/PaymentMethods/Tinka/Models/Recipient.ts index dab47a4f..9ca15255 100644 --- a/src/PaymentMethods/Tinka/Models/Recipient.ts +++ b/src/PaymentMethods/Tinka/Models/Recipient.ts @@ -1,19 +1,19 @@ -import {Customer} from "../../../Models/Interfaces/ICustomer"; -import IAddress from "../../../Models/Interfaces/IAddress"; -import {TinkaAddress} from "./Address"; -import IPhone from "../../../Models/Interfaces/IPhone"; -import {TinkaPhone} from "./Phone"; -import {TinkaPerson} from "./Person"; -import {IPerson} from "../../../Models/Interfaces/IRecipient"; +import { Customer } from '../../../Models/Interfaces/ICustomer'; +import IAddress from '../../../Models/Interfaces/IAddress'; +import { TinkaAddress } from './Address'; +import IPhone from '../../../Models/Interfaces/IPhone'; +import { TinkaPhone } from './Phone'; +import { TinkaPerson } from './Person'; +import { IPerson } from '../../../Models/Interfaces/IRecipient'; export class Recipient extends Customer { set address(value: IAddress) { - this.set('address', new TinkaAddress(value)) + this.set('address', new TinkaAddress(value)); } set phone(value: IPhone) { - this.set('phone', new TinkaPhone(value)) + this.set('phone', new TinkaPhone(value)); } set recipient(value: IPerson) { - this.set('recipient', new TinkaPerson(value)) + this.set('recipient', new TinkaPerson(value)); } } diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index 818a8847..fc64fb5e 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' -import {IPay, Pay} from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; +import { IPay, Pay } from './Models/Pay'; export default class Tinka extends PayablePaymentMethod { - protected _paymentName = 'Tinka' + protected _paymentName = 'Tinka'; pay(payload: IPay) { - return super.pay(payload,new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/Trustly/Models/Customer.ts b/src/PaymentMethods/Trustly/Models/Customer.ts index e9ed2a09..f4627b59 100644 --- a/src/PaymentMethods/Trustly/Models/Customer.ts +++ b/src/PaymentMethods/Trustly/Models/Customer.ts @@ -1,10 +1,10 @@ -import {Model} from "../../../Models/Model"; +import { Model } from '../../../Models/Model'; export class Customer extends Model { set firstName(value: string) { - this.set('CustomerFirstName', value) + this.set('CustomerFirstName', value); } set lastName(value: string) { - this.set('customerLastName', value) + this.set('customerLastName', value); } } diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index cc674f30..ffd5c8c6 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -1,17 +1,17 @@ -import { IPaymentRequest } from '../../../Models/IRequest' -import {ServiceParameter} from "../../../Models/ServiceParameters"; -import {IPerson} from "../../../Models/Interfaces/IRecipient"; -import {Customer} from "./Customer"; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { Customer } from './Customer'; export interface IPay extends IPaymentRequest { - customer:Partial - country?:'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB' + customer: Partial; + country?: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB'; } export class Pay extends ServiceParameter { set customer(value: Partial) { - this.set('customer', new Customer(value)) + this.set('customer', new Customer(value)); } set country(value: string) { - this.set('country', value) + this.set('country', value); } } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index c36bb403..997fa183 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' -import {IPay, Pay} from './Models/Pay' +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; +import { IPay, Pay } from './Models/Pay'; export default class Trustly extends PayablePaymentMethod { - protected _paymentName = 'Trustly' + protected _paymentName = 'Trustly'; pay(payload: IPay) { - return super.pay(payload,new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/PaymentMethods/WeChatPay/Models/Pay.ts b/src/PaymentMethods/WeChatPay/Models/Pay.ts index a24c6917..15e43fb4 100644 --- a/src/PaymentMethods/WeChatPay/Models/Pay.ts +++ b/src/PaymentMethods/WeChatPay/Models/Pay.ts @@ -1,11 +1,11 @@ -import {IPaymentRequest} from "../../../Models/IRequest"; -import {ServiceParameter} from "../../../Models/ServiceParameters"; +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { - locale?: string + locale?: string; } export class Pay extends ServiceParameter { set locale(value: string) { - this.set('locale', value) + this.set('locale', value); } } diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 05f700a8..b318ec65 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,13 +1,13 @@ -import PayablePaymentMethod from '../PayablePaymentMethod' -import { IRefundRequest } from '../../Models/IRequest' -import {IPay, Pay} from "./Models/Pay"; +import PayablePaymentMethod from '../PayablePaymentMethod'; +import { IRefundRequest } from '../../Models/IRequest'; +import { IPay, Pay } from './Models/Pay'; export default class WeChatPay extends PayablePaymentMethod { - protected _paymentName = 'WeChatPay' + protected _paymentName = 'WeChatPay'; pay(payload: IPay) { - return super.pay(payload,new Pay(payload)) + return super.pay(payload, new Pay(payload)); } refund(payload: IRefundRequest) { - return super.refund(payload) + return super.refund(payload); } } diff --git a/src/Request/DataModels.ts b/src/Request/DataModels.ts index 93709518..7c0a7dbe 100644 --- a/src/Request/DataModels.ts +++ b/src/Request/DataModels.ts @@ -1,114 +1,108 @@ -import IRequest from '../Models/IRequest' -import { Model } from '../Models/Model' -import { ClientIP } from '../Constants/IPProtocolVersion' -import { DataFormatter } from '../Utils/Functions' -import { ServiceCode } from '../Utils/MethodTypes' -import { IService, ServiceList } from '../Models/IServiceList' -import { IAdditionalParameters } from '../Models/IParameters' +import IRequest from '../Models/IRequest'; +import { Model } from '../Models/Model'; +import { ClientIP } from '../Constants/IPProtocolVersion'; +import { DataFormatter } from '../Utils/Functions'; +import { ServiceCode } from '../Utils/MethodTypes'; +import { IService, ServiceList } from '../Models/IServiceList'; +import { IAdditionalParameters } from '../Models/IParameters'; export class TransactionData extends Model implements IRequest { constructor(data?: IRequest) { - super(data) + super(data); } set clientUserAgent(value: string) { - this.set('clientUserAgent', value) + this.set('clientUserAgent', value); } set order(order: string) { - this.set('order', order) + this.set('order', order); } set invoice(invoice: string) { - this.set('invoice', invoice) + this.set('invoice', invoice); } set description(description: string) { - this.set('description', description) + this.set('description', description); } set amountCredit(amountCredit: number) { - this.set('amountCredit', amountCredit) + this.set('amountCredit', amountCredit); } set amountDebit(amountDebit: number) { - this.set('amountDebit', amountDebit) + this.set('amountDebit', amountDebit); } set currency(currency: string) { - this.set('currency', currency) + this.set('currency', currency); } set clientIP(ipAddress: string) { - this.set('clientIP', new ClientIP(ipAddress)) + this.set('clientIP', new ClientIP(ipAddress)); } set additionalParameters(value: IAdditionalParameters) { this.set('additionalParameters', { - AdditionalParameter: DataFormatter.parametersMap(value) - }) + AdditionalParameter: DataFormatter.parametersMap(value), + }); } set customParameters(value: IAdditionalParameters) { this.set('customParameters', { - List: DataFormatter.parametersMap(value) - }) + List: DataFormatter.parametersMap(value), + }); } set pushURL(pushURL: string) { - this.set('pushURL', pushURL) + this.set('pushURL', pushURL); } set continueOnIncomplete(value: boolean) { - this.set('continueOnIncomplete', value ? 1 : 0) + this.set('continueOnIncomplete', value ? 1 : 0); } set culture(value: string) { - this.set('culture', value) + this.set('culture', value); } set originalTransactionKey(value: string) { - this.set('originalTransactionKey', value) + this.set('originalTransactionKey', value); } set originalTransactionReference(value: { type: string; reference: string }) { - this.set('originalTransactionReference', value) + this.set('originalTransactionReference', value); } set pushURLFailure(value: string) { - this.set('pushURLFailure', value) + this.set('pushURLFailure', value); } set returnURL(value: string) { - this.set('returnURL', value) + this.set('returnURL', value); } set returnURLCancel(value: string) { - this.set('returnURLCancel', value) + this.set('returnURLCancel', value); } set returnURLError(value: string) { - this.set('returnURLError', value) + this.set('returnURLError', value); } set returnURLReject(value: string) { - this.set('returnURLReject', value) + this.set('returnURLReject', value); } set servicesExcludedForClient(services: ServiceCode[] | string) { - this.set( - 'servicesExcludedForClient', - Array.isArray(services) ? services?.join(',') : services - ) + this.set('servicesExcludedForClient', Array.isArray(services) ? services?.join(',') : services); } get servicesSelectableByClient() { - return '' + return ''; } set servicesSelectableByClient(services: ServiceCode[] | string) { - this.set( - 'servicesSelectableByClient', - Array.isArray(services) ? services?.join(',') : services - ) + this.set('servicesSelectableByClient', Array.isArray(services) ? services?.join(',') : services); } set startRecurrent(value: boolean) { - this.set('startRecurrent', value) + this.set('startRecurrent', value); } - getServiceList(): ServiceList { - return this.get('services') + getServiceList(): ServiceList | undefined { + return this.get('services'); } - setServiceList(services: ServiceList) { - return this.set('services', services) + setServiceList(services: ServiceList | undefined) { + return this.set('services', services); } } export class DataRequestData extends TransactionData { set additionalParameters(parameters: IAdditionalParameters) { this.set('additionalParameters', { - List: DataFormatter.parametersMap(parameters) - }) + List: DataFormatter.parametersMap(parameters), + }); } } export class SpecificationRequestData extends Model { constructor(data?: IService[]) { - super({ services: data }) + super({ services: data }); } set services(data: IService[]) { this.set( @@ -116,9 +110,9 @@ export class SpecificationRequestData extends Model { data.map((service) => { return { Name: service.name, - Version: service.version - } + Version: service.version, + }; }) - ) + ); } } diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index f35a96fb..e00f96f9 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,17 +1,17 @@ -import { OutgoingHttpHeaders } from 'http' +import { OutgoingHttpHeaders } from 'http'; export type RequestHeaders = { - 'Content-type'?: string - Accept?: string - Culture?: string - Authorization?: string - Software?: string -} & OutgoingHttpHeaders + 'Content-type'?: string; + Accept?: string; + Culture?: string; + Authorization?: string; + Software?: string; +} & OutgoingHttpHeaders; export default class Headers { - private _headers: RequestHeaders = this.getDefaultHeaders() + private _headers: RequestHeaders = this.getDefaultHeaders(); get headers(): RequestHeaders { - return this._headers + return this._headers; } protected getDefaultHeaders() { return { @@ -19,22 +19,23 @@ export default class Headers { Accept: 'application/json', Culture: 'nl-NL', Authorization: '', - Channel:'Web', - Software: JSON.stringify({ + Channel: 'Web', + Software: JSON.stringify({ PlatformName: 'Node SDK', PlatformVersion: '1.0', ModuleSupplier: 'Buckaroo', ModuleName: 'BuckarooPayments', ModuleVersion: '1.0', - }) - } + }), + }; } - setSoftwareHeader(value: { - platformName?: string - platformVersion?: string - moduleSupplier?: string - moduleName?: string - moduleVersion?: string + setSoftwareHeader( + value: { + platformName?: string; + platformVersion?: string; + moduleSupplier?: string; + moduleName?: string; + moduleVersion?: string; } = {} ): this { this._headers.Software = JSON.stringify({ @@ -42,20 +43,20 @@ export default class Headers { PlatformVersion: value.platformVersion || '1.0', ModuleSupplier: value.moduleSupplier || 'Buckaroo', ModuleName: value.moduleName || 'BuckarooPayments', - ModuleVersion: value.moduleVersion || '1.0' - }) - return this + ModuleVersion: value.moduleVersion || '1.0', + }); + return this; } setHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { - this._headers[key] = headers[key] - }) - return this + this._headers[key] = headers[key]; + }); + return this; } removeHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { - delete this._headers[key] - }) - return this + delete this._headers[key]; + }); + return this; } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 52b6fc8d..9f6eec9e 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -1,91 +1,86 @@ -import { ICredentials } from '../Utils/Types' -import md5 from 'crypto-js/md5' -import hmacSHA256 from 'crypto-js/hmac-sha256' -import Base64 from 'crypto-js/enc-base64' -import crypto from 'crypto' +import { ICredentials } from '../Utils/Types'; +import md5 from 'crypto-js/md5'; +import hmacSHA256 from 'crypto-js/hmac-sha256'; +import Base64 from 'crypto-js/enc-base64'; +import crypto from 'crypto'; export class Hmac { - protected _data?: object - protected _url?: URL - protected _nonce?: string - protected _time?: string - protected _method?: string + protected _data?: object; + protected _url?: URL; + protected _nonce?: string; + protected _time?: string; + protected _method?: string; get nonce(): string { - return this._nonce || 'nonce_' + Math.floor(Math.random() * 9999999 + 1) + return this._nonce || 'nonce_' + Math.floor(Math.random() * 9999999 + 1); } set nonce(nonce: string) { - this._nonce = nonce + this._nonce = nonce; } get time(): string { - return this._time || String(Math.round(Date.now() / 1000)) + return this._time || String(Math.round(Date.now() / 1000)); } set time(time: string) { - this._time = time + this._time = time; } get method(): string { - return this._method || 'POST' + return this._method || 'POST'; } set method(method: string) { - this._method = method + this._method = method; } get url(): string | undefined { - if (this._url) - return encodeURIComponent( - this._url.href - .replace(this._url.protocol, '') - .replace(/^[^:/.]*[:/]+/i, '') - .replace(/(^\w+:|^)\/\//, '') - ).toLowerCase() + return this._url + ? encodeURIComponent( + this._url.href + .replace(this._url.protocol, '') + .replace(/^[^:/.]*[:/]+/i, '') + .replace(/(^\w+:|^)\/\//, '') + ).toLowerCase() + : undefined; } set url(url: string | undefined) { - if (url) this._url = new URL(url) + if (url) this._url = new URL(url); } get data(): string { - return this._data ? JSON.stringify(this._data) : '' + return this._data ? JSON.stringify(this._data) : ''; } set data(data: string) { try { - let jsonData = JSON.parse(data) + let jsonData = JSON.parse(data); if (Object.keys(jsonData).length > 0) { - this._data = jsonData + this._data = jsonData; } } catch (e) {} } get base64Data() { if (this._data) { - return Base64.stringify(md5(this.data)) + return Base64.stringify(md5(this.data)); } - return '' + return ''; } generate(credentials: ICredentials, nonce?: string, time?: string): string { - this._nonce = nonce || this.nonce - this._time = time || this.time - let hashString = this.getHashString(credentials.websiteKey) - let hashData = this.hashData(hashString, credentials.secretKey) - return `hmac ${credentials.websiteKey}:${hashData}:${this._nonce}:${this._time}` + this._nonce = nonce || this.nonce; + this._time = time || this.time; + let hashString = this.getHashString(credentials.websiteKey); + let hashData = this.hashData(hashString, credentials.secretKey); + return `hmac ${credentials.websiteKey}:${hashData}:${this._nonce}:${this._time}`; } - validate( - credentials: ICredentials, - authHeader: string, - url: string, - data: string, - method: string - ): boolean { - let header = authHeader.split(':') - let providedHash = header[1] - this.nonce = header[2] - this.time = header[3] - this.method = method - this.url = url - this.data = data - let hash = this.hashData(this.getHashString(credentials.websiteKey), credentials.secretKey) - return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(providedHash)) + validate(credentials: ICredentials, authHeader: string, url: string, data: string, method: string): boolean { + let header = authHeader.split(':'); + let providedHash = header[1]; + this.nonce = header[2]; + this.time = header[3]; + this.method = method; + this.url = url; + this.data = data; + let hash = this.hashData(this.getHashString(credentials.websiteKey), credentials.secretKey); + return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(providedHash)); } protected getHashString(websiteKey: string) { - return websiteKey + this.method + this.url + this.time + this.nonce + this.base64Data + return websiteKey + this.method + this.url + this.time + this.nonce + this.base64Data; } protected hashData(hashString: string, secretKey: string) { - return hmacSHA256(hashString, secretKey).toString(Base64) + return hmacSHA256(hashString, secretKey).toString(Base64); } } diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 78dba1ca..5b80ded3 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,58 +1,52 @@ -import { Agent, RequestOptions } from 'https' -import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse' -import * as https from "https"; +import { Agent, RequestOptions } from 'https'; +import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; +import * as https from 'https'; const defaultAgent = new Agent({ keepAlive: true, - keepAliveMsecs: 10000 -}) + keepAliveMsecs: 10000, +}); export default class HttpsClient { - protected _options: RequestOptions = {} + protected _options: RequestOptions = {}; constructor(agent?: Agent) { - this._options.timeout = 10000 - this._options.agent = agent || defaultAgent - this._options.sessionTimeout = 30000 - + this._options.timeout = 10000; + this._options.agent = agent || defaultAgent; + this._options.sessionTimeout = 30000; } - public sendRequest( - url: URL, - data: string, - options: RequestOptions = {}, - responseClass: R - ): Promise> { + public sendRequest(url: URL, data: string, options: RequestOptions = {}, responseClass: R): Promise> { return new Promise((resolve, reject) => { const req = https.request(url, { ...this._options, - ...options - }) + ...options, + }); req.on('error', (err) => { - reject(err) - }) + reject(err); + }); req.on('timeout', () => { - req.destroy() - }) + req.destroy(); + }); req.on('response', (res) => { - let response: any[] = [] + let response: any[] = []; res.on('data', (chunk) => { - response.push(chunk) - }) + response.push(chunk); + }); res.on('end', () => { try { - resolve(new responseClass(res, Buffer.concat(response).toString()) as InstanceType) + resolve(new responseClass(res, Buffer.concat(response).toString()) as InstanceType); } catch (e) { try { - reject(Buffer.concat(response).toString()) + reject(Buffer.concat(response).toString()); } catch (e) { - reject(e) + reject(e); } } - }) - }) + }); + }); if (data) { - req.write(data) + req.write(data); } - req.end() - return req - }) + req.end(); + return req; + }); } } diff --git a/src/Request/Request.ts b/src/Request/Request.ts index 3ba09df1..8e551e2d 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -1,127 +1,90 @@ -import Headers from './Headers' -import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse' -import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels' -import Buckaroo from '../index' -import Endpoints, { RequestTypes } from '../Constants/Endpoints' -import { TransactionResponse } from '../Models/Response/TransactionResponse' -import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse' -import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse' -import HttpMethods from '../Constants/HttpMethods' -import { RequestOptions } from 'https' -import PaymentMethod from '../PaymentMethods/PaymentMethod' -import { ICredentials } from '../Utils/Types' -import { Hmac } from './Hmac' -import { MethodFromServiceCode, ServiceCode } from '../Utils/MethodTypes' -import { IService } from '../Models/IServiceList' +import Headers from './Headers'; +import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; +import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels'; +import Buckaroo from '../index'; +import Endpoints, { RequestTypes } from '../Constants/Endpoints'; +import { TransactionResponse } from '../Models/Response/TransactionResponse'; +import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; +import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; +import HttpMethods from '../Constants/HttpMethods'; +import { RequestOptions } from 'https'; +import { ICredentials } from '../Utils/Types'; +import { Hmac } from './Hmac'; +import { IService } from '../Models/IServiceList'; +import IRequest from '../Models/IRequest'; -export default class Request< - HttpResponse extends HttpResponseConstructor = HttpResponseConstructor, - RequestData extends object | undefined = undefined -> extends Headers { - protected _data?: object | object[] | undefined - protected _httpMethod: HttpMethods - protected _path?: string - protected _responseHandler?: HttpResponseConstructor - constructor( - path?: string, - method?: HttpMethods, - data?: RequestData, - responseHandler?: HttpResponse - ) { - super() - this._path = path - this._data = data - this._httpMethod = method || HttpMethods.GET - this._responseHandler = responseHandler +export default class Request extends Headers { + protected _data?: object | object[] | undefined; + protected _httpMethod: HttpMethods; + protected _path?: string; + protected _responseHandler?: HttpResponseConstructor; + constructor(path?: string, method?: HttpMethods, data?: RequestData, responseHandler?: HttpResponse) { + super(); + this._path = path; + this._data = data; + this._httpMethod = method || HttpMethods.GET; + this._responseHandler = responseHandler; } get httpMethod(): HttpMethods { - return this._httpMethod + return this._httpMethod; } get data(): RequestData { - return this._data as any + return this._data as any; } get url(): URL { - return new URL(Endpoints[Buckaroo.Client.config.mode] + (this._path || '')) + return new URL(Endpoints[Buckaroo.Client.config.mode] + (this._path || '')); } protected get responseHandler(): HttpResponse { - return (this._responseHandler || HttpClientResponse) as HttpResponse + return (this._responseHandler || HttpClientResponse) as HttpResponse; } - protected setAuthorizationHeader( - data: string, - credentials: ICredentials = Buckaroo.Client.credentials - ): this { - let hmac = new Hmac() - hmac.data = data - hmac.method = this.httpMethod - hmac.url = this.url.toString() - this.headers.Authorization = hmac.generate(credentials) - return this + protected setAuthorizationHeader(data: string, credentials: ICredentials = Buckaroo.Client.credentials): this { + let hmac = new Hmac(); + hmac.data = data; + hmac.method = this.httpMethod; + hmac.url = this.url.toString(); + this.headers.Authorization = hmac.generate(credentials); + return this; } request(options: RequestOptions = {}) { - let data = this._httpMethod === HttpMethods.GET ? '' : JSON.stringify(this._data) - this.setAuthorizationHeader(data) + let data = this._httpMethod === HttpMethods.GET ? '' : JSON.stringify(this._data); + this.setAuthorizationHeader(data); return Buckaroo.Client.httpClient.sendRequest( this.url, data, { method: this._httpMethod, headers: this.headers, - ...options + ...options, }, this.responseHandler - ) + ); } - static Transaction(data?: TransactionData) { - return new Request(RequestTypes.Transaction, HttpMethods.POST, data, TransactionResponse) + static Transaction(payload?: IRequest) { + return new Request(RequestTypes.Transaction, HttpMethods.POST, new TransactionData(payload), TransactionResponse); } - static DataRequest(data?: DataRequestData) { - return new Request(RequestTypes.Data, HttpMethods.POST, data, TransactionResponse) + static DataRequest(payload?: IRequest) { + return new Request(RequestTypes.Data, HttpMethods.POST, new DataRequestData(payload), TransactionResponse); } - static Specification( - type: RequestTypes.Data | RequestTypes.Transaction, - data: IService[] | IService - ) { + static Specification(type: RequestTypes.Data | RequestTypes.Transaction, data: IService[] | IService) { if (Array.isArray(data)) { - return new Request( - type + `/Specifications`, - HttpMethods.POST, - new SpecificationRequestData(data), - SpecificationRequestResponse - ) + return new Request(type + `/Specifications`, HttpMethods.POST, new SpecificationRequestData(data), SpecificationRequestResponse); } - return new Request( - type + `/Specification/${data?.name}?serviceVersion=${data?.version}`, - HttpMethods.GET, - undefined, - SpecificationRequestResponse - ) + return new Request(type + `/Specification/${data?.name}?serviceVersion=${data?.version}`, HttpMethods.GET, undefined, SpecificationRequestResponse); } - static BatchTransaction(data: TransactionData[] = []) { + static BatchTransaction(payload: IRequest[] = []) { return new Request( RequestTypes.BatchTransaction, HttpMethods.POST, - data, + payload.map((data) => new TransactionData(data)), BatchRequestResponse - ) + ); } - static BatchDataRequest(data: DataRequestData[] = []) { - return new Request(RequestTypes.BatchData, HttpMethods.POST, data, BatchRequestResponse) - } - combine( - method: Method - ): Method extends ServiceCode ? MethodFromServiceCode : Method - combine(request: R): this - combine(data): PaymentMethod | this { - if (!(data instanceof Request)) { - let paymentMethod: PaymentMethod = - data instanceof PaymentMethod ? data : Buckaroo.Client.method(data) - if (this.data instanceof TransactionData) { - paymentMethod.combine(this.data) - } - return paymentMethod - } else { - this._data = { ...this._data, ...data.data } - } - return this + static BatchDataRequest(payload: IRequest[] = []) { + return new Request( + RequestTypes.BatchData, + HttpMethods.POST, + payload.map((data) => new DataRequestData(data)), + BatchRequestResponse + ); } } diff --git a/src/Services/TransactionService.ts b/src/Services/TransactionService.ts index c4e5140c..70653f3a 100644 --- a/src/Services/TransactionService.ts +++ b/src/Services/TransactionService.ts @@ -1,31 +1,20 @@ -import Request from '../Request/Request' -import HttpMethods from '../Constants/HttpMethods' -import { TransactionResponse } from '../Models/Response/TransactionResponse' -import { RequestTypes } from '../Constants/Endpoints' +import Request from '../Request/Request'; +import HttpMethods from '../Constants/HttpMethods'; +import { TransactionResponse } from '../Models/Response/TransactionResponse'; +import { RequestTypes } from '../Constants/Endpoints'; export default class TransactionService { - private readonly _key: string + private readonly _key: string; constructor(key: string) { - this._key = key + this._key = key; } status() { - return new Request( - `${RequestTypes.Transaction}/Status/${this._key}`, - HttpMethods.GET, - undefined, - TransactionResponse - ).request() + return new Request(`${RequestTypes.Transaction}/Status/${this._key}`, HttpMethods.GET, undefined, TransactionResponse).request(); } refundInfo() { - return new Request( - `${RequestTypes.Transaction}/RefundInfo/${this._key}`, - HttpMethods.GET - ).request() + return new Request(`${RequestTypes.Transaction}/RefundInfo/${this._key}`, HttpMethods.GET).request(); } cancelInfo() { - return new Request( - `${RequestTypes.Transaction}/Cancel/${this._key}`, - HttpMethods.GET - ).request() + return new Request(`${RequestTypes.Transaction}/Cancel/${this._key}`, HttpMethods.GET).request(); } } diff --git a/src/Utils/Functions.ts b/src/Utils/Functions.ts index 1995cff0..0ee20f6f 100644 --- a/src/Utils/Functions.ts +++ b/src/Utils/Functions.ts @@ -1,46 +1,36 @@ -import { - IAdditionalParameters, - IFormattedParameter, - IParameter, - IServiceParameters, - ServiceParameterTypes -} from '../Models/IParameters' +import { IAdditionalParameters, IFormattedParameter, IParameter, IServiceParameters, ServiceParameterTypes } from '../Models/IParameters'; export function uniqid(prefix: string = '', random: boolean = false) { - const sec = Date.now() * 1000 + Math.random() * 1000 - const id = sec.toString(16).replace(/\./g, '').padEnd(14, '0') - return `${prefix}${id}${random ? `.${Math.trunc(Math.random() * 100000000)}` : ''}` + const sec = Date.now() * 1000 + Math.random() * 1000; + const id = sec.toString(16).replace(/\./g, '').padEnd(14, '0'); + return `${prefix}${id}${random ? `.${Math.trunc(Math.random() * 100000000)}` : ''}`; } export class Str { private static replace(search: string[], replace: string, subject: string): string { - let result: string = subject + let result: string = subject; for (let value of search) { - result = result.split(value).join(replace) + result = result.split(value).join(replace); } - return result + return result; } public static ucfirst(value: string): string { - return value.charAt(0).toUpperCase() + value.slice(1) + return value.charAt(0).toUpperCase() + value.slice(1); } public static lcfirst(value: string): string { - return value.charAt(0).toLowerCase() + value.slice(1) + return value.charAt(0).toLowerCase() + value.slice(1); } public static ciEquals(a: string, b: string) { - return a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0 + return a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0; } } export abstract class DataFormatter { - static parametersMap( - parameters: IAdditionalParameters, - index1 = 'Name', - index2 = 'Value' - ): IFormattedParameter[] { + static parametersMap(parameters: IAdditionalParameters, index1 = 'Name', index2 = 'Value'): IFormattedParameter[] { return Object.keys(parameters).map((key) => { return { [index1]: Str.ucfirst(key), - [index2]: parameters[key] - } - }) as any + [index2]: parameters[key], + }; + }) as any; } static serviceParametersMap( parameters: IServiceParameters | ServiceParameterTypes | undefined, @@ -50,53 +40,40 @@ export abstract class DataFormatter { parametersArray: IParameter[] = [] ): IParameter[] { if (groups[parameter.name]) { - parameter.groupType = Str.ucfirst(groups[parameter.name]) + parameter.groupType = Str.ucfirst(groups[parameter.name]); } if (parameters instanceof Array) { parameters.forEach((element) => { if (countable.includes(parameter.name)) { - parameter.groupID = (parameter.groupID || 0) + 1 + parameter.groupID = (parameter.groupID || 0) + 1; } - this.serviceParametersMap( - element, - groups, - countable, - { ...parameter }, - parametersArray - ) - }) + this.serviceParametersMap(element, groups, countable, { ...parameter }, parametersArray); + }); } else if (typeof parameters === 'object') { for (const key of Object.keys(parameters)) { - this.serviceParametersMap( - parameters[key], - groups, - countable, - { ...parameter, name: key }, - parametersArray - ) + this.serviceParametersMap(parameters[key], groups, countable, { ...parameter, name: key }, parametersArray); } } else if (parameters !== undefined) { - parametersArray.push({ ...parameter, value: parameters }) + parametersArray.push({ ...parameter, value: parameters }); } - return parametersArray + return parametersArray; } static parametersReverseMap(parameter: IFormattedParameter[] = []): IAdditionalParameters { return parameter.reduce((total, currentValue) => { - return { ...total, [Str.lcfirst(currentValue.name)]: currentValue.value } - }, {}) + return { ...total, [Str.lcfirst(currentValue.name)]: currentValue.value }; + }, {}); } } export function getIPAddress() { - const interfaces = require('os').networkInterfaces() + const interfaces = require('os').networkInterfaces(); for (const devName in interfaces) { - let iface = interfaces[devName] + let iface = interfaces[devName]; for (let i = 0; i < iface.length; i++) { - let alias = iface[i] - if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) - return alias.address + let alias = iface[i]; + if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) return alias.address; } } - return '0.0.0.0' + return '0.0.0.0'; } diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index efee4b52..4ac975da 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,44 +1,48 @@ -import type Ideal from '../PaymentMethods/Ideal' -import type Afterpay from '../PaymentMethods/Afterpay' -import type AfterpayDigiAccept from '../PaymentMethods/AfterpayDigiAccept' -import type ApplePay from '../PaymentMethods/ApplePay' -import type Bancontact from '../PaymentMethods/Bancontact' -import type Banktransfer from '../PaymentMethods/BankTransfer' -import type Belfius from '../PaymentMethods/Belfius' -import type Billink from '../PaymentMethods/Billink' -import type BuckarooVoucher from '../PaymentMethods/BuckarooVoucher' -import type BuckarooWallet from '../PaymentMethods/BuckarooWallet' -import type CreditCard from '../PaymentMethods/CreditCard' -import type CreditClick from '../PaymentMethods/CreditClick' -import type CreditManagement from '../PaymentMethods/CreditManagement' -import type Emandates from '../PaymentMethods/Emandates' -import type EPS from '../PaymentMethods/EPS' -import type GiftCard from '../PaymentMethods/GiftCard' -import type Giropay from '../PaymentMethods/Giropay' -import type IdealQr from '../PaymentMethods/IdealQR' -import type Idin from '../PaymentMethods/Idin' -import type In3Old from '../PaymentMethods/In3Old' -import type KBC from '../PaymentMethods/KBC' -import type Klarna from '../PaymentMethods/Klarna' -import type KlarnaKp from '../PaymentMethods/KlarnaKP' -import type Marketplaces from '../PaymentMethods/Marketplaces' -import type Payconiq from '../PaymentMethods/Payconiq' -import type PayByBank from '../PaymentMethods/PayByBank' -import type Paypal from '../PaymentMethods/Paypal' -import type PayPerEmail from '../PaymentMethods/PayPerEmail' -import type PiM from '../PaymentMethods/PiM' -import type PointOfSale from '../PaymentMethods/PointOfSale' -import type Przelewy24 from '../PaymentMethods/Przelewy24' -import type SEPA from '../PaymentMethods/SEPA' -import type Sofort from '../PaymentMethods/Sofort' -import type Subscriptions from '../PaymentMethods/Subscriptions' -import type Surepay from '../PaymentMethods/Surepay' -import type Thunes from '../PaymentMethods/Thunes' -import type Tinka from '../PaymentMethods/Tinka' -import type Alipay from '../PaymentMethods/Alipay' -import type Trustly from '../PaymentMethods/Trustly' -import type Wechatpay from '../PaymentMethods/WeChatPay' -import type In3 from '../PaymentMethods/In3' +import type Ideal from '../PaymentMethods/Ideal'; +import type Afterpay from '../PaymentMethods/Afterpay'; +import type AfterpayDigiAccept from '../PaymentMethods/AfterpayDigiAccept'; +import type ApplePay from '../PaymentMethods/ApplePay'; +import type Bancontact from '../PaymentMethods/Bancontact'; +import type Banktransfer from '../PaymentMethods/BankTransfer'; +import type Belfius from '../PaymentMethods/Belfius'; +import type Billink from '../PaymentMethods/Billink'; +import type BuckarooVoucher from '../PaymentMethods/BuckarooVoucher'; +import type BuckarooWallet from '../PaymentMethods/BuckarooWallet'; +import type CreditCard from '../PaymentMethods/CreditCard'; +import type CreditClick from '../PaymentMethods/CreditClick'; +import type CreditManagement from '../PaymentMethods/CreditManagement'; +import type Emandates from '../PaymentMethods/Emandates'; +import type EPS from '../PaymentMethods/EPS'; +import type GiftCard from '../PaymentMethods/GiftCard'; +import type Giropay from '../PaymentMethods/Giropay'; +import type IdealQr from '../PaymentMethods/IdealQR'; +import type Idin from '../PaymentMethods/Idin'; +import type In3Old from '../PaymentMethods/In3Old'; +import type KBC from '../PaymentMethods/KBC'; +import type Klarna from '../PaymentMethods/Klarna'; +import type KlarnaKp from '../PaymentMethods/KlarnaKP'; +import type Marketplaces from '../PaymentMethods/Marketplaces'; +import type Payconiq from '../PaymentMethods/Payconiq'; +import type PayByBank from '../PaymentMethods/PayByBank'; +import type Paypal from '../PaymentMethods/Paypal'; +import type PayPerEmail from '../PaymentMethods/PayPerEmail'; +import type PiM from '../PaymentMethods/PiM'; +import type PointOfSale from '../PaymentMethods/PointOfSale'; +import type Przelewy24 from '../PaymentMethods/Przelewy24'; +import type SEPA from '../PaymentMethods/SEPA'; +import type Sofort from '../PaymentMethods/Sofort'; +import type Subscriptions from '../PaymentMethods/Subscriptions'; +import type Surepay from '../PaymentMethods/Surepay'; +import type Thunes from '../PaymentMethods/Thunes'; +import type Tinka from '../PaymentMethods/Tinka'; +import type Alipay from '../PaymentMethods/Alipay'; +import type Trustly from '../PaymentMethods/Trustly'; +import type Wechatpay from '../PaymentMethods/WeChatPay'; +import type In3 from '../PaymentMethods/In3'; +import type MultiBanco from '../PaymentMethods/Multibanco'; +import type Index from "../PaymentMethods/Mbway"; + +//toDo refactor this export type AllMethods = readonly [ { class: Afterpay; code: MethodTypes['Afterpay'] }, @@ -81,23 +85,22 @@ export type AllMethods = readonly [ { class: Thunes; code: MethodTypes['Thunes'] }, { class: Tinka; code: MethodTypes['Tinka'] }, { class: Trustly; code: MethodTypes['Trustly'] }, - { class: Wechatpay; code: MethodTypes['WeChatPay'] } -] -export type ServiceCode = AllMethods[number]['code'][number] + { class: Wechatpay; code: MethodTypes['WeChatPay'] }, + { class: MultiBanco; code: MethodTypes['Multibanco'] }, + { class: Index ; code: MethodTypes['Mbway'] }, +]; +export type ServiceCode = AllMethods[number]['code'][number]; -export type MethodFromServiceCode< - Code extends ServiceCode, - Methods extends AllMethods[number] = AllMethods[number] -> = { +export type MethodFromServiceCode = { [Key in Methods['code'][number]]: Methods extends { - class: infer Class - code: readonly (infer Codes)[] + class: infer Class; + code: readonly (infer Codes)[]; } ? Extract extends never ? never : Class - : never -}[Code] + : never; +}[Code]; export const Methods = { Afterpay: ['afterpay'], @@ -110,20 +113,7 @@ export const Methods = { Billink: ['billink'], BuckarooVoucher: ['buckaroovoucher'], BuckarooWallet: ['BuckarooWalletCollecting'], - CreditCard: [ - 'creditcard', - 'mastercard', - 'visa', - 'amex', - 'vpay', - 'maestro', - 'visaelectron', - 'cartebleuevisa', - 'cartebancaire', - 'dankort', - 'nexi', - 'postepay' - ], + CreditCard: ['creditcard', 'mastercard', 'visa', 'amex', 'vpay', 'maestro', 'visaelectron', 'cartebleuevisa', 'cartebancaire', 'dankort', 'nexi', 'postepay'], CreditClick: ['creditclick'], CreditManagement: ['CreditManagement3'], Emandates: ['emandate'], @@ -152,7 +142,7 @@ export const Methods = { 'wonenzo', 'yourgift', 'vvvgiftcard', - 'parfumcadeaukaart' + 'parfumcadeaukaart', ], Giropay: ['giropay'], IdealQR: ['idealqr'], @@ -178,23 +168,23 @@ export const Methods = { Thunes: ['thunes'], Tinka: ['tinka'], Trustly: ['trustly'], - WeChatPay: ['wechatpay'] -} as const + WeChatPay: ['wechatpay'], + Multibanco: ['multibanco'], + Mbway: ['MBWay'], +} as const; -type MethodTypes = typeof Methods -export default function getMethod( - code: Code -): MethodFromServiceCode { - let method: string | undefined +type MethodTypes = typeof Methods; +export default function getMethod(code: Code): MethodFromServiceCode { + let method: string | undefined; for (const key in Methods) { if (Methods[key].includes(code)) { - method = key - break + method = key; + break; } } - if (!method) throw new Error(`Wrong payment method code has been given`) + if (!method) throw new Error(`Wrong payment method code has been given`); - let methodClass = require(`../PaymentMethods/${method}`).default + let methodClass = require(`../PaymentMethods/${method}`).default; - return new methodClass(code) + return new methodClass(code); } diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 0a362d74..a40e3d88 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -1,21 +1,21 @@ -import { ServiceCode } from './MethodTypes' +import { ServiceCode } from './MethodTypes'; export declare interface IConfig { - mode: Mode - currency: string - continueOnIncomplete?: 0 | 1 - returnURL?: string - returnURLCancel?: string - pushURL?: string - returnURLError?: string - returnURLReject?: string - activePaymentMethods?: ServiceCode[] - disabledPaymentMethods?: ServiceCode[] + mode: Mode; + currency: string; + continueOnIncomplete?: 0 | 1; + returnURL?: string; + returnURLCancel?: string; + pushURL?: string; + returnURLError?: string; + returnURLReject?: string; + activePaymentMethods?: ServiceCode[]; + disabledPaymentMethods?: ServiceCode[]; } export declare interface ICredentials { - websiteKey: string - secretKey: string + websiteKey: string; + secretKey: string; } -export type Mode = 'LIVE' | 'TEST' +export type Mode = 'LIVE' | 'TEST'; diff --git a/src/index.ts b/src/index.ts index 78f1a730..e7c3f254 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,59 +1,58 @@ -import {IConfig, ICredentials} from './Utils/Types' -import HttpsClient from './Request/HttpsClient' -import {Agent} from 'https' -import getMethod, {MethodFromServiceCode, ServiceCode} from './Utils/MethodTypes' -import Request from './Request/Request' -import NoService from './PaymentMethods/NoService' -import TransactionService from './Services/TransactionService' -import {Credentials} from './Handlers/Credentials' -import {RequestTypes} from "./Constants/Endpoints"; +import { IConfig, ICredentials } from './Utils/Types'; +import HttpsClient from './Request/HttpsClient'; +import { Agent } from 'https'; +import getMethod, { MethodFromServiceCode, ServiceCode } from './Utils/MethodTypes'; +import Request from './Request/Request'; +import NoService from './PaymentMethods/NoService'; +import TransactionService from './Services/TransactionService'; +import { Credentials } from './Handlers/Credentials'; export default class Buckaroo { - private readonly _credentials: Credentials - private _config: IConfig - private readonly _httpClient: HttpsClient - private static _client: Buckaroo + private readonly _credentials: Credentials; + private _config: IConfig; + private readonly _httpClient: HttpsClient; + private static _client: Buckaroo; constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { - this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey) - this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) } - this._httpClient = new HttpsClient(agent) + this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); + this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; + this._httpClient = new HttpsClient(agent); } - static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent):Buckaroo { - return this._client = new this(credentials, config, agent) + static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { + return (this._client = new this(credentials, config, agent)); } static get Client(): Buckaroo { - return this._client + return this._client; } get credentials(): ICredentials { - return this._credentials + return this._credentials; } confirmCredentials() { - return this._credentials.confirm() + return this._credentials.confirm(); } get config(): IConfig { - return { ...this._config } + return { ...this._config }; } set config(value: IConfig) { - this._config = value + this._config = value; } get httpClient() { - return this._httpClient + return this._httpClient; } transaction(key: string) { - return new TransactionService(key) + return new TransactionService(key); } - batch(type:RequestTypes.BatchData | RequestTypes.BatchTransaction = RequestTypes.BatchTransaction) { - if (type === RequestTypes.BatchData) { - return Request.BatchDataRequest - } - return Request.BatchTransaction + get batch() { + return { + transaction: Request.BatchTransaction, + data: Request.BatchDataRequest, + }; } - method(): NoService - method(name: Name): MethodFromServiceCode + method(): NoService; + method(name: Name): MethodFromServiceCode; method(name?: ServiceCode) { if (!name) { - return new NoService() + return new NoService(); } - return getMethod(name) + return getMethod(name); } } diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index b6bbbd81..f69f792e 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -1,18 +1,18 @@ -import Buckaroo from '../src' +import Buckaroo from '../src'; -require('dotenv').config() +require('dotenv').config(); const BuckarooClient = Buckaroo.InitializeClient( { secretKey: process.env.BPE_SECRET_KEY || '', - websiteKey: process.env.BPE_WEBSITE_KEY || '' + websiteKey: process.env.BPE_WEBSITE_KEY || '', }, { mode: process.env.BPE_MODE === 'LIVE' ? 'LIVE' : 'TEST', currency: process.env.BPE_CURRENCY_CODE || 'EUR', returnURL: process.env.BPE_RETURN_URL || '', returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', - pushURL: process.env.BPE_PUSH_URL || '' + pushURL: process.env.BPE_PUSH_URL || '', } -) -export default BuckarooClient +); +export default BuckarooClient; diff --git a/tests/Client.test.ts b/tests/Client.test.ts index cfeaf6f2..0b7c6ffd 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -1,26 +1,25 @@ -import client from './BuckarooClient.test' -import { TransactionData } from '../src/Request/DataModels' -import { TransactionResponse } from '../src/Models/Response/TransactionResponse' -import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse' -import { uniqid } from '../src/Utils/Functions' -import { creditManagementTestInvoice } from "./PaymentMethods/CreditManagment.test"; +import client from './BuckarooClient.test'; +import { TransactionResponse } from '../src/Models/Response/TransactionResponse'; +import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse'; +import { uniqid } from '../src/Utils/Functions'; +import { creditManagementTestInvoice } from './PaymentMethods/CreditManagment.test'; +import IRequest from "../src/Models/IRequest"; describe('Testing Buckaroo Client', () => { - test('Credentials', () => { - return client - .confirmCredentials() - .then((response) => { - expect(response).toBeTruthy() - }) - }) + test('Credentials', () => { + return client.confirmCredentials().then((response) => { + expect(response).toBeTruthy(); + }); + }); test('Batch transaction', async () => { - const transactionData: TransactionData[] = [] + const transactionData:IRequest[] = []; + const creditManagement = client.method('CreditManagement3') + const sepaDirectDebit = client.method('sepadirectdebit') for (let i = 0; i < 3; i++) { - let invoice = client - .method('CreditManagement3') - .createCombinedInvoice(creditManagementTestInvoice()) - .combine('sepadirectdebit') - .pay({ + creditManagement.createCombinedInvoice(creditManagementTestInvoice()) + + sepaDirectDebit.combine(creditManagement).pay( + { invoice: uniqid(), amountDebit: 10.1, iban: 'NL13TEST0123456789', @@ -29,48 +28,44 @@ describe('Testing Buckaroo Client', () => { mandateReference: '1DCtestreference', mandateDate: '2022-07-03', customer: { - name: 'John Smith' - } - }) - transactionData.push(invoice.data) + name: 'John Smith', + }, + }); + transactionData.push(sepaDirectDebit.getPayload()); } - await client - .batch(transactionData) + await client.batch + .transaction(transactionData) .request() .then((response) => { - expect(response).toBeTruthy() + expect(response.data.message === '3 transactions were queued for processing.').toBeTruthy(); }) .catch((err) => { - expect(err).toBeUndefined() - }) - }) + expect(err).toBeUndefined(); + }); + }); describe('Transaction', () => { - const transactionService = client.transaction('39F3EC520A3F4A25B0A1899D4FF0E1CB') + const transactionService = client.transaction('39F3EC520A3F4A25B0A1899D4FF0E1CB'); test('transaction Status', async () => { await transactionService .status() .then((res) => { - expect(res instanceof TransactionResponse).toBeTruthy() + expect(res instanceof TransactionResponse).toBeTruthy(); }) .catch((err) => { - expect(err).toBeUndefined() - }) - }) + expect(err).toBeUndefined(); + }); + }); test('transaction Cancel Info', async () => { - await transactionService - .cancelInfo() - .then((res) => { - expect(res instanceof HttpClientResponse).toBeTruthy() - }) - }) + await transactionService.cancelInfo().then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy(); + }); + }); test('transaction Refund Info', async () => { - await transactionService - .refundInfo() - .then((res) => { - expect(res instanceof HttpClientResponse).toBeTruthy() - }) - }) - }) -}) + await transactionService.refundInfo().then((res) => { + expect(res instanceof HttpClientResponse).toBeTruthy(); + }); + }); + }); +}); diff --git a/tests/Models/index.ts b/tests/Models/index.ts index c94f262d..33fc1452 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -1,10 +1,10 @@ -import { ICompany, IPerson } from '../../src/Models/Interfaces/IRecipient' -import IAddress from '../../src/Models/Interfaces/IAddress' -import IArticle from '../../src/Models/Interfaces/IArticle' -import IPhone from '../../src/Models/Interfaces/IPhone' -import IBankAccount from '../../src/Models/Interfaces/IBankAccount' -import RecipientCategory from '../../src/Constants/RecipientCategory' -import { getIPAddress } from '../../src/Utils/Functions' +import { ICompany, IPerson } from '../../src/Models/Interfaces/IRecipient'; +import IAddress from '../../src/Models/Interfaces/IAddress'; +import IArticle from '../../src/Models/Interfaces/IArticle'; +import IPhone from '../../src/Models/Interfaces/IPhone'; +import IBankAccount from '../../src/Models/Interfaces/IBankAccount'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { getIPAddress } from '../../src/Utils/Functions'; export const TestPerson: IPerson = { birthDate: '1990-01-01', @@ -16,8 +16,8 @@ export const TestPerson: IPerson = { lastName: 'Do', lastNamePrefix: 'testlastprefix', placeOfBirth: 't', - title: 'title' -} + title: 'title', +}; export const TestCompany: ICompany = { category: RecipientCategory.COMPANY, careOf: 'test', @@ -25,17 +25,17 @@ export const TestCompany: ICompany = { companyName: 'testCompany', culture: 'culture', vatApplicable: false, - vatNumber: '321' -} -export const TestAddress:IAddress = { + vatNumber: '321', +}; +export const TestAddress: IAddress = { city: 'city', country: 'NL', houseNumber: '2313432', houseNumberAdditional: '324', state: 'state', street: 'street', - zipcode: '32323' -} + zipcode: '32323', +}; export const TestArticle: IArticle = { description: 'test', identifier: 'identifier', @@ -44,24 +44,24 @@ export const TestArticle: IArticle = { type: 'PhysicalArticle', unitCode: '23', vatCategory: '323', - vatPercentage: 1 -} + vatPercentage: 1, +}; -export const TestPhone:IPhone = { +export const TestPhone: IPhone = { fax: '23232', landline: '323123', - mobile: '21312332' -} -export const TestEmail = 'test@hotmail.com' -export const TestBankAccount:IBankAccount = { + mobile: '21312332', +}; +export const TestEmail = 'test@hotmail.com'; +export const TestBankAccount: IBankAccount = { accountName: 'accountName', bic: 'bic', - iban: 'iban' -} + iban: 'iban', +}; export const TestBilling = { recipient: TestPerson, address: TestAddress, phone: TestPhone, - email: TestEmail -} -export const TestIp = getIPAddress() + email: TestEmail, +}; +export const TestIp = getIPAddress(); diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index 6f76e793..11c71294 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -1,87 +1,78 @@ -import buckarooClientTest from '../BuckarooClient.test' -import { RequestTypes } from '../../src/Constants/Endpoints' -import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay' -import RecipientCategory from '../../src/Constants/RecipientCategory' +import buckarooClientTest from '../BuckarooClient.test'; +import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; const method = buckarooClientTest.method('afterpay') describe('AfterPay methods', () => { - test('Pay', () => { - return method + test('Pay', () => { + return method .pay(paymentPayload) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ invoice: 'testinvoice 123', //Set invoice number of the transaction to refund originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', //Set transaction key of the transaction to refund - amountCredit: 1.23 + amountCredit: 1.23, }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data.isFailed()).toBeDefined(); + }); + }); test('Authorize', async () => { await method .authorize(paymentPayload) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('CancelAuthorize', async () => { await method .cancelAuthorize({ invoice: 'testinvoice 123', originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', - amountCredit: 1.23 + amountCredit: 1.23, }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Capture', async () => { await method .capture({ ...paymentPayload, - originalTransactionKey: '123456789' + originalTransactionKey: '123456789', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('PayRemainder', async () => { await method .payRemainder({} as any) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('AuthorizeRemainder', async () => { await method .authorizeRemainder({} as any) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) - test('Spercifications', async () => { - return method - .specification(RequestTypes.Transaction) - .request() - .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); const paymentPayload: IPay = { clientIP: '127.0.0.1', @@ -96,7 +87,7 @@ const paymentPayload: IPay = { companyName: 'buckarooTest', conversationLanguage: 'NL', identificationNumber: 'IdNumber12345', - customerNumber: 'customerNumber12345' + customerNumber: 'customerNumber12345', }, address: { street: 'Hoofdstraat', @@ -104,13 +95,13 @@ const paymentPayload: IPay = { houseNumberAdditional: 'a', zipcode: '1234AB', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, email: 'test@buckaroo.nl', phone: { mobile: '0612345678', - landline: '0513123456' - } + landline: '0513123456', + }, }, articles: [ { @@ -118,9 +109,9 @@ const paymentPayload: IPay = { price: 10, description: 'Test', quantity: 4, - identifier: 'test' - } + identifier: 'test', + }, ], description: 'Test', - merchantImageUrl: 'https://www.buckaroo.nl/Themes/Buckaroo/Content/images/logo.png' -} + merchantImageUrl: 'https://www.buckaroo.nl/Themes/Buckaroo/Content/images/logo.png', +}; diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 6aea7af7..ddc6ef68 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,11 +1,11 @@ -import { RequestTypes } from '../../src/Constants/Endpoints' -import { TestBilling } from '../Models' -import buckarooClientTest from '../BuckarooClient.test' -import { uniqid } from '../../src/Utils/Functions' -import Gender from '../../src/Constants/Gender' -import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay' +import { RequestTypes } from '../../src/Constants/Endpoints'; +import { TestBilling } from '../Models'; +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import Gender from '../../src/Constants/Gender'; +import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay'; -const method = buckarooClientTest.method('afterpaydigiaccept') +const method = buckarooClientTest.method('afterpaydigiaccept'); describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { @@ -20,30 +20,30 @@ describe('AfterPayDigiAccept methods', () => { merchantImageUrl: '', ourReference: '', summaryImageUrl: '', - yourReference: '' + yourReference: '', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Pay', async () => { await method .pay({ ...paymentPayload, clientIP: '127.0.0.1' }) .request() .then((data) => { - expect(data.data).toBeDefined() - }) - }) + expect(data.data).toBeDefined(); + }); + }); test('Specification', async () => { await method .specification(RequestTypes.Transaction) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); const paymentPayload: IPay = { amountDebit: 40.5, @@ -60,7 +60,7 @@ const paymentPayload: IPay = { initials: 'AB', lastName: 'Do', birthDate: '1990-01-01', - culture: 'NL' + culture: 'NL', }, address: { street: 'Hoofdstraat', @@ -68,12 +68,12 @@ const paymentPayload: IPay = { houseNumberAdditional: 'a', zipcode: '1234AB', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, phone: { - mobile: '0698765433' + mobile: '0698765433', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, shipping: { recipient: { @@ -84,7 +84,7 @@ const paymentPayload: IPay = { companyName: 'Buckaroo B.V.', birthDate: '1990-01-01', chamberOfCommerce: '12345678', - vatNumber: 'NL12345678' + vatNumber: 'NL12345678', }, address: { street: 'Kalverstraat', @@ -92,12 +92,12 @@ const paymentPayload: IPay = { houseNumberAdditional: 'b', zipcode: '4321EB', city: 'Amsterdam', - country: 'NL' + country: 'NL', }, phone: { - mobile: '0698765433' + mobile: '0698765433', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, articles: [ { @@ -105,14 +105,14 @@ const paymentPayload: IPay = { description: 'Blue Toy Car', price: 10.0, quantity: 2, - vatCategory: '1' + vatCategory: '1', }, { identifier: uniqid(), description: 'Red Toy Car', price: 10.0, quantity: 2, - vatCategory: '1' - } - ] -} + vatCategory: '1', + }, + ], +}; diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index f449f0a5..c31e9cb8 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,28 +1,28 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const alipay = buckarooClientTest.method('alipay') +const alipay = buckarooClientTest.method('alipay'); describe('Alipay methods', () => { test('Pay Simple Payload', async () => { await alipay .pay({ amountDebit: 10, - useMobileView: false + useMobileView: false, }) .request() .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy() - }) - }) + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await alipay .refund({ amountCredit: 5, - originalTransactionKey: 'F397777A251645F8BDD81547B5005B4B' + originalTransactionKey: 'F397777A251645F8BDD81547B5005B4B', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) -}) + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index e84c8fd2..f5686ac3 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -1,9 +1,9 @@ -import { uniqid } from '../../src/Utils/Functions' +import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test') -import ApplePay from '../../src/PaymentMethods/ApplePay' +require('../BuckarooClient.test'); +import ApplePay from '../../src/PaymentMethods/ApplePay'; -const method = new ApplePay() +const method = new ApplePay(); describe('Applepay methods', () => { test('Pay Simple Payload', async () => { @@ -11,43 +11,43 @@ describe('Applepay methods', () => { .pay({ amountDebit: 10, paymentData: 'sad', - customerCardName: '87y7y8' + customerCardName: '87y7y8', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Pay Redirect Payload', async () => { await method .payRedirect({ amountDebit: 10, invoice: uniqid(), servicesSelectableByClient: 'applepay', - continueOnIncomplete: true + continueOnIncomplete: true, }) .request() .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy() - }) - }) + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Specifications', async () => { await method .specification() .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 14f98d73..7e99eb6a 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,88 +1,88 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('bancontactmrcash') +const method = buckarooClientTest.method('bancontactmrcash'); describe('BanContact methods', () => { test('Pay Simple Payload', async () => { await method .pay({ amountDebit: 10, - saveToken: true + saveToken: true, }) .request() .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy() - }) - }) + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Authenticate', async () => { await method .authenticate({ amountDebit: 10 }) .request() .then((data) => { - expect(data.isWaitingOnUserInput()).toBeDefined() - }) - }) + expect(data.isWaitingOnUserInput()).toBeDefined(); + }); + }); test('PayOneClick', async () => { await method .payOneClick({ originalTransactionKey: 'dsad', - amountDebit: 12 + amountDebit: 12, }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('CompletePayment', async () => { await method .completePayment({ originalTransactionKey: 'dsad', - encryptedCardData: 'sUIB' + encryptedCardData: 'sUIB', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('PayEncrypted', async () => { await method .payEncrypted({ amountDebit: 10, - encryptedCardData: 'yrtgdd' + encryptedCardData: 'yrtgdd', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('PayRecurring', async () => { await method .payRecurring({ amountDebit: 10, - originalTransactionKey: 'sadas' + originalTransactionKey: 'sadas', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Specifications', () => { method .specification() .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 301d1896..19813fc4 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,6 +1,6 @@ -import Gender from '../../src/Constants/Gender' -import buckarooClientTest from '../BuckarooClient.test' -const method = buckarooClientTest.method('transfer') +import Gender from '../../src/Constants/Gender'; +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('transfer'); describe('Transfer methods', () => { test('Pay', async () => { @@ -10,15 +10,15 @@ describe('Transfer methods', () => { customer: { firstName: 'John', lastName: 'Doe', - gender: Gender.MALE + gender: Gender.MALE, }, email: 'test@hotmail.com', sendMail: true, - dateDue: '2024-10-10' + dateDue: '2024-10-10', }) .request() .then((res) => { - expect(res.isAwaitingConsumer()).toBeDefined() - }) - }) -}) + expect(res.isAwaitingConsumer()).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index 8775b83e..d82ce631 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,35 +1,35 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('belfius') +const method = buckarooClientTest.method('belfius'); describe('testing methods', () => { test('Pay Simple Payload', async () => { await method .pay({ - amountDebit: 10 + amountDebit: 10, }) .request() .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy() - }) - }) + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 5, - originalTransactionKey: '86CFE2CB5901463EADE061633BDB9EC8' + originalTransactionKey: '86CFE2CB5901463EADE061633BDB9EC8', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Specifications', async () => { await method .specification() .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index a0083174..fdcd8496 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,10 +1,10 @@ -import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay' -import buckarooClientTest from '../BuckarooClient.test' -import RecipientCategory from '../../src/Constants/RecipientCategory' +import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay'; +import buckarooClientTest from '../BuckarooClient.test'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; -require('../BuckarooClient.test') +require('../BuckarooClient.test'); -const method = buckarooClientTest.method('billink') +const method = buckarooClientTest.method('billink'); describe('Billink methods', () => { test('Pay', async () => { @@ -12,54 +12,54 @@ describe('Billink methods', () => { .pay(payload) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 12, - originalTransactionKey: 'ytgty' + originalTransactionKey: 'ytgty', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Authorize', async () => { await method .authorize(payload) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('CancelAuthorize', async () => { await method .cancelAuthorize({ originalTransactionKey: 'ytgty', amountCredit: 10, - invoice: 'sdsa' + invoice: 'sdsa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Capture', async () => { await method .capture({ originalTransactionKey: 'ytgty', invoice: "'dsa", amountDebit: 123, - articles: payload.articles + articles: payload.articles, }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); const payload: IPay = { amountDebit: 50.3, @@ -76,7 +76,7 @@ const payload: IPay = { firstName: 'John', lastName: 'Do', birthDate: '01-01-1990', - chamberOfCommerce: 'TEST' + chamberOfCommerce: 'TEST', }, address: { street: 'Hoofdstraat', @@ -84,13 +84,13 @@ const payload: IPay = { houseNumberAdditional: 'a', zipcode: '1234AB', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, phone: { mobile: '0698765433', - landline: '0109876543' + landline: '0109876543', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, shipping: { recipient: { @@ -100,7 +100,7 @@ const payload: IPay = { initials: 'JD', firstName: 'John', lastName: 'Do', - birthDate: '1990-01-01' + birthDate: '1990-01-01', }, address: { street: 'Kalverstraat', @@ -108,8 +108,8 @@ const payload: IPay = { houseNumberAdditional: 'b', zipcode: '4321EB', city: 'Amsterdam', - country: 'NL' - } + country: 'NL', + }, }, articles: [ { @@ -118,7 +118,7 @@ const payload: IPay = { vatPercentage: 21, quantity: 2, price: 20.1, - priceExcl: 5 + priceExcl: 5, }, { identifier: 'Articlenumber2', @@ -126,7 +126,7 @@ const payload: IPay = { vatPercentage: 21, quantity: 1, price: 10.1, - priceExcl: 5 - } - ] -} + priceExcl: 5, + }, + ], +}; diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 8a8e5e65..8924d03e 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,61 +1,61 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('buckaroovoucher') +const method = buckarooClientTest.method('buckaroovoucher'); describe('testing methods', () => { test('Pay', async () => { await method .pay({ amountDebit: 12, - voucherCode: '' + voucherCode: '', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 12, - originalTransactionKey: '' + originalTransactionKey: '', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('GetBalance', async () => { await method .getBalance({ - voucherCode: 'WP6W-XXXX-XXXX-56T7' + voucherCode: 'WP6W-XXXX-XXXX-56T7', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('CreateApplication', async () => { await method .create({ creationBalance: 12, usageType: 1, validFrom: '2021-01-01', - validUntil: '2024-01-01' + validUntil: '2024-01-01', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('DeactivateVoucher', async () => { await method .deactivate({ - voucherCode: '' + voucherCode: '', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index caaa661e..2ce608aa 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -1,7 +1,7 @@ -import buckarooClientTest from '../BuckarooClient.test' -import { uniqid } from '../../src/Utils/Functions' +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; -const method = buckarooClientTest.method('BuckarooWalletCollecting') +const method = buckarooClientTest.method('BuckarooWalletCollecting'); describe('BuckarooWallet methods', () => { test('Pay', async () => { @@ -9,51 +9,51 @@ describe('BuckarooWallet methods', () => { .pay({ invoice: 'string', amountDebit: 12, - walletId: '2' + walletId: '2', }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ invoice: 'string', amountCredit: 12, - originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('CancelReservation', async () => { await method .cancel({ invoice: 'BuckarooWalletInvoiceId', originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', amountDebit: 1, - walletMutationGuid: '49B018248ECE4346AC20B902' + walletMutationGuid: '49B018248ECE4346AC20B902', }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('deposit', async () => { await method .deposit({ invoice: 'string', walletId: '', amountCredit: 12, - originalTransactionKey: '' + originalTransactionKey: '', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Update', async () => { await method .update({ @@ -62,30 +62,30 @@ describe('BuckarooWallet methods', () => { email: 'test@buckaroo.nl', customer: { firstName: 'John', - lastName: 'string' + lastName: 'string', }, bankAccount: { - iban: 'NL13TEST0123456789' - } + iban: 'NL13TEST0123456789', + }, }) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('Withdrawal', async () => { await method .withdrawal({ invoice: 'BuckarooWalletInvoiceId', walletId: '10', amountDebit: 10, - originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE' + originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('Create Wallet', async () => { await method .create({ @@ -93,25 +93,25 @@ describe('BuckarooWallet methods', () => { email: 'test@buckaroo.nl', customer: { firstName: 'John', - lastName: 'string' + lastName: 'string', }, bankAccount: { - iban: 'NL13TEST0123456789' - } + iban: 'NL13TEST0123456789', + }, }) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('GetInfo', async () => { await method .getInfo({ - walletId: '10' + walletId: '10', }) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) -}) + expect(data.isSuccess()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index ae44fe6f..1347f275 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -1,121 +1,121 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('visa') +const method = buckarooClientTest.method('visa'); describe('testing methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10 + amountDebit: 10, }) .request() .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy() - }) - }) + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B' + originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Authorize', async () => { await method .authorize({ - amountDebit: 10 + amountDebit: 10, }) .request() .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy() - }) - }) + expect(data.isWaitingOnUserInput()).toBeTruthy(); + }); + }); test('PayEncrypted', async () => { await method .payEncrypted({ amountDebit: 10, name: 'Visa', - encryptedCardData: '' + encryptedCardData: '', }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('PayWithSecurityCode', async () => { await method .payWithSecurityCode({ amountDebit: 10, encryptedSecurityCode: 'sad', - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('AuthorizeWithSecurityCode', async () => { await method .authorizeWithSecurityCode({ amountDebit: 10, encryptedSecurityCode: 'sad', - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('AuthorizeEncrypted', async () => { await method .authorizeEncrypted({ amountDebit: 10, encryptedCardData: 'sad', - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('CancelAuthorize', async () => { await method .cancelAuthorize({ originalTransactionKey: 'sad', amountCredit: 10, - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('Capture', async () => { await method .capture({ originalTransactionKey: 'sad', amountDebit: 10, - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) + expect(data).toBeDefined(); + }); + }); test('PayRecurrent', async () => { await method .payRecurrent({ originalTransactionKey: 'sad', amountDebit: 10, - name: 'Visa' + name: 'Visa', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index 5f28deeb..0171df35 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -1,6 +1,6 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('creditclick') +const method = buckarooClientTest.method('creditclick'); describe('Testing CreditClick methods', () => { test('Pay', async () => { @@ -9,26 +9,26 @@ describe('Testing CreditClick methods', () => { amountDebit: 31, person: { firstName: 'test', - lastName: 'test' + lastName: 'test', }, - email: 't.tester@test.nl' + email: 't.tester@test.nl', }) .request() .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy() - }) - }) + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 31, originalTransactionKey: 'C85BABFCCA2D4921B9CFBA0EBDF82C70', description: 'test', - refundReason: 'Fraudulent' + refundReason: 'Fraudulent', }) .request() .then((response) => { - expect(response.isFailed()).toBeTruthy() - }) - }) -}) + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index 0e281776..980f74f2 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -1,10 +1,10 @@ -import { IInvoice } from '../../src/PaymentMethods/CreditManagement/Models/Invoice' -import Gender from '../../src/Constants/Gender' -import CreditManagementInstallmentInterval from '../../src/Constants/CreditManagementInstallmentInterval' -import buckarooClientTest from '../BuckarooClient.test' -import { uniqid } from '../../src/Utils/Functions' +import { IInvoice } from '../../src/PaymentMethods/CreditManagement/Models/Invoice'; +import Gender from '../../src/Constants/Gender'; +import CreditManagementInstallmentInterval from '../../src/Constants/CreditManagementInstallmentInterval'; +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; -const creditManagement = buckarooClientTest.method('CreditManagement3') +const creditManagement = buckarooClientTest.method('CreditManagement3'); describe('Testing Credit Management', () => { test('CreateInvoice', async () => { @@ -12,9 +12,9 @@ describe('Testing Credit Management', () => { .createInvoice(creditManagementTestInvoice()) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('CreateInvoice With Articles', async () => { await creditManagement .createInvoice( @@ -27,7 +27,7 @@ describe('Testing Credit Management', () => { schemeKey: '2amq34', poNumber: 'PO-12345', debtor: { - code: 'johnsmith4' + code: 'johnsmith4', }, articles: [ { @@ -45,7 +45,7 @@ describe('Testing Credit Management', () => { vatPercentage: 21, totalVat: 0.6, totalAmountExVat: 8.4, - totalAmount: 123 + totalAmount: 123, }, { productGroupName: 'Toys', @@ -62,55 +62,55 @@ describe('Testing Credit Management', () => { vatPercentage: 21, totalVat: 0.6, totalAmountExVat: 8.4, - totalAmount: 123 - } - ] + totalAmount: 123, + }, + ], }) ) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('Pause Invoice', async () => { await creditManagement .pauseInvoice({ invoice: 'Testinvoice184915' }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('UnPause Invoice', async () => { await creditManagement .unpauseInvoice({ invoice: 'Testinvoice184915' }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('Invoice Info', async () => { await creditManagement .invoiceInfo({ invoice: 'INV001', - invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }] + invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }], }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('Debtor Info', async () => { await creditManagement .debtorInfo({ debtor: { - code: 'TestDebtor123123' - } + code: 'TestDebtor123123', + }, }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('AddOrUpdateProductLines', async () => { await creditManagement .addOrUpdateProductLines({ @@ -124,7 +124,7 @@ describe('Testing Credit Management', () => { totalVat: 12, totalAmount: 123, quantity: 2, - price: 20.1 + price: 20.1, }, { type: 'Regular', @@ -134,49 +134,47 @@ describe('Testing Credit Management', () => { totalVat: 12, totalAmount: 123, quantity: 1, - price: 10.1 - } - ] + price: 10.1, + }, + ], }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('resumeDebtorFile', async () => { await creditManagement .resumeDebtorFile({ debtorFileGuid: 'd42' }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('pauseDebtorFile', async () => { await creditManagement .pauseDebtorFile({ debtorFileGuid: 'd42' }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('addOrUpdateDebtor', async () => { await creditManagement .addOrUpdateDebtor( creditManagementTestInvoice({ addressUnreachable: false, emailUnreachable: false, - mobileUnreachable: false + mobileUnreachable: false, }) ) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('CreateCombinedInvoice', async () => { - const combinedInvoice = creditManagement.createCombinedInvoice( - creditManagementTestInvoice() - ) + const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); buckarooClientTest .method('sepadirectdebit') .combine(combinedInvoice.data) @@ -188,15 +186,15 @@ describe('Testing Credit Management', () => { collectDate: '2020-07-03', amountDebit: 10.1, customer: { - name: 'John Smith' + name: 'John Smith', }, - invoice: uniqid('TestInvoice') + invoice: uniqid('TestInvoice'), }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('CreatePaymentPlan', async () => { await creditManagement .createPaymentPlan({ @@ -209,24 +207,24 @@ describe('Testing Credit Management', () => { interval: CreditManagementInstallmentInterval.MONTH, paymentPlanCostAmount: 3.5, paymentPlanCostAmountVat: 1.2, - recipientEmail: 'test@buckaroo.nl' + recipientEmail: 'test@buckaroo.nl', }) .request() .then((data) => { - expect(data.isValidationFailure()).toBeTruthy() - }) - }) + expect(data.isValidationFailure()).toBeTruthy(); + }); + }); test('pauseInvoice', async () => { await creditManagement .pauseInvoice({ - invoice: 'd42' + invoice: 'd42', }) .request() .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); export const creditManagementTestInvoice = (append: object = {}): IInvoice => { return { applyStartRecurrent: false, @@ -238,11 +236,11 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { maxStepIndex: 1, allowedServices: 'ideal,mastercard', debtor: { - code: 'johnsmith4' + code: 'johnsmith4', }, email: 'youremail@example.nl', phone: { - mobile: '06198765432' + mobile: '06198765432', }, person: { culture: 'nl-NL', @@ -251,14 +249,14 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { firstName: 'Test', lastNamePrefix: 'Jones', lastName: 'Aflever', - gender: Gender.MALE + gender: Gender.MALE, }, company: { culture: 'nl-NL', name: 'My Company Corporation', vatApplicable: true, vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741' + chamberOfCommerce: '20091741', }, address: { street: 'Hoofdtraat', @@ -267,8 +265,8 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { zipcode: '8441ER', city: 'Heerenveen', state: 'Friesland', - country: 'NL' + country: 'NL', }, - ...append - } -} + ...append, + }; +}; diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index 42cc1ec5..d6582f81 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -1,25 +1,25 @@ -import buckarooClientTest from '../BuckarooClient.test' -const method = buckarooClientTest.method('eps') +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('eps'); describe('Testing Eps methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10.1 + amountDebit: 10.1, }) .request() .then((response) => { - expect(response.isSuccess()).toBeTruthy() - }) - }) + expect(response.isSuccess()).toBeTruthy(); + }); + }); test('Refund', async () => { method .refund({ amountCredit: 10.1, - originalTransactionKey: '1234567890' + originalTransactionKey: '1234567890', }) .request() .then((response) => { - expect(response.isFailed()).toBeTruthy() - }) - }) -}) + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 5bf84791..b033cf8a 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,14 +1,14 @@ -import buckarooClientTest from '../BuckarooClient.test' -const method = buckarooClientTest.method('emandate') +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { await method .issuerList() .request() .then((response) => { - expect(response.isSuccess()).toBeTruthy() - }) - }) + expect(response.isSuccess()).toBeTruthy(); + }); + }); test('CreateMandate', async () => { method .createMandate({ @@ -16,41 +16,41 @@ describe('Testing Emandates methods', () => { language: 'nl', continueOnIncomplete: true, purchaseId: 'purchaseid1234', - sequenceType: 0 + sequenceType: 0, }) .request() .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy() - }) - }) + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); test('GetStatus', async () => { method .status({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC' }) .request() .then((response) => { - expect(response.isSuccess()).toBeTruthy() - }) - }) + expect(response.isSuccess()).toBeTruthy(); + }); + }); test('ModifyMandate', async () => { method .modifyMandate({ originalMandateId: '1DC014098EC5C1F40AD803B83A425153BBC', - continueOnIncomplete: true + continueOnIncomplete: true, }) .request() .then((response) => { - expect(response.isFailed()).toBeTruthy() - }) - }) + expect(response.isFailed()).toBeTruthy(); + }); + }); test('CancelMandate', async () => { method .cancelMandate({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC', - purchaseId: 'purchaseid1234' + purchaseId: 'purchaseid1234', }) .request() .then((response) => { - expect(response.isValidationFailure()).toBeTruthy() - }) - }) -}) + expect(response.isValidationFailure()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index cfb38e13..2f624487 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -1,6 +1,6 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('boekenbon') +const method = buckarooClientTest.method('boekenbon'); describe('GiftCard methods', () => { test('Pay', async () => { @@ -8,33 +8,32 @@ describe('GiftCard methods', () => { .pay({ amountDebit: 10, intersolveCardnumber: '0000000000000000001', - intersolvePIN: '500' + intersolvePIN: '500', }) - .request() - expect(responsePay.isSuccess()).toBeTruthy() + .request(); + expect(responsePay.isSuccess()).toBeTruthy(); const responseRemainderPay = await buckarooClientTest .method('ideal') .payRemainder({ amountDebit: 10.1, issuer: 'ABNANL2A', invoice: responsePay.data.invoice, - originalTransactionKey: - responsePay.data.relatedTransactions[0].relatedTransactionKey + originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, }) - .request() - expect(responseRemainderPay.isPendingProcessing()).toBeTruthy() - }) + .request(); + expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); + }); test('Refund', async () => { await method .refund({ amountCredit: 5, originalTransactionKey: '9F99B530DA5449EB919D27351D28BDF2', email: '', - lastName: '' + lastName: '', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) -}) + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index b90e0508..88408e99 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -1,28 +1,28 @@ -import buckarooClientTest from '../BuckarooClient.test' -import { uniqid } from '../../src/Utils/Functions' -const method = buckarooClientTest.method('giropay') +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +const method = buckarooClientTest.method('giropay'); describe('Testing Giropay methods', () => { test('Pay', async () => { await method .pay({ bic: 'GENODETT488', - amountDebit: 10.1 + amountDebit: 10.1, }) .request() .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy() - }) - }) + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 10, invoice: uniqid(), - originalTransactionKey: '2D04704995B74D679AACC59F87XXXXXX' + originalTransactionKey: '2D04704995B74D679AACC59F87XXXXXX', }) .request() .then((response) => { - expect(response.isFailed()).toBeTruthy() - }) - }) -}) + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index fd365b07..bab287a1 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,30 +1,30 @@ -import {getIPAddress, uniqid} from '../../src/Utils/Functions' -import buckarooClientTest from '../BuckarooClient.test' -const ideal = buckarooClientTest.method('ideal') +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import buckarooClientTest from '../BuckarooClient.test'; +const ideal = buckarooClientTest.method('ideal'); describe('testing Ideal methods', () => { - test('Issuers', () => { - return ideal.issuers().then((response) => { - expect(Array.isArray(response)).toBeTruthy() - }) - }) - test('Pay Simple Payload', () => { - return ideal + test('Issuers', () => { + return ideal.issuers().then((response) => { + expect(Array.isArray(response)).toBeTruthy(); + }); + }); + test('Pay Simple Payload', () => { + return ideal .pay({ amountDebit: 10.1, issuer: 'ABNANL2A', continueOnIncomplete: false, additionalParameters: { initiated_by_magento: 1, - service_action: 'something' - } + service_action: 'something', + }, }) .request() .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy() - }) - }) - test('Refund',() => { - return ideal + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + test('Refund', () => { + return ideal .refund({ order: uniqid(), invoice: uniqid(), @@ -33,23 +33,23 @@ describe('testing Ideal methods', () => { clientIP: getIPAddress(), additionalParameters: { initiated_by_magento: '1', - service_action: 'something' - } + service_action: 'something', + }, }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('InstantRefund', () => { - return ideal + return ideal .instantRefund({ amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) -}) + expect(data.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/IdealQR.test.ts b/tests/PaymentMethods/IdealQR.test.ts index 6413896d..7ffeab00 100644 --- a/tests/PaymentMethods/IdealQR.test.ts +++ b/tests/PaymentMethods/IdealQR.test.ts @@ -1,6 +1,6 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('idealqr') +const method = buckarooClientTest.method('idealqr'); describe('Testing IdealQR methods', () => { test('Pay', async () => { await method @@ -21,12 +21,12 @@ describe('Testing IdealQR methods', () => { isProcessing: false, additionalParameters: { initiated_by_magento: '1', - service_action: 'something' - } + service_action: 'something', + }, }) .request() .then((response) => { - expect(response.isSuccess()).toBeTruthy() - }) - }) -}) + expect(response.isSuccess()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 14e55fc6..0d0a848a 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -1,9 +1,9 @@ -import buckarooClientTest from '../BuckarooClient.test' -import { uniqid } from '../../src/Utils/Functions' -import { IPay } from '../../src/PaymentMethods/In3/Models/Pay' -import RecipientCategory from '../../src/Constants/RecipientCategory' +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import { IPay } from '../../src/PaymentMethods/In3/Models/Pay'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; -const in3 = buckarooClientTest.method('In3') +const in3 = buckarooClientTest.method('In3'); describe('Testing In3 methods', () => { test('Pay', async () => { @@ -11,9 +11,9 @@ describe('Testing In3 methods', () => { .pay(payload) .request() .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy() - }) - }) + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await in3 .refund({ @@ -21,14 +21,14 @@ describe('Testing In3 methods', () => { originalTransactionKey: '', merchantImageUrl: '', summaryImageUrl: '', - articles: [] + articles: [], }) .request() .then((data) => { - expect(data.isSuccess()).toBeFalsy() - }) - }) -}) + expect(data.isSuccess()).toBeFalsy(); + }); + }); +}); const payload: IPay = { amountDebit: 52.3, @@ -45,7 +45,7 @@ const payload: IPay = { birthDate: '1990-01-01', customerNumber: '12345', companyName: 'Buckaroo', - chamberOfCommerce: '123456' + chamberOfCommerce: '123456', }, address: { street: 'Hoofdstraat', @@ -53,12 +53,12 @@ const payload: IPay = { houseNumberAdditional: 'a', zipcode: '1234AB', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, phone: { - mobile: '0698765433' + mobile: '0698765433', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, shipping: { recipient: { @@ -66,7 +66,7 @@ const payload: IPay = { careOf: 'J', firstName: 'John', lastName: 'Dona', - chamberOfCommerce: '123456' + chamberOfCommerce: '123456', }, address: { street: 'Kalverstraat', @@ -74,8 +74,8 @@ const payload: IPay = { houseNumberAdditional: 'b', zipcode: '4321EB', city: 'Amsterdam', - country: 'NL' - } + country: 'NL', + }, }, articles: [ { @@ -85,7 +85,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 2, - price: 20.1 + price: 20.1, }, { identifier: 'Articlenumber2', @@ -94,7 +94,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 1, - price: 10.1 + price: 10.1, }, { identifier: 'USPShippingID', @@ -103,7 +103,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 1, - price: 2 - } - ] -} + price: 2, + }, + ], +}; diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index af3cc398..f7e6c4a1 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -1,8 +1,8 @@ -import buckarooClientTest from '../BuckarooClient.test' -import Gender from '../../src/Constants/Gender' -import RecipientCategory from '../../src/Constants/RecipientCategory' +import buckarooClientTest from '../BuckarooClient.test'; +import Gender from '../../src/Constants/Gender'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; -const capayable = buckarooClientTest.method('capayable') +const capayable = buckarooClientTest.method('capayable'); describe('Testing capayable methods', () => { test('Pay', async () => { @@ -10,29 +10,29 @@ describe('Testing capayable methods', () => { .pay(paymentPayload) .request() .then((data) => { - expect(data.isSuccess()).toBeTruthy() - }) - }) + expect(data.isSuccess()).toBeTruthy(); + }); + }); test('Refund', async () => { await capayable .refund({ amountCredit: 42, - originalTransactionKey: '' + originalTransactionKey: '', }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy() - }) - }) + expect(data.isFailed()).toBeTruthy(); + }); + }); test('PayInInstallments', async () => { await capayable .payInInstallments(paymentPayload) .request() .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy() - }) - }) -}) + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); +}); const paymentPayload = { clientIP: '127.0.0.0', @@ -45,11 +45,11 @@ const paymentPayload = { culture: 'nl-NL', initials: 'J.S.', lastName: 'Aflever', - birthDate: '1990-01-01' + birthDate: '1990-01-01', }, company: { companyName: 'My Company B.V.', - chamberOfCommerce: '123456' + chamberOfCommerce: '123456', }, address: { street: 'Hoofdstraat', @@ -57,24 +57,24 @@ const paymentPayload = { houseNumberSuffix: 'a', zipcode: '8441EE', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, email: 'test@buckaroo.nl', phone: { - mobile: '0612345678' + mobile: '0612345678', }, articles: [ { identifier: '64381664f2f8b', price: 10, quantity: 1, - description: 'Blue Toy Car' - } + description: 'Blue Toy Car', + }, ], subtotals: [ { name: 'Verzendkosten', - value: 2 - } - ] -} + value: 2, + }, + ], +}; diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index 858e223c..93fa73f1 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,26 +1,26 @@ -import buckarooClientTest from '../BuckarooClient.test' -const method = buckarooClientTest.method('KBCPaymentButton') +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('KBCPaymentButton'); describe('Testing KBC methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10 + amountDebit: 10, }) .request() .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy() - }) - }) + expect(response.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { method .refund({ amountCredit: 10, - originalTransactionKey: 'B5675356904444F3965C33D280591C74' + originalTransactionKey: 'B5675356904444F3965C33D280591C74', }) .request() .then((response) => { - expect(response.isFailed()).toBeTruthy() - }) - }) -}) + expect(response.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index 8e98978b..a21696d0 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -1,27 +1,27 @@ -import buckarooClientTest from '../BuckarooClient.test' -import { IPay } from '../../src/PaymentMethods/Klarna/Models/Pay' -import { uniqid } from '../../src/Utils/Functions' -import RecipientCategory from '../../src/Constants/RecipientCategory' +import buckarooClientTest from '../BuckarooClient.test'; +import { IPay } from '../../src/PaymentMethods/Klarna/Models/Pay'; +import { uniqid } from '../../src/Utils/Functions'; +import RecipientCategory from '../../src/Constants/RecipientCategory'; -const klarna = buckarooClientTest.method('klarna') +const klarna = buckarooClientTest.method('klarna'); describe('Testing Klarna methods', () => { test('Pay', async () => { await klarna .pay(payload) .request() .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy() - }) - }) + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); test('PayInInstallments', async () => { await klarna .payInInstallments(payload) .request() .then((res) => { - expect(res).toBeDefined() - }) - }) -}) + expect(res).toBeDefined(); + }); + }); +}); let payload: IPay = { amountDebit: 50.3, @@ -33,7 +33,7 @@ let payload: IPay = { gender: 'female', firstName: 'John', lastName: 'Do', - birthDate: '1990-01-01' + birthDate: '1990-01-01', }, address: { street: 'Hoofdstraat', @@ -41,12 +41,12 @@ let payload: IPay = { houseNumberAdditional: 'a', zipcode: '1234AB', city: 'Heerenveen', - country: 'NL' + country: 'NL', }, phone: { - mobile: '0698765433' + mobile: '0698765433', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, shipping: { recipient: { @@ -54,7 +54,7 @@ let payload: IPay = { gender: 'male', firstName: 'John', lastName: 'Do', - birthDate: '1990-01-01' + birthDate: '1990-01-01', }, address: { street: 'Kalverstraat', @@ -62,9 +62,9 @@ let payload: IPay = { houseNumberAdditional: 'b', zipcode: '4321EB', city: 'Amsterdam', - country: 'NL' + country: 'NL', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, articles: [ { @@ -72,14 +72,14 @@ let payload: IPay = { description: 'Blue Toy Car', vatPercentage: 21, quantity: 2, - price: 20.1 + price: 20.1, }, { identifier: 'Articlenumber2', description: 'Red Toy Car', vatPercentage: 21, quantity: 1, - price: 10.1 - } - ] -} + price: 10.1, + }, + ], +}; diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 9c3b6232..34756c96 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,19 +1,19 @@ -import buckarooClientTest from '../BuckarooClient.test' -import gender from '../../src/Constants/Gender' -const klarnaKp = buckarooClientTest.method('klarnakp') +import buckarooClientTest from '../BuckarooClient.test'; +import gender from '../../src/Constants/Gender'; +const klarnaKp = buckarooClientTest.method('klarnakp'); describe('KlarnaKp', () => { test('Pay', async () => { await klarnaKp .pay({ amountDebit: 50.3, - reservationNumber: '2377577452' + reservationNumber: '2377577452', }) .request() .then((info) => { - expect(info.isFailed()).toBeTruthy() - }) - }) + expect(info.isFailed()).toBeTruthy(); + }); + }); test('Reserve', async () => { await klarnaKp .reserve({ @@ -23,33 +23,33 @@ describe('KlarnaKp', () => { billing: { recipient: { firstName: 'John', - lastName: 'Do' + lastName: 'Do', }, address: { street: 'Neherkade', houseNumber: '1', zipcode: '2521VA', city: 'Gravenhage', - country: 'NL' + country: 'NL', }, phone: { - mobile: '0612345678' + mobile: '0612345678', }, - email: 'youremail@example.nl' + email: 'youremail@example.nl', }, shipping: { recipient: { firstName: 'John', - lastName: 'Do' + lastName: 'Do', }, address: { street: 'Rosenburglaan', houseNumber: '216', zipcode: '4385 JM', city: 'Vlissingen', - country: 'NL' + country: 'NL', }, - email: 'test@buckaroo.nl' + email: 'test@buckaroo.nl', }, articles: [ { @@ -57,32 +57,32 @@ describe('KlarnaKp', () => { description: 'Blue Toy Car', vatPercentage: 21, quantity: 2, - price: 20.1 + price: 20.1, }, { identifier: 'Articlenumber2', description: 'Red Toy Car', vatPercentage: 21, quantity: 1, - price: 10.1 - } + price: 10.1, + }, ], additionalParameters: { initiated_by_magento: '1', - service_action: 'something' - } + service_action: 'something', + }, }) .request() .then((info) => { - expect(info.isPendingProcessing()).toBeTruthy() - }) - }) + expect(info.isPendingProcessing()).toBeTruthy(); + }); + }); test('Cancel', async () => { await klarnaKp .cancel({}) .request() .then((info) => { - expect(info).toBeDefined() - }) - }) -}) + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index 08e378c1..02b255a3 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,52 +1,76 @@ -require('../BuckarooClient.test') -import Marketplaces from '../../src/PaymentMethods/Marketplaces' -import Ideal from '../../src/PaymentMethods/Ideal' -const marketplaces = new Marketplaces() -const ideal = new Ideal() +import buckarooClientTest from '../BuckarooClient.test'; +const marketplaces = buckarooClientTest.method('marketplaces'); +const ideal = buckarooClientTest.method('ideal'); describe('Testing Marketplaces methods', () => { test('Split', async () => { marketplaces.split({ + description: 'INV0001', daysUntilTransfer: 2, marketplace: { amount: 10, - description: '' + description: '', }, - seller: [ + sellers: [ { accountId: '789C60F316D24B088ACD471', amount: 50, - description: '' + description: '', }, { accountId: '369C60F316D24B088ACD238', - amount: 35, - description: '' - } - ] - }) - ideal - .combine(marketplaces) + amount: 45, + description: '', + }, + ], + }); + return ideal + .combine(marketplaces.getPayload()) .pay({ issuer: 'ABNANL2A', - amountDebit: 95.0 + amountDebit: 95, }) + .request() .then((response) => { - expect(response.data).toBeDefined() - }) - }) + expect(response.isValidationFailure()).toBeTruthy(); + }); + }); test('transfer', async () => { - marketplaces.transfer({ originalTransactionKey: 'fwcafgdhgf' }).then((response) => { - expect(response.data).toBeDefined() - }) - }) + marketplaces + .transfer({ + originalTransactionKey: 'D3732474ED0', + marketplace: { + amount: 10, + description: 'INV0001 Commission Marketplace', + }, + sellers: [ + { + accountId: '789C60F316D24B088ACD471', + amount: 50, + description: 'INV001 Payout Make-Up Products BV', + }, + ], + }) + .request() + .then((response) => { + expect(response.isValidationFailure()).toBeTruthy(); + }); + }); test('refundSupplementary', async () => { - const market = marketplaces.refundSupplementary() + marketplaces.refundSupplementary({ + sellers: [ + { + accountId: '789C60F316D24B088ACD471', + description: 'INV001 Payout Make-Up Products BV', + }, + ], + }); ideal - .combine(market) + .combine(marketplaces) .refund({ originalTransactionKey: 'dasda', amountCredit: 10 }) + .request() .then((response) => { - expect(response.data).toBeDefined() - }) - }) -}) + expect(response.isValidationFailure()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts new file mode 100644 index 00000000..a8adbfc6 --- /dev/null +++ b/tests/PaymentMethods/Mbway.test.ts @@ -0,0 +1,13 @@ +import buckarooClientTest from "../BuckarooClient.test"; + +const method = buckarooClientTest.method("MBWay"); +describe("Mbway methods", () => { + test("Pay", () => { + return method + .pay({ + amountDebit: 0.1, + }).request().then((response) => { + expect(response.isValidationFailure()).toBeTruthy() + }) + }); +}) diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts new file mode 100644 index 00000000..b9260887 --- /dev/null +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -0,0 +1,15 @@ +import buckarooClientTest from '../BuckarooClient.test'; + +describe('Multibanco methods', () => { + test('Pay', async () => { + await buckarooClientTest + .method('multibanco') + .pay({ + amountDebit: 50.3, + }) + .request() + .then((info) => { + expect(info.isValidationFailure()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index cb9dce33..55cd92a6 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -1,47 +1,29 @@ -import Gender from '../../src/Constants/Gender' -import PayPerEmail from '../../src/PaymentMethods/PayPerEmail' - -require('../BuckarooClient.test') - -const method = new PayPerEmail() +import Gender from '../../src/Constants/Gender'; +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +const method = buckarooClientTest.method('payperemail'); describe('PayPerEmail methods', () => { test('paymentInvitation', async () => { await method .paymentInvitation({ - invoice: '123456', amountDebit: 10, - currency: 'EUR', - attachment: '', - additionalParameters: undefined, - clientIP: undefined, - continueOnIncomplete: 1, - culture: '', - customParameters: undefined, - customerEmail: '', - customerFirstName: '', - customerGender: Gender.NOT_APPLICABLE, - customerLastName: '', - description: '', - order: '', - originalTransactionKey: '', - originalTransactionReference: '', - pushURL: '', - pushURLFailure: '', - returnURL: '', - returnURLCancel: '', - returnURLError: '', - returnURLReject: '', - servicesExcludedForClient: '', - servicesSelectableByClient: '', - startRecurrent: false, - email: 's', - expirationDate: '', + order: uniqid(), + invoice: uniqid(), merchantSendsEmail: false, - paymentMethodsAllowed: 'ideal' + email: 'johnsmith@gmail.com', + expirationDate: '2030-01-01', + paymentMethodsAllowed: 'ideal,mastercard,paypal', + attachment: '', + customer: { + gender: Gender.FEMALE, + firstName: 'John', + lastName: 'Smith', + }, }) + .request() .then((response) => { - expect(response).toBeDefined() - }) - }) -}) + expect(response).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index 3e3c9c42..2a7b62f9 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,34 +1,37 @@ -import buckarooClientTest from "../BuckarooClient.test"; -const payconiq = buckarooClientTest.method("payconiq"); +import buckarooClientTest from '../BuckarooClient.test'; +const payconiq = buckarooClientTest.method('payconiq'); describe('Payconiq', () => { test('Pay', async () => { await payconiq .pay({ amountDebit: 50.3, - order: '123456' - }).request() - .then((info) => { - expect(info.data).toBeDefined() + order: '123456', }) - }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); test('Refund', async () => { await payconiq .refund({ amountCredit: 50.3, - originalTransactionKey: '123456' - }).request() - .then((info) => { - expect(info.data).toBeDefined() + originalTransactionKey: '123456', }) - }) + .request() + .then((info) => { + expect(info.data).toBeDefined(); + }); + }); test('InstantRefund', async () => { await payconiq .instantRefund({ amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' - }).request() - .then((data) => { - expect(data).toBeDefined() + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', }) - }) -}) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 36d5e035..3070cf01 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,7 +1,7 @@ -require('../BuckarooClient.test') -import PayByBank from '../../src/PaymentMethods/PayByBank' +require('../BuckarooClient.test'); +import PayByBank from '../../src/PaymentMethods/PayByBank'; -const paymentInitiation = new PayByBank('PayByBank') +const paymentInitiation = new PayByBank('PayByBank'); describe('PayByBank methods', () => { test('Pay', async () => { @@ -10,22 +10,22 @@ describe('PayByBank methods', () => { amountDebit: 50.3, order: '123456', issuer: 'INGBNL2A', - countryCode: 'NL' + countryCode: 'NL', }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) + expect(info.data).toBeDefined(); + }); + }); test('Refund', async () => { await paymentInitiation .refund({ amountCredit: 50.3, - originalTransactionKey: '123456' + originalTransactionKey: '123456', }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) -}) + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 83ebfd03..60a57436 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,34 +1,34 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; -require('../BuckarooClient.test') -import Paypal from '../../src/PaymentMethods/Paypal' +require('../BuckarooClient.test'); +import Paypal from '../../src/PaymentMethods/Paypal'; -const method = new Paypal('paypal') +const method = new Paypal('paypal'); describe('Paypal', () => { test('Pay', async () => { await method .pay({ - amountDebit: 50.3 + amountDebit: 50.3, }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) + expect(info.data).toBeDefined(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 50.3, - originalTransactionKey: '123456' + originalTransactionKey: '123456', }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) + expect(info.data).toBeDefined(); + }); + }); test('ExtraInfo', async () => { - buckarooClientTest.method('subscriptions').createCombined({}) + buckarooClientTest.method('subscriptions').createCombined({}); await method .extraInfo({ amountDebit: 50.3, @@ -38,16 +38,16 @@ describe('Paypal', () => { city: 'Heerenveen', state: 'Friesland', zipcode: '8441AB', - country: 'NL' + country: 'NL', }, addressOverride: false, costumer: { name: 'John' }, noShipping: '0', - phone: { mobile: '0612345678' } + phone: { mobile: '0612345678' }, }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) -}) + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index 46dca2bb..f1f444d4 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -1,12 +1,12 @@ -require('../BuckarooClient.test') -import PiM from '../../src/PaymentMethods/PiM' +require('../BuckarooClient.test'); +import PiM from '../../src/PaymentMethods/PiM'; -const pim = new PiM() +const pim = new PiM(); describe('PiM', () => { test('generate', async () => { await pim.generate().then((info) => { - expect(info).toBeDefined() - }) - }) -}) + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 653405a2..3482c22b 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,7 +1,7 @@ -require('../BuckarooClient.test') -import Przelewy24 from '../../src/PaymentMethods/Przelewy24' +require('../BuckarooClient.test'); +import Przelewy24 from '../../src/PaymentMethods/Przelewy24'; -const method = new Przelewy24('Przelewy24') +const method = new Przelewy24('Przelewy24'); describe('Przelewy24', () => { test('Pay', async () => { @@ -10,24 +10,24 @@ describe('Przelewy24', () => { amountDebit: 50.3, customer: { firstName: 'test', - lastName: 'test' + lastName: 'test', }, - email: 'test@hotmail.com' + email: 'test@hotmail.com', }) .request() .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy() - }) - }) + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 50.3, - originalTransactionKey: '123456' + originalTransactionKey: '123456', }) .request() .then((info) => { - expect(info.data).toBeDefined() - }) - }) -}) + expect(info.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index 6bed227d..42295c05 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -1,7 +1,7 @@ -require('../BuckarooClient.test') -import SEPA from '../../src/PaymentMethods/SEPA' +require('../BuckarooClient.test'); +import SEPA from '../../src/PaymentMethods/SEPA'; -const method = new SEPA() +const method = new SEPA(); describe('SEPA', () => { test('Pay', async () => { @@ -33,45 +33,45 @@ describe('SEPA', () => { returnURLReject: '', servicesExcludedForClient: '', servicesSelectableByClient: '', - startRecurrent: false + startRecurrent: false, }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 50.3, - originalTransactionKey: '' + originalTransactionKey: '', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('Authorize', async () => { await method .authorize({ amountDebit: 0, collectDate: '', customerIBAN: '', - customeraccountname: '' + customeraccountname: '', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('PayRecurrent', async () => { await method .payRecurrent({ collectDate: '', amountDebit: 50.3, - originalTransactionKey: '' + originalTransactionKey: '', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('ExtraInfo', async () => { await method .extraInfo({ @@ -111,20 +111,20 @@ describe('SEPA', () => { servicesSelectableByClient: '', startRecurrent: false, street: '', - zipcode: '' + zipcode: '', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('Emandates', async () => { await method .payWithEmandate({ mandateReference: '', - amountDebit: 50.3 + amountDebit: 50.3, }) .then((info) => { - expect(info).toBeDefined() - }) - }) -}) + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index 0424c4c6..f0d8d127 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -1,37 +1,37 @@ -require('../BuckarooClient.test') -import Sofort from '../../src/PaymentMethods/Sofort' -const method = new Sofort() +require('../BuckarooClient.test'); +import Sofort from '../../src/PaymentMethods/Sofort'; +const method = new Sofort(); describe('Sofort', () => { test('Pay', async () => { await method .pay({ amountDebit: 50.3, - order: '123456' + order: '123456', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 50.3, - originalTransactionKey: '123456' + originalTransactionKey: '123456', }) .then((info) => { - expect(info).toBeDefined() - }) - }) + expect(info).toBeDefined(); + }); + }); test('InstantRefund', async () => { await method .instantRefund({ amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1' + originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', }) .then((data) => { - expect(data).toBeDefined() - }) - }) -}) + expect(data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index ffac707b..57f830c6 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,159 +1,151 @@ -import buckarooClientTest from '../BuckarooClient.test' +import buckarooClientTest from '../BuckarooClient.test'; +import {describe} from "node:test"; -const subscription = buckarooClientTest.method('subscriptions') +const subscription = buckarooClientTest.method('subscriptions'); -test('Create', async () => { - subscription - .create({ - additionalParameters: { - signature: '123213' - }, - ratePlans: { - add: { - startDate: '2024-07-23', - ratePlanCode: 'zfv59mmy' - } - }, - ratePlanCharges: { - add: { - ratePlanChargeCode: 'test' - } - }, - configurationCode: 'gfyh9fe4', - configuration: { - name: 'owiejr' - }, - debtor: { - code: 'johnsmith4' - } - }) - .request() - .then((data) => { - expect(data.hasError()).toBeTruthy() - }) - .catch((e) => { - expect(e).toBeDefined() - }) - .catch((e) => { - expect(e).toBeDefined() - }) -}) -test('Update', async () => { - subscription - .update({ - email: 'test@buckaroo.nl', - subscriptionGuid: 'FC512FC9CC3A485D8CF3D1804FF6xxxx', - configurationCode: '9wqe32ew', - ratePlan: { - update: { - ratePlanGuid: 'F075470B1BB24B9291943A888A2Fxxxx', - startDate: '2022-01-01', - endDate: '2030-01-01' - } - } - }) - .request() - .then((data) => { - expect(data).toBeDefined() - }) -}) +describe('Subscription methods', () => { + test('Create', () => { + return subscription + .create({ + additionalParameters: { + signature: '123213', + }, + ratePlans: { + add: { + startDate: '2024-07-23', + ratePlanCode: 'zfv59mmy', + }, + }, + ratePlanCharges: { + add: { + ratePlanChargeCode: 'test', + }, + }, + configurationCode: 'gfyh9fe4', + configuration: { + name: 'owiejr', + }, + debtor: { + code: 'johnsmith4', + }, + }) + .request() + .then((data) => { + expect(data.hasError()).toBeTruthy(); + }) + }); + test('Update', async () => { + subscription + .update({ + email: 'test@buckaroo.nl', + subscriptionGuid: 'FC512FC9CC3A485D8CF3D1804FF6xxxx', + configurationCode: '9wqe32ew', + ratePlan: { + update: { + ratePlanGuid: 'F075470B1BB24B9291943A888A2Fxxxx', + startDate: '2022-01-01', + endDate: '2030-01-01', + }, + }, + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Combined Subscription', async () => { + subscription + .createCombined({ + pushURL: 'https://buckaroo.dev/push', + includeTransaction: false, + transactionVatPercentage: 5, + configurationCode: 'gfyh9fe4', + email: 'test@buckaroo.nl', + ratePlans: { + add: { + startDate: '2033-01-01', + ratePlanCode: '9863hdcj', + }, + }, + phone: { + mobile: '0612345678', + }, + debtor: { + code: 'johnsmith4', + }, + company: { + culture: 'nl-NL', + companyName: 'My Company Coporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741', + }, + address: { + street: 'Hoofdstraat', + houseNumber: '90', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL', + }, + }) + subscription.combine('ideal') + .pay({ + issuer: 'ABNANL2A', + amountDebit: 10, + startRecurrent: true, + }).request().then((data) => { + expect(data).toBeDefined(); + }) + }) -test('Combined Subscription', async () => { - const combinable = subscription - .createCombined({ - pushURL: 'https://buckaroo.dev/push', - includeTransaction: false, - transactionVatPercentage: 5, - configurationCode: 'gfyh9fe4', - email: 'test@buckaroo.nl', - ratePlans: { - add: { - startDate: '2033-01-01', - ratePlanCode: '9863hdcj' - } - }, - phone: { - mobile: '0612345678' - }, - debtor: { - code: 'johnsmith4' - }, - company: { - culture: 'nl-NL', - companyName: 'My Company Coporation', - vatApplicable: true, - vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741' - }, - address: { - street: 'Hoofdstraat', - houseNumber: '90', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL' - } - }) - .combine('ideal') - .pay({ - issuer: 'ABNANL2A', - amountDebit: 10, - startRecurrent: true - }) - .request() - .then((res) => { - expect(res).toBeDefined() + test('Update Combined Subscription', async () => { + subscription + .updateCombined({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }) + subscription.combine('ideal') + .pay({ + issuer: 'ABNANL2A', + amountDebit: 10, + }).request().then((data) => { + expect(data).toBeDefined(); }) -}) + }); -test('Update Combined Subscription', async () => { - const combinable = subscription - .updateCombined({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - .combine('ideal') - .pay({ - issuer: 'ABNANL2A', - amountDebit: 10 - }) - .request() - .then((res) => { - expect(res).toBeDefined() - }) -}) - -test('Stop Subscription', async () => { - const stop = await subscription.stop({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - expect(stop).toBeDefined() -}) -test('Subscription Info', async () => { - const info = await subscription.info({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - expect(info).toBeDefined() -}) -test('Delete Subscription Config', async () => { - await subscription - .deletePaymentConfig({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - .request() - .then((res) => { - expect(res.httpResponse.statusCode === 200).toBeTruthy() - }) -}) -test('Subscription Pause', async () => { - const pause = await subscription.pause({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', - resumeDate: '2030-01-01' - }) - expect(pause).toBeDefined() -}) -test('Subscription Resume', async () => { - const resume = await subscription.resume({ - resumeDate: '2030-01-01', - subscriptionGuid: '515461997AD34C50881D74157E38A64D' - }) - expect(resume).toBeDefined() + test('Stop Subscription', async () => { + const stop = await subscription.stop({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }); + expect(stop).toBeDefined(); + }); + test('Subscription Info', async () => { + const info = await subscription.info({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }); + expect(info).toBeDefined(); + }); + test('Delete Subscription Config', async () => { + await subscription + .deletePaymentConfig({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }) + .request() + .then((res) => { + expect(res.httpResponse.statusCode === 200).toBeTruthy(); + }); + }); + test('Subscription Pause', async () => { + const pause = await subscription.pause({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + resumeDate: '2030-01-01', + }); + expect(pause).toBeDefined(); + }); + test('Subscription Resume', async () => { + const resume = await subscription.resume({ + resumeDate: '2030-01-01', + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }); + expect(resume).toBeDefined(); + }); }) diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 0ed4b594..5b5ee80d 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -1,16 +1,16 @@ -require('../BuckarooClient.test') -import SurePay from '../../src/PaymentMethods/Surepay' +require('../BuckarooClient.test'); +import SurePay from '../../src/PaymentMethods/Surepay'; -const method = new SurePay() +const method = new SurePay(); describe('Sofort', () => { test('Verify', async () => { await method .verify({ - customeraccountname: 'string' + customeraccountname: 'string', }) .then((info) => { - expect(info).toBeDefined() - }) - }) -}) + expect(info).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index c2e760bb..a560ee72 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -1,28 +1,28 @@ -require('../BuckarooClient.test') +require('../BuckarooClient.test'); -import Thunes from '../../src/PaymentMethods/Thunes' +import Thunes from '../../src/PaymentMethods/Thunes'; -const thunes = new Thunes() +const thunes = new Thunes(); describe('Thunes methods', () => { test('authorize', async () => { thunes.authorize({ amountDebit: 0 }).then((res) => { - expect(res.data).toBeDefined() - }) - }) + expect(res.data).toBeDefined(); + }); + }); test('capture', async () => { thunes.capture({ amountDebit: 0, originalTransactionKey: '1' }).then((res) => { - expect(res.data).toBeDefined() - }) - }) + expect(res.data).toBeDefined(); + }); + }); test('getStatus', async () => { thunes.getStatus({ originalTransactionKey: '111111111111' }).then((res) => { - expect(res.data).toBeDefined() - }) - }) + expect(res.data).toBeDefined(); + }); + }); test('cancel', async () => { thunes.cancel({ originalTransactionKey: '111111111111' }).then((res) => { - expect(res.data).toBeDefined() - }) - }) -}) + expect(res.data).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 818455da..19dc8954 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,64 +1,66 @@ -import Gender from "../../src/Constants/Gender"; -import buckarooClientTest from "../BuckarooClient.test"; -const method = buckarooClientTest.method('tinka') +import Gender from '../../src/Constants/Gender'; +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('tinka'); describe('Tinka', () => { test('Pay', async () => { await method .pay({ billing: { recipient: { - lastNamePrefix: "the" + lastNamePrefix: 'the', }, - email: "billingcustomer@buckaroo.nl", + email: 'billingcustomer@buckaroo.nl', phone: { - mobile: "0109876543" + mobile: '0109876543', }, address: { - street: "Hoofdstraat", - houseNumber: "80", - houseNumberAdditional: "A", - zipcode: "8441EE", - city: "Heerenveen", - country: "NL" - } + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'A', + zipcode: '8441EE', + city: 'Heerenveen', + country: 'NL', + }, }, customer: { - gender : Gender.MALE, + gender: Gender.MALE, firstName: 'Buck', - lastName : 'Aroo', - initials :'BA', - birthDate : '1990-01-01', + lastName: 'Aroo', + initials: 'BA', + birthDate: '1990-01-01', }, amountDebit: 3.5, articles: [ { type: '1', - description: "Blue Toy Car", - brand: "Ford Focus", - manufacturer: "Ford", - color: "Red", - size: "Small", + description: 'Blue Toy Car', + brand: 'Ford Focus', + manufacturer: 'Ford', + color: 'Red', + size: 'Small', quantity: 1, price: 3.5, - unitCode: "test" - } + unitCode: 'test', + }, ], deliveryDate: '09-07-2020', deliveryMethod: 'CompanyStore', - paymentMethod: 'Credit' - }).request() - .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy() + paymentMethod: 'Credit', }) - }) + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 3.5, - originalTransactionKey: '1234567890' - }).request() - .then((res) => { - expect(res.isFailed()).toBeTruthy() + originalTransactionKey: '1234567890', }) - }) -}) + .request() + .then((res) => { + expect(res.isFailed()).toBeTruthy(); + }); + }); +}); diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index cd8e93c6..5fd739f2 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -1,7 +1,7 @@ -require('../BuckarooClient.test') -import Trustly from '../../src/PaymentMethods/Trustly' +require('../BuckarooClient.test'); +import Trustly from '../../src/PaymentMethods/Trustly'; -const method = new Trustly() +const method = new Trustly(); describe('Trustly', () => { test('Pay', async () => { @@ -10,10 +10,10 @@ describe('Trustly', () => { amountDebit: 12, customerCountryCode: 'DE', customerFirstName: 'da', - customerLastName: '34' + customerLastName: '34', }) .then((response) => { - expect(response).toBeDefined() - }) - }) -}) + expect(response).toBeDefined(); + }); + }); +}); diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 98fb6a83..cd118fd1 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,24 +1,26 @@ -import buckarooClientTest from "../BuckarooClient.test"; -const method = buckarooClientTest.method('wechatpay') +import buckarooClientTest from '../BuckarooClient.test'; +const method = buckarooClientTest.method('wechatpay'); describe('WechatPay', () => { test('Pay', async () => { await method .pay({ amountDebit: 3.5, - locale: 'en-US' - }).request() - .then((response) => { - expect(response.isPendingProcessing()).toBeDefined() + locale: 'en-US', }) - }) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeDefined(); + }); + }); test('Refund', async () => { await method .refund({ amountCredit: 3.5, - originalTransactionKey: '1234567890' - }).request() - .then((response) => { - expect(response.data).toBeDefined() + originalTransactionKey: '1234567890', }) - }) -}) + .request() + .then((response) => { + expect(response.data).toBeDefined(); + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 39f52037..1307b466 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,5 +14,5 @@ "outDir": "dist", "resolveJsonModule": true }, - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts"] } From a0e0ada0fdfcd3ddc9e7cbe056199bf6cb2b9298 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:49:35 +0200 Subject: [PATCH 10/52] BP-3010 --- src/PaymentMethods/Mbway/index.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/PaymentMethods/Mbway/index.ts diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts new file mode 100644 index 00000000..83c20778 --- /dev/null +++ b/src/PaymentMethods/Mbway/index.ts @@ -0,0 +1,5 @@ +import PayablePaymentMethod from "../PayablePaymentMethod"; + +export default class Mbway extends PayablePaymentMethod { + protected _paymentName = "MB WAY"; +} From bfc6a0336f844a5cf85d8cc6f0a4de276d54335e Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:13:30 +0200 Subject: [PATCH 11/52] Add Mbway --- src/PaymentMethods/Mbway/index.ts | 5 +++++ src/Utils/MethodTypes.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/PaymentMethods/Mbway/index.ts diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts new file mode 100644 index 00000000..242026c2 --- /dev/null +++ b/src/PaymentMethods/Mbway/index.ts @@ -0,0 +1,5 @@ +import PayablePaymentMethod from "../PayablePaymentMethod"; + +export default class Mbway extends PayablePaymentMethod { + protected _paymentName = 'MBWay'; +} diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 4ac975da..5ecec099 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -40,7 +40,7 @@ import type Trustly from '../PaymentMethods/Trustly'; import type Wechatpay from '../PaymentMethods/WeChatPay'; import type In3 from '../PaymentMethods/In3'; import type MultiBanco from '../PaymentMethods/Multibanco'; -import type Index from "../PaymentMethods/Mbway"; +import type Mbway from "../PaymentMethods/Mbway"; //toDo refactor this @@ -87,7 +87,7 @@ export type AllMethods = readonly [ { class: Trustly; code: MethodTypes['Trustly'] }, { class: Wechatpay; code: MethodTypes['WeChatPay'] }, { class: MultiBanco; code: MethodTypes['Multibanco'] }, - { class: Index ; code: MethodTypes['Mbway'] }, + { class: Mbway ; code: MethodTypes['Mbway'] }, ]; export type ServiceCode = AllMethods[number]['code'][number]; From f2852c224516a3fadc92c0a78b15de2b7bb8e2d3 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 09:54:23 +0200 Subject: [PATCH 12/52] add rollup dependencies --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d774ede..adb5023c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,13 @@ "jest": "^29.4.2", "prettier": "^2.8.3", "ts-jest": "^29.0.5", - "typescript": "^4.9.4" + "typescript": "^4.9.4", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/preset-env": "^7.23.2", + "@babel/preset-typescript": "^7.23.2", + "rollup-plugin-babel": "^4.4.0", + "rollup-plugin-json": "^4.0.0", + "rollup-plugin-node-resolve": "^5.2.0" }, "dependencies": { "crypto-js": "^4.1.1", From b267390e3210f2bb515af81fee98afdceb882a6a Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 12:50:38 +0200 Subject: [PATCH 13/52] improvements + change current http client to axios + improve payment methods handler --- package.json | 12 +- src/Handlers/Credentials.ts | 2 +- src/Models/Response/HttpClientResponse.ts | 42 +++-- src/PaymentMethods/PaymentMethod.ts | 14 +- src/PaymentMethods/index.ts | 84 ++++++++++ src/Request/Headers.ts | 11 +- src/Request/HttpsClient.ts | 70 ++++---- src/Request/Request.ts | 56 ++++--- src/Utils/Functions.ts | 30 +++- src/Utils/MethodTypes.ts | 196 ++-------------------- src/index.ts | 29 ++-- tsconfig.spec.json | 5 + 12 files changed, 246 insertions(+), 305 deletions(-) create mode 100644 src/PaymentMethods/index.ts create mode 100644 tsconfig.spec.json diff --git a/package.json b/package.json index adb5023c..51b94105 100644 --- a/package.json +++ b/package.json @@ -26,20 +26,20 @@ "author": "Rinor Haziri", "license": "ISC", "devDependencies": { + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/preset-env": "^7.23.2", + "@babel/preset-typescript": "^7.23.2", "@types/crypto-js": "^4.1.1", "@types/jest": "^29.4.0", "@types/node": "^18.11.18", "dotenv": "^16.0.3", "jest": "^29.4.2", "prettier": "^2.8.3", - "ts-jest": "^29.0.5", - "typescript": "^4.9.4", - "@babel/plugin-proposal-class-properties": "^7.18.6", - "@babel/preset-env": "^7.23.2", - "@babel/preset-typescript": "^7.23.2", "rollup-plugin-babel": "^4.4.0", "rollup-plugin-json": "^4.0.0", - "rollup-plugin-node-resolve": "^5.2.0" + "rollup-plugin-node-resolve": "^5.2.0", + "ts-jest": "^29.0.5", + "typescript": "^4.9.4" }, "dependencies": { "crypto-js": "^4.1.1", diff --git a/src/Handlers/Credentials.ts b/src/Handlers/Credentials.ts index 938b5d4c..09996d78 100644 --- a/src/Handlers/Credentials.ts +++ b/src/Handlers/Credentials.ts @@ -16,7 +16,7 @@ export class Credentials implements ICredentials { }) .request() .then((response) => { - return response.httpResponse.statusCode === 200; + return response.httpResponse.status === 200 }) .catch(() => { return false; diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts index b2f37d27..8d49820f 100644 --- a/src/Models/Response/HttpClientResponse.ts +++ b/src/Models/Response/HttpClientResponse.ts @@ -1,27 +1,27 @@ -import { IncomingMessage } from 'http'; -import { JsonModel } from '../Model'; -import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler'; -import { ICredentials } from '../../Utils/Types'; +import { IncomingMessage } from 'http' +import { JsonModel } from '../Model' +import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler' +import { ICredentials } from '../../Utils/Types' +import {AxiosResponse} from "axios"; export interface HttpResponseConstructor { - new (httpResponse: IncomingMessage, data: string): IHttpClientResponse; + new (httpResponse: AxiosResponse, data: string): IHttpClientResponse } export interface IHttpClientResponse { - httpResponse: IncomingMessage; - data: object; + httpResponse: AxiosResponse } export class HttpClientResponse implements IHttpClientResponse { - protected readonly _httpResponse: IncomingMessage; - protected readonly _data: object; - protected readonly _rawData: string; - constructor(httpResponse: IncomingMessage, data: string) { - this._httpResponse = httpResponse; - this._rawData = data; - this._data = new JsonModel(JSON.parse(data)); + protected readonly _httpResponse: AxiosResponse + protected readonly _data: object + protected readonly _rawData: string + constructor(httpResponse: AxiosResponse) { + this._httpResponse = httpResponse + this._rawData = httpResponse.data + this._data = new JsonModel(httpResponse.data) } - get httpResponse(): IncomingMessage { - return this._httpResponse; + get httpResponse(): AxiosResponse { + return this._httpResponse } get rawData(): string { return this._rawData; @@ -30,6 +30,14 @@ export class HttpClientResponse implements IHttpClientResponse { return this._data; } validateResponse(credentials: ICredentials) { - return new ReplyHandler(credentials, this._rawData, this.httpResponse.headers['authorization'], this.httpResponse.url, this.httpResponse.method).validate().isValid(); + return new ReplyHandler( + credentials, + this._rawData, + this.httpResponse.headers['authorization'], + this.httpResponse.request.url, + this.httpResponse.request.method + ) + .validate() + .isValid() } } diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index 2796da8b..55bdfbca 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -6,16 +6,16 @@ import {IService, ServiceList} from '../Models/IServiceList'; import { ServiceParameter } from '../Models/ServiceParameters'; import { IParameter } from '../Models/IParameters'; import { TransactionData } from '../Request/DataModels'; -import {MethodFromServiceCode, ServiceCode} from "../Utils/MethodTypes"; +import {PaymentMethodInstance, ServiceCode} from "../Utils/MethodTypes"; export default abstract class PaymentMethod { protected _paymentName: string = ''; - protected _serviceCode?: string; + protected _serviceCode?: ServiceCode = 'noservice'; protected _serviceVersion: number = 0; protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; - constructor(serviceCode?: string) { - this._serviceCode = serviceCode ?? this.paymentName; + constructor(serviceCode?: ServiceCode) { + this._serviceCode = serviceCode ?? this.serviceCode; } get serviceVersion() { return this._serviceVersion; @@ -23,8 +23,8 @@ export default abstract class PaymentMethod { set serviceVersion(value: number) { this._serviceVersion = value; } - get serviceCode() { - return this._serviceCode || ''; + get serviceCode(): ServiceCode { + return this._serviceCode || 'noservice'; } get paymentName() { return this._paymentName; @@ -75,7 +75,7 @@ export default abstract class PaymentMethod { return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); } - combine(data: Name): MethodFromServiceCode; + combine(data: Name): PaymentMethodInstance; combine(data: Payload): this; combine(method: Method): this; combine(data): this { diff --git a/src/PaymentMethods/index.ts b/src/PaymentMethods/index.ts new file mode 100644 index 00000000..405af608 --- /dev/null +++ b/src/PaymentMethods/index.ts @@ -0,0 +1,84 @@ +export {default as ideal} from './Ideal' +export {default as idealprocessing} from './Ideal' +export {default as afterpay} from './Afterpay' +export {default as afterpaydigiaccept} from './AfterpayDigiAccept' +export {default as applepay} from './ApplePay' +export {default as bancontactmrcash} from './Bancontact' +export {default as transfer} from './BankTransfer' +export {default as belfius} from './Belfius' +export {default as billink} from './Billink' +export {default as buckaroovoucher} from './BuckarooVoucher' +export {default as BuckarooWalletCollecting} from './BuckarooWallet' +export {default as CreditCard} from './CreditCard' + +// Credit Cards +export {default as creditcard} from './CreditCard' +export {default as mastercard} from './CreditCard' +export {default as visa} from './CreditCard' +export {default as amex} from './CreditCard' +export {default as vpay} from './CreditCard' +export {default as maestro} from './CreditCard' +export {default as visaelectron} from './CreditCard' +export {default as cartebleuevisa} from './CreditCard' +export {default as cartebancaire} from './CreditCard' +export {default as dankort} from './CreditCard' +export {default as nexi} from './CreditCard' +export {default as postepay} from './CreditCard' + +export {default as creditclick} from './CreditClick' +export {default as CreditManagement3} from './CreditManagement' +export {default as emandate} from './Emandates' +export {default as eps} from './EPS' + +// Gift Cards +export {default as giftcard} from './GiftCard' +export {default as westlandbon} from './GiftCard' +export {default as babygiftcard} from './GiftCard' +export {default as babyparkgiftcard} from './GiftCard' +export {default as beautywellness} from './GiftCard' +export {default as boekenbon} from './GiftCard' +export {default as boekenvoordeel} from './GiftCard' +export {default as designshopsgiftcard} from './GiftCard' +export {default as fashioncheque} from './GiftCard' +export {default as fashionucadeaukaart} from './GiftCard' +export {default as fijncadeau} from './GiftCard' +export {default as koffiecadeau} from './GiftCard' +export {default as kokenzo} from './GiftCard' +export {default as kookcadeau} from './GiftCard' +export {default as nationaleentertainmentcard} from './GiftCard' +export {default as naturesgift} from './GiftCard' +export {default as podiumcadeaukaart} from './GiftCard' +export {default as shoesaccessories} from './GiftCard' +export {default as webshopgiftcard} from './GiftCard' +export {default as wijncadeau} from './GiftCard' +export {default as wonenzo} from './GiftCard' +export {default as yourgift} from './GiftCard' +export {default as vvvgiftcard} from './GiftCard' +export {default as parfumcadeaukaart} from './GiftCard' + +export {default as giropay} from './Giropay' +export {default as idealqr} from './IdealQR' +export {default as idin} from './Idin' +export {default as capayable} from './In3Old' +export {default as KBCPaymentButton} from './KBC' +export {default as klarna} from './Klarna' +export {default as klarnakp} from './KlarnaKP' +export {default as Marketplaces} from './Marketplaces' +export {default as payconiq} from './Payconiq' +export {default as PayByBank} from './PayByBank' +export {default as paypal} from './Paypal' +export {default as payperemail} from './PayPerEmail' +export {default as PiM} from './PiM' +export {default as pointofsale} from './PointOfSale' +export {default as przelewy24} from './Przelewy24' +export {default as sepadirectdebit} from './SEPA' +export {default as sofortueberweisung} from './Sofort' +export {default as subscriptions} from './Subscriptions' +export {default as surepay} from './Surepay' +export {default as thunes} from './Thunes' +export {default as tinka} from './Tinka' +export {default as alipay} from './Alipay' +export {default as trustly} from './Trustly' +export {default as wechatpay} from './WeChatPay' +export {default as In3} from './In3' +export {default as noservice} from './NoService' diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index e00f96f9..06d3cb49 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -1,19 +1,22 @@ -import { OutgoingHttpHeaders } from 'http'; +import {AxiosRequestConfig} from "axios"; export type RequestHeaders = { - 'Content-type'?: string; + 'Content-Type'?: string; Accept?: string; Culture?: string; Authorization?: string; Software?: string; -} & OutgoingHttpHeaders; + [header: string]: any; +} + +export type RequestConfig = { headers: RequestHeaders } | AxiosRequestConfig export default class Headers { private _headers: RequestHeaders = this.getDefaultHeaders(); get headers(): RequestHeaders { return this._headers; } - protected getDefaultHeaders() { + protected getDefaultHeaders(): RequestHeaders { return { 'Content-type': 'application/json; charset=utf-8', Accept: 'application/json', diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 5b80ded3..7d48a1eb 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,52 +1,38 @@ -import { Agent, RequestOptions } from 'https'; -import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; -import * as https from 'https'; +import axios, {AxiosInstance, AxiosRequestConfig} from 'axios'; +import {HttpResponseConstructor} from '../Models/Response/HttpClientResponse'; +import {RequestConfig, RequestHeaders} from "./Headers"; -const defaultAgent = new Agent({ - keepAlive: true, - keepAliveMsecs: 10000, -}); export default class HttpsClient { - protected _options: RequestOptions = {}; - constructor(agent?: Agent) { + private _axiosInstance: AxiosInstance; + protected _options: AxiosRequestConfig = {}; + + constructor() { this._options.timeout = 10000; - this._options.agent = agent || defaultAgent; - this._options.sessionTimeout = 30000; + this._options.maxRedirects = 10; + this._options.withCredentials = true; + this._axiosInstance = axios.create(this._options); } - public sendRequest(url: URL, data: string, options: RequestOptions = {}, responseClass: R): Promise> { - return new Promise((resolve, reject) => { - const req = https.request(url, { + + public async sendRequest( + url: URL, + data: string, + options: RequestConfig, + responseClass: R + ): Promise> { + try { + const response = await this._axiosInstance.request({ + url: url.toString(), + data, ...this._options, ...options, }); - req.on('error', (err) => { - reject(err); - }); - req.on('timeout', () => { - req.destroy(); - }); - req.on('response', (res) => { - let response: any[] = []; - res.on('data', (chunk) => { - response.push(chunk); - }); - res.on('end', () => { - try { - resolve(new responseClass(res, Buffer.concat(response).toString()) as InstanceType); - } catch (e) { - try { - reject(Buffer.concat(response).toString()); - } catch (e) { - reject(e); - } - } - }); - }); - if (data) { - req.write(data); + + return new responseClass(response, response.data) as InstanceType; + } catch (error: unknown) { + if (axios.isAxiosError(error)) { + throw error.response?.data ?? error; } - req.end(); - return req; - }); + throw error; + } } } diff --git a/src/Request/Request.ts b/src/Request/Request.ts index 8e551e2d..cc55112c 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -1,17 +1,19 @@ -import Headers from './Headers'; -import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; -import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels'; -import Buckaroo from '../index'; -import Endpoints, { RequestTypes } from '../Constants/Endpoints'; -import { TransactionResponse } from '../Models/Response/TransactionResponse'; -import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; -import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; -import HttpMethods from '../Constants/HttpMethods'; -import { RequestOptions } from 'https'; -import { ICredentials } from '../Utils/Types'; -import { Hmac } from './Hmac'; -import { IService } from '../Models/IServiceList'; -import IRequest from '../Models/IRequest'; +import Headers from './Headers' +import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse' +import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels' +import Buckaroo from '../index' +import Endpoints, { RequestTypes } from '../Constants/Endpoints' +import { TransactionResponse } from '../Models/Response/TransactionResponse' +import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse' +import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse' +import HttpMethods from '../Constants/HttpMethods' +import { RequestOptions } from 'https' +import PaymentMethod from '../PaymentMethods/PaymentMethod' +import { ICredentials } from '../Utils/Types' +import { Hmac } from './Hmac' +import { ServiceCode, AvailablePaymentMethods} from '../Utils/MethodTypes' +import { IService } from '../Models/IServiceList' +import IRequest from "../Models/IRequest"; export default class Request extends Headers { protected _data?: object | object[] | undefined; @@ -79,12 +81,24 @@ export default class Request new DataRequestData(data)), - BatchRequestResponse - ); + static BatchDataRequest(data: DataRequestData[] = []) { + return new Request(RequestTypes.BatchData, HttpMethods.POST, data, BatchRequestResponse) + } + combine( + method: Method + ): Method extends ServiceCode ? AvailablePaymentMethods[Method] : Method + combine(request: R): this + combine(data): PaymentMethod | this { + if (!(data instanceof Request)) { + let paymentMethod: PaymentMethod = + data instanceof PaymentMethod ? data : Buckaroo.Client.method(data) + if (this.data instanceof TransactionData) { + paymentMethod.combine(this.data) + } + return paymentMethod + } else { + this._data = { ...this._data, ...data.data } + } + return this } } diff --git a/src/Utils/Functions.ts b/src/Utils/Functions.ts index 0ee20f6f..d6fcad93 100644 --- a/src/Utils/Functions.ts +++ b/src/Utils/Functions.ts @@ -1,4 +1,11 @@ -import { IAdditionalParameters, IFormattedParameter, IParameter, IServiceParameters, ServiceParameterTypes } from '../Models/IParameters'; +import os from 'os'; +import { + IAdditionalParameters, + IFormattedParameter, + IParameter, + IServiceParameters, + ServiceParameterTypes +} from '../Models/IParameters' export function uniqid(prefix: string = '', random: boolean = false) { const sec = Date.now() * 1000 + Math.random() * 1000; @@ -65,15 +72,22 @@ export abstract class DataFormatter { }, {}); } } -export function getIPAddress() { - const interfaces = require('os').networkInterfaces(); +export const getIPAddress = (): string => { + const interfaces = os.networkInterfaces(); + for (const devName in interfaces) { - let iface = interfaces[devName]; + const iface = interfaces[devName]; + + if (!iface) { + continue; + } - for (let i = 0; i < iface.length; i++) { - let alias = iface[i]; - if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) return alias.address; + for (const alias of iface) { + if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) { + return alias.address; + } } } + return '0.0.0.0'; -} +}; diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 4ac975da..89f02090 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,190 +1,16 @@ -import type Ideal from '../PaymentMethods/Ideal'; -import type Afterpay from '../PaymentMethods/Afterpay'; -import type AfterpayDigiAccept from '../PaymentMethods/AfterpayDigiAccept'; -import type ApplePay from '../PaymentMethods/ApplePay'; -import type Bancontact from '../PaymentMethods/Bancontact'; -import type Banktransfer from '../PaymentMethods/BankTransfer'; -import type Belfius from '../PaymentMethods/Belfius'; -import type Billink from '../PaymentMethods/Billink'; -import type BuckarooVoucher from '../PaymentMethods/BuckarooVoucher'; -import type BuckarooWallet from '../PaymentMethods/BuckarooWallet'; -import type CreditCard from '../PaymentMethods/CreditCard'; -import type CreditClick from '../PaymentMethods/CreditClick'; -import type CreditManagement from '../PaymentMethods/CreditManagement'; -import type Emandates from '../PaymentMethods/Emandates'; -import type EPS from '../PaymentMethods/EPS'; -import type GiftCard from '../PaymentMethods/GiftCard'; -import type Giropay from '../PaymentMethods/Giropay'; -import type IdealQr from '../PaymentMethods/IdealQR'; -import type Idin from '../PaymentMethods/Idin'; -import type In3Old from '../PaymentMethods/In3Old'; -import type KBC from '../PaymentMethods/KBC'; -import type Klarna from '../PaymentMethods/Klarna'; -import type KlarnaKp from '../PaymentMethods/KlarnaKP'; -import type Marketplaces from '../PaymentMethods/Marketplaces'; -import type Payconiq from '../PaymentMethods/Payconiq'; -import type PayByBank from '../PaymentMethods/PayByBank'; -import type Paypal from '../PaymentMethods/Paypal'; -import type PayPerEmail from '../PaymentMethods/PayPerEmail'; -import type PiM from '../PaymentMethods/PiM'; -import type PointOfSale from '../PaymentMethods/PointOfSale'; -import type Przelewy24 from '../PaymentMethods/Przelewy24'; -import type SEPA from '../PaymentMethods/SEPA'; -import type Sofort from '../PaymentMethods/Sofort'; -import type Subscriptions from '../PaymentMethods/Subscriptions'; -import type Surepay from '../PaymentMethods/Surepay'; -import type Thunes from '../PaymentMethods/Thunes'; -import type Tinka from '../PaymentMethods/Tinka'; -import type Alipay from '../PaymentMethods/Alipay'; -import type Trustly from '../PaymentMethods/Trustly'; -import type Wechatpay from '../PaymentMethods/WeChatPay'; -import type In3 from '../PaymentMethods/In3'; -import type MultiBanco from '../PaymentMethods/Multibanco'; -import type Index from "../PaymentMethods/Mbway"; +import * as AllPaymentMethods from '../PaymentMethods' -//toDo refactor this +export type AvailablePaymentMethods = typeof AllPaymentMethods; +export type ServiceCode = keyof AvailablePaymentMethods; +export type PaymentMethodInstance = InstanceType; -export type AllMethods = readonly [ - { class: Afterpay; code: MethodTypes['Afterpay'] }, - { class: AfterpayDigiAccept; code: MethodTypes['AfterpayDigiAccept'] }, - { class: Alipay; code: MethodTypes['Alipay'] }, - { class: ApplePay; code: MethodTypes['ApplePay'] }, - { class: Bancontact; code: MethodTypes['Bancontact'] }, - { class: Banktransfer; code: MethodTypes['BankTransfer'] }, - { class: Belfius; code: MethodTypes['Belfius'] }, - { class: Billink; code: MethodTypes['Billink'] }, - { class: BuckarooVoucher; code: MethodTypes['BuckarooVoucher'] }, - { class: BuckarooWallet; code: MethodTypes['BuckarooWallet'] }, - { class: CreditCard; code: MethodTypes['CreditCard'] }, - { class: CreditClick; code: MethodTypes['CreditClick'] }, - { class: CreditManagement; code: MethodTypes['CreditManagement'] }, - { class: Emandates; code: MethodTypes['Emandates'] }, - { class: EPS; code: MethodTypes['EPS'] }, - { class: GiftCard; code: MethodTypes['GiftCard'] }, - { class: Giropay; code: MethodTypes['Giropay'] }, - { class: Ideal; code: MethodTypes['Ideal'] }, - { class: IdealQr; code: MethodTypes['IdealQR'] }, - { class: Idin; code: MethodTypes['Idin'] }, - { class: In3Old; code: MethodTypes['In3Old'] }, - { class: In3; code: MethodTypes['In3'] }, - { class: KBC; code: MethodTypes['KBC'] }, - { class: Klarna; code: MethodTypes['Klarna'] }, - { class: KlarnaKp; code: MethodTypes['KlarnaKP'] }, - { class: Marketplaces; code: MethodTypes['Marketplaces'] }, - { class: Payconiq; code: MethodTypes['Payconiq'] }, - { class: PayByBank; code: MethodTypes['PayByBank'] }, - { class: Paypal; code: MethodTypes['Paypal'] }, - { class: PayPerEmail; code: MethodTypes['PayPerEmail'] }, - { class: PiM; code: MethodTypes['PiM'] }, - { class: PointOfSale; code: MethodTypes['PointOfSale'] }, - { class: Przelewy24; code: MethodTypes['Przelewy24'] }, - { class: SEPA; code: MethodTypes['SEPA'] }, - { class: Sofort; code: MethodTypes['Sofort'] }, - { class: Subscriptions; code: MethodTypes['Subscriptions'] }, - { class: Surepay; code: MethodTypes['Surepay'] }, - { class: Thunes; code: MethodTypes['Thunes'] }, - { class: Tinka; code: MethodTypes['Tinka'] }, - { class: Trustly; code: MethodTypes['Trustly'] }, - { class: Wechatpay; code: MethodTypes['WeChatPay'] }, - { class: MultiBanco; code: MethodTypes['Multibanco'] }, - { class: Index ; code: MethodTypes['Mbway'] }, -]; -export type ServiceCode = AllMethods[number]['code'][number]; - -export type MethodFromServiceCode = { - [Key in Methods['code'][number]]: Methods extends { - class: infer Class; - code: readonly (infer Codes)[]; +export function getMethod( + code: Code +): PaymentMethodInstance { + const methodClass = AllPaymentMethods['ideal']; + if (!methodClass) { + throw new Error(`Invalid payment method code: ${code}`); } - ? Extract extends never - ? never - : Class - : never; -}[Code]; - -export const Methods = { - Afterpay: ['afterpay'], - AfterpayDigiAccept: ['afterpaydigiaccept'], - Alipay: ['alipay'], - ApplePay: ['applepay'], - Bancontact: ['bancontactmrcash'], - BankTransfer: ['transfer'], - Belfius: ['belfius'], - Billink: ['billink'], - BuckarooVoucher: ['buckaroovoucher'], - BuckarooWallet: ['BuckarooWalletCollecting'], - CreditCard: ['creditcard', 'mastercard', 'visa', 'amex', 'vpay', 'maestro', 'visaelectron', 'cartebleuevisa', 'cartebancaire', 'dankort', 'nexi', 'postepay'], - CreditClick: ['creditclick'], - CreditManagement: ['CreditManagement3'], - Emandates: ['emandate'], - EPS: ['eps'], - GiftCard: [ - 'giftcard', - 'westlandbon', - 'babygiftcard', - 'babyparkgiftcard', - 'beautywellness', - 'boekenbon', - 'boekenvoordeel', - 'designshopsgiftcard', - 'fashioncheque', - 'fashionucadeaukaart', - 'fijncadeau', - 'koffiecadeau', - 'kokenzo', - 'kookcadeau', - 'nationaleentertainmentcard', - 'naturesgift', - 'podiumcadeaukaart', - 'shoesaccessories', - 'webshopgiftcard', - 'wijncadeau', - 'wonenzo', - 'yourgift', - 'vvvgiftcard', - 'parfumcadeaukaart', - ], - Giropay: ['giropay'], - IdealQR: ['idealqr'], - Idin: ['idin'], - In3Old: ['capayable'], - In3: ['In3'], - KBC: ['KBCPaymentButton'], - Klarna: ['klarna'], - Ideal: ['ideal', 'idealprocessing'], - Przelewy24: ['przelewy24'], - KlarnaKP: ['klarnakp'], - Marketplaces: ['Marketplaces'], - PayByBank: ['PayByBank'], - PayPerEmail: ['payperemail'], - Payconiq: ['payconiq'], - Paypal: ['paypal'], - PiM: ['PiM'], - PointOfSale: ['pointofsale'], - SEPA: ['sepadirectdebit'], - Sofort: ['sofortueberweisung'], - Subscriptions: ['subscriptions'], - Surepay: ['surepay'], - Thunes: ['thunes'], - Tinka: ['tinka'], - Trustly: ['trustly'], - WeChatPay: ['wechatpay'], - Multibanco: ['multibanco'], - Mbway: ['MBWay'], -} as const; - -type MethodTypes = typeof Methods; -export default function getMethod(code: Code): MethodFromServiceCode { - let method: string | undefined; - for (const key in Methods) { - if (Methods[key].includes(code)) { - method = key; - break; - } - } - if (!method) throw new Error(`Wrong payment method code has been given`); - - let methodClass = require(`../PaymentMethods/${method}`).default; - return new methodClass(code); + return new methodClass(code as any) as PaymentMethodInstance; } diff --git a/src/index.ts b/src/index.ts index 10cf181e..3d1d2354 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,12 @@ -import { IConfig, ICredentials } from './Utils/Types'; -import HttpsClient from './Request/HttpsClient'; -import { Agent } from 'https'; -import getMethod, { MethodFromServiceCode, ServiceCode } from './Utils/MethodTypes'; -import Request from './Request/Request'; -import NoService from './PaymentMethods/NoService'; -import TransactionService from './Services/TransactionService'; -import { Credentials } from './Handlers/Credentials'; +import {IConfig, ICredentials} from './Utils/Types' +import HttpsClient from './Request/HttpsClient' +import {Agent} from 'https' +import {getMethod, PaymentMethodInstance, ServiceCode} from './Utils/MethodTypes' +import Request from './Request/Request' +import NoService from './PaymentMethods/NoService' +import TransactionService from './Services/TransactionService' +import {Credentials} from './Handlers/Credentials' +import {RequestTypes} from "./Constants/Endpoints"; export default class Buckaroo { private readonly _credentials: Credentials; @@ -13,9 +14,9 @@ export default class Buckaroo { private readonly _httpClient: HttpsClient; private static _client: Buckaroo; constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { - this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); - this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; - this._httpClient = new HttpsClient(agent); + this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey) + this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) } + this._httpClient = new HttpsClient() } static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { return (this._client = new this(credentials, config, agent)); @@ -47,9 +48,9 @@ export default class Buckaroo { data: Request.BatchDataRequest, }; } - method(): NoService; - method(name: Name): MethodFromServiceCode; - method(name?: ServiceCode) { + method(): NoService + method(name: K): PaymentMethodInstance + method(name?: K) { if (!name) { return new NoService(); } diff --git a/tsconfig.spec.json b/tsconfig.spec.json new file mode 100644 index 00000000..a607ee7f --- /dev/null +++ b/tsconfig.spec.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "types": ["jest", "node"] + } +} From 1a96562c95573966a80f963e1529829987d297d1 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 13:17:41 +0200 Subject: [PATCH 14/52] code formatting --- .babelrc | 24 +++-- .editorconfig | 2 +- .prettierrc.json | 2 + CHANGELOG.md | 14 +-- CONTRIBUTING.md | 23 ++-- README.md | 32 +++--- example/additional_services/subscription.ts | 5 +- example/response/push.ts | 10 +- example/transaction/ideal.ts | 8 +- rollup.config.js | 73 +++++++------ src/Constants/Endpoints.ts | 2 + src/Constants/Gender.ts | 1 + src/Constants/HttpMethods.ts | 1 + src/Constants/IPProtocolVersion.ts | 2 + src/Constants/RecipientCategory.ts | 1 + src/Constants/ResponseStatus.ts | 1 + src/Handlers/Credentials.ts | 2 + src/Handlers/Reply/ReplyHandler.ts | 30 +++--- src/Models/IRequest.ts | 3 + src/Models/IServiceList.ts | 13 ++- src/Models/Interfaces/IAddress.ts | 7 ++ src/Models/Interfaces/IArticle.ts | 10 ++ src/Models/Interfaces/IBankAccount.ts | 3 + src/Models/Interfaces/ICustomer.ts | 4 + src/Models/Interfaces/IDebtor.ts | 1 + src/Models/Interfaces/IEmail.ts | 3 + src/Models/Interfaces/IPhone.ts | 2 + src/Models/Interfaces/IRecipient.ts | 22 ++++ src/Models/Model.ts | 56 +++++++--- src/Models/Response/BatchRequestResponse.ts | 1 + src/Models/Response/HttpClientResponse.ts | 16 ++- .../Response/SpecificationRequestResponse.ts | 3 + src/Models/Response/TransactionResponse.ts | 32 +++++- src/Models/ServiceParameters.ts | 14 ++- src/PaymentMethods/Afterpay/Model/Article.ts | 7 ++ src/PaymentMethods/Afterpay/Model/Customer.ts | 3 + src/PaymentMethods/Afterpay/Model/Pay.ts | 30 ++++-- src/PaymentMethods/Afterpay/Model/Phone.ts | 1 + .../Afterpay/Model/Recipient.ts | 6 ++ src/PaymentMethods/Afterpay/Model/Refund.ts | 15 +-- src/PaymentMethods/Afterpay/index.ts | 7 ++ .../AfterpayDigiAccept/Model/Article.ts | 9 ++ .../AfterpayDigiAccept/Model/Customer.ts | 14 ++- .../AfterpayDigiAccept/Model/Pay.ts | 31 ++++-- .../AfterpayDigiAccept/Services/Address.ts | 36 ++++--- .../AfterpayDigiAccept/Services/Phone.ts | 1 + .../AfterpayDigiAccept/index.ts | 7 ++ src/PaymentMethods/Alipay/index.ts | 1 + src/PaymentMethods/ApplePay/Models/Pay.ts | 2 + src/PaymentMethods/ApplePay/index.ts | 3 + src/PaymentMethods/Bancontact/Models/Pay.ts | 4 + src/PaymentMethods/Bancontact/index.ts | 7 ++ src/PaymentMethods/BankTransfer/Models/Pay.ts | 8 ++ src/PaymentMethods/BankTransfer/index.ts | 1 + src/PaymentMethods/Belfius/index.ts | 2 + src/PaymentMethods/Billink/Models/Address.ts | 3 + src/PaymentMethods/Billink/Models/Article.ts | 3 + src/PaymentMethods/Billink/Models/Capture.ts | 12 ++- src/PaymentMethods/Billink/Models/Customer.ts | 5 + src/PaymentMethods/Billink/Models/Pay.ts | 28 +++-- src/PaymentMethods/Billink/Models/Phone.ts | 3 + src/PaymentMethods/Billink/Models/Refund.ts | 1 + src/PaymentMethods/Billink/index.ts | 6 ++ .../BuckarooVoucher/Models/Create.ts | 4 + .../BuckarooVoucher/Models/Pay.ts | 1 + src/PaymentMethods/BuckarooVoucher/index.ts | 4 + .../BuckarooWallet/Models/Customer.ts | 2 + .../BuckarooWallet/Models/Wallet.ts | 5 + src/PaymentMethods/BuckarooWallet/index.ts | 10 ++ .../CreditCard/Models/CardData.ts | 1 + .../CreditCard/Models/SecurityCode.ts | 1 + src/PaymentMethods/CreditCard/index.ts | 9 ++ src/PaymentMethods/CreditClick/Models/Pay.ts | 2 + .../CreditClick/Models/Refund.ts | 1 + src/PaymentMethods/CreditClick/index.ts | 2 + .../Models/AddOrUpdateProductLines.ts | 20 ++-- .../CreditManagement/Models/Address.ts | 1 + .../CreditManagement/Models/Article.ts | 14 +++ .../CreditManagement/Models/CreditNote.ts | 5 + .../CreditManagement/Models/Debtor.ts | 5 + .../CreditManagement/Models/DebtorInfo.ts | 10 +- .../CreditManagement/Models/Invoice.ts | 49 ++++++--- .../CreditManagement/Models/PaymentPlan.ts | 10 ++ .../Models/multiInfoInvoice.ts | 8 +- src/PaymentMethods/CreditManagement/index.ts | 13 ++- .../Emandates/Models/Mandate.ts | 8 ++ src/PaymentMethods/Emandates/index.ts | 7 +- src/PaymentMethods/GiftCard/Models/Pay.ts | 11 ++ src/PaymentMethods/GiftCard/Models/Refund.ts | 1 + src/PaymentMethods/GiftCard/index.ts | 1 + src/PaymentMethods/Giropay/Models/Pay.ts | 2 + src/PaymentMethods/Giropay/index.ts | 1 + src/PaymentMethods/Ideal/Models/Pay.ts | 2 + src/PaymentMethods/Ideal/index.ts | 7 +- .../IdealQR/Models/IGenerate.ts | 10 ++ src/PaymentMethods/IdealQR/index.ts | 1 + src/PaymentMethods/Idin/index.ts | 3 + src/PaymentMethods/In3/Models/Article.ts | 5 + src/PaymentMethods/In3/Models/Pay.ts | 28 +++-- src/PaymentMethods/In3/Models/Phone.ts | 2 + src/PaymentMethods/In3/Models/Recipient.ts | 27 +++++ src/PaymentMethods/In3/Models/Refund.ts | 4 + src/PaymentMethods/In3/index.ts | 2 + src/PaymentMethods/In3Old/Models/Article.ts | 1 + src/PaymentMethods/In3Old/Models/Pay.ts | 39 ++++--- src/PaymentMethods/In3Old/Models/Subtotal.ts | 2 + src/PaymentMethods/In3Old/index.ts | 3 + src/PaymentMethods/Klarna/Models/Article.ts | 2 + src/PaymentMethods/Klarna/Models/Pay.ts | 25 +++-- src/PaymentMethods/Klarna/Models/Recipient.ts | 3 + .../Klarna/Services/KlarnaAddress.ts | 6 ++ .../Klarna/Services/KlarnaPhone.ts | 1 + src/PaymentMethods/Klarna/index.ts | 3 + src/PaymentMethods/KlarnaKP/Models/IPay.ts | 1 + .../KlarnaKP/Models/IReserve.ts | 14 ++- src/PaymentMethods/KlarnaKP/index.ts | 6 ++ .../Marketplaces/Models/Marketplace.ts | 2 + .../Marketplaces/Models/Seller.ts | 3 + .../Marketplaces/Models/Split.ts | 23 ++-- src/PaymentMethods/Marketplaces/index.ts | 4 + src/PaymentMethods/Mbway/index.ts | 4 +- src/PaymentMethods/NoService/index.ts | 4 +- src/PaymentMethods/PayByBank/Models/IPay.ts | 2 + src/PaymentMethods/PayByBank/index.ts | 3 + .../PayPerEmail/Models/Attachments.ts | 2 + .../PayPerEmail/Models/Invitation.ts | 17 ++- src/PaymentMethods/PayPerEmail/index.ts | 1 + src/PaymentMethods/PayablePaymentMethod.ts | 14 ++- src/PaymentMethods/Payconiq/index.ts | 1 + src/PaymentMethods/PaymentMethod.ts | 101 +++++++++++------- src/PaymentMethods/Paypal/Models/Address.ts | 27 +++-- src/PaymentMethods/Paypal/Models/ExtraInfo.ts | 4 + src/PaymentMethods/Paypal/Models/Pay.ts | 4 + src/PaymentMethods/Paypal/index.ts | 3 + src/PaymentMethods/PiM/index.ts | 2 + src/PaymentMethods/Przelewy24/Models/Pay.ts | 5 + src/PaymentMethods/Przelewy24/index.ts | 2 + src/PaymentMethods/SEPA/Models/Pay.ts | 13 +++ src/PaymentMethods/SEPA/index.ts | 5 + src/PaymentMethods/Sofort/index.ts | 2 + .../Subscriptions/Models/Configuration.ts | 3 + .../Subscriptions/Models/ISubscription.ts | 82 +++++++++----- .../Subscriptions/Models/RatePlan.ts | 19 ++++ .../Subscriptions/Models/RatePlanCharge.ts | 13 +++ src/PaymentMethods/Subscriptions/index.ts | 8 ++ src/PaymentMethods/Surepay/index.ts | 2 + src/PaymentMethods/Thunes/index.ts | 4 + src/PaymentMethods/Tinka/Models/Address.ts | 2 + src/PaymentMethods/Tinka/Models/Article.ts | 3 + src/PaymentMethods/Tinka/Models/Pay.ts | 31 ++++-- src/PaymentMethods/Tinka/Models/Person.ts | 2 + src/PaymentMethods/Tinka/Models/Recipient.ts | 2 + src/PaymentMethods/Tinka/index.ts | 2 + src/PaymentMethods/Trustly/Models/Customer.ts | 1 + src/PaymentMethods/Trustly/Models/Pay.ts | 2 + src/PaymentMethods/Trustly/index.ts | 2 + src/PaymentMethods/WeChatPay/Models/Pay.ts | 1 + src/PaymentMethods/WeChatPay/index.ts | 2 + src/Request/DataModels.ts | 29 +++++ src/Request/Headers.ts | 36 ++++--- src/Request/Hmac.ts | 70 +++++++----- src/Request/HttpsClient.ts | 11 +- src/Request/Request.ts | 97 +++++++++++------ src/Services/TransactionService.ts | 11 +- src/Utils/Functions.ts | 37 +++++-- src/Utils/MethodTypes.ts | 19 +++- src/Utils/Types.ts | 2 +- src/index.ts | 42 +++++--- tests/Client.test.ts | 35 +++--- tests/PaymentMethods/AfterPay.test.ts | 2 +- tests/PaymentMethods/ApplePay.test.ts | 2 +- tests/PaymentMethods/BankTransfer.test.ts | 1 + tests/PaymentMethods/EPS.test.ts | 1 + tests/PaymentMethods/Emandate.test.ts | 1 + tests/PaymentMethods/GiroPay.test.ts | 1 + tests/PaymentMethods/Ideal.test.ts | 1 + tests/PaymentMethods/KBC.test.ts | 1 + tests/PaymentMethods/KlarnaKp.test.ts | 1 + tests/PaymentMethods/Marketplaces.test.ts | 1 + tests/PaymentMethods/Mbway.test.ts | 16 +-- tests/PaymentMethods/PayPerEmail.test.ts | 1 + tests/PaymentMethods/Payconiq.test.ts | 1 + tests/PaymentMethods/Paypal.test.ts | 2 +- tests/PaymentMethods/Sofort.test.ts | 1 + tests/PaymentMethods/Subscriptions.test.ts | 100 ++++++++--------- tests/PaymentMethods/Tinka.test.ts | 1 + tests/PaymentMethods/WechatPay.test.ts | 1 + tsconfig-declarations.json | 16 +-- tsconfig.json | 15 ++- tsconfig.spec.json | 8 ++ 190 files changed, 1524 insertions(+), 552 deletions(-) create mode 100644 tsconfig.spec.json diff --git a/.babelrc b/.babelrc index d4e2cf80..8848b6b7 100644 --- a/.babelrc +++ b/.babelrc @@ -1,14 +1,16 @@ { - "plugins": ["@babel/plugin-proposal-class-properties"], - "presets": [ - "@babel/preset-typescript", - [ - "@babel/preset-env", - { - "targets": { - "node": "6.9" - } - } + "plugins": [ + "@babel/plugin-proposal-class-properties" + ], + "presets": [ + "@babel/preset-typescript", + [ + "@babel/preset-env", + { + "targets": { + "node": "6.9" + } + } + ] ] - ] } diff --git a/.editorconfig b/.editorconfig index 1eb3fe00..66e9a457 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ [*] charset = utf-8 end_of_line = crlf -indent_size = 2 +indent_size = 4 indent_style = space insert_final_newline = true max_line_length = 200 diff --git a/.prettierrc.json b/.prettierrc.json index 0eb852f9..7b308a2f 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,4 +1,6 @@ { + "bracketSpacing": true, + "printWidth": 120, "trailingComma": "es5", "tabWidth": 4, "singleQuote": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ecbe30f..2e193626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,13 @@ All notable changes to this project will be documented in this file. ## [1.0.0] -- Refactor method calls. -- Batch api calls. -- Response and push validation. -- Add general models. -- Add PayByBank -- Add In3 new +- Refactor method calls. +- Batch api calls. +- Response and push validation. +- Add general models. +- Add PayByBank +- Add In3 new ## [0.9.0] -- Beta release. +- Beta release. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11412766..042bdfac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,23 +2,24 @@ ### Repository setup: -- Fork the repository to your account -- more details about [how to fork a repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) can be found [here](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo): +- Fork the repository to your account +- more details about [how to fork a repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) can be + found [here](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo): ### Making changes: -- create a branch from develop branch -- name of the branch shoul be something like: `feature/GITHUB-ISSUE-ID-slug` (eg: `feature/50-configprovider-update`) -- including unit tests is encouraged +- create a branch from develop branch +- name of the branch shoul be something like: `feature/GITHUB-ISSUE-ID-slug` (eg: `feature/50-configprovider-update`) +- including unit tests is encouraged ### Pull Request: -- open the PR to develop branch -- if there is no issue referenced, add a description about the problem and the way it is being solved -- Allow edits from maintainers +- open the PR to develop branch +- if there is no issue referenced, add a description about the problem and the way it is being solved +- Allow edits from maintainers ### Contribution to refactoring: -- include unit tests -- open the Pull Request -- check that git workflows checks have passed +- include unit tests +- open the Pull Request +- check that git workflows checks have passed diff --git a/README.md b/README.md index 0f6a69c6..9f41ab52 100644 --- a/README.md +++ b/README.md @@ -14,26 +14,28 @@ ### Index -- [About](#about) -- [Requirements](#requirements) -- [Installation](#installation) -- [Example](#example) -- [Contribute](#contribute) -- [Versioning](#versioning) -- [Additional information](#additional-information) +- [About](#about) +- [Requirements](#requirements) +- [Installation](#installation) +- [Example](#example) +- [Contribute](#contribute) +- [Versioning](#versioning) +- [Additional information](#additional-information) --- ### About -Buckaroo is the Payment Service Provider for all your online payments with more than 15,000 companies relying on Buckaroo's platform to securely process their payments, subscriptions and unpaid invoices. Buckaroo developed their own Node SDK. The SDK is a modern, open-source Node.js library that makes it easy to integrate your Javascript application with Buckaroo's services. Start accepting payments today with Buckaroo. +Buckaroo is the Payment Service Provider for all your online payments with more than 15,000 companies relying on Buckaroo's platform to securely process their payments, subscriptions and unpaid +invoices. Buckaroo developed their own Node SDK. The SDK is a modern, open-source Node.js library that makes it easy to integrate your Javascript application with Buckaroo's services. Start accepting +payments today with Buckaroo. ### Requirements To use the Buckaroo API client, the following things are required: -- A Buckaroo account ([Dutch](https://www.buckaroo.nl/start) or [English](https://www.buckaroo.eu/solutions/request-form)) -- Node.js 6.14.× or greater +- A Buckaroo account ([Dutch](https://www.buckaroo.nl/start) or [English](https://www.buckaroo.eu/solutions/request-form)) +- Node.js 6.14.× or greater ### Installation @@ -91,14 +93,14 @@ If you want to contribute as well, then please follow our [Contribution Guidelin

-- **MAJOR:** Breaking changes that require additional testing/caution -- **MINOR:** Changes that should not have a big impact -- **PATCHES:** Bug and hotfixes only +- **MAJOR:** Breaking changes that require additional testing/caution +- **MINOR:** Changes that should not have a big impact +- **PATCHES:** Bug and hotfixes only ### Additional information -- **Support:** https://support.buckaroo.eu/contact -- **Contact:** [support@buckaroo.nl](mailto:support@buckaroo.nl) or [+31 (0)30 711 50 50](tel:+310307115050) +- **Support:** https://support.buckaroo.eu/contact +- **Contact:** [support@buckaroo.nl](mailto:support@buckaroo.nl) or [+31 (0)30 711 50 50](tel:+310307115050) ## License diff --git a/example/additional_services/subscription.ts b/example/additional_services/subscription.ts index 844c7573..cd7e10ca 100644 --- a/example/additional_services/subscription.ts +++ b/example/additional_services/subscription.ts @@ -2,7 +2,7 @@ require('../buckarooClient'); import Subscriptions from '../../src/PaymentMethods/Subscriptions'; import Ideal from '../../src/PaymentMethods/Ideal'; -const subscription = new Subscriptions() +const subscription = new Subscriptions(); subscription.createCombined({ address: undefined, allowedServices: '', @@ -33,6 +33,7 @@ subscription.createCombined({ amountDebit: 1, currency: 'EUR', description: 'test', - }).request() + }) + .request(); console.log(combinedPayment); })(); diff --git a/example/response/push.ts b/example/response/push.ts index 17c9b2f5..14a50969 100644 --- a/example/response/push.ts +++ b/example/response/push.ts @@ -1,5 +1,5 @@ -import buckaroo from '../buckarooClient'; -import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler'; +import buckaroo from "../buckarooClient"; +import { ReplyHandler } from "../../src/Handlers/Reply/ReplyHandler"; //START HTTP POST PUSH let post_data = `{ @@ -32,10 +32,10 @@ reply_handler.isValid(); // Return either true or false //END HTTP POST PUSH //START JSON PUSH -const auth_header = 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572'; +const auth_header = "IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572"; post_data = - '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}'; -const uri = 'https://buckaroo.dev/push'; + "{\"transaction\":{\"Key\":\"5340604668D74435AA344E1428ED1292\",\"Invoice\":\"62d68b6c8ab0c\",\"ServiceCode\":\"ideal\",\"Status\":{\"Code\":{\"Code\":190,\"Description\":\"Success\"},\"SubCode\":{\"Code\":\"S001\",\"Description\":\"transaction successfully processed\"},\"DateTime\":\"2022-07-19T12:46:12\"},\"IsTest\":true,\"Order\":\"ORDER_NO_62d68b6ca2df3\",\"Currency\":\"EUR\",\"AmountDebit\":10.1,\"TransactionType\":\"C021\",\"Services\":[{\"Name\":\"ideal\",\"Action\":null,\"Parameters\":[{\"Name\":\"consumerIssuer\",\"Value\":\"ABN AMRO\"},{\"Name\":\"transactionId\",\"Value\":\"0000000000000001\"},{\"Name\":\"consumerName\",\"Value\":\"J. de Tèster\"},{\"Name\":\"consumerIBAN\",\"Value\":\"NL44RABO0123456789\"},{\"Name\":\"consumerBIC\",\"Value\":\"RABONL2U\"}],\"VersionAsProperty\":2}],\"CustomParameters\":null,\"AdditionalParameters\":{\"List\":[{\"Name\":\"initiated_by_magento\",\"Value\":\"1\"},{\"Name\":\"service_action\",\"Value\":\"something\"}]},\"MutationType\":1,\"RelatedTransactions\":null,\"IsCancelable\":false,\"IssuingCountry\":null,\"StartRecurrent\":false,\"Recurring\":false,\"CustomerName\":\"J. de Tèster\",\"PayerHash\":\"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da\",\"PaymentKey\":\"AEC974D455FF4A4B9B4C21E437A04838\",\"Description\":null}}"; +const uri = "https://buckaroo.dev/push"; reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri); reply_handler.validate(); diff --git a/example/transaction/ideal.ts b/example/transaction/ideal.ts index b61ac5c9..71212fdc 100644 --- a/example/transaction/ideal.ts +++ b/example/transaction/ideal.ts @@ -6,16 +6,16 @@ const ideal = buckarooClient.method('ideal'); ideal .pay({ amountDebit: 10.1, - issuer: 'ABNANL2A', - description: 'Ideal Payment', + issuer: "ABNANL2A", + description: "Ideal Payment", }) .request(); //Refund ideal .refund({ - originalTransactionKey: '', + originalTransactionKey: "", amountCredit: 10.1, - invoice: '', + invoice: "", }) .request(); diff --git a/rollup.config.js b/rollup.config.js index a8a1f249..bd98e43e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,37 +4,44 @@ const resolve = require('rollup-plugin-node-resolve'); const babel = require('rollup-plugin-babel'); module.exports = { - input: join('src', 'index.ts'), - external: [ - // These Node.js internals are external to our bundles… - 'crypto', 'https', 'querystring', 'url', 'util', - // …as are the dependencies listed in our package.json. - ...Object.keys(require('./package.json').dependencies), - ], - output: [{ file: join('dist', 'buckaroo.cjs.js'), format: 'cjs' }, { file: join('dist', 'buckaroo.esm.js'), format: 'es' }], - plugins: [ - json(), - resolve({ - extensions: ['.ts'], - customResolveOptions: { - moduleDirectory: 'src', - }, - preferBuiltins: true, - }), - babel({ - extensions: ['.ts'], - }), - { - name: 'cert', - transform(code, id) { - if (id.endsWith('.pem') == false) { - return null; - } - return { - code: `export default ${JSON.stringify(code)}`, - map: { mappings: '' } - }; - } - } - ], + input: join('src', 'index.ts'), + external: [ + // These Node.js internals are external to our bundles… + 'crypto', + 'https', + 'querystring', + 'url', + 'util', + // …as are the dependencies listed in our package.json. + ...Object.keys(require('./package.json').dependencies), + ], + output: [ + { file: join('dist', 'buckaroo.cjs.js'), format: 'cjs' }, + { file: join('dist', 'buckaroo.esm.js'), format: 'es' }, + ], + plugins: [ + json(), + resolve({ + extensions: ['.ts'], + customResolveOptions: { + moduleDirectory: 'src', + }, + preferBuiltins: true, + }), + babel({ + extensions: ['.ts'], + }), + { + name: 'cert', + transform(code, id) { + if (id.endsWith('.pem') == false) { + return null; + } + return { + code: `export default ${JSON.stringify(code)}`, + map: { mappings: '' }, + }; + }, + }, + ], }; diff --git a/src/Constants/Endpoints.ts b/src/Constants/Endpoints.ts index d3a9449a..bd6b8885 100644 --- a/src/Constants/Endpoints.ts +++ b/src/Constants/Endpoints.ts @@ -2,10 +2,12 @@ enum Endpoints { LIVE = 'https://checkout.buckaroo.nl', TEST = 'https://testcheckout.buckaroo.nl', } + export enum RequestTypes { Data = '/json/DataRequest', Transaction = '/json/Transaction', BatchData = '/json/batch/DataRequests', BatchTransaction = '/json/batch/Transactions', } + export default Endpoints; diff --git a/src/Constants/Gender.ts b/src/Constants/Gender.ts index 0253e8db..0a4f8284 100644 --- a/src/Constants/Gender.ts +++ b/src/Constants/Gender.ts @@ -4,4 +4,5 @@ enum Gender { FEMALE = 2, NOT_APPLICABLE = 9, } + export default Gender; diff --git a/src/Constants/HttpMethods.ts b/src/Constants/HttpMethods.ts index 8f7a9c52..1d12e316 100644 --- a/src/Constants/HttpMethods.ts +++ b/src/Constants/HttpMethods.ts @@ -2,4 +2,5 @@ enum HttpMethods { GET = 'GET', POST = 'POST', } + export default HttpMethods; diff --git a/src/Constants/IPProtocolVersion.ts b/src/Constants/IPProtocolVersion.ts index 3bdd8ebd..087cd59e 100644 --- a/src/Constants/IPProtocolVersion.ts +++ b/src/Constants/IPProtocolVersion.ts @@ -1,6 +1,7 @@ import * as IpAddress from 'ip-address'; import { getIPAddress } from '../Utils/Functions'; + export class IPProtocolVersion { public static readonly IPV4: number = 0; public static readonly IPV6: number = 1; @@ -19,6 +20,7 @@ export class IPProtocolVersion { export class ClientIP { type: IPProtocolVersion; address: string; + constructor(ipAddress: string = getIPAddress()) { this.type = IPProtocolVersion.getVersion(ipAddress); this.address = ipAddress; diff --git a/src/Constants/RecipientCategory.ts b/src/Constants/RecipientCategory.ts index 5649e99b..edd1954d 100644 --- a/src/Constants/RecipientCategory.ts +++ b/src/Constants/RecipientCategory.ts @@ -2,4 +2,5 @@ enum RecipientCategory { PERSON = 'PERSON', COMPANY = 'COMPANY', } + export default RecipientCategory; diff --git a/src/Constants/ResponseStatus.ts b/src/Constants/ResponseStatus.ts index 6af8ffd8..4b91a7fd 100644 --- a/src/Constants/ResponseStatus.ts +++ b/src/Constants/ResponseStatus.ts @@ -14,4 +14,5 @@ enum ResponseStatus { BUCKAROO_AUTHORIZE_TYPE_ACCEPT = 'I013', BUCKAROO_AUTHORIZE_TYPE_GROUP_TRANSACTION = 'I150', } + export default ResponseStatus; diff --git a/src/Handlers/Credentials.ts b/src/Handlers/Credentials.ts index 938b5d4c..e436b573 100644 --- a/src/Handlers/Credentials.ts +++ b/src/Handlers/Credentials.ts @@ -5,10 +5,12 @@ import { RequestTypes } from '../Constants/Endpoints'; export class Credentials implements ICredentials { secretKey: string; websiteKey: string; + constructor(secretKey: string, websiteKey: string) { this.secretKey = secretKey; this.websiteKey = websiteKey; } + confirm() { return Request.Specification(RequestTypes.Transaction, { name: 'ideal', diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 8e15faee..ce7e6537 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -11,6 +11,7 @@ export class ReplyHandler { private _isValid: boolean = false; private strategy: 'JSON' | 'HTTP' = 'JSON'; private method?: string; + constructor(credentials: ICredentials, data: string, auth_header?: string, uri?: string, httpMethod?: string) { this._data = this.formatStringData(data); this.credentials = credentials; @@ -18,9 +19,24 @@ export class ReplyHandler { this.auth_header = auth_header; this.method = httpMethod; } + isValid(): boolean { return this._isValid; } + + validate() { + if (this.strategy === 'HTTP') { + let { brq_signature, BRQ_SIGNATURE, ...data } = this._data as any; + this._isValid = this.validateHttp(data, brq_signature || BRQ_SIGNATURE); + return this; + } + if (this.strategy === 'JSON' && this.auth_header && this.uri) { + this._isValid = this.validateJson(this.auth_header, this.uri, JSON.stringify(this._data)); + return this; + } + throw new Error('Invalid response data'); + } + private formatStringData(value: string) { try { let data = JSON.parse(value); @@ -35,21 +51,11 @@ export class ReplyHandler { return objData; } } - validate() { - if (this.strategy === 'HTTP') { - let { brq_signature, BRQ_SIGNATURE, ...data } = this._data as any; - this._isValid = this.validateHttp(data, brq_signature || BRQ_SIGNATURE); - return this; - } - if (this.strategy === 'JSON' && this.auth_header && this.uri) { - this._isValid = this.validateJson(this.auth_header, this.uri, JSON.stringify(this._data)); - return this; - } - throw new Error('Invalid response data'); - } + private validateJson(auth_header: string, url: string, data: string) { return new Hmac().validate(this.credentials, auth_header, url, data, this.method || HttpMethods.POST); } + private validateHttp(data: object, signature: string) { let stringData = ''; for (const key in data) { diff --git a/src/Models/IRequest.ts b/src/Models/IRequest.ts index 7e4882c3..1c7bae92 100644 --- a/src/Models/IRequest.ts +++ b/src/Models/IRequest.ts @@ -28,12 +28,15 @@ export default interface IRequest { servicesExcludedForClient?: ServiceCode[] | string; customParameters?: IAdditionalParameters; additionalParameters?: IAdditionalParameters; + [key: string]: any; } + export declare interface IPaymentRequest extends IRequest { amountDebit: number; amountCredit?: never; } + export declare interface IRefundRequest extends IRequest { amountCredit: number; amountDebit?: never; diff --git a/src/Models/IServiceList.ts b/src/Models/IServiceList.ts index c8ec7aea..f664defc 100644 --- a/src/Models/IServiceList.ts +++ b/src/Models/IServiceList.ts @@ -7,19 +7,24 @@ export interface IService { version?: number; parameters?: IParameter[]; } + export class Service extends Model implements IService { constructor(data: IService) { super(data); } + set action(value: string) { this.set('action', value); } + set name(value: string) { this.set('name', value); } + set version(value: number) { this.set('version', value); } + set parameters(value: IParameter[]) { this.set( 'parameters', @@ -27,25 +32,29 @@ export class Service extends Model implements IService { ); } } + export class ServiceList extends Model { constructor(...list: IService[]) { super({ list: list }); } + get list(): Service[] { return this.get('serviceList'); } + set list(services: IService[]) { this.set( 'serviceList', services.map((service) => new Service(service)) ); } + addService(service: IService) { if (this.getService(service.name)) { this.list[this.list.findIndex((s) => s.name === service.name)] = new Service(service); - }else - this.list.push(new Service(service)); + } else this.list.push(new Service(service)); } + getService(name: string) { return this.list.find((service) => service.name.toLowerCase() === name.toLowerCase()); } diff --git a/src/Models/Interfaces/IAddress.ts b/src/Models/Interfaces/IAddress.ts index 5412ca4a..bd840cda 100644 --- a/src/Models/Interfaces/IAddress.ts +++ b/src/Models/Interfaces/IAddress.ts @@ -9,25 +9,32 @@ export default interface IAddress { state?: string; country: string; } + export class Address extends Model implements IAddress { set street(street: string) { this.set('street', street); } + set houseNumber(houseNumber: string) { this.set('houseNumber', houseNumber); } + set houseNumberAdditional(houseNumberAdditional: string) { this.set('houseNumberAdditional', houseNumberAdditional); } + set zipcode(zipcode: string) { this.set('zipcode', zipcode); } + set city(city: string) { this.set('city', city); } + set state(state: string) { this.set('state', state); } + set country(country: string) { this.set('country', country); } diff --git a/src/Models/Interfaces/IArticle.ts b/src/Models/Interfaces/IArticle.ts index bfb45b7a..8128310c 100644 --- a/src/Models/Interfaces/IArticle.ts +++ b/src/Models/Interfaces/IArticle.ts @@ -12,34 +12,44 @@ export default interface IArticle { vatCategory: string; description: string; } + export class Article extends Model implements IArticle { set identifier(identifier: string) { this.set('identifier', identifier); } + set type(type: string) { this.set('type', type); } + set brand(brand: string) { this.set('brand', brand); } + set manufacturer(manufacturer: string) { this.set('manufacturer', manufacturer); } + set unitCode(unitCode: string) { this.set('unitCode', unitCode); } + set price(price: number) { this.set('price', price); } + set quantity(quantity: number) { this.set('quantity', quantity); } + set vatPercentage(vatPercentage: number) { this.set('vatPercentage', vatPercentage); } + set vatCategory(vatCategory: string) { this.set('vatCategory', vatCategory); } + set description(description: string) { this.set('description', description); } diff --git a/src/Models/Interfaces/IBankAccount.ts b/src/Models/Interfaces/IBankAccount.ts index d41fe272..a9e4bd70 100644 --- a/src/Models/Interfaces/IBankAccount.ts +++ b/src/Models/Interfaces/IBankAccount.ts @@ -5,13 +5,16 @@ export default interface IBankAccount { bic: string; accountName: string; } + export class BankAccount extends Model implements IBankAccount { set accountName(accountName: string) { this.set('accountName', accountName); } + set bic(bic: string) { this.set('bic', bic); } + set iban(iban: string) { this.set('iban', iban); } diff --git a/src/Models/Interfaces/ICustomer.ts b/src/Models/Interfaces/ICustomer.ts index 43fa43c0..277a522b 100644 --- a/src/Models/Interfaces/ICustomer.ts +++ b/src/Models/Interfaces/ICustomer.ts @@ -10,16 +10,20 @@ export interface ICustomer { recipient?: Partial; address?: Partial; } + export class Customer extends Model { set address(address: Partial) { this.set('address', new Address(address)); } + set email(email: string) { this.set('email', email); } + set phone(phone: Partial) { this.set('phone', new Phone(phone)); } + set recipient(recipient: IPerson | ICompany) { if (recipient.category === recipientCategory.PERSON) { this.set('recipient', new Person(recipient)); diff --git a/src/Models/Interfaces/IDebtor.ts b/src/Models/Interfaces/IDebtor.ts index 6fc2a66b..f2d1cc9e 100644 --- a/src/Models/Interfaces/IDebtor.ts +++ b/src/Models/Interfaces/IDebtor.ts @@ -3,6 +3,7 @@ import { Model } from '../Model'; export default interface IDebtor { code: string; } + export class Debtor extends Model { set code(value: string) { this.set('code', value); diff --git a/src/Models/Interfaces/IEmail.ts b/src/Models/Interfaces/IEmail.ts index 663c7dc7..a03eeb5c 100644 --- a/src/Models/Interfaces/IEmail.ts +++ b/src/Models/Interfaces/IEmail.ts @@ -3,13 +3,16 @@ import { Model } from '../Model'; export default interface IEmail { email: string; } + export class Email extends Model implements IEmail { constructor(data: IEmail) { super(data); } + get email() { return ''; } + set email(email: string) { this.set('email', email); } diff --git a/src/Models/Interfaces/IPhone.ts b/src/Models/Interfaces/IPhone.ts index 530eb475..850ab726 100644 --- a/src/Models/Interfaces/IPhone.ts +++ b/src/Models/Interfaces/IPhone.ts @@ -10,9 +10,11 @@ export class Phone extends Model implements IPhone { set landline(landline: string) { this.set('landline', landline); } + set mobile(mobile: string) { this.set('mobile', mobile); } + set fax(fax: string) { this.set('fax', fax); } diff --git a/src/Models/Interfaces/IRecipient.ts b/src/Models/Interfaces/IRecipient.ts index f175fb8b..9213909b 100644 --- a/src/Models/Interfaces/IRecipient.ts +++ b/src/Models/Interfaces/IRecipient.ts @@ -5,6 +5,7 @@ import Gender from '../../Constants/Gender'; export interface IRecipient { [key: string]: any; } + export interface IPerson extends IRecipient { category: RecipientCategory.PERSON; gender: string | Gender; @@ -18,6 +19,7 @@ export interface IPerson extends IRecipient { birthDate: string; placeOfBirth: string; } + export interface ICompany extends IRecipient { category: RecipientCategory.COMPANY; companyName: string; @@ -26,68 +28,88 @@ export interface ICompany extends IRecipient { vatNumber: string; chamberOfCommerce: string; } + export class Recipient extends Model implements IRecipient { set birthDate(value: string) { this.set('birthDate', value); } + set careOf(value: string) { this.set('careOf', value); } + set category(value: RecipientCategory) { this.set('category', value); } + set culture(value: string) { this.set('culture', value); } + set firstName(value: string) { this.set('firstName', value); } + set gender(value: string) { this.set('gender', value); } + set initials(value: string) { this.set('initials', value); } + set lastName(value: string) { this.set('lastName', value); } + set lastNamePrefix(value: string) { this.set('lastNamePrefix', value); } + set placeOfBirth(value: string) { this.set('placeOfBirth', value); } + set title(value: string) { this.set('title', value); } } + export class Person extends Recipient implements IPerson { constructor(data: Partial) { super(data); } + set category(value: RecipientCategory.PERSON) { this.set('category', value); } } + export class Company extends Recipient implements ICompany { constructor(data: Partial) { super(data as any); } + set category(value: RecipientCategory.COMPANY) { this.set('category', value); } + set chamberOfCommerce(value: string) { this.set('chamberOfCommerce', value); } + set companyName(value: string) { this.set('companyName', value); } + set culture(value: string) { this.set('culture', value); } + set vatApplicable(value: boolean) { this.set('vatApplicable', value); } + set vatNumber(value: string) { this.set('vatNumber', value); } diff --git a/src/Models/Model.ts b/src/Models/Model.ts index c98808d4..1d64b690 100644 --- a/src/Models/Model.ts +++ b/src/Models/Model.ts @@ -1,9 +1,12 @@ import { Str } from '../Utils/Functions'; + export class Model { [key: keyof any]: any; + constructor(...args: any[]) { this.initialize(...args); } + initialize(data?: any) { if (data instanceof Object && !Array.isArray(data)) { if (data.constructor === this.constructor) { @@ -12,7 +15,30 @@ export class Model { } return this; } - protected setOwnProperties(data: object = {}, properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors()) { + + set(name: string, value: any, hidden: boolean = false): this { + this.defineProperty(name, value, hidden); + return this; + } + + get(prop: string): any { + return this.has(prop)?.get?.call(this); + } + + has(prop: string, model = this): PropertyDescriptor | undefined { + return getObjectProperty(model, prop, Model.prototype); + } + + getData(callBack?: ((this: any, key: string, value: any) => any) | undefined): { + [key: string]: any; + } { + return JSON.parse(JSON.stringify(this), callBack); + } + + protected setOwnProperties( + data: object = {}, + properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors() + ) { for (const key in properties) { if (properties[key].set) { let value = data[key] ?? properties[key].get?.call(this); @@ -21,18 +47,22 @@ export class Model { } return this; } + protected setDataProperties(data: object = {}) { for (const dataKey in data) { if (data.hasOwnProperty(dataKey) && data[dataKey] !== undefined) this.set(dataKey, data[dataKey]); } return this; } + protected privateName(name: string): string { return Str.ucfirst(name); } + protected publicName(name: string): string { return Str.lcfirst(name); } + protected getAllPropertyDescriptors(descriptors = {}, root = Model.prototype): { [p: string]: PropertyDescriptor } { // Loop through the prototype chain let currentObj = Object.getPrototypeOf(this); @@ -47,6 +77,7 @@ export class Model { } return descriptors; } + protected defineProperty(name: string, value: any, hidden: boolean = false) { let privateName = this.privateName(name); Object.defineProperty(this, privateName, { @@ -63,27 +94,13 @@ export class Model { configurable: true, }); } - set(name: string, value: any, hidden: boolean = false): this { - this.defineProperty(name, value, hidden); - return this; - } - get(prop: string): any { - return this.has(prop)?.get?.call(this); - } - has(prop: string, model = this): PropertyDescriptor | undefined { - return getObjectProperty(model, prop, Model.prototype); - } - getData(callBack?: ((this: any, key: string, value: any) => any) | undefined): { - [key: string]: any; - } { - return JSON.parse(JSON.stringify(this), callBack); - } } export class JsonModel extends Model { constructor(data: object) { super(data); } + initialize(data?: any) { return this.setDataProperties(data); } @@ -95,6 +112,7 @@ export class JsonModel extends Model { }); return this; } + get(value: any) { if (Array.isArray(value)) { return value.map((v) => new JsonModel(v)); @@ -108,8 +126,12 @@ export class JsonModel extends Model { return value; } } + export function getObjectProperty(object: object, property: string, root: any = null) { if (object !== root) { - return Object.getOwnPropertyDescriptor(object, property) ?? getObjectProperty(Object.getPrototypeOf(object), property, root); + return ( + Object.getOwnPropertyDescriptor(object, property) ?? + getObjectProperty(Object.getPrototypeOf(object), property, root) + ); } } diff --git a/src/Models/Response/BatchRequestResponse.ts b/src/Models/Response/BatchRequestResponse.ts index c569125e..5758d1b4 100644 --- a/src/Models/Response/BatchRequestResponse.ts +++ b/src/Models/Response/BatchRequestResponse.ts @@ -5,6 +5,7 @@ export class BatchRequestResponse extends HttpClientResponse { return this._data as any; } } + export interface BatchResponseData { message: string; errors?: { diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts index b2f37d27..74af86c9 100644 --- a/src/Models/Response/HttpClientResponse.ts +++ b/src/Models/Response/HttpClientResponse.ts @@ -6,6 +6,7 @@ import { ICredentials } from '../../Utils/Types'; export interface HttpResponseConstructor { new (httpResponse: IncomingMessage, data: string): IHttpClientResponse; } + export interface IHttpClientResponse { httpResponse: IncomingMessage; data: object; @@ -15,21 +16,34 @@ export class HttpClientResponse implements IHttpClientResponse { protected readonly _httpResponse: IncomingMessage; protected readonly _data: object; protected readonly _rawData: string; + constructor(httpResponse: IncomingMessage, data: string) { this._httpResponse = httpResponse; this._rawData = data; this._data = new JsonModel(JSON.parse(data)); } + get httpResponse(): IncomingMessage { return this._httpResponse; } + get rawData(): string { return this._rawData; } + get data() { return this._data; } + validateResponse(credentials: ICredentials) { - return new ReplyHandler(credentials, this._rawData, this.httpResponse.headers['authorization'], this.httpResponse.url, this.httpResponse.method).validate().isValid(); + return new ReplyHandler( + credentials, + this._rawData, + this.httpResponse.headers['authorization'], + this.httpResponse.url, + this.httpResponse.method + ) + .validate() + .isValid(); } } diff --git a/src/Models/Response/SpecificationRequestResponse.ts b/src/Models/Response/SpecificationRequestResponse.ts index faa33acf..7bc97141 100644 --- a/src/Models/Response/SpecificationRequestResponse.ts +++ b/src/Models/Response/SpecificationRequestResponse.ts @@ -1,9 +1,11 @@ import { Str } from '../../Utils/Functions'; import { HttpClientResponse } from './HttpClientResponse'; + export class SpecificationRequestResponse extends HttpClientResponse { get data(): ISpecificationRequestResponse { return this._data as any; } + getActionRequestParameters(actionName: string): RequestParameter[] | undefined { let actions = this.data.actions?.find((action) => { if (Str.ciEquals(action.name, actionName)) { @@ -52,6 +54,7 @@ export type RequestParameter = { inputPattern: string; autoCompleteType: string; }; + export interface ISpecificationRequestResponse { name: string; version: number; diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index 9e6c9065..68d35a33 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -8,70 +8,97 @@ export class TransactionResponse extends HttpClientResponse { get data(): ITransactionResponse { return this._data as any; } + getStatusCode() { return this.data.status.code.code.toString(); } + getSubStatusCode() { return this.data.status.subCode.code.toString(); } + isSuccess() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS; } + isFailed() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED; } + isCanceled() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT; + return ( + this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || + this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT + ); } + isAwaitingConsumer() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER; } + isPendingProcessing() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING; } + isWaitingOnUserInput() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT; } + isRejected() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED; } + isValidationFailure() { return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE; } + hasRedirect() { return this.data.requiredAction?.redirectURL.length > 0 && this.data.requiredAction?.name === 'Redirect'; } + getRedirectUrl() { if (this.hasRedirect()) return this.data.requiredAction?.redirectURL; return ''; } + getServices() { return this.data.services; } + getMethod() { return this.data.services?.[0].name; } + getServiceAction() { return this.data.services?.[0].action; } + getCustomParameters() { return DataFormatter.parametersReverseMap(this.data.customParameters?.list ?? []); } + getAdditionalParameters() { - return DataFormatter.parametersReverseMap(this.data.additionalParameters?.additionalParameter ?? this.data.additionalParameters?.['list'] ?? []); + return DataFormatter.parametersReverseMap( + this.data.additionalParameters?.additionalParameter ?? this.data.additionalParameters?.['list'] ?? [] + ); } + getTransactionKey() { return this.data.key; } + getPaymentKey() { return this.data.paymentKey; } + getAmountDebit() { return this.data.amountDebit; } + getAmountCredit() { return this.data.amountCredit; } + hasError() { return ( this.data.requestErrors && @@ -83,6 +110,7 @@ export class TransactionResponse extends HttpClientResponse { this.data.requestErrors.customParameterErrors.length > 0) ); } + getErrorMessage() { return this.data.status.code.description; } diff --git a/src/Models/ServiceParameters.ts b/src/Models/ServiceParameters.ts index bcb4185e..1329deb7 100644 --- a/src/Models/ServiceParameters.ts +++ b/src/Models/ServiceParameters.ts @@ -3,16 +3,22 @@ import { DataFormatter } from '../Utils/Functions'; import { IParameter } from './IParameters'; export class ServiceParameter extends Model { + toParameterList(): IParameter[] { + return DataFormatter.serviceParametersMap(this.getData(), this.getGroups(), this.getCountable()); + } + protected getGroups(groups: { [key: Capitalize]: Capitalize } = {}) { return groups; } + protected getCountable(countable: Capitalize[] = []) { return countable; } - protected getAllPropertyDescriptors(descriptors = {}, root: Model = ServiceParameter.prototype): { [p: string]: PropertyDescriptor } { + + protected getAllPropertyDescriptors( + descriptors = {}, + root: Model = ServiceParameter.prototype + ): { [p: string]: PropertyDescriptor } { return super.getAllPropertyDescriptors(descriptors, root); } - toParameterList(): IParameter[] { - return DataFormatter.serviceParametersMap(this.getData(), this.getGroups(), this.getCountable()); - } } diff --git a/src/PaymentMethods/Afterpay/Model/Article.ts b/src/PaymentMethods/Afterpay/Model/Article.ts index 95420745..04a81428 100644 --- a/src/PaymentMethods/Afterpay/Model/Article.ts +++ b/src/PaymentMethods/Afterpay/Model/Article.ts @@ -7,25 +7,32 @@ export interface IAfterPayArticle extends Partial { refundType?: 'Refund' | 'Return'; marketPlaceSellerId?: string; } + export class AfterPayArticle extends Article { constructor(article: Interface) { super(article); } + get price(): number { return this.get('grossUnitPrice'); } + set price(price: number) { this.set('grossUnitPrice', price); } + set imageUrl(imageUrl: string) { this.set('imageUrl', imageUrl); } + set url(url: string) { this.set('url', url); } + set refundType(refundType: string) { this.set('refundType', refundType); } + set marketPlaceSellerId(marketPlaceSellerId: string) { this.set('marketPlaceSellerId', marketPlaceSellerId); } diff --git a/src/PaymentMethods/Afterpay/Model/Customer.ts b/src/PaymentMethods/Afterpay/Model/Customer.ts index 7c1885c9..70a7a055 100644 --- a/src/PaymentMethods/Afterpay/Model/Customer.ts +++ b/src/PaymentMethods/Afterpay/Model/Customer.ts @@ -16,12 +16,15 @@ export default class Customer extends Model implements ICustomer { this.set('recipient', new AfterPayCompany(recipient)); } } + set address(address: IAddress) { this.set('address', new Address(address)); } + set email(email: string) { this.set('email', email); } + set phone(phone: IPhone) { this.set('phone', new Phone(phone)); } diff --git a/src/PaymentMethods/Afterpay/Model/Pay.ts b/src/PaymentMethods/Afterpay/Model/Pay.ts index 721e8b25..85518425 100644 --- a/src/PaymentMethods/Afterpay/Model/Pay.ts +++ b/src/PaymentMethods/Afterpay/Model/Pay.ts @@ -17,45 +17,55 @@ export interface IPay extends IPaymentRequest { yourReference?: string; ourReference?: string; } + export class Pay extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Billing: 'BillingCustomer', - Shipping: 'ShippingCustomer', - Articles: 'Article', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } set shipping(shipping: ICustomer) { this.set('shipping', new Customer(shipping)); } + set billing(billing: ICustomer) { this.set('billing', new Customer(billing)); if (this.get('shipping') === undefined) { this.shipping = billing; } } + set articles(articles: IAfterPayArticle[]) { this.set( 'articles', articles.map((article) => new AfterPayArticle(article)) ); } + set bankAccount(bankAccount: string) { this.set('bankAccount', bankAccount); } + set bankCode(bankCode: string) { this.set('bankCode', bankCode); } + set merchantImageUrl(merchantImageUrl: string) { this.set('merchantImageUrl', merchantImageUrl); } + set summaryImageUrl(summaryImageUrl: string) { this.set('summaryImageUrl', summaryImageUrl); } + set ourReference(ourReference: string) { this.set('ourReference', ourReference); } + + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/Afterpay/Model/Phone.ts b/src/PaymentMethods/Afterpay/Model/Phone.ts index 4d90cdc3..8e6adff8 100644 --- a/src/PaymentMethods/Afterpay/Model/Phone.ts +++ b/src/PaymentMethods/Afterpay/Model/Phone.ts @@ -1,4 +1,5 @@ import { Phone as IPhone } from '../../../Models/Interfaces/IPhone'; + export default class Phone extends IPhone { get mobile(): string { return this.get('mobilePhone'); diff --git a/src/PaymentMethods/Afterpay/Model/Recipient.ts b/src/PaymentMethods/Afterpay/Model/Recipient.ts index 447215b7..8901d3a1 100644 --- a/src/PaymentMethods/Afterpay/Model/Recipient.ts +++ b/src/PaymentMethods/Afterpay/Model/Recipient.ts @@ -4,25 +4,31 @@ export class AfterPayCompany extends Company { set title(title: string) { this.set('salutation', title); } + set chamberOfCommerce(chamberOfCommerce: string) { this.set('identificationNumber', chamberOfCommerce); } } + export interface IAfterPayPerson extends IPerson { customerNumber?: string; identificationNumber?: string; conversationLanguage?: string; } + export class AfterPayPerson extends Person { constructor(data: IAfterPayPerson) { super(data); } + set customerNumber(customerNumber: string) { this.set('customerNumber', customerNumber); } + set identificationNumber(identificationNumber: string) { this.set('identificationNumber', identificationNumber); } + set conversationLanguage(conversationLanguage: string) { this.set('conversationLanguage', conversationLanguage); } diff --git a/src/PaymentMethods/Afterpay/Model/Refund.ts b/src/PaymentMethods/Afterpay/Model/Refund.ts index b781c37a..b3731b51 100644 --- a/src/PaymentMethods/Afterpay/Model/Refund.ts +++ b/src/PaymentMethods/Afterpay/Model/Refund.ts @@ -5,19 +5,22 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IRefund extends IRefundRequest { articles?: IAfterPayArticle[]; } + export class Refund extends ServiceParameter { + set articles(articles: IAfterPayArticle[]) { + this.set( + 'articles', + articles.map((article) => new AfterPayArticle(article)) + ); + } + protected getGroups() { return super.getGroups({ Articles: 'Article', }); } + protected getCountable() { return super.getCountable(['Articles']); } - set articles(articles: IAfterPayArticle[]) { - this.set( - 'articles', - articles.map((article) => new AfterPayArticle(article)) - ); - } } diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 7c806c93..40b4ff73 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -6,27 +6,34 @@ import { IRefund, Refund } from './Model/Refund'; export default class Afterpay extends PayablePaymentMethod { protected _paymentName = 'Afterpay'; protected _serviceVersion = 1; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefund) { return super.refund(payload, new Refund(payload)); } + authorize(payload: IPay) { this.setServiceList('Authorize', new Pay(payload)); return this.transactionRequest(payload); } + cancelAuthorize(payload: IRefundRequest) { this.setServiceList('CancelAuthorize'); return super.transactionRequest(payload); } + capture(payload: IPaymentRequest) { this.setServiceList('Capture', new Pay(payload)); return super.transactionRequest(payload); } + payRemainder(payload: IPay) { return super.payRemainder(payload, new Pay(payload)); } + authorizeRemainder(payload: IPay) { this.setServiceList('AuthorizeRemainder', new Pay(payload)); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts index 5d8f2aa6..a34dd393 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts @@ -4,30 +4,39 @@ export default class Article extends ArticleClass { get identifier(): string { return this.get('articleId'); } + set identifier(identifier: string) { this.set('articleId', identifier); } + get quantity(): number { return this.get('articleQuantity'); } + set quantity(quantity: number) { this.set('articleQuantity', quantity); } + get price(): number { return this.get('articleUnitprice'); } + set price(price: number) { this.set('articleUnitprice', price); } + get vatCategory(): string { return this.get('articleVatcategory'); } + set vatCategory(vatCategory: string) { this.set('articleVatcategory', vatCategory); } + get description(): string { return this.get('articleDescription'); } + set description(description: string) { this.set('articleDescription', description); } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts index 369d0c1c..cce38580 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts @@ -7,23 +7,29 @@ export class Customer extends Model implements ICustomer { constructor(data?: ICustomer, prefix?: string) { super(data, prefix); } + get prefix() { return ''; } - initialize(data?: any, prefix: string = '') { - this.set('prefix', prefix, true); - return super.initialize(data); - } + set recipient(recipient: ICustomer['recipient']) { this.set('recipient', recipient); } + set address(address: ICustomer['address']) { this.set('address', new Address(address, this.prefix)); } + set email(email: ICustomer['email']) { this.set(this.prefix + 'Email', email); } + set phone(phone: ICustomer['phone']) { this.set('phone', new Phone(phone)); } + + initialize(data?: any, prefix: string = '') { + this.set('prefix', prefix, true); + return super.initialize(data); + } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts index c1f29bc8..b2934b40 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -17,51 +17,64 @@ export interface IPay extends IPaymentRequest { shipping?: ICustomer; articles: Partial[]; } + export class Pay extends ServiceParameter implements Omit { - protected getGroups() { - return super.getGroups({ - Articles: 'Article', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } + protected accept: boolean = true; + set addressesDiffer(value: boolean) { this.set('addressesDiffer', value); } + set articles(articles: IArticle[]) { this.set( 'articles', articles.map((article) => new Article(article)) ); } + set b2b(value: boolean) { this.set('b2b', value); } + set billing(billing: ICustomer) { this.set('billing', new Customer(billing, 'Billing')); if (this.get('shipping') === undefined) { this.shipping = billing; } } + set shipping(shipping: ICustomer) { this.addressesDiffer = true; this.set('shipping', new Customer(shipping, 'Shipping')); } + set costCentre(value: string) { this.set('costCentre', value); } + set customerIPAddress(value: string) { this.set('customerIPAddress', value); } + set department(value: string) { this.set('department', value); } + set establishmentNumber(value: number) { this.set('establishmentNumber', value); } + set shippingCosts(value: number) { this.set('shippingCosts', value); } - protected accept: boolean = true; + + protected getGroups() { + return super.getGroups({ + Articles: 'Article', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts index 013522f6..c5f883ff 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts @@ -1,34 +1,42 @@ import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; -export class Address extends AddressClass { - private get prefix() { - return ''; - } - private set prefix(value: string) { - this.set('prefix', value); - } - initialize(data?: any, prefix: string = '') { - this.set('prefix', prefix, true); - return super.initialize(data); - } - protected privateName(name: string): string { - return super.privateName(name); - } +export class Address extends AddressClass { get houseNumberAdditional() { return this.get('houseNumberSuffix'); } + set houseNumberAdditional(value: string) { this.set('houseNumberSuffix', value); } + get zipcode() { return this.get('postalCode'); } + set zipcode(value: string) { this.set('postalCode', value); } + set country(value: string) { if (this.prefix === 'Shipping' && value === 'NL') { this.set('countryCode', value); } else this.set('country', value); } + + private get prefix() { + return ''; + } + + private set prefix(value: string) { + this.set('prefix', value); + } + + initialize(data?: any, prefix: string = '') { + this.set('prefix', prefix, true); + return super.initialize(data); + } + + protected privateName(name: string): string { + return super.privateName(name); + } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts index 3d906054..d230cca4 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts @@ -1,4 +1,5 @@ import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; + export class Phone extends PhoneClass { set mobile(value: string) { this.set('phoneNumber', value); diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index d3c406b6..fca5323c 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -6,28 +6,35 @@ import { Pay } from './Model/Pay'; export default class AfterpayDigiAccept extends PayablePaymentMethod { protected _paymentName = 'AfterpayDigiAccept'; protected _serviceVersion = 2; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + authorize(payload: IPay) { this.setServiceList('Authorize', new Pay(payload)); return super.transactionRequest(payload); } + cancelAuthorize(payload: IRefundRequest) { this.setServiceList('CancelAuthorize'); return super.transactionRequest(payload); } + capture(payload: IRequest) { this.setServiceList('Capture'); return super.transactionRequest(payload); } + payRemainder(payload: IPay) { this.setServiceList('PayRemainder'); return super.transactionRequest(payload); } + authorizeRemainder(payload: IPay) { this.setServiceList('AuthorizeRemainder'); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index e542b3dd..c60bedc3 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -9,6 +9,7 @@ export default class Alipay extends PayablePaymentMethod { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); return super.pay(payload, serviceParameters); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/ApplePay/Models/Pay.ts b/src/PaymentMethods/ApplePay/Models/Pay.ts index 3125e3e8..a75b5132 100644 --- a/src/PaymentMethods/ApplePay/Models/Pay.ts +++ b/src/PaymentMethods/ApplePay/Models/Pay.ts @@ -5,10 +5,12 @@ export interface IPay extends IPaymentRequest { paymentData: string; customerCardName: string; } + export class Pay extends ServiceParameter { set paymentData(value: string) { this.set('paymentData', value); } + set customerCardName(value: string) { this.set('customerCardName', value); } diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index eeea17c3..41f885de 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -4,12 +4,15 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class ApplePay extends PayablePaymentMethod { protected _paymentName = 'ApplePay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + payRedirect(payload: IPaymentRequest) { this.setPayPayload(payload); return this.transactionRequest(); diff --git a/src/PaymentMethods/Bancontact/Models/Pay.ts b/src/PaymentMethods/Bancontact/Models/Pay.ts index 3ba0d1eb..e78ea659 100644 --- a/src/PaymentMethods/Bancontact/Models/Pay.ts +++ b/src/PaymentMethods/Bancontact/Models/Pay.ts @@ -4,9 +4,11 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { saveToken?: boolean; } + export interface IPayEncrypted extends IPaymentRequest { encryptedCardData: string; } + export interface IPayComplete extends IRequest { encryptedCardData: string; originalTransactionKey: string; @@ -16,10 +18,12 @@ export interface IPayOneClick extends IRequest { originalTransactionKey: string; amountDebit: number; } + export class Pay extends ServiceParameter { set encryptedCardData(value: string) { this.set('encryptedCardData', value); } + set saveToken(value: boolean) { this.set('saveToken', value); } diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index b5bfaa3b..29f95c23 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -4,28 +4,35 @@ import { IRefundRequest } from '../../Models/IRequest'; export default class Bancontact extends PayablePaymentMethod { protected _paymentName = 'Bancontact'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + authenticate(payload: IPay) { this.setServiceList('Authenticate', new Pay(payload)); return this.transactionRequest(payload); } + payOneClick(payload: IPayOneClick) { this.setServiceList('PayOneClick', new Pay(payload)); return this.transactionRequest(payload); } + payEncrypted(payload: IPayEncrypted) { this.setServiceList('PayEncrypted', new Pay(payload)); return this.transactionRequest(payload); } + completePayment(payload: IPayComplete) { this.setServiceList('CompletePayment', new Pay(payload)); return this.dataRequest(payload); } + payRecurring(payload: IPayOneClick) { this.setServiceList('PayRecurring', new Pay(payload)); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/BankTransfer/Models/Pay.ts b/src/PaymentMethods/BankTransfer/Models/Pay.ts index b4dc31ce..a6502bd2 100644 --- a/src/PaymentMethods/BankTransfer/Models/Pay.ts +++ b/src/PaymentMethods/BankTransfer/Models/Pay.ts @@ -8,30 +8,38 @@ export interface IPay extends IPaymentRequest { dateDue?: string; customerCountry?: string; } + class BankTransferPerson extends Person { set firstName(value: string) { this.set('customerFirstName', value); } + set lastName(value: string) { this.set('customerLastName', value); } + set gender(value: string) { this.set('customerGender', value); } } + export class Pay extends ServiceParameter { set sendMail(sendMail: boolean) { this.set('sendMail', sendMail); } + set dateDue(dateDue: string) { this.set('dateDue', dateDue); } + set country(country: string) { this.set('customerCountry', country); } + set customer(person: IPerson) { this.set('customer', new BankTransferPerson(person)); } + set email(email: string) { this.set('customerEmail', email); } diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 34e2faf9..ab3de8c6 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -8,6 +8,7 @@ export default class BankTransfer extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index a77723c9..a265077e 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -3,9 +3,11 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Belfius extends PayablePaymentMethod { protected _paymentName = 'Belfius'; + pay(payload: IPaymentRequest) { return super.pay(payload); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Billink/Models/Address.ts b/src/PaymentMethods/Billink/Models/Address.ts index 57d259d9..69d34609 100644 --- a/src/PaymentMethods/Billink/Models/Address.ts +++ b/src/PaymentMethods/Billink/Models/Address.ts @@ -1,11 +1,14 @@ import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; + export class Address extends AddressClass { set houseNumber(houseNumber: string) { this.set('streetNumber', houseNumber); } + set houseNumberAdditional(houseNumberAdditional: string) { this.set('streetNumberAdditional', houseNumberAdditional); } + set zipcode(zipcode: string) { this.set('postalCode', zipcode); } diff --git a/src/PaymentMethods/Billink/Models/Article.ts b/src/PaymentMethods/Billink/Models/Article.ts index 0de0e503..974ed43e 100644 --- a/src/PaymentMethods/Billink/Models/Article.ts +++ b/src/PaymentMethods/Billink/Models/Article.ts @@ -1,11 +1,14 @@ import IArticle, { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; + export interface IBillinkArticle extends Partial { priceExcl: number; } + export class Article extends ArticleClass { set priceExcl(priceExcl: number) { this.set('grossUnitPriceExcl', priceExcl); } + set price(price: number) { this.set('grossUnitPriceIncl', price); } diff --git a/src/PaymentMethods/Billink/Models/Capture.ts b/src/PaymentMethods/Billink/Models/Capture.ts index 53fb86d0..915c3f44 100644 --- a/src/PaymentMethods/Billink/Models/Capture.ts +++ b/src/PaymentMethods/Billink/Models/Capture.ts @@ -5,16 +5,18 @@ import { IPaymentRequest } from '../../../Models/IRequest'; export interface ICapture extends IPaymentRequest { articles?: IBillinkArticle[]; } + export class Capture extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Articles: 'Article', - }); - } set articles(articels: IBillinkArticle[]) { this.set( 'articles', articels.map((article) => new Article(article)) ); } + + protected getGroups() { + return super.getGroups({ + Articles: 'Article', + }); + } } diff --git a/src/PaymentMethods/Billink/Models/Customer.ts b/src/PaymentMethods/Billink/Models/Customer.ts index 80f03cc0..2745df8a 100644 --- a/src/PaymentMethods/Billink/Models/Customer.ts +++ b/src/PaymentMethods/Billink/Models/Customer.ts @@ -10,9 +10,11 @@ export class BillinkCustomer extends Customer { set address(address: IAddress) { this.set('address', new Address(address)); } + set phone(phone: IPhone) { this.set('phone', new Phone(phone)); } + set recipient(recipient: IPerson | ICompany) { if (recipient.category === recipientCategory.PERSON) { this.set('recipient', new BillinkPerson(recipient)); @@ -26,14 +28,17 @@ export class BillinkPerson extends Person { set category(category: recipientCategory.PERSON) { this.set('category', 'B2C'); } + set title(title: string) { this.set('salutation', title); } } + export class BillinkCompany extends Company { set category(category: recipientCategory.COMPANY) { this.set('category', 'B2B'); } + set title(title: string) { this.set('salutation', title); } diff --git a/src/PaymentMethods/Billink/Models/Pay.ts b/src/PaymentMethods/Billink/Models/Pay.ts index 860b0872..fd36a268 100644 --- a/src/PaymentMethods/Billink/Models/Pay.ts +++ b/src/PaymentMethods/Billink/Models/Pay.ts @@ -12,39 +12,47 @@ export interface IPay extends IPaymentRequest { VATNumber?: string; summaryImageUrl?: string; } + export class Pay extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Billing: 'BillingCustomer', - Shipping: 'ShippingCustomer', - Articles: 'Article', - }); - } - protected getCountable(countable: Capitalize[] = []): Capitalize[] { - return super.getCountable(['Articles']); - } set billing(billing: ICustomer) { this.set('billing', new BillinkCustomer(billing)); if (this.get('shipping') === undefined) { this.shipping = billing; } } + set shipping(shipping: ICustomer) { this.set('shipping', new BillinkCustomer(shipping)); } + set articles(articles: IBillinkArticle[]) { this.set( 'articles', articles.map((article) => new Article(article)) ); } + set trackandtrace(trackandtrace: string) { this.set('trackandtrace', trackandtrace); } + set VATNumber(VATNumber: string) { this.set('VATNumber', VATNumber); } + set summaryImageUrl(summaryImageUrl: string) { this.set('summaryImageUrl', summaryImageUrl); } + + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article', + }); + } + + protected getCountable(countable: Capitalize[] = []): Capitalize[] { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/Billink/Models/Phone.ts b/src/PaymentMethods/Billink/Models/Phone.ts index dc51b0f6..b42bd22b 100644 --- a/src/PaymentMethods/Billink/Models/Phone.ts +++ b/src/PaymentMethods/Billink/Models/Phone.ts @@ -1,11 +1,14 @@ import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; + export class Phone extends PhoneClass { set fax(fax: string) { this.set('mobilePhone', fax); } + set landline(landline: string) { this.set('mobilePhone', landline); } + set mobile(mobile: string) { this.set('mobilePhone', mobile); } diff --git a/src/PaymentMethods/Billink/Models/Refund.ts b/src/PaymentMethods/Billink/Models/Refund.ts index cd2a59d6..64349d6f 100644 --- a/src/PaymentMethods/Billink/Models/Refund.ts +++ b/src/PaymentMethods/Billink/Models/Refund.ts @@ -4,6 +4,7 @@ import { IRefundRequest } from '../../../Models/IRequest'; export interface IRefund extends IRefundRequest { refundReason?: string; } + export class Refund extends ServiceParameter { set refundReason(value: string) { this.set('refundreason', value); diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 666397a4..9a4b6b7a 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -2,24 +2,30 @@ import PayablePaymentMethod from '../PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; + export default class Billink extends PayablePaymentMethod { protected _paymentName = 'Billink'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefund) { return super.refund(payload, new Refund(payload)); } + authorize(payload: IPay) { this.setPayPayload(payload); this.setServiceList('Authorize', new Pay(payload)); return super.transactionRequest(); } + cancelAuthorize(payload: IRefund) { this.setPayload(payload); this.setServiceList('CancelAuthorize', new Refund(payload)); return super.transactionRequest(); } + capture(payload: ICapture) { this.setPayPayload(payload); this.setServiceList('Capture', new Capture(payload)); diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts index 4f079442..ccfe02fd 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts @@ -17,15 +17,19 @@ export class Create extends ServiceParameter { set groupReference(value: string) { this.set('groupReference', value); } + set usageType(value: 1 | 2) { this.set('usageType', value); } + set validFrom(value: string) { this.set('validFrom', value); } + set validUntil(value: string) { this.set('validUntil', value); } + set creationBalance(value: number) { this.set('creationBalance', value); } diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts index 1b266f9d..88cbb0fe 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { voucherCode: string; } + export class Pay extends ServiceParameter { set voucherCode(voucherCode: string) { this.set('voucherCode', voucherCode); diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 663c4dee..8295b574 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -5,17 +5,21 @@ import { Create, ICreate } from './Models/Create'; export default class BuckarooVoucher extends PayablePaymentMethod { protected _paymentName = 'BuckarooVoucher'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + getBalance(payload: IRequest & Pick) { this.setServiceList('GetBalance', new Pay(payload)); return this.dataRequest(payload); } + create(payload: IRequest & ICreate) { this.setServiceList('CreateApplication', new Create(payload)); return this.dataRequest(payload); } + deactivate(payload: IRequest & Pick) { this.setServiceList('DeactivateVoucher', new Pay(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts index 86bc02dd..c501886a 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts @@ -3,9 +3,11 @@ import RecipientCategory from '../../../Constants/RecipientCategory'; export class Customer extends Person { set category(value: RecipientCategory.PERSON) {} + set firstName(value: string) { this.set('consumerFirstName', value); } + set lastName(value: string) { this.set('consumerLastName', value); } diff --git a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts index 6d3f8877..a8b862a7 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts @@ -18,18 +18,23 @@ export class Wallet extends ServiceParameter { set walletId(value: string) { this.set('walletId', value); } + set customer(value: Partial) { this.set('customer', new Customer(value)); } + set email(value: string) { this.set('consumerEmail', value); } + set status(value: string) { this.set('status', value); } + set walletMutationGuid(value: string) { this.set('walletMutationGuid', value); } + set bankAccount(value: IBankAccount) { this.set('bankAccount', new BankAccount(value)); } diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index d6b634c5..d8433373 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -4,46 +4,56 @@ import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest export default class BuckarooWallet extends PayablePaymentMethod { protected _paymentName = 'BuckarooWallet'; + pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + create(payload: IWallet & IRequest) { this._requiredFields = ['currency']; this.setPayload(payload); this.setServiceList('Create', new Wallet(payload)); return this.dataRequest(); } + deposit(payload: IWallet & IRefundRequest) { this.setPayload(payload); this.setServiceList('Deposit', new Wallet(payload)); return super.transactionRequest(); } + reserve(payload: IWallet & IRefundRequest) { this.setPayload(payload); this.setServiceList('Reserve', new Wallet(payload)); return super.transactionRequest(); } + withdrawal(payload: IWallet & IPaymentRequest) { this.setPayPayload(payload); this.setServiceList('Withdrawal', new Wallet(payload)); return super.transactionRequest(); } + cancel(payload: IPaymentRequest & { walletMutationGuid: string }) { this.setPayPayload(payload); this.setServiceList('Withdrawal', new Wallet(payload)); return super.transactionRequest(); } + update(payload: IWallet) { this.setServiceList('Update', new Wallet(payload)); return this.dataRequest(payload); } + getInfo(payload: IWallet) { this.setServiceList('GetInfo', new Wallet(payload)); return this.dataRequest(payload); } + release(payload: IWallet & IRefundRequest) { this.setServiceList('Release', new Wallet(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/CreditCard/Models/CardData.ts b/src/PaymentMethods/CreditCard/Models/CardData.ts index 5934fca8..56c160af 100644 --- a/src/PaymentMethods/CreditCard/Models/CardData.ts +++ b/src/PaymentMethods/CreditCard/Models/CardData.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ICardData extends IPaymentRequest { encryptedCardData: string; } + export class CardData extends ServiceParameter { set encryptedCardData(value: string) { this.set('encryptedCardData', value); diff --git a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts index 347610bf..3409cfe2 100644 --- a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts +++ b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface ISecurityCode extends IPaymentRequest { encryptedSecurityCode: string; } + export class SecurityCode extends ServiceParameter { set encryptedSecurityCode(value: string) { this.set('encryptedSecurityCode', value); diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index be773707..84466f82 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -5,45 +5,54 @@ import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; export default class CreditCard extends PayablePaymentMethod { protected _paymentName = 'CreditCard'; + payEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('PayEncrypted', new CardData(payload)); return super.transactionRequest(); } + payWithSecurityCode(payload: ISecurityCode) { this.setPayPayload(payload); this.setServiceList('PayWithSecurityCode', new SecurityCode(payload)); return super.transactionRequest(); } + authorize(payload: IPaymentRequest) { this.setPayPayload(payload); this.setServiceList('Authorize'); return super.transactionRequest(); } + authorizeWithSecurityCode(payload: ISecurityCode) { this.setPayPayload(payload); this.setServiceList('AuthorizeWithSecurityCode', new SecurityCode(payload)); return super.transactionRequest(); } + authorizeEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('AuthorizeEncrypted', new CardData(payload)); return super.transactionRequest(); } + cancelAuthorize(payload: IRefundRequest) { this.setServiceList('CancelAuthorize'); return super.transactionRequest(payload); } + capture(payload: IRequest) { this.setPayPayload(payload); this.setServiceList('Capture'); return super.transactionRequest(); } + payRecurrent(payload: IRequest) { this.setPayPayload(payload); this.setServiceList('PayRecurrent'); return super.transactionRequest(); } + payRemainderEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('PayRemainderEncrypted', new CardData(payload)); diff --git a/src/PaymentMethods/CreditClick/Models/Pay.ts b/src/PaymentMethods/CreditClick/Models/Pay.ts index 66a98c6a..fd8506f2 100644 --- a/src/PaymentMethods/CreditClick/Models/Pay.ts +++ b/src/PaymentMethods/CreditClick/Models/Pay.ts @@ -6,10 +6,12 @@ export interface IPay extends IPaymentRequest { person: Partial; email?: string; } + export class Pay extends ServiceParameter { set person(value: Partial) { this.set('person', value); } + set email(value: string) { this.set('email', value); } diff --git a/src/PaymentMethods/CreditClick/Models/Refund.ts b/src/PaymentMethods/CreditClick/Models/Refund.ts index 3f972b6d..21fcbbe5 100644 --- a/src/PaymentMethods/CreditClick/Models/Refund.ts +++ b/src/PaymentMethods/CreditClick/Models/Refund.ts @@ -10,6 +10,7 @@ export class Refund extends ServiceParameter { set description(value: string) { this.set('description', value); } + set refundReason(value: IRefund['refundReason']) { this.set('refundreason', value); } diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index c5635a52..66bcc3fc 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -4,9 +4,11 @@ import { IRefund, Refund } from './Models/Refund'; export default class CreditClick extends PayablePaymentMethod { protected _paymentName = 'CreditClick'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefund) { return super.refund(payload, new Refund(payload)); } diff --git a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts index 1331b7fc..26a07561 100644 --- a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts +++ b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts @@ -6,22 +6,26 @@ export interface IAddOrUpdateProductLines extends IRequest { invoiceKey: string; articles: ICreditArticle[]; } + export class AddOrUpdateProductLines extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Articles: 'ProductLine', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } set invoiceKey(value: string) { this.set('invoiceKey', value); } + set articles(value: ICreditArticle[]) { this.set( 'articles', value.map((article) => new CreditArticle(article)) ); } + + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/CreditManagement/Models/Address.ts b/src/PaymentMethods/CreditManagement/Models/Address.ts index c578bc57..97bb968c 100644 --- a/src/PaymentMethods/CreditManagement/Models/Address.ts +++ b/src/PaymentMethods/CreditManagement/Models/Address.ts @@ -1,4 +1,5 @@ import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; + export class Address extends AddressClass { set houseNumberAdditional(value: string) { this.set('houseNumberSuffix', value); diff --git a/src/PaymentMethods/CreditManagement/Models/Article.ts b/src/PaymentMethods/CreditManagement/Models/Article.ts index 3f0880e1..66f0d1bc 100644 --- a/src/PaymentMethods/CreditManagement/Models/Article.ts +++ b/src/PaymentMethods/CreditManagement/Models/Article.ts @@ -1,4 +1,5 @@ import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; + export interface ICreditArticle extends Partial { totalVat: number; productLine?: string; @@ -11,43 +12,56 @@ export interface ICreditArticle extends Partial { totalAmountExVat?: number; totalAmount?: number; } + export class CreditArticle extends Article implements ICreditArticle { set identifier(value: string) { this.set('productId', value); } + set description(value: string) { this.set('productName', value); } + set price(value: number) { this.set('pricePerUnit', value); } + set productLine(value: string) { this.set('productLine', value); } + set productGroupName(value: string) { this.set('productGroupName', value); } + set productGroupOrderIndex(value: number) { this.set('productGroupOrderIndex', value); } + set productOrderIndex(value: number) { this.set('productOrderIndex', value); } + set unitOfMeasurement(value: string) { this.set('unitOfMeasurement', value); } + set discountPercentage(value: number) { this.set('discountPercentage', value); } + set totalDiscount(value: number) { this.set('totalDiscount', value); } + set totalVat(value: number) { this.set('totalVat', value); } + set totalAmountExVat(value: number) { this.set('totalAmountExVat', value); } + set totalAmount(value: number) { this.set('totalAmount', value); } diff --git a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts index f430087e..ea547859 100644 --- a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts +++ b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts @@ -8,19 +8,24 @@ export interface ICreditNote extends IRequest { invoiceAmountVAT: string; sendCreditNoteMessage: string; } + export class CreditNote extends ServiceParameter implements ICreditNote { set originalInvoiceNumber(value: string) { this.set('originalInvoiceNumber', value); } + set invoiceDate(value: string) { this.set('invoiceDate', value); } + set invoiceAmount(value: string) { this.set('invoiceAmount', value); } + set invoiceAmountVAT(value: string) { this.set('invoiceAmountVAT', value); } + set sendCreditNoteMessage(value: string) { this.set('sendCreditNoteMessage', value); } diff --git a/src/PaymentMethods/CreditManagement/Models/Debtor.ts b/src/PaymentMethods/CreditManagement/Models/Debtor.ts index 52ba497d..31429399 100644 --- a/src/PaymentMethods/CreditManagement/Models/Debtor.ts +++ b/src/PaymentMethods/CreditManagement/Models/Debtor.ts @@ -11,19 +11,24 @@ export interface IDebtor extends IInvoice { faxUnreachable?: boolean; } + export class Debtor extends Invoice { set addressUnreachable(value: boolean) { this.set('addressUnreachable', value); } + set emailUnreachable(value: boolean) { this.set('emailUnreachable', value); } + set mobileUnreachable(value: boolean) { this.set('mobileUnreachable', value); } + set landlineUnreachable(value: boolean) { this.set('landlineUnreachable', value); } + set faxUnreachable(value: boolean) { this.set('faxUnreachable', value); } diff --git a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts index 9d3f28f4..dedbd1fd 100644 --- a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts +++ b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts @@ -1,19 +1,23 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; import IDebtor, { Debtor as DebtorClass } from '../../../Models/Interfaces/IDebtor'; import IRequest from '../../../Models/IRequest'; + export interface IDebtorInfo extends IRequest { debtor: IDebtor; } + export class DebtorInfo extends ServiceParameter { + set debtor(debtor: IDebtor) { + this.set('debtor', new Debtor(debtor)); + } + protected getGroups() { return super.getGroups({ Debtor: 'Debtor', }); } - set debtor(debtor: IDebtor) { - this.set('debtor', new Debtor(debtor)); - } } + class Debtor extends DebtorClass { set code(value: string) { this.set('DebtorCode', value); diff --git a/src/PaymentMethods/CreditManagement/Models/Invoice.ts b/src/PaymentMethods/CreditManagement/Models/Invoice.ts index 21df35a4..18442db9 100644 --- a/src/PaymentMethods/CreditManagement/Models/Invoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/Invoice.ts @@ -27,77 +27,96 @@ export interface IInvoice extends IRequest { invoiceNumber?: string; applyStartRecurrent?: boolean; } -export class Invoice extends ServiceParameter implements IInvoice { - protected getGroups() { - return super.getGroups({ - Articles: 'ProductLine', - Address: 'Address', - Company: 'Company', - Person: 'Person', - Debtor: 'Debtor', - Email: 'Email', - Phone: 'Phone', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } +export class Invoice extends ServiceParameter implements IInvoice { set invoiceAmount(value: number) { this.set('invoiceAmount', value); } + set invoiceAmountVAT(value: number) { this.set('invoiceAmountVAT', value); } + set invoiceDate(value: string) { this.set('invoiceDate', value); } + set dueDate(value: string) { this.set('dueDate', value); } + set schemeKey(value: string) { this.set('schemeKey', value); } + set maxStepIndex(value: number) { this.set('maxStepIndex', value); } + set allowedServices(value: string) { this.set('allowedServices', value); } + set allowedServicesAfterDueDate(value: string) { this.set('allowedServicesAfterDueDate', value); } + set code(value: string) { this.set('code', value); } + set person(value: Partial) { this.set('person', value); } + set company(value: Partial) { this.set('company', value); } + set address(value: Partial) { this.set('address', new Address(value)); } + set debtor(value: IDebtor) { this.set('debtor', value); } + set email(value: string) { this.set('email', value); } + set phone(value: IPhone) { this.set('phone', value); } + set articles(value: ICreditArticle[]) { this.set( 'articles', value.map((article) => new CreditArticle(article)) ); } + set invoiceNumber(value: string) { this.set('invoiceNumber', value); } + set applyStartRecurrent(value: boolean) { this.set('applyStartRecurrent', value); } + + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine', + Address: 'Address', + Company: 'Company', + Person: 'Person', + Debtor: 'Debtor', + Email: 'Email', + Phone: 'Phone', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts index 19eb8a44..2fcbdb10 100644 --- a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts +++ b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts @@ -14,34 +14,44 @@ export interface IPaymentPlan extends IRequest { paymentPlanCostAmountVat?: number; recipientEmail?: string; } + export class PaymentPlan extends ServiceParameter implements IPaymentPlan { set includedInvoiceKey(value: string) { this.set('includedInvoiceKey', value); } + set dossierNumber(value: string) { this.set('dossierNumber', value); } + set installmentCount(value: number) { this.set('installmentCount', value); } + set installmentAmount(value: number) { this.set('installmentAmount', value); } + set initialAmount(value: number) { this.set('initialAmount', value); } + set startDate(value: string) { this.set('startDate', value); } + set interval(value: CreditManagementInstallmentInterval) { this.set('interval', value); } + set paymentPlanCostAmount(value: number) { this.set('paymentPlanCostAmount', value); } + set paymentPlanCostAmountVat(value: number) { this.set('paymentPlanCostAmountVat', value); } + set recipientEmail(value: string) { this.set('recipientEmail', value); } diff --git a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts index 17a1c17f..4fff9b38 100644 --- a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts @@ -5,11 +5,13 @@ export interface IMultiInfoInvoice extends IRequest { invoice: string; invoices?: { invoiceNumber: string }[]; } + export class MultiInfoInvoice extends ServiceParameter { - protected getCountable() { - return super.getCountable(['Invoices']); - } set invoices(value: { invoiceNumber: string }[]) { this.set('invoices', value); } + + protected getCountable() { + return super.getCountable(['Invoices']); + } } diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 65fc0f9d..652299d4 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -6,49 +6,59 @@ import { IPaymentPlan, PaymentPlan } from './Models/PaymentPlan'; import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice'; import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines'; import IRequest from '../../Models/IRequest'; -import { IDebtorInfo, DebtorInfo } from './Models/DebtorInfo'; +import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; import { ServiceParameter } from '../../Models/ServiceParameters'; export default class CreditManagement extends PaymentMethod { protected _paymentName = 'CreditManagement'; protected _serviceVersion = 1; protected _requiredFields = ['currency']; + createInvoice(payload: IInvoice) { this.setServiceList('CreateInvoice', new Invoice(payload)); return this.dataRequest(payload); } + createCombinedInvoice(payload: IInvoice) { this.setServiceList('CreateCombinedInvoice', new Invoice(payload)); return this.transactionRequest(payload); } + createCreditNote(payload: ICreditNote) { this.setServiceList('CreateCreditNote', new CreditNote(payload)); return this.dataRequest(payload); } + addOrUpdateDebtor(payload: IDebtor) { this.setServiceList('AddOrUpdateDebtor', new Debtor(payload)); return this.dataRequest(payload); } + createPaymentPlan(payload: IPaymentPlan) { this.setServiceList('CreatePaymentPlan', new PaymentPlan(payload)); return this.dataRequest(payload); } + terminatePaymentPlan(payload: Required>) { this.setServiceList('TerminatePaymentPlan', new PaymentPlan(payload)); return this.dataRequest(payload); } + pauseInvoice(payload: Required>) { this.setServiceList('PauseInvoice'); return this.dataRequest(payload); } + unpauseInvoice(payload: Required>) { this.setServiceList('UnpauseInvoice'); return this.dataRequest(payload); } + invoiceInfo(payload: IMultiInfoInvoice) { this.setServiceList('InvoiceInfo', new MultiInfoInvoice(payload)); return this.dataRequest(payload); } + debtorInfo(payload: IDebtorInfo) { this.setServiceList('DebtorInfo', new DebtorInfo(payload)); return this.dataRequest(payload); @@ -58,6 +68,7 @@ export default class CreditManagement extends PaymentMethod { this.setServiceList('AddOrUpdateProductLines', new AddOrUpdateProductLines(payload)); return this.dataRequest(payload); } + resumeDebtorFile(payload: { debtorFileGuid: string }) { let debtorFile = new ServiceParameter().set('debtorFileGuid', payload.debtorFileGuid); this.setServiceList('ResumeDebtorFile', debtorFile); diff --git a/src/PaymentMethods/Emandates/Models/Mandate.ts b/src/PaymentMethods/Emandates/Models/Mandate.ts index e9bfe23d..7bb97195 100644 --- a/src/PaymentMethods/Emandates/Models/Mandate.ts +++ b/src/PaymentMethods/Emandates/Models/Mandate.ts @@ -17,27 +17,35 @@ export class Mandate extends ServiceParameter { set debtorBankId(value: string) { this.set('debtorBankId', value); } + set debtorReference(value: string) { this.set('debtorReference', value); } + set sequenceType(value: number) { this.set('sequenceType', value); } + set purchaseId(value: string) { this.set('purchaseId', value); } + set mandateId(value: string) { this.set('mandateId', value); } + set language(value: string) { this.set('language', value); } + set emandateReason(value: string) { this.set('emandateReason', value); } + set maxAmount(value: number) { this.set('maxAmount', value); } + set originalMandateId(value: string) { this.set('originalMandateId', value); } diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 9a589058..e6592785 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -3,24 +3,29 @@ import { IConfig } from '../../Utils/Types'; import { IMandate, Mandate } from './Models/Mandate'; export default class Emandates extends PaymentMethod { - protected _paymentName = 'Emandates'; _requiredFields: Array = ['currency']; + protected _paymentName = 'Emandates'; + issuerList() { this.setServiceList('GetIssuerList'); return this.dataRequest(); } + createMandate(payload: IMandate) { this.setServiceList('CreateMandate', new Mandate(payload)); return this.dataRequest(payload); } + status(payload: IMandate) { this.setServiceList('GetStatus', new Mandate(payload)); return this.dataRequest(payload); } + modifyMandate(payload: IMandate) { this.setServiceList('ModifyMandate', new Mandate(payload)); return this.dataRequest(payload); } + cancelMandate(payload: IMandate) { this.setServiceList('CancelMandate', new Mandate(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/GiftCard/Models/Pay.ts b/src/PaymentMethods/GiftCard/Models/Pay.ts index 6f1942c0..143ce712 100644 --- a/src/PaymentMethods/GiftCard/Models/Pay.ts +++ b/src/PaymentMethods/GiftCard/Models/Pay.ts @@ -13,37 +13,48 @@ export default interface IPay extends IPaymentRequest { cardNumber?: string; pin?: string; } + export class Pay extends ServiceParameter { set fashionChequeCardNumber(value: string) { this.set('fashionChequeCardNumber', value); } + set fashionChequePin(value: string) { this.set('fashionChequePin', value); } + set intersolveCardnumber(value: string) { this.set('intersolveCardnumber', value); } + set intersolvePIN(value: string) { this.set('intersolvePIN', value); } + set tcsCardnumber(value: string) { this.set('tcsCardnumber', value); } + set tcsValidationCode(value: string) { this.set('tcsValidationCode', value); } + set lastName(value: string) { this.set('lastName', value); } + set email(value: string) { this.set('email', value); } + set cardNumber(value: string) { this.set('cardNumber', value); } + set pin(value: string) { this.set('pin', value); } + set issuer(value: string) { this.set('issuer', value); } diff --git a/src/PaymentMethods/GiftCard/Models/Refund.ts b/src/PaymentMethods/GiftCard/Models/Refund.ts index 96803981..4b26c73d 100644 --- a/src/PaymentMethods/GiftCard/Models/Refund.ts +++ b/src/PaymentMethods/GiftCard/Models/Refund.ts @@ -10,6 +10,7 @@ export class Refund extends ServiceParameter { set email(value: string) { this.set('amount', value); } + set lastName(value: string) { this.set('lastName', value); } diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 3cda781c..7d6bdfab 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -8,6 +8,7 @@ export default class GiftCard extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefund) { return super.refund(payload, new Refund(payload)); } diff --git a/src/PaymentMethods/Giropay/Models/Pay.ts b/src/PaymentMethods/Giropay/Models/Pay.ts index 66a0fe43..c35c3b5c 100644 --- a/src/PaymentMethods/Giropay/Models/Pay.ts +++ b/src/PaymentMethods/Giropay/Models/Pay.ts @@ -5,10 +5,12 @@ export interface IPay extends IPaymentRequest { bic?: string; costumerIBAN?: string; } + export class Pay extends ServiceParameter { set bic(value: string) { this.set('bic', value); } + set costumerIBAN(value: string) { this.set('costumerIBAN', value); } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 6f5d3131..ad030e5c 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -3,6 +3,7 @@ import { IPay, Pay } from './Models/Pay'; export default class Giropay extends PayablePaymentMethod { protected _paymentName = 'Giropay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Ideal/Models/Pay.ts b/src/PaymentMethods/Ideal/Models/Pay.ts index 17555ec6..e0fec08a 100644 --- a/src/PaymentMethods/Ideal/Models/Pay.ts +++ b/src/PaymentMethods/Ideal/Models/Pay.ts @@ -1,8 +1,10 @@ import { IPaymentRequest } from '../../../Models/IRequest'; import { ServiceParameter } from '../../../Models/ServiceParameters'; + export interface IPay extends IPaymentRequest { issuer?: string; } + export class Pay extends ServiceParameter { set issuer(value: string) { this.set('issuer', value); diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index a62140e1..0bd2bad0 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -1,4 +1,4 @@ -import { Pay, IPay } from './Models/Pay'; +import { IPay, Pay } from './Models/Pay'; import PayablePaymentMethod from '../PayablePaymentMethod'; import { RequestTypes } from '../../Constants/Endpoints'; import { IRefundRequest } from '../../Models/IRequest'; @@ -6,15 +6,19 @@ import { IRefundRequest } from '../../Models/IRequest'; export default class Ideal extends PayablePaymentMethod { protected _paymentName = 'Ideal'; protected _serviceVersion = 2; + constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { super(serviceCode); } + pay(data: IPay) { return super.pay(data, new Pay(data)); } + payRemainder(payload: IPay) { return super.payRemainder(payload, new Pay(payload)); } + issuers() { return this.specification(RequestTypes.Transaction) .request() @@ -27,6 +31,7 @@ export default class Ideal extends PayablePaymentMethod { }); }); } + instantRefund(data: IRefundRequest) { return super.refund(data); } diff --git a/src/PaymentMethods/IdealQR/Models/IGenerate.ts b/src/PaymentMethods/IdealQR/Models/IGenerate.ts index 74f99f8f..db98e238 100644 --- a/src/PaymentMethods/IdealQR/Models/IGenerate.ts +++ b/src/PaymentMethods/IdealQR/Models/IGenerate.ts @@ -13,34 +13,44 @@ export interface IGenerate extends IRequest { maxAmount: number; imageSize: number; } + export class Generate extends ServiceParameter implements IGenerate { set amount(value: number) { this.set('amount', value); } + set amountIsChangeable(value: boolean) { this.set('amountIsChangeable', value); } + set purchaseId(value: string) { this.set('purchaseId', value); } + set description(value: string) { this.set('description', value); } + set isOneOff(value: boolean) { this.set('isOneOff', value); } + set expiration(value: string) { this.set('expiration', value); } + set isProcessing(value: boolean) { this.set('isProcessing', value); } + set minAmount(value: number) { this.set('minAmount', value); } + set maxAmount(value: number) { this.set('maxAmount', value); } + set imageSize(value: number) { this.set('imageSize', value); } diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index bc6831a3..4c9548c9 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -3,6 +3,7 @@ import PaymentMethod from '../PaymentMethod'; export default class IdealQR extends PaymentMethod { protected _paymentName = 'IdealQR'; + generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index f2cc1eeb..d4196442 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,14 +1,17 @@ import PaymentMethod from '../PaymentMethod'; import { IPay } from '../Ideal/Models/Pay'; + export default class Idin extends PaymentMethod { protected _paymentName = 'Idin'; identify(payload: IPay) { return this.dataRequest(payload); } + verify(payload: IPay) { return this.dataRequest(payload); } + login(payload: IPay) { return this.dataRequest(payload); } diff --git a/src/PaymentMethods/In3/Models/Article.ts b/src/PaymentMethods/In3/Models/Article.ts index 57815ea5..3f07a023 100644 --- a/src/PaymentMethods/In3/Models/Article.ts +++ b/src/PaymentMethods/In3/Models/Article.ts @@ -5,19 +5,24 @@ export interface IIn3Article extends IArticle { url?: string; quantityDescription?: string; } + export class In3Article extends Article implements In3Article { set category(value: string) { this.set('category', value); } + get price() { return this.get('grossUnitPrice'); } + set price(value: number) { this.set('grossUnitPrice', value); } + set url(value: string) { this.set('url', value); } + set quantityDescription(value: string) { this.set('quantityDescription', value); } diff --git a/src/PaymentMethods/In3/Models/Pay.ts b/src/PaymentMethods/In3/Models/Pay.ts index ea3367b3..d6a661d6 100644 --- a/src/PaymentMethods/In3/Models/Pay.ts +++ b/src/PaymentMethods/In3/Models/Pay.ts @@ -10,39 +10,47 @@ export interface IPay extends IPaymentRequest { shipping?: Partial; articles?: Partial[]; } + export default class Pay extends ServiceParameter { - protected getGroups(): {} { - return super.getGroups({ - Billing: 'BillingCustomer', - Shipping: 'ShippingCustomer', - Articles: 'Article', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } set invoiceDate(value: string) { this.set('invoiceDate', value); } + set invoiceUrl(value: string) { this.set('invoiceUrl', value); } + get billing() { return new In3Recipient(); } + set billing(billing: IIn3Recipient) { this.set('billing', new In3Recipient(billing)); if (this.get('shipping') === undefined) { this.shipping = billing; } } + set shipping(shipping: IIn3Recipient) { this.set('shipping', new In3Recipient(shipping)); } + set articles(articles: In3Article[]) { this.set( 'articles', articles.map((article) => new In3Article(article)) ); } + + protected getGroups(): {} { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/In3/Models/Phone.ts b/src/PaymentMethods/In3/Models/Phone.ts index 3c14a9e0..b6485c7e 100644 --- a/src/PaymentMethods/In3/Models/Phone.ts +++ b/src/PaymentMethods/In3/Models/Phone.ts @@ -4,9 +4,11 @@ export class In3Phone extends Phone { set landline(value: string) { this.set('phone', value); } + set mobile(value: string) { this.set('phone', value); } + set fax(value: string) { this.set('phone', value); } diff --git a/src/PaymentMethods/In3/Models/Recipient.ts b/src/PaymentMethods/In3/Models/Recipient.ts index 82d88134..4510e4a8 100644 --- a/src/PaymentMethods/In3/Models/Recipient.ts +++ b/src/PaymentMethods/In3/Models/Recipient.ts @@ -10,10 +10,12 @@ export interface IIn3Recipient extends ICustomer { recipient: Partial; phone: IPhone; } + export class In3Recipient extends Model implements In3Recipient { get recipient(): In3Company | IIn3Person { return new In3Person({}); } + set recipient(value: In3Company | IIn3Person) { if (value.category === RecipientCategory.COMPANY) { this.set('recipient', new In3Company(value)); @@ -21,21 +23,27 @@ export class In3Recipient extends Model implements In3Recipient { this.set('recipient', new In3Person(value)); } else throw new Error('Invalid recipient category'); } + get address(): IAddress { return new In3Address(); } + set address(value: IAddress) { this.set('address', new In3Address(value)); } + get email(): string { return ''; } + set email(value: string) { this.set('email', value); } + get phone(): IPhone { return new In3Phone(); } + set phone(value: IPhone) { this.set('phone', new In3Phone(value)); } @@ -47,65 +55,84 @@ export interface IIn3Person extends IPerson { conversationLanguage: string; lastName: string; } + export interface IIn3Company extends ICompany { customerNumber: string; } + export class In3Person extends Person implements IIn3Person { set category(value: RecipientCategory.PERSON) { this.set('category', 'B2C'); } + set customerNumber(value: string) { this.set('customerNumber', value); } + set identificationNumber(value: string) { this.set('identificationNumber', value); } + set conversationLanguage(value: string) { this.set('conversationLanguage', value); } } + export class In3Company extends Company implements IIn3Company { set category(value: RecipientCategory.COMPANY) { this.set('category', 'B2B'); } + set customerNumber(value: string) { this.set('customerNumber', value); } + get title() { return this.get('salutation'); } + set title(value: string) { this.set('salutation', value); } + get chamberOfCommerce() { return this.get('cocNumber'); } + set chamberOfCommerce(value: string) { this.set('cocNumber', value); } } + export class In3Address extends Address { get houseNumber() { return this.get('streetNumber'); } + set houseNumber(value: string) { this.set('streetNumber', value); } + get houseNumberAdditional() { return this.get('streetNumberSuffix'); } + set houseNumberAdditional(value: string) { this.set('streetNumberSuffix', value); } + get zipcode() { return this.get('postalCode'); } + set zipcode(value: string) { this.set('postalCode', value); } + get country() { return this.get('countryCode'); } + set country(value: string) { this.set('countryCode', value); } diff --git a/src/PaymentMethods/In3/Models/Refund.ts b/src/PaymentMethods/In3/Models/Refund.ts index 62e8eb61..8559d97d 100644 --- a/src/PaymentMethods/In3/Models/Refund.ts +++ b/src/PaymentMethods/In3/Models/Refund.ts @@ -7,14 +7,18 @@ export interface IRefund extends IRefundRequest { summaryImageUrl: string; articles: IIn3Article[]; } + export class Refund extends ServiceParameter { protected _countable: string[] = ['articles']; + set merchantImageUrl(value: string) { this.set('merchantImageUrl', value); } + set summaryImageUrl(value: string) { this.set('summaryImageUrl', value); } + set articles(value: IIn3Article[]) { this.set('article', value); } diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index f8aa8dcf..860c88df 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -5,9 +5,11 @@ import { IRefund, Refund } from './Models/Refund'; export default class In3 extends PayablePaymentMethod { protected _paymentName = 'In3'; + pay(payload: IPaymentRequest) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefund) { return super.refund(payload, new Refund(payload)); } diff --git a/src/PaymentMethods/In3Old/Models/Article.ts b/src/PaymentMethods/In3Old/Models/Article.ts index 9f4e408c..fe4f1d40 100644 --- a/src/PaymentMethods/In3Old/Models/Article.ts +++ b/src/PaymentMethods/In3Old/Models/Article.ts @@ -4,6 +4,7 @@ export class In3OldArticle extends Article { set identifier(identifier: string) { this.set('code', identifier); } + set description(description: string) { this.set('name', description); } diff --git a/src/PaymentMethods/In3Old/Models/Pay.ts b/src/PaymentMethods/In3Old/Models/Pay.ts index 183a4c1b..396b127b 100644 --- a/src/PaymentMethods/In3Old/Models/Pay.ts +++ b/src/PaymentMethods/In3Old/Models/Pay.ts @@ -24,52 +24,63 @@ export interface IPay extends IPaymentRequest { articles: Partial[]; subtotals: ISubtotal[]; } + export class Pay extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Articles: 'ProductLine', - Subtotals: 'SubtotalLine', - Address: 'Address', - Customer: 'Person', - Company: 'Company', - Phone: 'Phone', - Email: 'Email', - }); - } - protected getCountable() { - return super.getCountable(['Articles', 'Subtotals']); - } set customerType(value: RecipientCategory) { this.set('customerType', value); } + set invoiceDate(value: string) { this.set('invoiceDate', value); } + set email(value: string) { this.set('email', value); } + set phone(value: Partial) { this.set('phone', new In3OldPhone(value)); } + set company(value: Partial) { this.set('company', new In3OldCompany(value)); } + set customer(value: Partial) { this.set('customer', new Person(value)); } + set address(value: Partial) { this.set('address', new In3OldAddress(value)); } + set articles(value: Partial[]) { this.set( 'articles', value.map((article) => new In3OldArticle(article)) ); } + set subtotals(value: ISubtotal[]) { this.set( 'subtotals', value.map((subtotal) => new Subtotal(subtotal)) ); } + + protected getGroups() { + return super.getGroups({ + Articles: 'ProductLine', + Subtotals: 'SubtotalLine', + Address: 'Address', + Customer: 'Person', + Company: 'Company', + Phone: 'Phone', + Email: 'Email', + }); + } + + protected getCountable() { + return super.getCountable(['Articles', 'Subtotals']); + } } diff --git a/src/PaymentMethods/In3Old/Models/Subtotal.ts b/src/PaymentMethods/In3Old/Models/Subtotal.ts index 85d70540..2882348b 100644 --- a/src/PaymentMethods/In3Old/Models/Subtotal.ts +++ b/src/PaymentMethods/In3Old/Models/Subtotal.ts @@ -4,10 +4,12 @@ export interface ISubtotal { name: string; value: number; } + export class Subtotal extends Model implements ISubtotal { set name(name: string) { this.set('name', name); } + set value(value: number) { this.set('value', value); } diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 8c2ec8f3..72440054 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,10 +1,13 @@ import PayablePaymentMethod from '../PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; + export default class In3Old extends PayablePaymentMethod { protected _paymentName = 'In3Old'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + payInInstallments(payload: IPay) { this.setPayPayload(payload); this.setServiceList('PayInInstallments', new Pay(payload)); diff --git a/src/PaymentMethods/Klarna/Models/Article.ts b/src/PaymentMethods/Klarna/Models/Article.ts index f09cbd84..cd78389e 100644 --- a/src/PaymentMethods/Klarna/Models/Article.ts +++ b/src/PaymentMethods/Klarna/Models/Article.ts @@ -1,8 +1,10 @@ import { Article } from '../../../Models/Interfaces/IArticle'; + export class KlarnaArticle extends Article { get price() { return this.get('grossUnitPrice'); } + set price(price: number) { this.set('grossUnitPrice', price); } diff --git a/src/PaymentMethods/Klarna/Models/Pay.ts b/src/PaymentMethods/Klarna/Models/Pay.ts index 2426c893..2310fc6e 100644 --- a/src/PaymentMethods/Klarna/Models/Pay.ts +++ b/src/PaymentMethods/Klarna/Models/Pay.ts @@ -10,30 +10,35 @@ export interface IPay extends IPaymentRequest { shipping?: ICustomer; articles: Partial[]; } + export class Pay extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Billing: 'BillingCustomer', - Shipping: 'ShippingCustomer', - Articles: 'Article', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } set billing(billing: ICustomer) { this.set('billing', new KlarnaRecipient(billing)); if (this.get('shipping') === undefined) { this.shipping = billing; } } + set shipping(shipping: ICustomer) { this.set('shipping', new KlarnaRecipient(shipping)); } + set articles(articles: IArticle[]) { this.set( 'articles', articles.map((article) => new KlarnaArticle(article)) ); } + + protected getGroups() { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/Klarna/Models/Recipient.ts b/src/PaymentMethods/Klarna/Models/Recipient.ts index d35fbd92..0b06dc4d 100644 --- a/src/PaymentMethods/Klarna/Models/Recipient.ts +++ b/src/PaymentMethods/Klarna/Models/Recipient.ts @@ -11,9 +11,11 @@ export class KlarnaRecipient extends Model implements ICustomer { set email(email: string) { this.set('email', email); } + set address(address: IAddress) { this.set('address', new KlarnaAddress(address)); } + set recipient(recipient: Partial) { if (recipient.category === RecipientCategory.PERSON) { // @ts-ignore @@ -23,6 +25,7 @@ export class KlarnaRecipient extends Model implements ICustomer { this.set('recipient', new Company({ ...recipient, category: 'B2B' })); } } + set phone(phone: IPhone) { this.set('phone', new KlarnaPhone(phone)); } diff --git a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts index a1c94c57..10d3aed2 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts @@ -1,20 +1,26 @@ import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; + export class KlarnaAddress extends Address implements IAddress { get houseNumber(): string { return this.get('streetNumber'); } + set houseNumber(houseNumber: string) { this.set('streetNumber', houseNumber); } + get houseNumberAdditional(): string { return this.get('streetNumberAdditional'); } + set houseNumberAdditional(houseNumberAdditional: string) { this.set('streetNumberAdditional', houseNumberAdditional); } + get zipcode(): string { return this.get('postalCode'); } + set zipcode(zipcode: string) { this.set('postalCode', zipcode); } diff --git a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts index ae578493..03b4a00f 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts @@ -4,6 +4,7 @@ export class KlarnaPhone extends Phone { get mobile(): string { return this.get('phone'); } + set mobile(mobile: string) { this.set('phone', mobile); } diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 57c384cf..6db2b934 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -3,13 +3,16 @@ import PayablePaymentMethod from '../PayablePaymentMethod'; export default class Klarna extends PayablePaymentMethod { protected _paymentName = 'Klarna'; + pay(data: IPay) { return super.pay(data, new Pay(data)); } + payInInstallments(data: IPay) { this.setServiceList('PayInInstallments', new Pay(data)); return super.pay(data); } + payRemainder(payload: IPay) { return super.payRemainder(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/KlarnaKP/Models/IPay.ts b/src/PaymentMethods/KlarnaKP/Models/IPay.ts index 0b520759..2edf9dd8 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IPay.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IPay.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { reservationNumber?: string; } + export class Pay extends ServiceParameter { set reservationNumber(value: string) { this.set('reservationNumber', value); diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts index 4a04df3f..3ca3b1ac 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -14,29 +14,37 @@ export interface IReserve extends IRequest { shippingSameAsBilling?: boolean; pno?: string; } + export class Reserve extends ServiceParameter implements IReserve { - protected getCountable() { - return super.getCountable(['Articles']); - } set reservationNumber(value: string) { this.set('reservationNumber', value); } + set gender(value: Gender.MALE | Gender.FEMALE) { this.set('gender', value); } + set operatingCountry(value: string) { this.set('operatingCountry', value); } + set pno(value: string) { this.set('pno', value); } + set billing(value: ICustomer) { this.set('billing', value); } + set shipping(value: ICustomer) { this.set('shipping', value); } + set articles(value: IArticle[]) { this.set('articles', value); } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 54e6c84d..0c9d41eb 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -6,25 +6,31 @@ import { IReserve, Reserve } from './Models/IReserve'; export default class KlarnaKP extends PayablePaymentMethod { protected _paymentName = 'KlarnaKP'; protected _serviceVersion = 1; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + reserve(payload: IReserve) { this.setServiceList('Reserve', new Reserve(payload)); return this.dataRequest(payload); } + cancel(payload: IRequest) { this.setServiceList('CancelReservation'); return this.dataRequest(payload); } + update(payload: IRequest) { this.setServiceList('UpdateReservation'); return this.dataRequest(payload); } + extend(payload: IRequest) { this.setServiceList('ExtendReservation'); return this.dataRequest(payload); } + addShippingInfo(payload: IRequest) { this.setServiceList('AddShippingInfo'); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Marketplaces/Models/Marketplace.ts b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts index 6018c57b..b96d3d33 100644 --- a/src/PaymentMethods/Marketplaces/Models/Marketplace.ts +++ b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts @@ -4,10 +4,12 @@ export interface IMarketplace { amount: number; description: string; } + export class Marketplace extends Model implements IMarketplace { set amount(value: number) { this.set('amount', value); } + set description(value: string) { this.set('description', value); } diff --git a/src/PaymentMethods/Marketplaces/Models/Seller.ts b/src/PaymentMethods/Marketplaces/Models/Seller.ts index 4a329ebc..19703baa 100644 --- a/src/PaymentMethods/Marketplaces/Models/Seller.ts +++ b/src/PaymentMethods/Marketplaces/Models/Seller.ts @@ -5,13 +5,16 @@ export interface ISeller { amount?: number; description?: string; } + export class Seller extends Model implements ISeller { set accountId(value: string) { this.set('accountId', value); } + set amount(value: number) { this.set('amount', value); } + set description(value: string) { this.set('description', value); } diff --git a/src/PaymentMethods/Marketplaces/Models/Split.ts b/src/PaymentMethods/Marketplaces/Models/Split.ts index ea803db3..abff8adc 100644 --- a/src/PaymentMethods/Marketplaces/Models/Split.ts +++ b/src/PaymentMethods/Marketplaces/Models/Split.ts @@ -8,26 +8,31 @@ export interface ISplit extends IRequest { marketplace?: IMarketplace; daysUntilTransfer?: number; } + export class Split extends ServiceParameter { - protected getCountable() { - return super.getCountable(['Sellers']); - } - protected getGroups() { - return super.getGroups({ - Sellers: 'Seller', - Marketplace: 'Marketplace', - }); - } set seller(value: ISeller[]) { this.set( 'sellers', value.map((seller: ISeller) => new Seller(seller)) ); } + set marketplace(value: IMarketplace) { this.set('marketplace', new Marketplace(value)); } + set daysUntilTransfer(value: number) { this.set('daysUntilTransfer', value); } + + protected getCountable() { + return super.getCountable(['Sellers']); + } + + protected getGroups() { + return super.getGroups({ + Sellers: 'Seller', + Marketplace: 'Marketplace', + }); + } } diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 5b795c93..9fb37419 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,18 +1,22 @@ import PaymentMethod from '../PaymentMethod'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; + export default class Marketplaces extends PaymentMethod { get paymentName() { return 'Marketplaces'; } + split(payload: ISplit) { this.setServiceList('Split', new Split(payload)); return this.dataRequest(payload); } + transfer(payload: ITransfer) { this.setServiceList('Transfer', new Split(payload)); return this.dataRequest(payload); } + refundSupplementary(payload: ISplit) { this.setServiceList('RefundSupplementary', new Split(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index 83c20778..0db45c7c 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from "../PayablePaymentMethod"; +import PayablePaymentMethod from '../PayablePaymentMethod'; export default class Mbway extends PayablePaymentMethod { - protected _paymentName = "MB WAY"; + protected _paymentName = 'MB WAY'; } diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index fd9d4ab2..7e984075 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,10 +1,12 @@ import PayablePaymentMethod from '../PayablePaymentMethod'; export default class NoService extends PayablePaymentMethod { + protected _paymentName = 'noserivce'; + get paymentName() { return 'NoService'; } - protected _paymentName = 'noserivce'; + protected setServiceList(): this { return this; } diff --git a/src/PaymentMethods/PayByBank/Models/IPay.ts b/src/PaymentMethods/PayByBank/Models/IPay.ts index e29e8c50..e6a55706 100644 --- a/src/PaymentMethods/PayByBank/Models/IPay.ts +++ b/src/PaymentMethods/PayByBank/Models/IPay.ts @@ -5,10 +5,12 @@ export default interface IPay extends IPaymentRequest { issuer: string; countryCode: string; } + export class Pay extends ServiceParameter { set issuer(value: string) { this.set('issuer', value); } + set countryCode(value: string) { this.set('countryCode', value); } diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 5ecb0f64..ba0bf067 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -4,12 +4,15 @@ import IPay, { Pay } from './Models/IPay'; export default class PayByBank extends PayablePaymentMethod { protected _paymentName = 'PayByBank'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + issuers() { return this.specification() .request() diff --git a/src/PaymentMethods/PayPerEmail/Models/Attachments.ts b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts index f356a111..cd55893e 100644 --- a/src/PaymentMethods/PayPerEmail/Models/Attachments.ts +++ b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts @@ -1,7 +1,9 @@ import { Model } from '../../../Models/Model'; + export interface IAttachments { name: string; } + export class Attachments extends Model implements IAttachments { set name(value: string) { this.set('attachment', value); diff --git a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts index bfaba57a..6821d3d5 100644 --- a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts +++ b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts @@ -12,42 +12,53 @@ export interface IInvitation extends IRequest { attachments?: IAttachments[]; attachment?: string; } + export class Invitation extends ServiceParameter { - protected getCountable() { - return super.getCountable(['Attachments']); - } set attachment(value: string) { this.set('attachment', value); } + set customer(value: Partial) { this.set('customer', new Customer(value)); } + set merchantSendsEmail(value: boolean) { this.set('merchantSendsEmail', value); } + set attachments(value: IAttachments[]) { this.set( 'attachments', value.map((attachment: IAttachments) => new Attachments(attachment)) ); } + set email(value: string) { this.set('customerEmail', value); } + set paymentMethodsAllowed(value: string) { this.set('paymentMethodsAllowed', value); } + set expirationDate(value: string) { this.set('expirationDate', value); } + + protected getCountable() { + return super.getCountable(['Attachments']); + } } + class Customer extends Person { set gender(value: string) { this.set('customergender', value); } + set firstName(value: string) { this.set('customerFirstName', value); } + set lastName(value: string) { this.set('customerLastName', value); } diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 261675a6..9957e683 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -3,6 +3,7 @@ import { IInvitation, Invitation } from './Models/Invitation'; export default class PayPerEmail extends PaymentMethod { protected _paymentName = 'PayPerEmail'; + paymentInvitation(payload: IInvitation) { this.setServiceList('paymentInvitation', new Invitation(payload)); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/PayablePaymentMethod.ts b/src/PaymentMethods/PayablePaymentMethod.ts index 776f2794..c13692dd 100644 --- a/src/PaymentMethods/PayablePaymentMethod.ts +++ b/src/PaymentMethods/PayablePaymentMethod.ts @@ -6,24 +6,28 @@ import { IParameter } from '../Models/IParameters'; export default abstract class PayablePaymentMethod extends PaymentMethod { protected _requiredFields: Array = ['currency', 'returnURL', 'returnURLCancel', 'pushURL']; - protected setPayPayload(payload: IRequest) { - payload.invoice = payload.invoice ?? uniqid(); - payload.order = payload.order ?? uniqid(); - super.setPayload(payload); - } + pay(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { this.setPayPayload(payload); this.setServiceList('Pay', serviceParameters); return this.transactionRequest(); } + payRemainder(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { this.setPayPayload(payload); this.setServiceList('PayRemainder', serviceParameters); return this.transactionRequest(); } + refund(payload: IRefundRequest, serviceParameters?: ServiceParameter | IParameter[]) { this.setPayload(payload); this.setServiceList('Refund', serviceParameters); return this.transactionRequest(); } + + protected setPayPayload(payload: IRequest) { + payload.invoice = payload.invoice ?? uniqid(); + payload.order = payload.order ?? uniqid(); + super.setPayload(payload); + } } diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index ab4badc2..f8ff8435 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -3,6 +3,7 @@ import { IRefundRequest } from '../../Models/IRequest'; export default class Payconiq extends PayablePaymentMethod { protected _paymentName = 'Payconiq'; + instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index 2796da8b..a81dc7fe 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -2,33 +2,75 @@ import { RequestTypes } from '../Constants/Endpoints'; import IRequest from '../Models/IRequest'; import Buckaroo from '../index'; import Request from '../Request/Request'; -import {IService, ServiceList} from '../Models/IServiceList'; +import { IService, ServiceList } from '../Models/IServiceList'; import { ServiceParameter } from '../Models/ServiceParameters'; import { IParameter } from '../Models/IParameters'; import { TransactionData } from '../Request/DataModels'; -import {MethodFromServiceCode, ServiceCode} from "../Utils/MethodTypes"; +import { MethodFromServiceCode, ServiceCode } from '../Utils/MethodTypes'; export default abstract class PaymentMethod { - protected _paymentName: string = ''; - protected _serviceCode?: string; - protected _serviceVersion: number = 0; protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; + constructor(serviceCode?: string) { this._serviceCode = serviceCode ?? this.paymentName; } + + protected _paymentName: string = ''; + + get paymentName() { + return this._paymentName; + } + + protected _serviceCode?: string; + + get serviceCode() { + return this._serviceCode || ''; + } + + protected _serviceVersion: number = 0; + get serviceVersion() { return this._serviceVersion; } + set serviceVersion(value: number) { this._serviceVersion = value; } - get serviceCode() { - return this._serviceCode || ''; + + setPayload(payload?: IRequest) { + this.setRequiredFields(); + this._payload.initialize(payload); } - get paymentName() { - return this._paymentName; + + getPayload(): Record { + return this._payload.getData(); } + + getServiceList() { + return this._payload.getServiceList(); + } + + public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { + return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); + } + + combine(data: Name): MethodFromServiceCode; + + combine(data: Payload): this; + + combine(method: Method): this; + + combine(data): this { + if (typeof data === 'string') { + const method: PaymentMethod = Buckaroo.Client.method(data as any); + method.setPayload(this._payload); + return method as any; + } + this.setPayload(data instanceof PaymentMethod ? data.getPayload() : data); + return this; + } + protected setRequiredFields(requiredFields: Array = this._requiredFields) { for (const fieldKey of requiredFields) { let field = this._payload[fieldKey] ?? Buckaroo.Client.config[fieldKey]; @@ -39,19 +81,19 @@ export default abstract class PaymentMethod { } return this; } - setPayload(payload?: IRequest) { - this.setRequiredFields(); - this._payload.initialize(payload); - } - getPayload():Record { - return this._payload.getData(); - } - protected setServiceList(action: string, serviceParameters?: IParameter[] | ServiceParameter, serviceCode = this.serviceCode, serviceVersion = this.serviceVersion) { - const service:IService = { + + protected setServiceList( + action: string, + serviceParameters?: IParameter[] | ServiceParameter, + serviceCode = this.serviceCode, + serviceVersion = this.serviceVersion + ) { + const service: IService = { name: serviceCode, action: action, version: serviceVersion, - parameters: serviceParameters instanceof ServiceParameter ? serviceParameters.toParameterList() : serviceParameters, + parameters: + serviceParameters instanceof ServiceParameter ? serviceParameters.toParameterList() : serviceParameters, }; if (this.getServiceList() instanceof ServiceList) { this.getServiceList()!.addService(service); @@ -60,31 +102,14 @@ export default abstract class PaymentMethod { } return this; } - getServiceList() { - return this._payload.getServiceList(); - } + protected transactionRequest(payload?: IRequest) { this.setPayload(payload); return Request.Transaction(this._payload); } + protected dataRequest(payload?: IRequest) { this.setPayload(payload); return Request.DataRequest(this._payload); } - public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { - return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); - } - - combine(data: Name): MethodFromServiceCode; - combine(data: Payload): this; - combine(method: Method): this; - combine(data): this { - if(typeof data === "string") { - const method:PaymentMethod = Buckaroo.Client.method(data as any) - method.setPayload(this._payload); - return method as any - } - this.setPayload(data instanceof PaymentMethod ? data.getPayload() : data); - return this; - } } diff --git a/src/PaymentMethods/Paypal/Models/Address.ts b/src/PaymentMethods/Paypal/Models/Address.ts index 4f3592e1..c9d4b634 100644 --- a/src/PaymentMethods/Paypal/Models/Address.ts +++ b/src/PaymentMethods/Paypal/Models/Address.ts @@ -4,32 +4,41 @@ export interface IAddress extends Partial { street: string; street2?: string; } + export class Address extends AddressClass { set street2(value: string) { this.set('street2', value); } - set street(value: string) { - this.set('street1', value); - } + get street() { return this.get('street1'); } - set city(value: string) { - this.set('cityName', value); + + set street(value: string) { + this.set('street1', value); } + get city() { return this.get('cityName'); } - set state(value: string) { - this.set('stateOrProvince', value); + + set city(value: string) { + this.set('cityName', value); } + get state() { return this.get('stateOrProvince'); } - set zipcode(value: string) { - this.set('postalCode', value); + + set state(value: string) { + this.set('stateOrProvince', value); } + get zipcode() { return this.get('postalCode'); } + + set zipcode(value: string) { + this.set('postalCode', value); + } } diff --git a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts index 05365590..ae31103d 100644 --- a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts +++ b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts @@ -17,15 +17,19 @@ export class ExtraInfo extends ServiceParameter { set address(value: IAddress) { this.set('address', new Address(value)); } + set customer(value: IPerson) { this.set('customer', new Person(value)); } + set phone(value: IPhone) { this.set('phone', new Phone(value)); } + set noShipping(value: string) { this.set('noShipping', value); } + set addressOverride(value: boolean) { this.set('addressOverride', value); } diff --git a/src/PaymentMethods/Paypal/Models/Pay.ts b/src/PaymentMethods/Paypal/Models/Pay.ts index 23f97d1d..a4c361f8 100644 --- a/src/PaymentMethods/Paypal/Models/Pay.ts +++ b/src/PaymentMethods/Paypal/Models/Pay.ts @@ -13,15 +13,19 @@ export class Pay extends ServiceParameter { set buyerEmail(value: string) { this.set('buyerEmail', value); } + set productName(value: string) { this.set('productName', value); } + set billingAgreementDescription(value: string) { this.set('billingAgreementDescription', value); } + set pageStyle(value: string) { this.set('pageStyle', value); } + set payPalOrderId(value: string) { this.set('payPalOrderId', value); } diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 5178dfe0..f25fd4e6 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -9,14 +9,17 @@ export default class Paypal extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } + payRecurrent(payload: IPaymentRequest) { this.setPayPayload(payload); this.setServiceList('PayRecurring'); return super.transactionRequest(payload); } + extraInfo(payload: IExtraInfo) { this.setPayPayload(payload); this.setServiceList('Pay,ExtraInfo', new ExtraInfo(payload)); diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index c932f282..366b03f2 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,7 +1,9 @@ import PaymentMethod from '../PaymentMethod'; + export default class PiM extends PaymentMethod { protected _paymentName = 'PiM'; protected _requiredFields = ['currency']; + generate() { this.setServiceList('Generate'); return this.dataRequest(); diff --git a/src/PaymentMethods/Przelewy24/Models/Pay.ts b/src/PaymentMethods/Przelewy24/Models/Pay.ts index 107b946d..7e37a4ba 100644 --- a/src/PaymentMethods/Przelewy24/Models/Pay.ts +++ b/src/PaymentMethods/Przelewy24/Models/Pay.ts @@ -1,22 +1,27 @@ import { IPaymentRequest } from '../../../Models/IRequest'; import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; import { ServiceParameter } from '../../../Models/ServiceParameters'; + export interface IPay extends IPaymentRequest { email: string; customer: Partial; } + export class Pay extends ServiceParameter { set email(email: string) { this.set('customerEmail', email); } + set customer(customer: Partial) { this.set('customer', new Customer(customer)); } } + export class Customer extends Person { set firstName(email: string) { this.set('customerFirstName', email); } + set lastName(email: string) { this.set('customerLastName', email); } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 1a40340a..45f19d02 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -4,9 +4,11 @@ import { IPay, Pay } from './Models/Pay'; export default class Przelewy24 extends PayablePaymentMethod { protected _paymentName = 'Przelewy24'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index f62c28a0..ab268b15 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -10,43 +10,56 @@ export interface IPay extends IPaymentRequest { mandateReference?: string; mandateDate?: string; } + export class Pay extends ServiceParameter { get bic(): string { return this.get('customerbic'); } + set bic(value: string) { this.set('customerbic', value); } + get iban(): string { return this.get('customerIBAN'); } + set iban(value: string) { this.set('customerIBAN', value); } + set collectDate(value: string) { this.set('collectDate', value); } + set mandateReference(value: string) { this.set('mandateReference', value); } + set mandateDate(value: string) { this.set('mandateDate', value); } + set customer(value: Partial) { this.set('customer', new Customer(value)); } } + export class Customer extends Person { set category(value) {} + get name(): string { return this.get('customeraccountname'); } + set name(value: string) { this.set('customeraccountname', value); } + get firstName(): string { return this.get('customeraccountname'); } + set firstName(value: string) { this.set('customeraccountname', value); } diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 6d944335..8d58ed45 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -7,24 +7,29 @@ import { IPaymentRequest } from '../../Models/IRequest'; export default class SEPA extends PayablePaymentMethod { protected _paymentName = 'SEPA'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + authorize(payload: IPay) { this.setPayPayload(payload); this.setServiceList('Authorize', new Pay(payload)); return this.transactionRequest(); } + payRecurrent(payload: Pick & IPaymentRequest) { this.setPayPayload(payload); this.setServiceList('PayRecurrent', new Pay(payload)); return this.transactionRequest(); } + extraInfo(payload: IExtraInfo) { this.setPayPayload(payload); this.setServiceList('Pay,ExtraInfo', new Pay(payload)); return this.transactionRequest(); } + payWithEmandate(payload: IEmandate) { payload.invoice = payload.invoice || uniqid(); this.setPayPayload(payload); diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 18b00696..85ca18bf 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -7,9 +7,11 @@ export default class Sofort extends PayablePaymentMethod { pay(payload: IPaymentRequest) { return super.pay(payload); } + refund(payload: IRefundRequest) { return super.refund(payload); } + instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/Subscriptions/Models/Configuration.ts b/src/PaymentMethods/Subscriptions/Models/Configuration.ts index f5186f33..27b25839 100644 --- a/src/PaymentMethods/Subscriptions/Models/Configuration.ts +++ b/src/PaymentMethods/Subscriptions/Models/Configuration.ts @@ -10,13 +10,16 @@ export type IConfiguration = { generateInvoiceSpecification?: boolean; skipPayPerEmail?: boolean; }; + export class Configuration extends Model implements IConfiguration { set name(value: string) { this.set('name', value); } + set schemeKey(value: string) { this.set('schemeKey', value); } + set invoiceNumberPrefix(value: string) { this.set('invoiceNumberPrefix', value); } diff --git a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts index ab50281d..9daa869c 100644 --- a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts @@ -38,90 +38,82 @@ export interface ISubscription extends IRequest { } export class Subscription extends ServiceParameter implements ISubscription { - getGroups() { - return super.getGroups({ - Debtor: 'Debtor', - Person: 'Person', - Email: 'Email', - Address: 'Address', - AddRatePlan: 'AddRatePlan', - Configuration: 'AddConfiguration', - UpdateRatePlan: 'UpdateRatePlan', - DisableRatePlan: 'DisableRatePlan', - AddRatePlanCharge: 'AddRatePlanCharge', - UpdateRatePlanCharge: 'UpdateRatePlanCharge', - DisableRatePlanCharge: 'DisableRatePlanCharge', - }); - } set configurationCode(configurationCode: string) { this.set('configurationCode', configurationCode); } + set includeTransaction(includeTransaction: boolean) { this.set('includeTransaction', includeTransaction); } + set transactionVatPercentage(transactionVatPercentage: number) { this.set('transactionVatPercentage', transactionVatPercentage); } + set subscriptionGuid(value: string) { this.set('subscriptionGuid', value); } + set termStartDay(value: number) { this.set('termStartDay', value); } + set termStartMonth(value: number) { this.set('termStartMonth', value); } + set billingTiming(value: number) { this.set('billingTiming', value); } + set termStartWeek(value: string) { this.set('termStartWeek', value); } + set b2b(value: string) { this.set('b2b', value); } + set mandateReference(value: string) { this.set('mandateReference', value); } + set allowedServices(value: string) { this.set('allowedServices', value); } + set debtor(value: IDebtor) { this.set('debtor', value); } + set bankAccount(value: IBankAccount) { this.set('bankAccount', new BankAccount(value)); } + set email(value: string) { this.set('email', value); } + set phone(value: IPhone) { this.set('phone', new Phone(value)); } + set address(value: IAddress) { this.set('address', new Address(value)); } + set person(value: IPerson) { this.set('person', new Person(value)); } + set company(value: ICompany) { this.set('company', new Company(value)); } + set configuration(value: Configuration) { this.set('configuration', new Configuration(value)); } - protected set addRatePlan(value: IRatePlan) { - this.set('addRatePlan', new RatePlan(value)); - } - protected set updateRatePlan(value: IRatePlan) { - this.set('updateRatePlan', new RatePlan(value)); - } - protected set disableRatePlan(value: IRatePlan) { - this.set('disableRatePlan', new RatePlan(value)); - } - protected set addRatePlanCharge(value: IRatePlanCharge) { - this.set('addRatePlanCharge', new RatePlanCharge(value)); - } + set ratePlans(value: IRatePlans) { for (const key in value) { if (this.has(key + 'RatePlan')) { @@ -129,6 +121,7 @@ export class Subscription extends ServiceParameter implements ISubscription { } } } + set ratePlanCharges(value: IRatePlanCharges) { for (const key in value) { if (this.has(key + 'RatePlanCharge')) { @@ -136,13 +129,48 @@ export class Subscription extends ServiceParameter implements ISubscription { } } } + set customerIBAN(value: string) { this.set('customerIBAN', value); } + set customerAccountName(value: string) { this.set('customerAccountName', value); } + set customerBIC(value: string) { this.set('customerBIC', value); } + + protected set addRatePlan(value: IRatePlan) { + this.set('addRatePlan', new RatePlan(value)); + } + + protected set updateRatePlan(value: IRatePlan) { + this.set('updateRatePlan', new RatePlan(value)); + } + + protected set disableRatePlan(value: IRatePlan) { + this.set('disableRatePlan', new RatePlan(value)); + } + + protected set addRatePlanCharge(value: IRatePlanCharge) { + this.set('addRatePlanCharge', new RatePlanCharge(value)); + } + + getGroups() { + return super.getGroups({ + Debtor: 'Debtor', + Person: 'Person', + Email: 'Email', + Address: 'Address', + AddRatePlan: 'AddRatePlan', + Configuration: 'AddConfiguration', + UpdateRatePlan: 'UpdateRatePlan', + DisableRatePlan: 'DisableRatePlan', + AddRatePlanCharge: 'AddRatePlanCharge', + UpdateRatePlanCharge: 'UpdateRatePlanCharge', + DisableRatePlanCharge: 'DisableRatePlanCharge', + }); + } } diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts index 75537b2b..45492901 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts @@ -5,6 +5,7 @@ export interface IRatePlans { update?: IRatePlan; disable?: IRatePlan; } + export interface IRatePlan { type?: string; ratePlanGuid?: string; @@ -25,58 +26,76 @@ export interface IRatePlan { trialPeriodMonth?: string; inheritPaymentMethod?: boolean; } + export class RatePlan extends Model implements IRatePlan { set type(value: string) { this.set('type', value); } + set ratePlanGuid(value: string) { this.set('ratePlanGuid', value); } + set ratePlanCode(value: string) { this.set('ratePlanCode', value); } + set startDate(value: string) { this.set('startDate', value); } + set endDate(value: string) { this.set('endDate', value); } + set ratePlanName(value: string) { this.set('ratePlanName', value); } + set ratePlanDescription(value: string) { this.set('ratePlanDescription', value); } + set currency(value: string) { this.set('currency', value); } + set billingTiming(value: number) { this.set('billingTiming', value); } + set automaticTerm(value: boolean) { this.set('automaticTerm', value); } + set billingInterval(value: string) { this.set('billingInterval', value); } + set customNumberOfDays(value: number) { this.set('customNumberOfDays', value); } + set termStartDay(value: number) { this.set('termStartDay', value); } + set termStartWeek(value: string) { this.set('termStartWeek', value); } + set termStartMonth(value: string) { this.set('termStartMonth', value); } + set trialPeriodDays(value: number) { this.set('trialPeriodDays', value); } + set trialPeriodMonth(value: string) { this.set('trialPeriodMonth', value); } + set inheritPaymentMethod(value: boolean) { this.set('inheritPaymentMethod', value); } diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts index 4de58c47..ddde8073 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts @@ -14,45 +14,58 @@ export interface IRatePlanCharge { b2b?: string; ratePlanChargeType?: string; } + export interface IRatePlanCharges { add?: IRatePlanCharge; update?: IRatePlanCharge; disable?: IRatePlanCharge; } + export class RatePlanCharge extends Model implements IRatePlanCharge { set ratePlanChargeCode(value: string) { this.set('ratePlanChargeCode', value); } + set ratePlanChargeName(value: string) { this.set('ratePlanChargeName', value); } + set ratePlanChargeProductId(value: string) { this.set('rateplanChargeProductId', value); } + set ratePlanChargeDescription(value: string) { this.set('rateplanChargeDescription', value); } + set unitOfMeasure(value: string) { this.set('unitOfMeasure', value); } + set baseNumberOfUnits(value: number) { this.set('baseNumberOfUnits', value); } + set partialBilling(value: string) { this.set('partialBilling', value); } + set pricePerUnit(value: number) { this.set('pricePerUnit', value); } + set priceIncludesVat(value: boolean) { this.set('priceIncludesVat', value); } + set vatPercentage(value: number) { this.set('vatPercentage', value); } + set b2b(value: string) { this.set('b2B', value); } + set ratePlanChargeType(value: string) { this.set('ratePlanChargeType', value); } diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 987da852..7de2df3e 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -7,34 +7,41 @@ export default class Subscriptions extends PaymentMethod { protected _paymentName = 'Subscriptions'; protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; + create(payload: ISubscription) { this.setPayload(payload); this.setServiceList('CreateSubscription', new Subscription(payload)); return this.dataRequest(); } + update(payload: ISubscription) { this.setPayload(payload); this.setServiceList('UpdateSubscription', new Subscription(payload)); return this.dataRequest(); } + createCombined(payload: ISubscription) { this.setPayload(payload); this.setServiceList('CreateCombinedSubscription', new Subscription(payload)); return this.dataRequest(); } + updateCombined(payload: ISubscription) { this.setPayload(payload); this.setServiceList('UpdateCombinedSubscription', new Subscription(payload)); return this.dataRequest(); } + stop(payload: { subscriptionGuid: string }) { this.setServiceList('StopSubscription', new Subscription(payload)); return this.dataRequest(); } + info(payload: { subscriptionGuid: string }) { this.setServiceList('StopSubscription', new Subscription(payload)); return this.dataRequest(); } + deletePaymentConfig(payload: { subscriptionGuid: string }) { this.setServiceList('DeletePaymentConfiguration', new Subscription(payload)); return this.dataRequest(); @@ -44,6 +51,7 @@ export default class Subscriptions extends PaymentMethod { this.setServiceList('PauseSubscription', new ResumeSubscription(payload)); return this.dataRequest(); } + resume(payload: { subscriptionGuid: string; resumeDate: string }) { this.setServiceList('ResumeSubscription', new ResumeSubscription(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 8cf863d4..e07723e9 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,8 +1,10 @@ import PaymentMethod from '../PaymentMethod'; import { IVerify } from './Models/Verify'; import { Parameter } from '../../Models/IParameters'; + export default class Surepay extends PaymentMethod { protected _paymentName = 'Surepay'; + verify(payload: IVerify) { const serviceParameter = new Parameter({ name: 'customeraccountname', value: payload.customeraccountname }); this.setServiceList('Verify', [serviceParameter]); diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 1d6c7873..5180b118 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -4,18 +4,22 @@ import IRequest from '../../Models/IRequest'; type key = Required>; export default class Thunes extends PaymentMethod { protected _paymentName = 'Thunes'; + getStatus(payload: key) { this.setServiceList('getStatus'); return this.dataRequest(payload); } + capture(payload: IRequest & key) { this.setServiceList('Capture'); return this.transactionRequest(payload); } + authorize(payload: IRequest) { this.setServiceList('Authorize'); return this.dataRequest(payload); } + cancel(payload: key) { this.setServiceList('Cancel'); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Tinka/Models/Address.ts b/src/PaymentMethods/Tinka/Models/Address.ts index b2d1eac5..60775cdd 100644 --- a/src/PaymentMethods/Tinka/Models/Address.ts +++ b/src/PaymentMethods/Tinka/Models/Address.ts @@ -4,9 +4,11 @@ export class TinkaAddress extends Address { set houseNumber(value: string) { this.set('streetNumber', value); } + set houseNumberAdditional(value: string) { this.set('streetNumberAdditional', value); } + set zipcode(value: string) { this.set('postalCode', value); } diff --git a/src/PaymentMethods/Tinka/Models/Article.ts b/src/PaymentMethods/Tinka/Models/Article.ts index 6a2e1a73..0d49aa99 100644 --- a/src/PaymentMethods/Tinka/Models/Article.ts +++ b/src/PaymentMethods/Tinka/Models/Article.ts @@ -4,13 +4,16 @@ export interface ITinkaArticle extends IArticle { color?: string; size?: string; } + export class TinkaArticle extends Article { set color(value: string) { this.set('color', value); } + set price(value: number) { this.set('unitGrossPrice', value); } + set size(value: string) { this.set('size', value); } diff --git a/src/PaymentMethods/Tinka/Models/Pay.ts b/src/PaymentMethods/Tinka/Models/Pay.ts index 91fedf53..f13829ca 100644 --- a/src/PaymentMethods/Tinka/Models/Pay.ts +++ b/src/PaymentMethods/Tinka/Models/Pay.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; import { ICustomer } from '../../../Models/Interfaces/ICustomer'; import { ITinkaPerson, TinkaPerson } from './Person'; import { Recipient } from './Recipient'; + export interface IPay extends IPaymentRequest { paymentMethod: string; deliveryMethod: string; @@ -13,43 +14,51 @@ export interface IPay extends IPaymentRequest { shipping?: ICustomer; billing: ICustomer; } -export class Pay extends ServiceParameter { - protected getGroups() { - return super.getGroups({ - Articles: 'Article', - Shipping: 'ShippingCustomer', - Billing: 'BillingCustomer', - }); - } - protected getCountable() { - return super.getCountable(['Articles']); - } +export class Pay extends ServiceParameter { set paymentMethod(value: string) { this.set('paymentMethod', value); } + set deliveryMethod(value: string) { this.set('deliveryMethod', value); } + set deliveryDate(value: string) { this.set('deliveryDate', value); } + set articles(value: ITinkaArticle[]) { this.set( 'articles', value.map((article) => new TinkaArticle(article)) ); } + set customer(value: ITinkaPerson) { this.set('customer', new TinkaPerson(value)); } + set shipping(value: ICustomer) { this.set('shipping', new Recipient(value)); } + set billing(value: ICustomer) { this.set('billing', new Recipient(value)); if (this.shipping === undefined) { this.shipping = value; } } + + protected getGroups() { + return super.getGroups({ + Articles: 'Article', + Shipping: 'ShippingCustomer', + Billing: 'BillingCustomer', + }); + } + + protected getCountable() { + return super.getCountable(['Articles']); + } } diff --git a/src/PaymentMethods/Tinka/Models/Person.ts b/src/PaymentMethods/Tinka/Models/Person.ts index 3dd65653..4058874e 100644 --- a/src/PaymentMethods/Tinka/Models/Person.ts +++ b/src/PaymentMethods/Tinka/Models/Person.ts @@ -8,10 +8,12 @@ export interface ITinkaPerson { initials: string; birthDate: string; } + export class TinkaPerson extends Person { set lastNamePrefix(value: string) { this.set('prefixLastName', value); } + set birthDate(value: string) { this.set('dateOfBirth', value); } diff --git a/src/PaymentMethods/Tinka/Models/Recipient.ts b/src/PaymentMethods/Tinka/Models/Recipient.ts index 9ca15255..7d880228 100644 --- a/src/PaymentMethods/Tinka/Models/Recipient.ts +++ b/src/PaymentMethods/Tinka/Models/Recipient.ts @@ -10,9 +10,11 @@ export class Recipient extends Customer { set address(value: IAddress) { this.set('address', new TinkaAddress(value)); } + set phone(value: IPhone) { this.set('phone', new TinkaPhone(value)); } + set recipient(value: IPerson) { this.set('recipient', new TinkaPerson(value)); } diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index fc64fb5e..2274831b 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -4,9 +4,11 @@ import { IPay, Pay } from './Models/Pay'; export default class Tinka extends PayablePaymentMethod { protected _paymentName = 'Tinka'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Trustly/Models/Customer.ts b/src/PaymentMethods/Trustly/Models/Customer.ts index f4627b59..88fe98cc 100644 --- a/src/PaymentMethods/Trustly/Models/Customer.ts +++ b/src/PaymentMethods/Trustly/Models/Customer.ts @@ -4,6 +4,7 @@ export class Customer extends Model { set firstName(value: string) { this.set('CustomerFirstName', value); } + set lastName(value: string) { this.set('customerLastName', value); } diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index ffd5c8c6..a94bbafa 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -7,10 +7,12 @@ export interface IPay extends IPaymentRequest { customer: Partial; country?: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB'; } + export class Pay extends ServiceParameter { set customer(value: Partial) { this.set('customer', new Customer(value)); } + set country(value: string) { this.set('country', value); } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 997fa183..28eed001 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -4,9 +4,11 @@ import { IPay, Pay } from './Models/Pay'; export default class Trustly extends PayablePaymentMethod { protected _paymentName = 'Trustly'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/WeChatPay/Models/Pay.ts b/src/PaymentMethods/WeChatPay/Models/Pay.ts index 15e43fb4..4d47ac5e 100644 --- a/src/PaymentMethods/WeChatPay/Models/Pay.ts +++ b/src/PaymentMethods/WeChatPay/Models/Pay.ts @@ -4,6 +4,7 @@ import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IPay extends IPaymentRequest { locale?: string; } + export class Pay extends ServiceParameter { set locale(value: string) { this.set('locale', value); diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index b318ec65..884d312e 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -4,9 +4,11 @@ import { IPay, Pay } from './Models/Pay'; export default class WeChatPay extends PayablePaymentMethod { protected _paymentName = 'WeChatPay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/Request/DataModels.ts b/src/Request/DataModels.ts index 7c0a7dbe..3b776e31 100644 --- a/src/Request/DataModels.ts +++ b/src/Request/DataModels.ts @@ -10,89 +10,116 @@ export class TransactionData extends Model implements IRequest { constructor(data?: IRequest) { super(data); } + set clientUserAgent(value: string) { this.set('clientUserAgent', value); } + set order(order: string) { this.set('order', order); } + set invoice(invoice: string) { this.set('invoice', invoice); } + set description(description: string) { this.set('description', description); } + set amountCredit(amountCredit: number) { this.set('amountCredit', amountCredit); } + set amountDebit(amountDebit: number) { this.set('amountDebit', amountDebit); } + set currency(currency: string) { this.set('currency', currency); } + set clientIP(ipAddress: string) { this.set('clientIP', new ClientIP(ipAddress)); } + set additionalParameters(value: IAdditionalParameters) { this.set('additionalParameters', { AdditionalParameter: DataFormatter.parametersMap(value), }); } + set customParameters(value: IAdditionalParameters) { this.set('customParameters', { List: DataFormatter.parametersMap(value), }); } + set pushURL(pushURL: string) { this.set('pushURL', pushURL); } + set continueOnIncomplete(value: boolean) { this.set('continueOnIncomplete', value ? 1 : 0); } + set culture(value: string) { this.set('culture', value); } + set originalTransactionKey(value: string) { this.set('originalTransactionKey', value); } + set originalTransactionReference(value: { type: string; reference: string }) { this.set('originalTransactionReference', value); } + set pushURLFailure(value: string) { this.set('pushURLFailure', value); } + set returnURL(value: string) { this.set('returnURL', value); } + set returnURLCancel(value: string) { this.set('returnURLCancel', value); } + set returnURLError(value: string) { this.set('returnURLError', value); } + set returnURLReject(value: string) { this.set('returnURLReject', value); } + set servicesExcludedForClient(services: ServiceCode[] | string) { this.set('servicesExcludedForClient', Array.isArray(services) ? services?.join(',') : services); } + get servicesSelectableByClient() { return ''; } + set servicesSelectableByClient(services: ServiceCode[] | string) { this.set('servicesSelectableByClient', Array.isArray(services) ? services?.join(',') : services); } + set startRecurrent(value: boolean) { this.set('startRecurrent', value); } + getServiceList(): ServiceList | undefined { return this.get('services'); } + setServiceList(services: ServiceList | undefined) { return this.set('services', services); } } + export class DataRequestData extends TransactionData { set additionalParameters(parameters: IAdditionalParameters) { this.set('additionalParameters', { @@ -100,10 +127,12 @@ export class DataRequestData extends TransactionData { }); } } + export class SpecificationRequestData extends Model { constructor(data?: IService[]) { super({ services: data }); } + set services(data: IService[]) { this.set( 'services', diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index e00f96f9..d567673f 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -13,22 +13,7 @@ export default class Headers { get headers(): RequestHeaders { return this._headers; } - protected getDefaultHeaders() { - return { - 'Content-type': 'application/json; charset=utf-8', - Accept: 'application/json', - Culture: 'nl-NL', - Authorization: '', - Channel: 'Web', - Software: JSON.stringify({ - PlatformName: 'Node SDK', - PlatformVersion: '1.0', - ModuleSupplier: 'Buckaroo', - ModuleName: 'BuckarooPayments', - ModuleVersion: '1.0', - }), - }; - } + setSoftwareHeader( value: { platformName?: string; @@ -47,16 +32,35 @@ export default class Headers { }); return this; } + setHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { this._headers[key] = headers[key]; }); return this; } + removeHeaders(headers: RequestHeaders) { Object.keys(headers).forEach((key) => { delete this._headers[key]; }); return this; } + + protected getDefaultHeaders() { + return { + 'Content-type': 'application/json; charset=utf-8', + Accept: 'application/json', + Culture: 'nl-NL', + Authorization: '', + Channel: 'Web', + Software: JSON.stringify({ + PlatformName: 'Node SDK', + PlatformVersion: '1.0', + ModuleSupplier: 'Buckaroo', + ModuleName: 'BuckarooPayments', + ModuleVersion: '1.0', + }), + }; + } } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 9f6eec9e..89b08a0f 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -6,59 +6,74 @@ import crypto from 'crypto'; export class Hmac { protected _data?: object; + + get data(): string { + return this._data ? JSON.stringify(this._data) : ''; + } + + set data(data: string) { + try { + let jsonData = JSON.parse(data); + if (Object.keys(jsonData).length > 0) { + this._data = jsonData; + } + } catch (e) {} + } + protected _url?: URL; + + get url(): string | undefined { + return this._url + ? encodeURIComponent( + this._url.href + .replace(this._url.protocol, '') + .replace(/^[^:/.]*[:/]+/i, '') + .replace(/(^\w+:|^)\/\//, '') + ).toLowerCase() + : undefined; + } + + set url(url: string | undefined) { + if (url) this._url = new URL(url); + } + protected _nonce?: string; - protected _time?: string; - protected _method?: string; get nonce(): string { return this._nonce || 'nonce_' + Math.floor(Math.random() * 9999999 + 1); } + set nonce(nonce: string) { this._nonce = nonce; } + + protected _time?: string; + get time(): string { return this._time || String(Math.round(Date.now() / 1000)); } + set time(time: string) { this._time = time; } + + protected _method?: string; + get method(): string { return this._method || 'POST'; } + set method(method: string) { this._method = method; } - get url(): string | undefined { - return this._url - ? encodeURIComponent( - this._url.href - .replace(this._url.protocol, '') - .replace(/^[^:/.]*[:/]+/i, '') - .replace(/(^\w+:|^)\/\//, '') - ).toLowerCase() - : undefined; - } - set url(url: string | undefined) { - if (url) this._url = new URL(url); - } - get data(): string { - return this._data ? JSON.stringify(this._data) : ''; - } - set data(data: string) { - try { - let jsonData = JSON.parse(data); - if (Object.keys(jsonData).length > 0) { - this._data = jsonData; - } - } catch (e) {} - } + get base64Data() { if (this._data) { return Base64.stringify(md5(this.data)); } return ''; } + generate(credentials: ICredentials, nonce?: string, time?: string): string { this._nonce = nonce || this.nonce; this._time = time || this.time; @@ -66,6 +81,7 @@ export class Hmac { let hashData = this.hashData(hashString, credentials.secretKey); return `hmac ${credentials.websiteKey}:${hashData}:${this._nonce}:${this._time}`; } + validate(credentials: ICredentials, authHeader: string, url: string, data: string, method: string): boolean { let header = authHeader.split(':'); let providedHash = header[1]; @@ -77,9 +93,11 @@ export class Hmac { let hash = this.hashData(this.getHashString(credentials.websiteKey), credentials.secretKey); return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(providedHash)); } + protected getHashString(websiteKey: string) { return websiteKey + this.method + this.url + this.time + this.nonce + this.base64Data; } + protected hashData(hashString: string, secretKey: string) { return hmacSHA256(hashString, secretKey).toString(Base64); } diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 5b80ded3..aff02ecc 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,6 +1,6 @@ +import * as https from 'https'; import { Agent, RequestOptions } from 'https'; import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; -import * as https from 'https'; const defaultAgent = new Agent({ keepAlive: true, @@ -8,12 +8,19 @@ const defaultAgent = new Agent({ }); export default class HttpsClient { protected _options: RequestOptions = {}; + constructor(agent?: Agent) { this._options.timeout = 10000; this._options.agent = agent || defaultAgent; this._options.sessionTimeout = 30000; } - public sendRequest(url: URL, data: string, options: RequestOptions = {}, responseClass: R): Promise> { + + public sendRequest( + url: URL, + data: string, + options: RequestOptions = {}, + responseClass: R + ): Promise> { return new Promise((resolve, reject) => { const req = https.request(url, { ...this._options, diff --git a/src/Request/Request.ts b/src/Request/Request.ts index 8e551e2d..b3f29318 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -13,11 +13,12 @@ import { Hmac } from './Hmac'; import { IService } from '../Models/IServiceList'; import IRequest from '../Models/IRequest'; -export default class Request extends Headers { - protected _data?: object | object[] | undefined; - protected _httpMethod: HttpMethods; +export default class Request< + HttpResponse extends HttpResponseConstructor = HttpResponseConstructor, + RequestData extends object | undefined = undefined +> extends Headers { protected _path?: string; - protected _responseHandler?: HttpResponseConstructor; + constructor(path?: string, method?: HttpMethods, data?: RequestData, responseHandler?: HttpResponse) { super(); this._path = path; @@ -25,52 +26,59 @@ export default class Request { @@ -32,6 +43,7 @@ export abstract class DataFormatter { }; }) as any; } + static serviceParametersMap( parameters: IServiceParameters | ServiceParameterTypes | undefined, groups: { [key: string]: string } = {}, @@ -51,7 +63,13 @@ export abstract class DataFormatter { }); } else if (typeof parameters === 'object') { for (const key of Object.keys(parameters)) { - this.serviceParametersMap(parameters[key], groups, countable, { ...parameter, name: key }, parametersArray); + this.serviceParametersMap( + parameters[key], + groups, + countable, + { ...parameter, name: key }, + parametersArray + ); } } else if (parameters !== undefined) { parametersArray.push({ ...parameter, value: parameters }); @@ -65,6 +83,7 @@ export abstract class DataFormatter { }, {}); } } + export function getIPAddress() { const interfaces = require('os').networkInterfaces(); for (const devName in interfaces) { diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 4ac975da..8618db04 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -40,7 +40,7 @@ import type Trustly from '../PaymentMethods/Trustly'; import type Wechatpay from '../PaymentMethods/WeChatPay'; import type In3 from '../PaymentMethods/In3'; import type MultiBanco from '../PaymentMethods/Multibanco'; -import type Index from "../PaymentMethods/Mbway"; +import type Index from '../PaymentMethods/Mbway'; //toDo refactor this @@ -87,7 +87,7 @@ export type AllMethods = readonly [ { class: Trustly; code: MethodTypes['Trustly'] }, { class: Wechatpay; code: MethodTypes['WeChatPay'] }, { class: MultiBanco; code: MethodTypes['Multibanco'] }, - { class: Index ; code: MethodTypes['Mbway'] }, + { class: Index; code: MethodTypes['Mbway'] } ]; export type ServiceCode = AllMethods[number]['code'][number]; @@ -113,7 +113,20 @@ export const Methods = { Billink: ['billink'], BuckarooVoucher: ['buckaroovoucher'], BuckarooWallet: ['BuckarooWalletCollecting'], - CreditCard: ['creditcard', 'mastercard', 'visa', 'amex', 'vpay', 'maestro', 'visaelectron', 'cartebleuevisa', 'cartebancaire', 'dankort', 'nexi', 'postepay'], + CreditCard: [ + 'creditcard', + 'mastercard', + 'visa', + 'amex', + 'vpay', + 'maestro', + 'visaelectron', + 'cartebleuevisa', + 'cartebancaire', + 'dankort', + 'nexi', + 'postepay', + ], CreditClick: ['creditclick'], CreditManagement: ['CreditManagement3'], Emandates: ['emandate'], diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index a40e3d88..432b4db8 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -18,4 +18,4 @@ export declare interface ICredentials { secretKey: string; } -export type Mode = 'LIVE' | 'TEST'; +export type Mode = "LIVE" | "TEST"; diff --git a/src/index.ts b/src/index.ts index 10cf181e..412e9977 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,45 +8,57 @@ import TransactionService from './Services/TransactionService'; import { Credentials } from './Handlers/Credentials'; export default class Buckaroo { + private static _client: Buckaroo; private readonly _credentials: Credentials; - private _config: IConfig; private readonly _httpClient: HttpsClient; - private static _client: Buckaroo; + constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; this._httpClient = new HttpsClient(agent); } - static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { - return (this._client = new this(credentials, config, agent)); - } + static get Client(): Buckaroo { return this._client; } - get credentials(): ICredentials { - return this._credentials; - } - confirmCredentials() { - return this._credentials.confirm(); - } + + private _config: IConfig; + get config(): IConfig { return { ...this._config }; } + set config(value: IConfig) { this._config = value; } + + get credentials(): ICredentials { + return this._credentials; + } + get httpClient() { return this._httpClient; } - transaction(key: string) { - return new TransactionService(key); - } + get batch() { return { transaction: Request.BatchTransaction, data: Request.BatchDataRequest, }; } + + static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { + return (this._client = new this(credentials, config, agent)); + } + + confirmCredentials() { + return this._credentials.confirm(); + } + + transaction(key: string) { + return new TransactionService(key); + } + method(): NoService; method(name: Name): MethodFromServiceCode; method(name?: ServiceCode) { @@ -58,4 +70,4 @@ export default class Buckaroo { } -export { Buckaroo }; \ No newline at end of file +export { Buckaroo }; diff --git a/tests/Client.test.ts b/tests/Client.test.ts index 0b7c6ffd..b7256733 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -3,7 +3,7 @@ import { TransactionResponse } from '../src/Models/Response/TransactionResponse' import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse'; import { uniqid } from '../src/Utils/Functions'; import { creditManagementTestInvoice } from './PaymentMethods/CreditManagment.test'; -import IRequest from "../src/Models/IRequest"; +import IRequest from '../src/Models/IRequest'; describe('Testing Buckaroo Client', () => { test('Credentials', () => { @@ -12,25 +12,24 @@ describe('Testing Buckaroo Client', () => { }); }); test('Batch transaction', async () => { - const transactionData:IRequest[] = []; - const creditManagement = client.method('CreditManagement3') - const sepaDirectDebit = client.method('sepadirectdebit') + const transactionData: IRequest[] = []; + const creditManagement = client.method('CreditManagement3'); + const sepaDirectDebit = client.method('sepadirectdebit'); for (let i = 0; i < 3; i++) { - creditManagement.createCombinedInvoice(creditManagementTestInvoice()) + creditManagement.createCombinedInvoice(creditManagementTestInvoice()); - sepaDirectDebit.combine(creditManagement).pay( - { - invoice: uniqid(), - amountDebit: 10.1, - iban: 'NL13TEST0123456789', - bic: 'TESTNL2A', - collectdate: '2024-07-03', - mandateReference: '1DCtestreference', - mandateDate: '2022-07-03', - customer: { - name: 'John Smith', - }, - }); + sepaDirectDebit.combine(creditManagement).pay({ + invoice: uniqid(), + amountDebit: 10.1, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + collectdate: '2024-07-03', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + customer: { + name: 'John Smith', + }, + }); transactionData.push(sepaDirectDebit.getPayload()); } diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index 11c71294..48554d07 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -2,7 +2,7 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; import RecipientCategory from '../../src/Constants/RecipientCategory'; -const method = buckarooClientTest.method('afterpay') +const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { test('Pay', () => { return method diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index f5686ac3..7e73c177 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -1,7 +1,7 @@ import { uniqid } from '../../src/Utils/Functions'; +import ApplePay from '../../src/PaymentMethods/ApplePay'; require('../BuckarooClient.test'); -import ApplePay from '../../src/PaymentMethods/ApplePay'; const method = new ApplePay(); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 19813fc4..76d2f770 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,5 +1,6 @@ import Gender from '../../src/Constants/Gender'; import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('transfer'); describe('Transfer methods', () => { diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index d6582f81..ac7d08dd 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('eps'); describe('Testing Eps methods', () => { test('Pay', async () => { diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index b033cf8a..bc4fb9e2 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index 88408e99..5a3b8a4c 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -1,5 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; + const method = buckarooClientTest.method('giropay'); describe('Testing Giropay methods', () => { test('Pay', async () => { diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index bab287a1..80c3b7e0 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,5 +1,6 @@ import { getIPAddress, uniqid } from '../../src/Utils/Functions'; import buckarooClientTest from '../BuckarooClient.test'; + const ideal = buckarooClientTest.method('ideal'); describe('testing Ideal methods', () => { test('Issuers', () => { diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index 93fa73f1..8bb76688 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('KBCPaymentButton'); describe('Testing KBC methods', () => { diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 34756c96..7a5e2294 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,5 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import gender from '../../src/Constants/Gender'; + const klarnaKp = buckarooClientTest.method('klarnakp'); describe('KlarnaKp', () => { diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index 02b255a3..ac906c36 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const marketplaces = buckarooClientTest.method('marketplaces'); const ideal = buckarooClientTest.method('ideal'); diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts index a8adbfc6..573be726 100644 --- a/tests/PaymentMethods/Mbway.test.ts +++ b/tests/PaymentMethods/Mbway.test.ts @@ -1,13 +1,15 @@ -import buckarooClientTest from "../BuckarooClient.test"; +import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method("MBWay"); -describe("Mbway methods", () => { - test("Pay", () => { +const method = buckarooClientTest.method('MBWay'); +describe('Mbway methods', () => { + test('Pay', () => { return method .pay({ amountDebit: 0.1, - }).request().then((response) => { - expect(response.isValidationFailure()).toBeTruthy() }) + .request() + .then((response) => { + expect(response.isValidationFailure()).toBeTruthy(); + }); }); -}) +}); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 55cd92a6..3e7cec9e 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -1,6 +1,7 @@ import Gender from '../../src/Constants/Gender'; import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; + const method = buckarooClientTest.method('payperemail'); describe('PayPerEmail methods', () => { diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index 2a7b62f9..f911b78a 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const payconiq = buckarooClientTest.method('payconiq'); describe('Payconiq', () => { test('Pay', async () => { diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 60a57436..72845d26 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,7 +1,7 @@ import buckarooClientTest from '../BuckarooClient.test'; +import Paypal from '../../src/PaymentMethods/Paypal'; require('../BuckarooClient.test'); -import Paypal from '../../src/PaymentMethods/Paypal'; const method = new Paypal('paypal'); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index f0d8d127..a5de8680 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -1,5 +1,6 @@ require('../BuckarooClient.test'); import Sofort from '../../src/PaymentMethods/Sofort'; + const method = new Sofort(); describe('Sofort', () => { diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 57f830c6..081401d7 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,10 +1,10 @@ import buckarooClientTest from '../BuckarooClient.test'; -import {describe} from "node:test"; +import { describe } from 'node:test'; const subscription = buckarooClientTest.method('subscriptions'); describe('Subscription methods', () => { - test('Create', () => { + test('Create', () => { return subscription .create({ additionalParameters: { @@ -32,7 +32,7 @@ describe('Subscription methods', () => { .request() .then((data) => { expect(data.hasError()).toBeTruthy(); - }) + }); }); test('Update', async () => { subscription @@ -54,62 +54,66 @@ describe('Subscription methods', () => { }); }); test('Combined Subscription', async () => { - subscription - .createCombined({ - pushURL: 'https://buckaroo.dev/push', - includeTransaction: false, - transactionVatPercentage: 5, - configurationCode: 'gfyh9fe4', - email: 'test@buckaroo.nl', - ratePlans: { - add: { - startDate: '2033-01-01', - ratePlanCode: '9863hdcj', - }, + subscription.createCombined({ + pushURL: 'https://buckaroo.dev/push', + includeTransaction: false, + transactionVatPercentage: 5, + configurationCode: 'gfyh9fe4', + email: 'test@buckaroo.nl', + ratePlans: { + add: { + startDate: '2033-01-01', + ratePlanCode: '9863hdcj', }, - phone: { - mobile: '0612345678', - }, - debtor: { - code: 'johnsmith4', - }, - company: { - culture: 'nl-NL', - companyName: 'My Company Coporation', - vatApplicable: true, - vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '90', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - }) - subscription.combine('ideal') + }, + phone: { + mobile: '0612345678', + }, + debtor: { + code: 'johnsmith4', + }, + company: { + culture: 'nl-NL', + companyName: 'My Company Coporation', + vatApplicable: true, + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741', + }, + address: { + street: 'Hoofdstraat', + houseNumber: '90', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL', + }, + }); + subscription + .combine('ideal') .pay({ issuer: 'ABNANL2A', amountDebit: 10, startRecurrent: true, - }).request().then((data) => { - expect(data).toBeDefined(); }) - }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); test('Update Combined Subscription', async () => { + subscription.updateCombined({ + subscriptionGuid: '515461997AD34C50881D74157E38A64D', + }); subscription - .updateCombined({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', - }) - subscription.combine('ideal') + .combine('ideal') .pay({ issuer: 'ABNANL2A', amountDebit: 10, - }).request().then((data) => { - expect(data).toBeDefined(); - }) + }) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); }); test('Stop Subscription', async () => { @@ -148,4 +152,4 @@ describe('Subscription methods', () => { }); expect(resume).toBeDefined(); }); -}) +}); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 19dc8954..3ed45629 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,5 +1,6 @@ import Gender from '../../src/Constants/Gender'; import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('tinka'); describe('Tinka', () => { test('Pay', async () => { diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index cd118fd1..7d213671 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; + const method = buckarooClientTest.method('wechatpay'); describe('WechatPay', () => { test('Pay', async () => { diff --git a/tsconfig-declarations.json b/tsconfig-declarations.json index 9b72f9ce..616f8e18 100644 --- a/tsconfig-declarations.json +++ b/tsconfig-declarations.json @@ -1,9 +1,9 @@ { - "extends": "./tsconfig.json", - "files": [], - "compilerOptions": { - "emitDeclarationOnly": true, - "declaration": true, - "declarationDir": "dist/types" - } -} \ No newline at end of file + "extends": "./tsconfig.json", + "files": [], + "compilerOptions": { + "emitDeclarationOnly": true, + "declaration": true, + "declarationDir": "dist/types" + } +} diff --git a/tsconfig.json b/tsconfig.json index 1307b466..e4b19fd1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,11 +2,16 @@ "compilerOptions": { "target": "es5", "module": "commonjs", - "lib": ["ES2021", "dom"], + "lib": [ + "ES2021", + "dom" + ], "strict": true, "esModuleInterop": true, - "skipLibCheck": true /* Skip type checking of declaration files. */, - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "skipLibCheck": true + /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true + /* Disallow inconsistently-cased references to the same file. */, "declaration": true, "sourceMap": true, "moduleResolution": "node", @@ -14,5 +19,7 @@ "outDir": "dist", "resolveJsonModule": true }, - "include": ["src/**/*.ts"] + "include": [ + "src/**/*.ts" + ] } diff --git a/tsconfig.spec.json b/tsconfig.spec.json new file mode 100644 index 00000000..0d6da8d0 --- /dev/null +++ b/tsconfig.spec.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "types": [ + "jest", + "node" + ] + } +} From 418ffcc7d11a08a2bfb58a0d76fd8f8df602a159 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 13:49:24 +0200 Subject: [PATCH 15/52] code formatter --- .editorconfig | 11 +---------- src/PaymentMethods/PaymentMethod.ts | 9 +++------ src/Request/Hmac.ts | 12 ++++-------- src/Request/Request.ts | 9 +++------ src/Utils/Types.ts | 2 +- src/index.ts | 3 +-- 6 files changed, 13 insertions(+), 33 deletions(-) diff --git a/.editorconfig b/.editorconfig index 66e9a457..075db380 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,13 +13,4 @@ ij_formatter_on_tag = @formatter:on ij_formatter_tags_enabled = true ij_smart_tabs = false ij_visual_guides = none -ij_wrap_on_typing = false - -[*.{ts,js}] -indent_size = 4 -ij_vue_indent_children_of_top_level = template -ij_vue_interpolation_new_line_after_start_delimiter = true -ij_vue_interpolation_new_line_before_end_delimiter = true -ij_vue_interpolation_wrap = off -ij_vue_keep_indents_on_empty_lines = false -ij_vue_spaces_within_interpolation_expressions = true +ij_wrap_on_typing = false \ No newline at end of file diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index a81dc7fe..a3ba7434 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -11,25 +11,22 @@ import { MethodFromServiceCode, ServiceCode } from '../Utils/MethodTypes'; export default abstract class PaymentMethod { protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; + protected _paymentName: string = ''; + protected _serviceCode?: string; + protected _serviceVersion: number = 0; constructor(serviceCode?: string) { this._serviceCode = serviceCode ?? this.paymentName; } - protected _paymentName: string = ''; - get paymentName() { return this._paymentName; } - protected _serviceCode?: string; - get serviceCode() { return this._serviceCode || ''; } - protected _serviceVersion: number = 0; - get serviceVersion() { return this._serviceVersion; } diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 89b08a0f..956244f0 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -6,6 +6,10 @@ import crypto from 'crypto'; export class Hmac { protected _data?: object; + protected _url?: URL; + protected _nonce?: string; + protected _time?: string; + protected _method?: string; get data(): string { return this._data ? JSON.stringify(this._data) : ''; @@ -20,8 +24,6 @@ export class Hmac { } catch (e) {} } - protected _url?: URL; - get url(): string | undefined { return this._url ? encodeURIComponent( @@ -37,8 +39,6 @@ export class Hmac { if (url) this._url = new URL(url); } - protected _nonce?: string; - get nonce(): string { return this._nonce || 'nonce_' + Math.floor(Math.random() * 9999999 + 1); } @@ -47,8 +47,6 @@ export class Hmac { this._nonce = nonce; } - protected _time?: string; - get time(): string { return this._time || String(Math.round(Date.now() / 1000)); } @@ -57,8 +55,6 @@ export class Hmac { this._time = time; } - protected _method?: string; - get method(): string { return this._method || 'POST'; } diff --git a/src/Request/Request.ts b/src/Request/Request.ts index b3f29318..d5df5893 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -18,6 +18,9 @@ export default class Request< RequestData extends object | undefined = undefined > extends Headers { protected _path?: string; + protected _data?: object | object[] | undefined; + protected _httpMethod: HttpMethods; + protected _responseHandler?: HttpResponseConstructor; constructor(path?: string, method?: HttpMethods, data?: RequestData, responseHandler?: HttpResponse) { super(); @@ -27,14 +30,10 @@ export default class Request< this._responseHandler = responseHandler; } - protected _data?: object | object[] | undefined; - get data(): RequestData { return this._data as any; } - protected _httpMethod: HttpMethods; - get httpMethod(): HttpMethods { return this._httpMethod; } @@ -43,8 +42,6 @@ export default class Request< return new URL(Endpoints[Buckaroo.Client.config.mode] + (this._path || '')); } - protected _responseHandler?: HttpResponseConstructor; - protected get responseHandler(): HttpResponse { return (this._responseHandler || HttpClientResponse) as HttpResponse; } diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 432b4db8..a40e3d88 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -18,4 +18,4 @@ export declare interface ICredentials { secretKey: string; } -export type Mode = "LIVE" | "TEST"; +export type Mode = 'LIVE' | 'TEST'; diff --git a/src/index.ts b/src/index.ts index 412e9977..6f44e52d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export default class Buckaroo { private static _client: Buckaroo; private readonly _credentials: Credentials; private readonly _httpClient: HttpsClient; + private _config: IConfig; constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); @@ -22,8 +23,6 @@ export default class Buckaroo { return this._client; } - private _config: IConfig; - get config(): IConfig { return { ...this._config }; } From 9f5ce4249b57e9bde9b80069023a6ff0d96d7a5b Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 14:12:36 +0200 Subject: [PATCH 16/52] fix constructor of PaymentMethod --- src/PaymentMethods/PaymentMethod.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/PaymentMethods/PaymentMethod.ts index 2de2e6c5..3eda4a80 100644 --- a/src/PaymentMethods/PaymentMethod.ts +++ b/src/PaymentMethods/PaymentMethod.ts @@ -15,7 +15,9 @@ export default abstract class PaymentMethod { protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; - constructor(serviceCode?: ServiceCode) {} + constructor(serviceCode?: ServiceCode) { + this._serviceCode = serviceCode ?? (this.paymentName as ServiceCode); + } get serviceVersion() { return this._serviceVersion; From 995d1e84c1f7f0f2a7bfe96b92d58d69a420caa0 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 16 Oct 2023 14:20:53 +0200 Subject: [PATCH 17/52] Update Request.ts --- src/Request/Request.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Request/Request.ts b/src/Request/Request.ts index acea81c8..f64844ec 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -106,23 +106,6 @@ export default class Request< ); } - combine( - method: Method - ): Method extends ServiceCode ? AvailablePaymentMethods[Method] : Method; - combine(request: R): this; - combine(data): PaymentMethod | this { - if (!(data instanceof Request)) { - let paymentMethod: PaymentMethod = data instanceof PaymentMethod ? data : Buckaroo.Client.method(data); - if (this.data instanceof TransactionData) { - paymentMethod.combine(this.data); - } - return paymentMethod; - } else { - this._data = { ...this._data, ...data.data }; - } - return this; - } - protected setAuthorizationHeader(data: string, credentials: ICredentials = Buckaroo.Client.credentials): this { let hmac = new Hmac(); hmac.data = data; From 8e317189052e2854be178b8f37d63d6cddb5654c Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 18 Oct 2023 09:30:12 +0200 Subject: [PATCH 18/52] few improvements + move Payment Method classes into Service folder + fix imports that can be usable from user + fix an issue with getMethod --- .editorconfig | 2 +- src/PaymentMethods/Afterpay/index.ts | 2 +- .../AfterpayDigiAccept/index.ts | 2 +- src/PaymentMethods/Alipay/index.ts | 2 +- src/PaymentMethods/ApplePay/index.ts | 2 +- src/PaymentMethods/Bancontact/index.ts | 2 +- src/PaymentMethods/BankTransfer/index.ts | 2 +- src/PaymentMethods/Belfius/index.ts | 2 +- src/PaymentMethods/Billink/index.ts | 2 +- src/PaymentMethods/BuckarooVoucher/index.ts | 2 +- src/PaymentMethods/BuckarooWallet/index.ts | 2 +- src/PaymentMethods/CreditCard/index.ts | 2 +- src/PaymentMethods/CreditClick/index.ts | 2 +- src/PaymentMethods/CreditManagement/index.ts | 2 +- src/PaymentMethods/EPS/index.ts | 2 +- src/PaymentMethods/Emandates/index.ts | 2 +- src/PaymentMethods/GiftCard/index.ts | 2 +- src/PaymentMethods/Giropay/index.ts | 2 +- src/PaymentMethods/Ideal/index.ts | 2 +- src/PaymentMethods/IdealQR/index.ts | 2 +- src/PaymentMethods/Idin/index.ts | 2 +- src/PaymentMethods/In3/index.ts | 2 +- src/PaymentMethods/In3Old/index.ts | 2 +- src/PaymentMethods/KBC/index.ts | 2 +- src/PaymentMethods/Klarna/index.ts | 2 +- src/PaymentMethods/KlarnaKP/index.ts | 2 +- src/PaymentMethods/Marketplaces/index.ts | 2 +- src/PaymentMethods/Mbway/index.ts | 2 +- src/PaymentMethods/Multibanco/index.ts | 2 +- src/PaymentMethods/NoService/index.ts | 2 +- src/PaymentMethods/PayByBank/index.ts | 2 +- src/PaymentMethods/PayPerEmail/index.ts | 2 +- src/PaymentMethods/Payconiq/index.ts | 2 +- src/PaymentMethods/PaymentMethods.ts | 84 ++++++++++++++++++ src/PaymentMethods/Paypal/index.ts | 2 +- src/PaymentMethods/PiM/index.ts | 2 +- src/PaymentMethods/PointOfSale/index.ts | 2 +- src/PaymentMethods/Przelewy24/index.ts | 2 +- src/PaymentMethods/SEPA/index.ts | 2 +- src/PaymentMethods/Sofort/index.ts | 2 +- src/PaymentMethods/Subscriptions/index.ts | 2 +- src/PaymentMethods/Surepay/index.ts | 2 +- src/PaymentMethods/Thunes/index.ts | 2 +- src/PaymentMethods/Tinka/index.ts | 2 +- src/PaymentMethods/Trustly/index.ts | 2 +- src/PaymentMethods/WeChatPay/index.ts | 2 +- src/PaymentMethods/index.ts | 85 +------------------ src/Request/Request.ts | 2 +- .../PayablePaymentMethod.ts | 0 .../PaymentMethod.ts | 0 src/Utils/MethodTypes.ts | 4 +- src/Utils/index.ts | 3 + src/buckaroo.ts | 69 +++++++++++++++ src/index.ts | 77 ++--------------- 54 files changed, 210 insertions(+), 204 deletions(-) create mode 100644 src/PaymentMethods/PaymentMethods.ts rename src/{PaymentMethods => Services}/PayablePaymentMethod.ts (100%) rename src/{PaymentMethods => Services}/PaymentMethod.ts (100%) create mode 100644 src/Utils/index.ts create mode 100644 src/buckaroo.ts diff --git a/.editorconfig b/.editorconfig index 075db380..0782fb75 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ charset = utf-8 end_of_line = crlf indent_size = 4 indent_style = space -insert_final_newline = true +insert_final_newline = false max_line_length = 200 tab_width = 4 trim_trailing_whitespace = true diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 40b4ff73..26f54931 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -1,6 +1,6 @@ import { IPay, Pay } from './Model/Pay'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefund, Refund } from './Model/Refund'; export default class Afterpay extends PayablePaymentMethod { diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index fca5323c..f4fe3a9e 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -1,6 +1,6 @@ import { IPay } from '../Afterpay/Model/Pay'; import IRequest, { IRefundRequest } from '../../Models/IRequest'; -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { Pay } from './Model/Pay'; export default class AfterpayDigiAccept extends PayablePaymentMethod { diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index c60bedc3..8a8c1e00 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { ServiceParameter } from '../../Models/ServiceParameters'; diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 41f885de..87fef5b0 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 29f95c23..a46aa9f1 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models/IRequest'; diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index ab3de8c6..55266d8b 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models/IRequest'; diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index a265077e..fc4c1873 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Belfius extends PayablePaymentMethod { diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 9a4b6b7a..d2819cbd 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 8295b574..bdadccd6 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import IRequest from '../../Models/IRequest'; import { Create, ICreate } from './Models/Create'; diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index d8433373..5ab90dfa 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IWallet, Wallet } from './Models/Wallet'; import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 84466f82..cfb3bfeb 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { CardData, ICardData } from './Models/CardData'; import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 66bcc3fc..894fdb37 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 652299d4..735358f0 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { IInvoice, Invoice } from './Models/Invoice'; import { CreditNote, ICreditNote } from './Models/CreditNote'; import { Debtor, IDebtor } from './Models/Debtor'; diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 1b87f1bb..8bfbd74d 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class EPS extends PayablePaymentMethod { protected _paymentName = 'EPS'; diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index e6592785..0c25ad11 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { IConfig } from '../../Utils/Types'; import { IMandate, Mandate } from './Models/Mandate'; diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 7d6bdfab..24f8d181 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import IPay, { Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index ad030e5c..47746319 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; export default class Giropay extends PayablePaymentMethod { diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index 0bd2bad0..b73212aa 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -1,5 +1,5 @@ import { IPay, Pay } from './Models/Pay'; -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { RequestTypes } from '../../Constants/Endpoints'; import { IRefundRequest } from '../../Models/IRequest'; diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 4c9548c9..66ace8c0 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,5 +1,5 @@ import { Generate, IGenerate } from './Models/IGenerate'; -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; export default class IdealQR extends PaymentMethod { protected _paymentName = 'IdealQR'; diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index d4196442..4713e909 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { IPay } from '../Ideal/Models/Pay'; export default class Idin extends PaymentMethod { diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index 860c88df..f9d45043 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest } from '../../Models/IRequest'; import Pay from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 72440054..a1bd94df 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; export default class In3Old extends PayablePaymentMethod { diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index ec1943b8..19451257 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; export default class KBC extends PayablePaymentMethod { diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 6db2b934..e51014c9 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,5 +1,5 @@ import { IPay, Pay } from './Models/Pay'; -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class Klarna extends PayablePaymentMethod { protected _paymentName = 'Klarna'; diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 0c9d41eb..7ae0b534 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/IPay'; import IRequest from '../../Models/IRequest'; import { IReserve, Reserve } from './Models/IReserve'; diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 9fb37419..f5657617 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index 0db45c7c..4d4f4b2d 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class Mbway extends PayablePaymentMethod { protected _paymentName = 'MB WAY'; diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index 4f661d23..2b58b8c4 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class MultiBanco extends PayablePaymentMethod { protected _paymentName = 'MultiBanco'; diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index 7e984075..fb717539 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class NoService extends PayablePaymentMethod { protected _paymentName = 'noserivce'; diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index ba0bf067..a164bdff 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import IPay, { Pay } from './Models/IPay'; diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 9957e683..700924b4 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { IInvitation, Invitation } from './Models/Invitation'; export default class PayPerEmail extends PaymentMethod { diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index f8ff8435..a7115888 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; export default class Payconiq extends PayablePaymentMethod { diff --git a/src/PaymentMethods/PaymentMethods.ts b/src/PaymentMethods/PaymentMethods.ts new file mode 100644 index 00000000..166b1c8b --- /dev/null +++ b/src/PaymentMethods/PaymentMethods.ts @@ -0,0 +1,84 @@ +export { default as ideal } from './Ideal'; +export { default as idealprocessing } from './Ideal'; +export { default as afterpay } from './Afterpay'; +export { default as afterpaydigiaccept } from './AfterpayDigiAccept'; +export { default as applepay } from './ApplePay'; +export { default as bancontactmrcash } from './Bancontact'; +export { default as transfer } from './BankTransfer'; +export { default as belfius } from './Belfius'; +export { default as billink } from './Billink'; +export { default as buckaroovoucher } from './BuckarooVoucher'; +export { default as BuckarooWalletCollecting } from './BuckarooWallet'; +export { default as CreditCard } from './CreditCard'; + +// Credit Cards +export { default as creditcard } from './CreditCard'; +export { default as mastercard } from './CreditCard'; +export { default as visa } from './CreditCard'; +export { default as amex } from './CreditCard'; +export { default as vpay } from './CreditCard'; +export { default as maestro } from './CreditCard'; +export { default as visaelectron } from './CreditCard'; +export { default as cartebleuevisa } from './CreditCard'; +export { default as cartebancaire } from './CreditCard'; +export { default as dankort } from './CreditCard'; +export { default as nexi } from './CreditCard'; +export { default as postepay } from './CreditCard'; + +export { default as creditclick } from './CreditClick'; +export { default as CreditManagement3 } from './CreditManagement'; +export { default as emandate } from './Emandates'; +export { default as eps } from './EPS'; + +// Gift Cards +export { default as giftcard } from './GiftCard'; +export { default as westlandbon } from './GiftCard'; +export { default as babygiftcard } from './GiftCard'; +export { default as babyparkgiftcard } from './GiftCard'; +export { default as beautywellness } from './GiftCard'; +export { default as boekenbon } from './GiftCard'; +export { default as boekenvoordeel } from './GiftCard'; +export { default as designshopsgiftcard } from './GiftCard'; +export { default as fashioncheque } from './GiftCard'; +export { default as fashionucadeaukaart } from './GiftCard'; +export { default as fijncadeau } from './GiftCard'; +export { default as koffiecadeau } from './GiftCard'; +export { default as kokenzo } from './GiftCard'; +export { default as kookcadeau } from './GiftCard'; +export { default as nationaleentertainmentcard } from './GiftCard'; +export { default as naturesgift } from './GiftCard'; +export { default as podiumcadeaukaart } from './GiftCard'; +export { default as shoesaccessories } from './GiftCard'; +export { default as webshopgiftcard } from './GiftCard'; +export { default as wijncadeau } from './GiftCard'; +export { default as wonenzo } from './GiftCard'; +export { default as yourgift } from './GiftCard'; +export { default as vvvgiftcard } from './GiftCard'; +export { default as parfumcadeaukaart } from './GiftCard'; + +export { default as giropay } from './Giropay'; +export { default as idealqr } from './IdealQR'; +export { default as idin } from './Idin'; +export { default as capayable } from './In3Old'; +export { default as KBCPaymentButton } from './KBC'; +export { default as klarna } from './Klarna'; +export { default as klarnakp } from './KlarnaKP'; +export { default as Marketplaces } from './Marketplaces'; +export { default as payconiq } from './Payconiq'; +export { default as PayByBank } from './PayByBank'; +export { default as paypal } from './Paypal'; +export { default as payperemail } from './PayPerEmail'; +export { default as PiM } from './PiM'; +export { default as pointofsale } from './PointOfSale'; +export { default as przelewy24 } from './Przelewy24'; +export { default as sepadirectdebit } from './SEPA'; +export { default as sofortueberweisung } from './Sofort'; +export { default as subscriptions } from './Subscriptions'; +export { default as surepay } from './Surepay'; +export { default as thunes } from './Thunes'; +export { default as tinka } from './Tinka'; +export { default as alipay } from './Alipay'; +export { default as trustly } from './Trustly'; +export { default as wechatpay } from './WeChatPay'; +export { default as In3 } from './In3'; +export { default as noservice } from './NoService'; \ No newline at end of file diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index f25fd4e6..f5453ca8 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index 366b03f2..f6e451ac 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; export default class PiM extends PaymentMethod { protected _paymentName = 'PiM'; diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index 1c1afba3..4c9d9388 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; export default class PointOfSale extends PayablePaymentMethod { protected _paymentName = 'PointOfSale'; diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 45f19d02..314a2d21 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 8d58ed45..e277cd8b 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IExtraInfo } from './Models/ExtraInfo'; import { IEmandate } from './Models/Emandate'; diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 85ca18bf..d8304531 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Sofort extends PayablePaymentMethod { diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 7de2df3e..833783f2 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -1,5 +1,5 @@ import { ISubscription, Subscription } from './Models/ISubscription'; -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import IRequest from '../../Models/IRequest'; import { ResumeSubscription } from './Models/ResumeSubscription'; diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index e07723e9..172159e6 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import { IVerify } from './Models/Verify'; import { Parameter } from '../../Models/IParameters'; diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 5180b118..ade4f9d3 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../PaymentMethod'; +import PaymentMethod from '../../Services/PaymentMethod'; import IRequest from '../../Models/IRequest'; type key = Required>; diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index 2274831b..32cb8401 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 28eed001..215ab2cf 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 884d312e..f954063c 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../PayablePaymentMethod'; +import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; diff --git a/src/PaymentMethods/index.ts b/src/PaymentMethods/index.ts index 90b894eb..220fc393 100644 --- a/src/PaymentMethods/index.ts +++ b/src/PaymentMethods/index.ts @@ -1,84 +1 @@ -export { default as ideal } from './Ideal'; -export { default as idealprocessing } from './Ideal'; -export { default as afterpay } from './Afterpay'; -export { default as afterpaydigiaccept } from './AfterpayDigiAccept'; -export { default as applepay } from './ApplePay'; -export { default as bancontactmrcash } from './Bancontact'; -export { default as transfer } from './BankTransfer'; -export { default as belfius } from './Belfius'; -export { default as billink } from './Billink'; -export { default as buckaroovoucher } from './BuckarooVoucher'; -export { default as BuckarooWalletCollecting } from './BuckarooWallet'; -export { default as CreditCard } from './CreditCard'; - -// Credit Cards -export { default as creditcard } from './CreditCard'; -export { default as mastercard } from './CreditCard'; -export { default as visa } from './CreditCard'; -export { default as amex } from './CreditCard'; -export { default as vpay } from './CreditCard'; -export { default as maestro } from './CreditCard'; -export { default as visaelectron } from './CreditCard'; -export { default as cartebleuevisa } from './CreditCard'; -export { default as cartebancaire } from './CreditCard'; -export { default as dankort } from './CreditCard'; -export { default as nexi } from './CreditCard'; -export { default as postepay } from './CreditCard'; - -export { default as creditclick } from './CreditClick'; -export { default as CreditManagement3 } from './CreditManagement'; -export { default as emandate } from './Emandates'; -export { default as eps } from './EPS'; - -// Gift Cards -export { default as giftcard } from './GiftCard'; -export { default as westlandbon } from './GiftCard'; -export { default as babygiftcard } from './GiftCard'; -export { default as babyparkgiftcard } from './GiftCard'; -export { default as beautywellness } from './GiftCard'; -export { default as boekenbon } from './GiftCard'; -export { default as boekenvoordeel } from './GiftCard'; -export { default as designshopsgiftcard } from './GiftCard'; -export { default as fashioncheque } from './GiftCard'; -export { default as fashionucadeaukaart } from './GiftCard'; -export { default as fijncadeau } from './GiftCard'; -export { default as koffiecadeau } from './GiftCard'; -export { default as kokenzo } from './GiftCard'; -export { default as kookcadeau } from './GiftCard'; -export { default as nationaleentertainmentcard } from './GiftCard'; -export { default as naturesgift } from './GiftCard'; -export { default as podiumcadeaukaart } from './GiftCard'; -export { default as shoesaccessories } from './GiftCard'; -export { default as webshopgiftcard } from './GiftCard'; -export { default as wijncadeau } from './GiftCard'; -export { default as wonenzo } from './GiftCard'; -export { default as yourgift } from './GiftCard'; -export { default as vvvgiftcard } from './GiftCard'; -export { default as parfumcadeaukaart } from './GiftCard'; - -export { default as giropay } from './Giropay'; -export { default as idealqr } from './IdealQR'; -export { default as idin } from './Idin'; -export { default as capayable } from './In3Old'; -export { default as KBCPaymentButton } from './KBC'; -export { default as klarna } from './Klarna'; -export { default as klarnakp } from './KlarnaKP'; -export { default as Marketplaces } from './Marketplaces'; -export { default as payconiq } from './Payconiq'; -export { default as PayByBank } from './PayByBank'; -export { default as paypal } from './Paypal'; -export { default as payperemail } from './PayPerEmail'; -export { default as PiM } from './PiM'; -export { default as pointofsale } from './PointOfSale'; -export { default as przelewy24 } from './Przelewy24'; -export { default as sepadirectdebit } from './SEPA'; -export { default as sofortueberweisung } from './Sofort'; -export { default as subscriptions } from './Subscriptions'; -export { default as surepay } from './Surepay'; -export { default as thunes } from './Thunes'; -export { default as tinka } from './Tinka'; -export { default as alipay } from './Alipay'; -export { default as trustly } from './Trustly'; -export { default as wechatpay } from './WeChatPay'; -export { default as In3 } from './In3'; -export { default as noservice } from "./NoService"; +export { default as PayablePaymentMethod } from '../Services/PayablePaymentMethod'; diff --git a/src/Request/Request.ts b/src/Request/Request.ts index f64844ec..d8b2c9c5 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -8,7 +8,7 @@ import { SpecificationRequestResponse } from '../Models/Response/SpecificationRe import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; import HttpMethods from '../Constants/HttpMethods'; import { RequestOptions } from 'https'; -import PaymentMethod from '../PaymentMethods/PaymentMethod'; +import PaymentMethod from '../Services/PaymentMethod'; import { ICredentials } from '../Utils/Types'; import { Hmac } from './Hmac'; import { AvailablePaymentMethods, ServiceCode } from '../Utils/MethodTypes'; diff --git a/src/PaymentMethods/PayablePaymentMethod.ts b/src/Services/PayablePaymentMethod.ts similarity index 100% rename from src/PaymentMethods/PayablePaymentMethod.ts rename to src/Services/PayablePaymentMethod.ts diff --git a/src/PaymentMethods/PaymentMethod.ts b/src/Services/PaymentMethod.ts similarity index 100% rename from src/PaymentMethods/PaymentMethod.ts rename to src/Services/PaymentMethod.ts diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index c590ff5a..62931520 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,11 +1,11 @@ -import * as AllPaymentMethods from '../PaymentMethods'; +import * as AllPaymentMethods from '../PaymentMethods/PaymentMethods'; export type AvailablePaymentMethods = typeof AllPaymentMethods; export type ServiceCode = keyof AvailablePaymentMethods; export type PaymentMethodInstance = InstanceType; export function getMethod(code: Code): PaymentMethodInstance { - const methodClass = AllPaymentMethods['ideal']; + const methodClass = AllPaymentMethods[code]; if (!methodClass) { throw new Error(`Invalid payment method code: ${code}`); } diff --git a/src/Utils/index.ts b/src/Utils/index.ts new file mode 100644 index 00000000..98568983 --- /dev/null +++ b/src/Utils/index.ts @@ -0,0 +1,3 @@ +export * from './MethodTypes'; +export * from './Types'; +export { getIPAddress, DataFormatter } from './Functions'; \ No newline at end of file diff --git a/src/buckaroo.ts b/src/buckaroo.ts new file mode 100644 index 00000000..a5d5f93e --- /dev/null +++ b/src/buckaroo.ts @@ -0,0 +1,69 @@ +import { IConfig, ICredentials } from './Utils/Types'; +import HttpsClient from './Request/HttpsClient'; +import { Agent } from 'https'; +import { getMethod, ServiceCode } from './Utils/MethodTypes'; +import Request from './Request/Request'; +import NoService from './PaymentMethods/NoService'; +import TransactionService from './Services/TransactionService'; +import { Credentials } from './Handlers/Credentials'; + +export default class Buckaroo { + private static _client: Buckaroo; + private readonly _credentials: Credentials; + private readonly _httpClient: HttpsClient; + private _config: IConfig; + + constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { + this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); + this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; + this._httpClient = new HttpsClient(); + } + + static get Client(): Buckaroo { + return this._client; + } + + get config(): IConfig { + return { ...this._config }; + } + + set config(value: IConfig) { + this._config = value; + } + + get credentials(): ICredentials { + return this._credentials; + } + + get httpClient() { + return this._httpClient; + } + + get batch() { + return { + transaction: Request.BatchTransaction, + data: Request.BatchDataRequest, + }; + } + + static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { + return (this._client = new this(credentials, config, agent)); + } + + method(name?: K) { + if (!name) { + return new NoService(); + } + return getMethod(name); + } + + confirmCredentials() { + return this._credentials.confirm(); + } + + transaction(key: string) { + return new TransactionService(key); + } +} + +export { Buckaroo }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 80b87844..2b22bea8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,74 +1,7 @@ -import { IConfig, ICredentials } from './Utils/Types'; -import HttpsClient from './Request/HttpsClient'; -import { Agent } from 'https'; -import { getMethod, PaymentMethodInstance, ServiceCode } from './Utils/MethodTypes'; -import Request from './Request/Request'; -import NoService from './PaymentMethods/NoService'; -import TransactionService from './Services/TransactionService'; -import { Credentials } from './Handlers/Credentials'; +import Buckaroo from './buckaroo'; -export default class Buckaroo { - private static _client: Buckaroo; - private readonly _credentials: Credentials; - private readonly _httpClient: HttpsClient; - private _config: IConfig; +export * from './Utils'; +export * from './PaymentMethods'; - constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { - this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); - this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; - this._httpClient = new HttpsClient(); - } - - static get Client(): Buckaroo { - return this._client; - } - - get config(): IConfig { - return { ...this._config }; - } - - set config(value: IConfig) { - this._config = value; - } - - get credentials(): ICredentials { - return this._credentials; - } - - get httpClient() { - return this._httpClient; - } - - get batch() { - return { - transaction: Request.BatchTransaction, - data: Request.BatchDataRequest, - }; - } - - static InitializeClient(credentials: ICredentials, config?: IConfig, agent?: Agent): Buckaroo { - return (this._client = new this(credentials, config, agent)); - } - - method(): NoService; - - method(name: K): PaymentMethodInstance; - - method(name?: K) { - if (!name) { - return new NoService(); - } - return getMethod(name); - } - - confirmCredentials() { - return this._credentials.confirm(); - } - - transaction(key: string) { - return new TransactionService(key); - } -} - - -export { Buckaroo }; +export default Buckaroo; +export { Buckaroo }; \ No newline at end of file From 5742a5d25f5234ce3c52878b421b7998f2b94ef2 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 19 Oct 2023 09:29:18 +0200 Subject: [PATCH 19/52] few improvements + add watch property on rollup compiler + add some missing imports + fix ReplyHandler issue --- package.json | 2 ++ src/Constants/index.ts | 4 ++++ src/Handlers/Reply/ReplyHandler.ts | 11 ++++------- src/Handlers/index.ts | 2 ++ src/Models/Interfaces/index.ts | 3 +++ src/Models/index.ts | 2 ++ src/PaymentMethods/PaymentMethods.ts | 2 +- src/Request/Request.ts | 2 -- src/buckaroo.ts | 5 +++-- src/index.ts | 3 +++ 10 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 src/Constants/index.ts create mode 100644 src/Handlers/index.ts create mode 100644 src/Models/Interfaces/index.ts create mode 100644 src/Models/index.ts diff --git a/package.json b/package.json index 51b94105..39600995 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ }, "scripts": { "build": "yarn build:library && yarn build:declarations", + "dev": "yarn dev:library && yarn build:declarations", "build:library": "rollup --config rollup.config.js", + "dev:library": "rollup --config rollup.config.js -w", "build:declarations": "tsc --project tsconfig-declarations.json", "test": "jest", "prettier": "prettier --write ." diff --git a/src/Constants/index.ts b/src/Constants/index.ts new file mode 100644 index 00000000..04d1e6dd --- /dev/null +++ b/src/Constants/index.ts @@ -0,0 +1,4 @@ +export * from './Endpoints'; +export * from './Gender'; +export { default as RecipientCategory } from './RecipientCategory'; +export * from './ResponseStatus'; diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index ce7e6537..4b405bd5 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -56,14 +56,11 @@ export class ReplyHandler { return new Hmac().validate(this.credentials, auth_header, url, data, this.method || HttpMethods.POST); } - private validateHttp(data: object, signature: string) { - let stringData = ''; - for (const key in data) { - stringData += key + '=' + data[key]; - } - stringData = stringData + this.credentials.websiteKey; + private validateHttp(data: Record, signature: string): boolean { + const sortedKeys = Object.keys(data).sort(); + const stringData = sortedKeys.map((key) => `${key}=${data[key]}`).join('') + this.credentials.secretKey; - let hash = crypto.createHash('sha1').update(stringData).digest('hex'); + const hash = crypto.createHash('sha1').update(stringData).digest('hex'); return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)); } diff --git a/src/Handlers/index.ts b/src/Handlers/index.ts new file mode 100644 index 00000000..f4b26137 --- /dev/null +++ b/src/Handlers/index.ts @@ -0,0 +1,2 @@ +export * from './Credentials'; +export * from './Reply/ReplyHandler'; diff --git a/src/Models/Interfaces/index.ts b/src/Models/Interfaces/index.ts new file mode 100644 index 00000000..eaee1753 --- /dev/null +++ b/src/Models/Interfaces/index.ts @@ -0,0 +1,3 @@ +import type IArticle from './IArticle'; + +export { IArticle }; \ No newline at end of file diff --git a/src/Models/index.ts b/src/Models/index.ts new file mode 100644 index 00000000..a2f1caaf --- /dev/null +++ b/src/Models/index.ts @@ -0,0 +1,2 @@ +export * from './Interfaces'; +export * from './IRequest'; diff --git a/src/PaymentMethods/PaymentMethods.ts b/src/PaymentMethods/PaymentMethods.ts index 166b1c8b..4495b92a 100644 --- a/src/PaymentMethods/PaymentMethods.ts +++ b/src/PaymentMethods/PaymentMethods.ts @@ -81,4 +81,4 @@ export { default as alipay } from './Alipay'; export { default as trustly } from './Trustly'; export { default as wechatpay } from './WeChatPay'; export { default as In3 } from './In3'; -export { default as noservice } from './NoService'; \ No newline at end of file +export { default as noservice } from "./NoService"; \ No newline at end of file diff --git a/src/Request/Request.ts b/src/Request/Request.ts index d8b2c9c5..65d039aa 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -8,10 +8,8 @@ import { SpecificationRequestResponse } from '../Models/Response/SpecificationRe import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; import HttpMethods from '../Constants/HttpMethods'; import { RequestOptions } from 'https'; -import PaymentMethod from '../Services/PaymentMethod'; import { ICredentials } from '../Utils/Types'; import { Hmac } from './Hmac'; -import { AvailablePaymentMethods, ServiceCode } from '../Utils/MethodTypes'; import { IService } from '../Models/IServiceList'; import IRequest from '../Models/IRequest'; diff --git a/src/buckaroo.ts b/src/buckaroo.ts index a5d5f93e..ffe86f6e 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -1,7 +1,6 @@ -import { IConfig, ICredentials } from './Utils/Types'; +import { getMethod, IConfig, ICredentials, PaymentMethodInstance, ServiceCode } from './Utils'; import HttpsClient from './Request/HttpsClient'; import { Agent } from 'https'; -import { getMethod, ServiceCode } from './Utils/MethodTypes'; import Request from './Request/Request'; import NoService from './PaymentMethods/NoService'; import TransactionService from './Services/TransactionService'; @@ -50,6 +49,8 @@ export default class Buckaroo { return (this._client = new this(credentials, config, agent)); } + method(): NoService; + method(name: Name): PaymentMethodInstance; method(name?: K) { if (!name) { return new NoService(); diff --git a/src/index.ts b/src/index.ts index 2b22bea8..fd29aec5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,8 @@ import Buckaroo from './buckaroo'; +export * from './Constants'; +export * from './Handlers'; +export * from './Models'; export * from './Utils'; export * from './PaymentMethods'; From aec41bbf8857644b2d08ee3be1d52e15f28cc2aa Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 19 Oct 2023 16:21:54 +0200 Subject: [PATCH 20/52] use object instead of string for data & fix ts errors Note: needed to change data from string to object, because we had error doing axios, on cases what no data provided, we send empty string, which isn't preferred --- src/Handlers/Reply/ReplyHandler.ts | 2 +- src/Models/Model.ts | 6 +++--- src/Models/Response/HttpClientResponse.ts | 4 ++-- src/Models/Response/TransactionResponse.ts | 4 +++- src/PaymentMethods/In3Old/Models/Phone.ts | 2 +- src/PaymentMethods/PaymentMethods.ts | 2 +- src/PaymentMethods/SEPA/Models/Pay.ts | 3 ++- .../Subscriptions/Models/ISubscription.ts | 12 ++++++------ src/Request/Headers.ts | 4 +++- src/Request/HttpsClient.ts | 16 +++++++++++----- src/Request/Request.ts | 13 ++++++------- src/Services/PaymentMethod.ts | 4 ++-- tsconfig.json | 3 ++- 13 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 4b405bd5..6c7bf20c 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -43,7 +43,7 @@ export class ReplyHandler { this.strategy = 'JSON'; return data; } catch (e) { - let objData = {}; + let objData: Record = {}; new URLSearchParams(value).forEach((value, name) => { objData[name] = value; }); diff --git a/src/Models/Model.ts b/src/Models/Model.ts index 1d64b690..6b9a01ca 100644 --- a/src/Models/Model.ts +++ b/src/Models/Model.ts @@ -36,7 +36,7 @@ export class Model { } protected setOwnProperties( - data: object = {}, + data: Record = {}, properties: { [key: string]: PropertyDescriptor } = this.getAllPropertyDescriptors() ) { for (const key in properties) { @@ -48,7 +48,7 @@ export class Model { return this; } - protected setDataProperties(data: object = {}) { + protected setDataProperties(data: Record = {}) { for (const dataKey in data) { if (data.hasOwnProperty(dataKey) && data[dataKey] !== undefined) this.set(dataKey, data[dataKey]); } @@ -127,7 +127,7 @@ export class JsonModel extends Model { } } -export function getObjectProperty(object: object, property: string, root: any = null) { +export function getObjectProperty(object: object, property: string, root: any = null): PropertyDescriptor | undefined { if (object !== root) { return ( Object.getOwnPropertyDescriptor(object, property) ?? diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts index a5071d40..a9b906bf 100644 --- a/src/Models/Response/HttpClientResponse.ts +++ b/src/Models/Response/HttpClientResponse.ts @@ -4,7 +4,7 @@ import { ICredentials } from '../../Utils/Types'; import { AxiosResponse } from 'axios'; export interface HttpResponseConstructor { - new (httpResponse: AxiosResponse, data: string): IHttpClientResponse; + new (httpResponse: AxiosResponse, data: object): IHttpClientResponse; } export interface IHttpClientResponse { @@ -37,7 +37,7 @@ export class HttpClientResponse implements IHttpClientResponse { validateResponse(credentials: ICredentials) { return new ReplyHandler( credentials, - this._rawData, + JSON.parse(this._rawData ?? {}), this.httpResponse.headers['authorization'], this.httpResponse.request.url, this.httpResponse.request.method diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index 68d35a33..82273cd5 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -79,7 +79,9 @@ export class TransactionResponse extends HttpClientResponse { getAdditionalParameters() { return DataFormatter.parametersReverseMap( - this.data.additionalParameters?.additionalParameter ?? this.data.additionalParameters?.['list'] ?? [] + this.data.additionalParameters?.additionalParameter ?? + (this.data.additionalParameters as Record)?.['list'] ?? + [] ); } diff --git a/src/PaymentMethods/In3Old/Models/Phone.ts b/src/PaymentMethods/In3Old/Models/Phone.ts index 2411f1e7..b087822a 100644 --- a/src/PaymentMethods/In3Old/Models/Phone.ts +++ b/src/PaymentMethods/In3Old/Models/Phone.ts @@ -1,7 +1,7 @@ import { Phone } from '../../../Models/Interfaces/IPhone'; export class In3OldPhone extends Phone { - set mobile(number) { + set mobile(number: string) { this.set('phone', number); } } diff --git a/src/PaymentMethods/PaymentMethods.ts b/src/PaymentMethods/PaymentMethods.ts index 4495b92a..166b1c8b 100644 --- a/src/PaymentMethods/PaymentMethods.ts +++ b/src/PaymentMethods/PaymentMethods.ts @@ -81,4 +81,4 @@ export { default as alipay } from './Alipay'; export { default as trustly } from './Trustly'; export { default as wechatpay } from './WeChatPay'; export { default as In3 } from './In3'; -export { default as noservice } from "./NoService"; \ No newline at end of file +export { default as noservice } from './NoService'; \ No newline at end of file diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index ab268b15..0fe90397 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -1,6 +1,7 @@ import { IPaymentRequest } from '../../../Models/IRequest'; import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; import { ServiceParameter } from '../../../Models/ServiceParameters'; +import RecipientCategory from '../../../Constants/RecipientCategory'; export interface IPay extends IPaymentRequest { customer?: Partial; @@ -46,7 +47,7 @@ export class Pay extends ServiceParameter { } export class Customer extends Person { - set category(value) {} + set category(value: RecipientCategory.PERSON) {} get name(): string { return this.get('customeraccountname'); diff --git a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts index 9daa869c..7e28c90c 100644 --- a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts @@ -115,19 +115,19 @@ export class Subscription extends ServiceParameter implements ISubscription { } set ratePlans(value: IRatePlans) { - for (const key in value) { + Object.entries(value).forEach(([key, val]) => { if (this.has(key + 'RatePlan')) { - this[key + 'RatePlan'] = value[key]; + this[key + 'RatePlan'] = val; } - } + }); } set ratePlanCharges(value: IRatePlanCharges) { - for (const key in value) { + Object.entries(value).forEach(([key, val]) => { if (this.has(key + 'RatePlanCharge')) { - this[key + 'RatePlanCharge'] = value[key]; + this[key + 'RatePlanCharge'] = val; } - } + }); } set customerIBAN(value: string) { diff --git a/src/Request/Headers.ts b/src/Request/Headers.ts index 882dbb34..7d1c620e 100644 --- a/src/Request/Headers.ts +++ b/src/Request/Headers.ts @@ -9,7 +9,9 @@ export type RequestHeaders = { [header: string]: any; }; -export type RequestConfig = { headers: RequestHeaders } | AxiosRequestConfig; +export interface RequestConfig extends AxiosRequestConfig { + headers?: RequestHeaders; +} export default class Headers { private _headers: RequestHeaders = this.getDefaultHeaders(); diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 90b4d4c4..e9d25b0b 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,6 +1,7 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; import { RequestConfig } from './Headers'; +import HttpMethods from '../Constants/HttpMethods'; export default class HttpsClient { protected _options: AxiosRequestConfig = {}; @@ -15,17 +16,22 @@ export default class HttpsClient { public async sendRequest( url: URL, - data: string, - options: RequestConfig, + data: object = {}, + options: RequestConfig = {}, responseClass: R ): Promise> { try { - const response = await this._axiosInstance.request({ + const config = { url: url.toString(), - data, ...this._options, ...options, - }); + }; + + if (options.method !== HttpMethods.GET) { + config.data = data; + } + + const response = await this._axiosInstance.request(config); return new responseClass(response, response.data) as InstanceType; } catch (error: unknown) { diff --git a/src/Request/Request.ts b/src/Request/Request.ts index 65d039aa..f95e0b42 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -1,4 +1,4 @@ -import Headers from './Headers'; +import Headers, { RequestConfig, RequestHeaders } from './Headers'; import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels'; import Buckaroo from '../index'; @@ -7,7 +7,6 @@ import { TransactionResponse } from '../Models/Response/TransactionResponse'; import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; import HttpMethods from '../Constants/HttpMethods'; -import { RequestOptions } from 'https'; import { ICredentials } from '../Utils/Types'; import { Hmac } from './Hmac'; import { IService } from '../Models/IServiceList'; @@ -89,24 +88,24 @@ export default class Request< return new Request(RequestTypes.BatchData, HttpMethods.POST, data, BatchRequestResponse); } - request(options: RequestOptions = {}) { - let data = this._httpMethod === HttpMethods.GET ? '' : JSON.stringify(this._data); + request(options: RequestConfig = {}) { + let data = (this._httpMethod === HttpMethods.GET ? {} : this._data) ?? {}; this.setAuthorizationHeader(data); return Buckaroo.Client.httpClient.sendRequest( this.url, data, { method: this._httpMethod, - headers: this.headers, + headers: this.headers as RequestHeaders, ...options, }, this.responseHandler ); } - protected setAuthorizationHeader(data: string, credentials: ICredentials = Buckaroo.Client.credentials): this { + protected setAuthorizationHeader(data?: object, credentials: ICredentials = Buckaroo.Client.credentials): this { let hmac = new Hmac(); - hmac.data = data; + hmac.data = JSON.stringify(data); hmac.method = this.httpMethod; hmac.url = this.url.toString(); this.headers.Authorization = hmac.generate(credentials); diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 3eda4a80..8438c877 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -58,7 +58,7 @@ export default abstract class PaymentMethod { combine(method: Method): this; - combine(data): this { + combine(data: any): this { if (typeof data === 'string') { const method: PaymentMethod = Buckaroo.Client.method(data as any); method.setPayload(this._payload); @@ -70,7 +70,7 @@ export default abstract class PaymentMethod { protected setRequiredFields(requiredFields: Array = this._requiredFields) { for (const fieldKey of requiredFields) { - let field = this._payload[fieldKey] ?? Buckaroo.Client.config[fieldKey]; + let field = this._payload[fieldKey] ?? (Buckaroo.Client.config as IRequest)[fieldKey]; if (field === undefined) { throw new Error(`Missing required config parameter ${String(fieldKey)}`); } diff --git a/tsconfig.json b/tsconfig.json index e4b19fd1..a7f1282e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "dom" ], "strict": true, + "noEmitOnError": true, "esModuleInterop": true, "skipLibCheck": true /* Skip type checking of declaration files. */, @@ -15,7 +16,7 @@ "declaration": true, "sourceMap": true, "moduleResolution": "node", - "noImplicitAny": false, + "noImplicitAny": true, "outDir": "dist", "resolveJsonModule": true }, From 9ea76b814014f20daa9baf7cc43a289f15598903 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 20 Oct 2023 16:51:03 +0200 Subject: [PATCH 21/52] fix issues for trusly and reply handler --- src/Handlers/Reply/ReplyHandler.ts | 4 +--- src/PaymentMethods/Trustly/Models/Customer.ts | 4 ++++ src/PaymentMethods/Trustly/Models/Pay.ts | 3 +-- tests/PaymentMethods/Trustly.test.ts | 9 ++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 6c7bf20c..970dcfb5 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -57,9 +57,7 @@ export class ReplyHandler { } private validateHttp(data: Record, signature: string): boolean { - const sortedKeys = Object.keys(data).sort(); - const stringData = sortedKeys.map((key) => `${key}=${data[key]}`).join('') + this.credentials.secretKey; - + const stringData = Object.keys(data).map((key) => `${key}=${data[key]}`).join('') + this.credentials.secretKey; const hash = crypto.createHash('sha1').update(stringData).digest('hex'); return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)); diff --git a/src/PaymentMethods/Trustly/Models/Customer.ts b/src/PaymentMethods/Trustly/Models/Customer.ts index 88fe98cc..71260929 100644 --- a/src/PaymentMethods/Trustly/Models/Customer.ts +++ b/src/PaymentMethods/Trustly/Models/Customer.ts @@ -8,4 +8,8 @@ export class Customer extends Model { set lastName(value: string) { this.set('customerLastName', value); } + + set countryCode(value: string) { + this.set('customerCountryCode', value); + } } diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index a94bbafa..594bd571 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -4,8 +4,7 @@ import { IPerson } from '../../../Models/Interfaces/IRecipient'; import { Customer } from './Customer'; export interface IPay extends IPaymentRequest { - customer: Partial; - country?: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB'; + customer: Partial & { country?: 'DE' | 'DK' | 'EE' | 'ES' | 'FI' | 'NL' | 'NO' | 'PL' | 'SE' | 'GB' }; } export class Pay extends ServiceParameter { diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 5fd739f2..33ef22cb 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -8,10 +8,13 @@ describe('Trustly', () => { await method .pay({ amountDebit: 12, - customerCountryCode: 'DE', - customerFirstName: 'da', - customerLastName: '34', + customer: { + firstName: 'Test', + lastName: 'Acceptatie', + country: 'NL', + }, }) + .request() .then((response) => { expect(response).toBeDefined(); }); From d1ad222998d6c5ed5fdb840fea05aebcc87674a1 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:52:41 +0200 Subject: [PATCH 22/52] Add GitHub action file --- .github/workflows/sonarqube.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/sonarqube.yml diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 00000000..19ac64b6 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,20 @@ +on: + push: + branches: + - main + - develop + pull_request: + types: [opened, synchronize, reopened] +name: SonarQube PR Analysis +jobs: + sonarqube: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} From ecdc727987df9fc5a7fd7c504456924e0c1ef6f7 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:58:12 +0200 Subject: [PATCH 23/52] Add sonarqube properties file --- sonar-project.properties | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..a1b5f9b5 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,9 @@ +# Unique key for the project +sonar.projectKey=buckaroo:node_sdk + +# Display name and version for the SonarQube UI +sonar.projectName=Buckaroo Node SDK +sonar.projectVersion=1.0 + +# Path to the source code, relative to the sonar-project.properties file +sonar.sources=. From 950fefa9986e0c5b636c42778c902da76e439bf7 Mon Sep 17 00:00:00 2001 From: Rinor12010 <105772190+Rinor12010@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:42:11 +0200 Subject: [PATCH 24/52] .fix --- src/Utils/MethodTypes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 2430880a..e02a60e5 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -40,7 +40,7 @@ import type Trustly from '../PaymentMethods/Trustly'; import type Wechatpay from '../PaymentMethods/WeChatPay'; import type In3 from '../PaymentMethods/In3'; import type MultiBanco from '../PaymentMethods/Multibanco'; -import type Mbway from "../PaymentMethods/Mbway"; +import type Mbway from '../PaymentMethods/Mbway'; //toDo refactor this @@ -183,7 +183,7 @@ export const Methods = { Trustly: ['trustly'], WeChatPay: ['wechatpay'], Multibanco: ['multibanco'], - Mbway: ['MBWay'], + Mbway: ['MBWay'] } as const; type MethodTypes = typeof Methods; From cf1e7d1d44c43c081f01a011e76b1e6ab2e11a61 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 26 Oct 2023 09:16:48 +0200 Subject: [PATCH 25/52] update + add missed tests for few methods + update few methods regarding their parameters + put some test default values for tests --- src/Handlers/Reply/ReplyHandler.ts | 5 +- src/Models/Interfaces/IAddress.ts | 2 + src/Models/Interfaces/IRecipient.ts | 4 + .../AfterpayDigiAccept/Model/Customer.ts | 22 +-- .../AfterpayDigiAccept/Model/Pay.ts | 8 +- .../AfterpayDigiAccept/Model/Recipient.ts | 39 +++++ .../AfterpayDigiAccept/Services/Address.ts | 45 +++--- .../AfterpayDigiAccept/Services/Phone.ts | 10 +- .../AfterpayDigiAccept/index.ts | 3 +- .../CreditClick/Models/Refund.ts | 2 +- .../CreditManagement/Models/Debtor.ts | 45 +++--- src/PaymentMethods/GiftCard/Models/Refund.ts | 2 +- src/PaymentMethods/Idin/Models/Pay.ts | 11 ++ src/PaymentMethods/Idin/index.ts | 5 +- src/PaymentMethods/In3/Models/Refund.ts | 9 -- src/PaymentMethods/In3/index.ts | 7 +- src/PaymentMethods/Klarna/index.ts | 2 +- src/PaymentMethods/KlarnaKP/Models/Address.ts | 27 ++++ src/PaymentMethods/KlarnaKP/Models/Article.ts | 32 ++++ .../KlarnaKP/Models/Customer.ts | 23 +++ src/PaymentMethods/KlarnaKP/Models/IPay.ts | 11 ++ .../KlarnaKP/Models/IReserve.ts | 20 ++- src/PaymentMethods/KlarnaKP/Models/Phone.ts | 11 ++ .../KlarnaKP/Models/Recipient.ts | 15 ++ src/PaymentMethods/KlarnaKP/index.ts | 2 +- .../PayPerEmail/Models/Invitation.ts | 1 + src/PaymentMethods/PaymentMethods.ts | 8 +- src/PaymentMethods/Paypal/Models/ExtraInfo.ts | 2 +- src/PaymentMethods/PiM/Models/Generate.ts | 47 ++++++ src/PaymentMethods/PiM/index.ts | 7 +- src/PaymentMethods/PointOfSale/Models/Pay.ts | 12 ++ src/PaymentMethods/PointOfSale/index.ts | 5 + src/PaymentMethods/SEPA/Models/ExtraInfo.ts | 15 +- src/PaymentMethods/Sofort/index.ts | 1 + .../Surepay/Models/BankAccount.ts | 16 ++ src/PaymentMethods/Surepay/Models/Verify.ts | 10 +- src/PaymentMethods/Surepay/index.ts | 8 +- src/Request/DataModels.ts | 4 + src/Services/PaymentMethod.ts | 6 + tests/Models/index.ts | 14 +- tests/PaymentMethods/AfterPay.test.ts | 108 ++++++-------- .../PaymentMethods/AfterPayDigiAccept.test.ts | 103 ++++++------- tests/PaymentMethods/Alipay.test.ts | 8 +- tests/PaymentMethods/ApplePay.test.ts | 30 ++-- tests/PaymentMethods/Bancontact.test.ts | 37 +++-- tests/PaymentMethods/BankTransfer.test.ts | 8 +- tests/PaymentMethods/Belfius.test.ts | 16 +- tests/PaymentMethods/Billink.test.ts | 66 +++++---- tests/PaymentMethods/BuckarooVoucher.test.ts | 14 +- tests/PaymentMethods/BuckarooWallet.test.ts | 54 +++---- tests/PaymentMethods/CreditCard.test.ts | 38 ++--- tests/PaymentMethods/CreditClick.test.ts | 16 +- tests/PaymentMethods/CreditManagment.test.ts | 77 +++++----- tests/PaymentMethods/EPS.test.ts | 8 +- tests/PaymentMethods/Emandate.test.ts | 14 +- tests/PaymentMethods/Giftcard.test.ts | 16 +- tests/PaymentMethods/GiroPay.test.ts | 8 +- tests/PaymentMethods/Ideal.test.ts | 11 +- tests/PaymentMethods/Idin.test.ts | 38 +++++ tests/PaymentMethods/In3.test.ts | 48 +++--- tests/PaymentMethods/In3Old.test.ts | 24 +-- tests/PaymentMethods/KBC.test.ts | 8 +- tests/PaymentMethods/Klarna.test.ts | 31 ++-- tests/PaymentMethods/KlarnaKp.test.ts | 41 ++---- tests/PaymentMethods/Marketplaces.test.ts | 21 ++- tests/PaymentMethods/Mbway.test.ts | 2 +- tests/PaymentMethods/Multibanco.test.ts | 2 +- tests/PaymentMethods/NoService.test.ts | 21 +++ tests/PaymentMethods/PayPerEmail.test.ts | 9 +- tests/PaymentMethods/Payconiq.test.ts | 15 +- .../PaymentMethods/PaymentInitiation.test.ts | 24 +-- tests/PaymentMethods/Paypal.test.ts | 16 +- tests/PaymentMethods/PiM.test.ts | 32 +++- tests/PaymentMethods/Pos.test.ts | 19 +++ tests/PaymentMethods/Przelewy24.test.ts | 19 ++- tests/PaymentMethods/SEPA.test.ts | 137 +++++++----------- tests/PaymentMethods/Sofort.test.ts | 25 ++-- tests/PaymentMethods/Subscriptions.test.ts | 51 ++++--- tests/PaymentMethods/SurePay.test.ts | 14 +- tests/PaymentMethods/Thunes.test.ts | 60 ++++++-- tests/PaymentMethods/Tinka.test.ts | 23 ++- tests/PaymentMethods/Trustly.test.ts | 9 +- tests/PaymentMethods/WechatPay.test.ts | 8 +- 83 files changed, 1106 insertions(+), 741 deletions(-) create mode 100644 src/PaymentMethods/AfterpayDigiAccept/Model/Recipient.ts create mode 100644 src/PaymentMethods/Idin/Models/Pay.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/Address.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/Article.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/Customer.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/Phone.ts create mode 100644 src/PaymentMethods/KlarnaKP/Models/Recipient.ts create mode 100644 src/PaymentMethods/PiM/Models/Generate.ts create mode 100644 src/PaymentMethods/PointOfSale/Models/Pay.ts create mode 100644 src/PaymentMethods/Surepay/Models/BankAccount.ts create mode 100644 tests/PaymentMethods/Idin.test.ts create mode 100644 tests/PaymentMethods/NoService.test.ts create mode 100644 tests/PaymentMethods/Pos.test.ts diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 970dcfb5..47d071e5 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -57,7 +57,10 @@ export class ReplyHandler { } private validateHttp(data: Record, signature: string): boolean { - const stringData = Object.keys(data).map((key) => `${key}=${data[key]}`).join('') + this.credentials.secretKey; + const stringData = + Object.keys(data) + .map((key) => `${key}=${data[key]}`) + .join('') + this.credentials.secretKey; const hash = crypto.createHash('sha1').update(stringData).digest('hex'); return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature)); diff --git a/src/Models/Interfaces/IAddress.ts b/src/Models/Interfaces/IAddress.ts index bd840cda..98dc9f20 100644 --- a/src/Models/Interfaces/IAddress.ts +++ b/src/Models/Interfaces/IAddress.ts @@ -8,6 +8,8 @@ export default interface IAddress { city: string; state?: string; country: string; + + [key: string]: any; } export class Address extends Model implements IAddress { diff --git a/src/Models/Interfaces/IRecipient.ts b/src/Models/Interfaces/IRecipient.ts index 9213909b..998ccd4f 100644 --- a/src/Models/Interfaces/IRecipient.ts +++ b/src/Models/Interfaces/IRecipient.ts @@ -80,6 +80,10 @@ export class Person extends Recipient implements IPerson { super(data); } + set name(value: string) { + this.set('name', value); + } + set category(value: RecipientCategory.PERSON) { this.set('category', value); } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts index cce38580..ff964599 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts @@ -2,34 +2,26 @@ import { Address } from '../Services/Address'; import { Model } from '../../../Models/Model'; import { Phone } from '../Services/Phone'; import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { Recipient } from './Recipient'; export class Customer extends Model implements ICustomer { - constructor(data?: ICustomer, prefix?: string) { - super(data, prefix); - } - - get prefix() { - return ''; + set prefix(value: string) { + this.set('prefix', value, true); } set recipient(recipient: ICustomer['recipient']) { - this.set('recipient', recipient); + this.set('recipient', new Recipient({ prefix: this.get('prefix'), ...recipient })); } set address(address: ICustomer['address']) { - this.set('address', new Address(address, this.prefix)); + this.set('address', new Address({ prefix: this.get('prefix'), ...address })); } set email(email: ICustomer['email']) { - this.set(this.prefix + 'Email', email); + this.set(`${this.get('prefix')}Email`, email); } set phone(phone: ICustomer['phone']) { - this.set('phone', new Phone(phone)); - } - - initialize(data?: any, prefix: string = '') { - this.set('prefix', prefix, true); - return super.initialize(data); + this.set('phone', new Phone({ prefix: this.get('prefix'), ...phone })); } } diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts index b2934b40..423b2e4b 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -37,15 +37,15 @@ export class Pay extends ServiceParameter implements Omit) { + this.set('address', new Address({ prefix: this.get('prefix'), ...address })); + } + + set recipient(recipient: Partial) { + this.set('recipient', new Recipient({ prefix: this.get('prefix'), ...recipient })); + } +} diff --git a/src/PaymentMethods/KlarnaKP/Models/IPay.ts b/src/PaymentMethods/KlarnaKP/Models/IPay.ts index 2edf9dd8..036e80eb 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IPay.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IPay.ts @@ -1,5 +1,6 @@ import { IPaymentRequest } from '../../../Models/IRequest'; import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Person } from '../../../Models/Interfaces/IRecipient'; export interface IPay extends IPaymentRequest { reservationNumber?: string; @@ -10,3 +11,13 @@ export class Pay extends ServiceParameter { this.set('reservationNumber', value); } } + +export class Customer extends Person { + set firstName(email: string) { + this.set('customerFirstName', email); + } + + set lastName(email: string) { + this.set('customerLastName', email); + } +} diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts index 3ca3b1ac..138565e9 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -3,6 +3,8 @@ import IRequest from '../../../Models/IRequest'; import { ICustomer } from '../../../Models/Interfaces/ICustomer'; import IArticle from '../../../Models/Interfaces/IArticle'; import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Customer } from './Customer'; +import Article from './Article'; export interface IReserve extends IRequest { gender?: Gender.MALE | Gender.FEMALE; @@ -33,15 +35,27 @@ export class Reserve extends ServiceParameter implements IReserve { } set billing(value: ICustomer) { - this.set('billing', value); + const customer = new Customer({ prefix: 'billing', ...value }); + this.set('billing', customer); } set shipping(value: ICustomer) { - this.set('shipping', value); + this.set('shipping', new Customer({ prefix: 'shipping', ...value })); } set articles(value: IArticle[]) { - this.set('articles', value); + this.set( + 'articles', + value.map((article) => new Article(article)) + ); + } + + protected getGroups(): {} { + return super.getGroups({ + Billing: 'BillingCustomer', + Shipping: 'ShippingCustomer', + Articles: 'Article', + }); } protected getCountable() { diff --git a/src/PaymentMethods/KlarnaKP/Models/Phone.ts b/src/PaymentMethods/KlarnaKP/Models/Phone.ts new file mode 100644 index 00000000..2b08fd98 --- /dev/null +++ b/src/PaymentMethods/KlarnaKP/Models/Phone.ts @@ -0,0 +1,11 @@ +import { Person } from '../../../Models/Interfaces/IRecipient'; + +export class Phone extends Person { + set prefix(value: string) { + this.set('prefix', value, true); + } + + set mobile(value: string) { + this.set(`${this.get('prefix')}CellPhoneNumber`, value); + } +} diff --git a/src/PaymentMethods/KlarnaKP/Models/Recipient.ts b/src/PaymentMethods/KlarnaKP/Models/Recipient.ts new file mode 100644 index 00000000..3712c3bf --- /dev/null +++ b/src/PaymentMethods/KlarnaKP/Models/Recipient.ts @@ -0,0 +1,15 @@ +import { Model } from '../../../Models/Model'; + +export class Recipient extends Model { + set prefix(value: string) { + this.set('prefix', value, true); + } + + set firstName(value: string) { + this.set(`${this.get('prefix')}FirstName`, value); + } + + set lastName(value: string) { + this.set(`${this.get('prefix')}LastName`, value); + } +} diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 7ae0b534..a0448cac 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -17,7 +17,7 @@ export default class KlarnaKP extends PayablePaymentMethod { } cancel(payload: IRequest) { - this.setServiceList('CancelReservation'); + this.setServiceList('CancelReservation', new Pay(payload)); return this.dataRequest(payload); } diff --git a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts index 6821d3d5..17b70ef7 100644 --- a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts +++ b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts @@ -4,6 +4,7 @@ import { Attachments, IAttachments } from './Attachments'; import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; export interface IInvitation extends IRequest { + currency: string; customer: Partial; email: string; merchantSendsEmail?: boolean; diff --git a/src/PaymentMethods/PaymentMethods.ts b/src/PaymentMethods/PaymentMethods.ts index 166b1c8b..8e85fdd2 100644 --- a/src/PaymentMethods/PaymentMethods.ts +++ b/src/PaymentMethods/PaymentMethods.ts @@ -63,13 +63,15 @@ export { default as capayable } from './In3Old'; export { default as KBCPaymentButton } from './KBC'; export { default as klarna } from './Klarna'; export { default as klarnakp } from './KlarnaKP'; -export { default as Marketplaces } from './Marketplaces'; +export { default as marketplaces } from './Marketplaces'; +export { default as MBWay } from './Mbway'; +export { default as multibanco } from './Multibanco'; export { default as payconiq } from './Payconiq'; export { default as PayByBank } from './PayByBank'; export { default as paypal } from './Paypal'; export { default as payperemail } from './PayPerEmail'; -export { default as PiM } from './PiM'; -export { default as pointofsale } from './PointOfSale'; +export { default as pim } from './PiM'; +export { default as pospayment } from './PointOfSale'; export { default as przelewy24 } from './Przelewy24'; export { default as sepadirectdebit } from './SEPA'; export { default as sofortueberweisung } from './Sofort'; diff --git a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts index ae31103d..fec52da4 100644 --- a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts +++ b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts @@ -7,7 +7,7 @@ import { IPaymentRequest } from '../../../Models/IRequest'; export interface IExtraInfo extends IPaymentRequest { address?: IAddress; - customer?: IPerson; + customer?: Partial; phone?: IPhone; noShipping?: string; addressOverride?: boolean; diff --git a/src/PaymentMethods/PiM/Models/Generate.ts b/src/PaymentMethods/PiM/Models/Generate.ts new file mode 100644 index 00000000..294b810c --- /dev/null +++ b/src/PaymentMethods/PiM/Models/Generate.ts @@ -0,0 +1,47 @@ +import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPerson } from '../../../Models/Interfaces/IRecipient'; + +export interface IGenerate extends IPaymentRequest { + description: string; + title: string; + return: Partial & { + nickname?: string; + birthNamePrefix?: string; + birthName?: string; + email: string; + }; + result: { + title: string; + text: string; + }; +} + +export class Generate extends ServiceParameter { + set description(value: string) { + this.set('description', value); + } + + set title(value: string) { + this.set('title', value); + } + + set return(value: IGenerate['return']) { + this.set('returnNickname', value.nickname); + this.set('returnInitials', value.initials); + this.set('returnFirstname', value.firstName); + this.set('returnLastnamePrefix', value.lastNamePrefix); + this.set('returnLastname', value.lastName); + this.set('returnBirthnamePrefix', value.birthNamePrefix); + this.set('returnBirthname', value.birthName); + this.set('returnDateOfBirth', value.birthDate); + this.set('returnGender', value.gender); + this.set('returnEmail', value.email); + } + + set result(value: IGenerate['result']) { + this.set('resultTitle', value.title); + this.set('resultText', value.text); + } +} + diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index f6e451ac..78ec3d79 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,11 +1,12 @@ import PaymentMethod from '../../Services/PaymentMethod'; +import { Generate, IGenerate } from './Models/Generate'; export default class PiM extends PaymentMethod { - protected _paymentName = 'PiM'; + protected _paymentName = 'pim'; protected _requiredFields = ['currency']; - generate() { - this.setServiceList('Generate'); + generate(payload: IGenerate) { + this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); } } diff --git a/src/PaymentMethods/PointOfSale/Models/Pay.ts b/src/PaymentMethods/PointOfSale/Models/Pay.ts new file mode 100644 index 00000000..f37d2191 --- /dev/null +++ b/src/PaymentMethods/PointOfSale/Models/Pay.ts @@ -0,0 +1,12 @@ +import { IPaymentRequest } from '../../../Models'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; + +export interface IPay extends IPaymentRequest { + terminalId: string; +} + +export class Pay extends ServiceParameter { + set terminalId(value: string) { + this.set('terminalID', value); + } +} diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index 4c9d9388..a7c9ec23 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,5 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { IPay, Pay } from './Models/Pay'; export default class PointOfSale extends PayablePaymentMethod { protected _paymentName = 'PointOfSale'; + + pay(payload: IPay) { + return super.pay(payload, new Pay(payload)); + } } diff --git a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts index 1916cdff..8e286768 100644 --- a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts +++ b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts @@ -1,16 +1,17 @@ import { IPaymentRequest } from '../../../Models/IRequest'; +import IAddress from '../../../Models/Interfaces/IAddress'; export interface IExtraInfo extends IPaymentRequest { - customeraccountname: string; - customerBIC?: string; - customerIBAN: string; - collectDate: string; + bic?: string; + iban: string; + collectDate?: string; mandateReference?: string; mandateDate?: string; - customerName?: string; - customerCode?: string; customerReferencePartyCode?: string; customerReferencePartyName?: string; - houseNumberSuffix: string; contractID: string; + customer: { + name: string; + }; + address: IAddress; } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index d8304531..404841ca 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -3,6 +3,7 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; export default class Sofort extends PayablePaymentMethod { protected _paymentName = 'Sofort'; + protected _serviceVersion = 1; pay(payload: IPaymentRequest) { return super.pay(payload); diff --git a/src/PaymentMethods/Surepay/Models/BankAccount.ts b/src/PaymentMethods/Surepay/Models/BankAccount.ts new file mode 100644 index 00000000..ac1a2758 --- /dev/null +++ b/src/PaymentMethods/Surepay/Models/BankAccount.ts @@ -0,0 +1,16 @@ +import { Model } from '../../../Models/Model'; + +export interface IBankAccount { + iban: string; + accountName: string; +} + +export class BankAccount extends Model implements IBankAccount { + set accountName(value: string) { + this.set('customeraccountname', value); + } + + set iban(iban: string) { + this.set('iban', iban); + } +} diff --git a/src/PaymentMethods/Surepay/Models/Verify.ts b/src/PaymentMethods/Surepay/Models/Verify.ts index 60b32e8e..5e0fabaf 100644 --- a/src/PaymentMethods/Surepay/Models/Verify.ts +++ b/src/PaymentMethods/Surepay/Models/Verify.ts @@ -1,5 +1,13 @@ import { IPaymentRequest } from '../../../Models/IRequest'; +import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { BankAccount, IBankAccount } from './BankAccount'; export interface IVerify extends IPaymentRequest { - customeraccountname: string; + bankAccount: Partial; +} + +export class Verify extends ServiceParameter { + set bankAccount(value: IBankAccount) { + this.set('bankAccount', new BankAccount(value)); + } } diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 172159e6..469fc45f 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,13 +1,11 @@ import PaymentMethod from '../../Services/PaymentMethod'; -import { IVerify } from './Models/Verify'; -import { Parameter } from '../../Models/IParameters'; +import { IVerify, Verify } from './Models/Verify'; export default class Surepay extends PaymentMethod { protected _paymentName = 'Surepay'; verify(payload: IVerify) { - const serviceParameter = new Parameter({ name: 'customeraccountname', value: payload.customeraccountname }); - this.setServiceList('Verify', [serviceParameter]); - return this.dataRequest(payload); + this.setServiceList('Verify', new Verify(payload)); + return super.dataRequest(payload); } } diff --git a/src/Request/DataModels.ts b/src/Request/DataModels.ts index 3b776e31..2e2dbcb2 100644 --- a/src/Request/DataModels.ts +++ b/src/Request/DataModels.ts @@ -126,6 +126,10 @@ export class DataRequestData extends TransactionData { List: DataFormatter.parametersMap(parameters), }); } + + set services(data: IService[]) { + this.set('services', data); + } } export class SpecificationRequestData extends Model { diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 8438c877..8528d761 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -35,6 +35,12 @@ export default abstract class PaymentMethod { return this._paymentName; } + setPaymentName(value: ServiceCode): this { + this._paymentName = value; + this._serviceCode = value; + return this; + } + setPayload(payload?: IRequest) { this.setRequiredFields(); this._payload.initialize(payload); diff --git a/tests/Models/index.ts b/tests/Models/index.ts index 33fc1452..031937c4 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -4,7 +4,8 @@ import IArticle from '../../src/Models/Interfaces/IArticle'; import IPhone from '../../src/Models/Interfaces/IPhone'; import IBankAccount from '../../src/Models/Interfaces/IBankAccount'; import RecipientCategory from '../../src/Constants/RecipientCategory'; -import { getIPAddress } from '../../src/Utils/Functions'; +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import Gender from '../../src/Constants/Gender'; export const TestPerson: IPerson = { birthDate: '1990-01-01', @@ -64,4 +65,15 @@ export const TestBilling = { phone: TestPhone, email: TestEmail, }; + +export const TestCustomer = { + identificationNumber: uniqid(), + gender: Gender.FEMALE, + culture: TestPerson.culture, + initials: TestPerson.initials, + lastName: TestPerson.lastName, + firstName: TestPerson.firstName, + birthDate: '1990-01-01', +}; + export const TestIp = getIPAddress(); diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index 48554d07..f053ebec 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -1,6 +1,42 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; + +const paymentPayload: IPay = { + invoice: uniqid(), + clientIP: getIPAddress(), + amountDebit: 100, + billing: { + recipient: { + category: RecipientCategory.PERSON, + firstName: 'Test', + lastName: 'Acceptatie', + birthDate: '01-01-1990', + }, + address: { + street: 'Hoofdstraat', + houseNumber: '80', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL', + }, + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678', + landline: '0201234567', + }, + }, + articles: [ + { + vatPercentage: 21, + price: 10, + description: 'Test', + quantity: 4, + identifier: 'test', + }, + ], +}; const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { @@ -15,9 +51,9 @@ describe('AfterPay methods', () => { test('Refund', async () => { await method .refund({ - invoice: 'testinvoice 123', //Set invoice number of the transaction to refund - originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', //Set transaction key of the transaction to refund - amountCredit: 1.23, + invoice: paymentPayload.invoice, //Set invoice number of the transaction to refund + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', //Set transaction key of the transaction to refund + amountCredit: paymentPayload.amountDebit, }) .request() .then((data) => { @@ -35,9 +71,9 @@ describe('AfterPay methods', () => { test('CancelAuthorize', async () => { await method .cancelAuthorize({ - invoice: 'testinvoice 123', - originalTransactionKey: '4E8BD922192746C3918BF4077CXXXXXX', - amountCredit: 1.23, + invoice: paymentPayload.invoice, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountCredit: 100, }) .request() .then((data) => { @@ -49,69 +85,11 @@ describe('AfterPay methods', () => { await method .capture({ ...paymentPayload, - originalTransactionKey: '123456789', + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { expect(data).toBeDefined(); }); }); - test('PayRemainder', async () => { - await method - .payRemainder({} as any) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); - test('AuthorizeRemainder', async () => { - await method - .authorizeRemainder({} as any) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); }); - -const paymentPayload: IPay = { - clientIP: '127.0.0.1', - amountDebit: 40, - billing: { - recipient: { - category: RecipientCategory.PERSON, - careOf: 'John Smith', - firstName: 'John', - lastName: 'Do', - birthDate: '1990-01-01', - companyName: 'buckarooTest', - conversationLanguage: 'NL', - identificationNumber: 'IdNumber12345', - customerNumber: 'customerNumber12345', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '13', - houseNumberAdditional: 'a', - zipcode: '1234AB', - city: 'Heerenveen', - country: 'NL', - }, - email: 'test@buckaroo.nl', - phone: { - mobile: '0612345678', - landline: '0513123456', - }, - }, - articles: [ - { - vatPercentage: 21, - price: 10, - description: 'Test', - quantity: 4, - identifier: 'test', - }, - ], - description: 'Test', - merchantImageUrl: 'https://www.buckaroo.nl/Themes/Buckaroo/Content/images/logo.png', -}; diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index ddc6ef68..022f8614 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,55 +1,18 @@ import { RequestTypes } from '../../src/Constants/Endpoints'; -import { TestBilling } from '../Models'; import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; -import Gender from '../../src/Constants/Gender'; +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay'; +import Gender from '../../src/Constants/Gender'; const method = buckarooClientTest.method('afterpaydigiaccept'); -describe('AfterPayDigiAccept methods', () => { - test('Authorize', async () => { - await method - .authorize({ - amountDebit: 0, - articles: [], - bankAccount: '', - bankCode: '', - billing: TestBilling, - clientIP: '', - merchantImageUrl: '', - ourReference: '', - summaryImageUrl: '', - yourReference: '', - }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); - test('Pay', async () => { - await method - .pay({ ...paymentPayload, clientIP: '127.0.0.1' }) - .request() - .then((data) => { - expect(data.data).toBeDefined(); - }); - }); - test('Specification', async () => { - await method - .specification(RequestTypes.Transaction) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); -}); - const paymentPayload: IPay = { - amountDebit: 40.5, + amountDebit: 100, + order: uniqid(), + invoice: uniqid(), b2b: true, addressesDiffer: true, - customerIPAddress: '0.0.0.0', + customerIPAddress: getIPAddress(), shippingCosts: 0.5, costCentre: 'Test', department: 'Test', @@ -58,20 +21,20 @@ const paymentPayload: IPay = { recipient: { gender: Gender.FEMALE, initials: 'AB', - lastName: 'Do', + lastName: 'Acceptatie', birthDate: '1990-01-01', culture: 'NL', }, address: { street: 'Hoofdstraat', - houseNumber: '13', + houseNumber: '80', houseNumberAdditional: 'a', - zipcode: '1234AB', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, phone: { - mobile: '0698765433', + mobile: '0612345678', }, email: 'test@buckaroo.nl', }, @@ -79,23 +42,23 @@ const paymentPayload: IPay = { recipient: { culture: 'NL', gender: Gender.MALE, - initials: 'YJ', - lastName: 'Jansen', + initials: 'TA', + lastName: 'Acceptatie', companyName: 'Buckaroo B.V.', + chamberOfCommerce: 'XXXXXX41', birthDate: '1990-01-01', - chamberOfCommerce: '12345678', - vatNumber: 'NL12345678', + vatNumber: 'NLXXXXXXXXXXB01', }, address: { - street: 'Kalverstraat', - houseNumber: '13', - houseNumberAdditional: 'b', - zipcode: '4321EB', - city: 'Amsterdam', + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', + zipcode: '8441ER', + city: 'Heerenveen', country: 'NL', }, phone: { - mobile: '0698765433', + mobile: '0612345678', }, email: 'test@buckaroo.nl', }, @@ -116,3 +79,29 @@ const paymentPayload: IPay = { }, ], }; +describe('AfterPayDigiAccept methods', () => { + test('Authorize', async () => { + await method + .authorize(paymentPayload) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); + test('Pay', async () => { + await method + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.data).toBeDefined(); + }); + }); + test('Specification', async () => { + await method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); + }); +}); \ No newline at end of file diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index c31e9cb8..6a8dd3f7 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const alipay = buckarooClientTest.method('alipay'); @@ -6,7 +7,7 @@ describe('Alipay methods', () => { test('Pay Simple Payload', async () => { await alipay .pay({ - amountDebit: 10, + amountDebit: 100, useMobileView: false, }) .request() @@ -17,8 +18,9 @@ describe('Alipay methods', () => { test('Refund', async () => { await alipay .refund({ - amountCredit: 5, - originalTransactionKey: 'F397777A251645F8BDD81547B5005B4B', + amountCredit: 0.01, + invoice: uniqid(), + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index 7e73c177..f6ded503 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -1,17 +1,16 @@ import { uniqid } from '../../src/Utils/Functions'; -import ApplePay from '../../src/PaymentMethods/ApplePay'; +import buckarooClientTest from '../BuckarooClient.test'; -require('../BuckarooClient.test'); - -const method = new ApplePay(); +const method = buckarooClientTest.method('applepay'); describe('Applepay methods', () => { - test('Pay Simple Payload', async () => { + test('Pay', async () => { await method .pay({ - amountDebit: 10, - paymentData: 'sad', - customerCardName: '87y7y8', + amountDebit: 100, + invoice: uniqid(), + paymentData: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + customerCardName: 'XXXXXXX', }) .request() .then((data) => { @@ -21,7 +20,7 @@ describe('Applepay methods', () => { test('Pay Redirect Payload', async () => { await method .payRedirect({ - amountDebit: 10, + amountDebit: 100, invoice: uniqid(), servicesSelectableByClient: 'applepay', continueOnIncomplete: true, @@ -34,20 +33,13 @@ describe('Applepay methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { expect(data).toBeDefined(); }); }); - test('Specifications', async () => { - await method - .specification() - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); }); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 7e99eb6a..44ae3fe4 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('bancontactmrcash'); @@ -6,7 +7,7 @@ describe('BanContact methods', () => { test('Pay Simple Payload', async () => { await method .pay({ - amountDebit: 10, + amountDebit: 100, saveToken: true, }) .request() @@ -17,8 +18,9 @@ describe('BanContact methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -27,7 +29,7 @@ describe('BanContact methods', () => { }); test('Authenticate', async () => { await method - .authenticate({ amountDebit: 10 }) + .authenticate({ invoice: uniqid(), amountDebit: 100 }) .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeDefined(); @@ -36,8 +38,9 @@ describe('BanContact methods', () => { test('PayOneClick', async () => { await method .payOneClick({ - originalTransactionKey: 'dsad', - amountDebit: 12, + invoice: uniqid(), + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100, }) .request() .then((data) => { @@ -47,8 +50,8 @@ describe('BanContact methods', () => { test('CompletePayment', async () => { await method .completePayment({ - originalTransactionKey: 'dsad', - encryptedCardData: 'sUIB', + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -58,8 +61,9 @@ describe('BanContact methods', () => { test('PayEncrypted', async () => { await method .payEncrypted({ - amountDebit: 10, - encryptedCardData: 'yrtgdd', + invoice: uniqid(), + amountDebit: 100, + encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -69,20 +73,13 @@ describe('BanContact methods', () => { test('PayRecurring', async () => { await method .payRecurring({ - amountDebit: 10, - originalTransactionKey: 'sadas', + invoice: uniqid(), + amountDebit: 100, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { expect(data).toBeDefined(); }); }); - test('Specifications', () => { - method - .specification() - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); }); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 76d2f770..0d0ba553 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -7,13 +7,13 @@ describe('Transfer methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10, + amountDebit: 100, customer: { - firstName: 'John', - lastName: 'Doe', + firstName: 'Test', + lastName: 'Acceptatie', gender: Gender.MALE, }, - email: 'test@hotmail.com', + email: 'test@buckaroo.nl', sendMail: true, dateDue: '2024-10-10', }) diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index d82ce631..c094b00d 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('belfius'); @@ -6,7 +7,7 @@ describe('testing methods', () => { test('Pay Simple Payload', async () => { await method .pay({ - amountDebit: 10, + amountDebit: 100, }) .request() .then((data) => { @@ -16,20 +17,13 @@ describe('testing methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 5, - originalTransactionKey: '86CFE2CB5901463EADE061633BDB9EC8', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { expect(data).toBeDefined(); }); }); - test('Specifications', async () => { - await method - .specification() - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); }); diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index fdcd8496..f64f79fd 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,12 +1,15 @@ import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay'; import buckarooClientTest from '../BuckarooClient.test'; import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { uniqid } from '../../src/Utils/Functions'; require('../BuckarooClient.test'); const method = buckarooClientTest.method('billink'); describe('Billink methods', () => { + const invoiceId = uniqid(); + test('Pay', async () => { await method .pay(payload) @@ -18,8 +21,9 @@ describe('Billink methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 12, - originalTransactionKey: 'ytgty', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -28,7 +32,7 @@ describe('Billink methods', () => { }); test('Authorize', async () => { await method - .authorize(payload) + .authorize({ ...payload, invoice: invoiceId }) .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); @@ -37,9 +41,9 @@ describe('Billink methods', () => { test('CancelAuthorize', async () => { await method .cancelAuthorize({ - originalTransactionKey: 'ytgty', - amountCredit: 10, - invoice: 'sdsa', + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountCredit: payload.amountDebit, + invoice: invoiceId, }) .request() .then((data) => { @@ -49,9 +53,9 @@ describe('Billink methods', () => { test('Capture', async () => { await method .capture({ - originalTransactionKey: 'ytgty', - invoice: "'dsa", - amountDebit: 123, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + invoice: invoiceId, + amountDebit: payload.amountDebit, articles: payload.articles, }) .request() @@ -62,52 +66,50 @@ describe('Billink methods', () => { }); const payload: IPay = { - amountDebit: 50.3, - order: '', - invoice: '', - trackAndTrace: 'TR0F123456789', - vATNumber: '2', + amountDebit: 100, + trackAndTrace: 'XXXXXXXXXXXXX', + vatNumber: 'NLXXXXXXXXXXB01', billing: { recipient: { category: RecipientCategory.PERSON, - careOf: 'John Smith', + careOf: 'Test Acceptatie', title: 'Female', - initials: 'JD', - firstName: 'John', - lastName: 'Do', + initials: 'TA', + firstName: 'Test', + lastName: 'Acceptatie', birthDate: '01-01-1990', - chamberOfCommerce: 'TEST', + chamberOfCommerce: 'XXXXXX41', }, address: { street: 'Hoofdstraat', - houseNumber: '13', + houseNumber: '80', houseNumberAdditional: 'a', - zipcode: '1234AB', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, phone: { - mobile: '0698765433', - landline: '0109876543', + mobile: '0612345678', + landline: '0201234567', }, email: 'test@buckaroo.nl', }, shipping: { recipient: { category: RecipientCategory.PERSON, - careOf: 'John Smith', + careOf: 'Test Acceptatie', title: 'Male', - initials: 'JD', - firstName: 'John', - lastName: 'Do', + initials: 'TA', + firstName: 'Test', + lastName: 'Acceptatie', birthDate: '1990-01-01', }, address: { - street: 'Kalverstraat', - houseNumber: '13', - houseNumberAdditional: 'b', - zipcode: '4321EB', - city: 'Amsterdam', + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', + zipcode: '8441ER', + city: 'Heerenveen', country: 'NL', }, }, diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 8924d03e..8b79be8e 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('buckaroovoucher'); @@ -6,8 +7,8 @@ describe('testing methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 12, - voucherCode: '', + amountDebit: 100, + voucherCode: 'XXXXXXX', }) .request() .then((data) => { @@ -17,8 +18,9 @@ describe('testing methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 12, - originalTransactionKey: '', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -28,7 +30,7 @@ describe('testing methods', () => { test('GetBalance', async () => { await method .getBalance({ - voucherCode: 'WP6W-XXXX-XXXX-56T7', + voucherCode: 'XXXXXXX', }) .request() .then((data) => { @@ -51,7 +53,7 @@ describe('testing methods', () => { test('DeactivateVoucher', async () => { await method .deactivate({ - voucherCode: '', + voucherCode: 'XXXXXXX', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index 2ce608aa..3ad4d9d4 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -7,9 +7,9 @@ describe('BuckarooWallet methods', () => { test('Pay', async () => { await method .pay({ - invoice: 'string', - amountDebit: 12, - walletId: '2', + invoice: uniqid(), + amountDebit: 100, + walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -19,9 +19,9 @@ describe('BuckarooWallet methods', () => { test('Refund', async () => { await method .refund({ - invoice: 'string', - amountCredit: 12, - originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -31,10 +31,10 @@ describe('BuckarooWallet methods', () => { test('CancelReservation', async () => { await method .cancel({ - invoice: 'BuckarooWalletInvoiceId', - originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', - amountDebit: 1, - walletMutationGuid: '49B018248ECE4346AC20B902', + invoice: uniqid(), + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100, + walletMutationGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -44,10 +44,10 @@ describe('BuckarooWallet methods', () => { test('deposit', async () => { await method .deposit({ - invoice: 'string', - walletId: '', - amountCredit: 12, - originalTransactionKey: '', + invoice: uniqid(), + walletId: 'XXXXXXXXXXXXXXXXXXXXX', + amountCredit: 100, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -57,15 +57,15 @@ describe('BuckarooWallet methods', () => { test('Update', async () => { await method .update({ - walletId: '10', + walletId: 'XXXXXXXXXXXXXXXXXXXXX', status: 'Disabled', email: 'test@buckaroo.nl', customer: { - firstName: 'John', - lastName: 'string', + firstName: 'Test', + lastName: 'Acceptatie', }, bankAccount: { - iban: 'NL13TEST0123456789', + iban: 'NLXXTESTXXXXXXXXXX', }, }) .request() @@ -76,10 +76,10 @@ describe('BuckarooWallet methods', () => { test('Withdrawal', async () => { await method .withdrawal({ - invoice: 'BuckarooWalletInvoiceId', - walletId: '10', - amountDebit: 10, - originalTransactionKey: '46FB241693914AA4AE7A8B6DB33DE', + invoice: uniqid(), + walletId: 'XXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -89,14 +89,14 @@ describe('BuckarooWallet methods', () => { test('Create Wallet', async () => { await method .create({ - walletId: uniqid(), + walletId: 'XXXXXXXXXXXXXXXXXXXXX', email: 'test@buckaroo.nl', customer: { - firstName: 'John', - lastName: 'string', + firstName: 'Test', + lastName: 'Acceptatie', }, bankAccount: { - iban: 'NL13TEST0123456789', + iban: 'NLXXTESTXXXXXXXXXX', }, }) .request() @@ -107,7 +107,7 @@ describe('BuckarooWallet methods', () => { test('GetInfo', async () => { await method .getInfo({ - walletId: '10', + walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index 1347f275..cb3f3b51 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('visa'); @@ -6,7 +7,7 @@ describe('testing methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10, + amountDebit: 100, }) .request() .then((data) => { @@ -16,8 +17,9 @@ describe('testing methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 5, - originalTransactionKey: 'F397DA6A251645F8BDD81547B5005B4B', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -27,7 +29,7 @@ describe('testing methods', () => { test('Authorize', async () => { await method .authorize({ - amountDebit: 10, + amountDebit: 100, }) .request() .then((data) => { @@ -37,9 +39,9 @@ describe('testing methods', () => { test('PayEncrypted', async () => { await method .payEncrypted({ - amountDebit: 10, + amountDebit: 100, name: 'Visa', - encryptedCardData: '', + encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -49,8 +51,8 @@ describe('testing methods', () => { test('PayWithSecurityCode', async () => { await method .payWithSecurityCode({ - amountDebit: 10, - encryptedSecurityCode: 'sad', + amountDebit: 100, + encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) .request() @@ -61,8 +63,8 @@ describe('testing methods', () => { test('AuthorizeWithSecurityCode', async () => { await method .authorizeWithSecurityCode({ - amountDebit: 10, - encryptedSecurityCode: 'sad', + amountDebit: 100, + encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) .request() @@ -73,8 +75,8 @@ describe('testing methods', () => { test('AuthorizeEncrypted', async () => { await method .authorizeEncrypted({ - amountDebit: 10, - encryptedCardData: 'sad', + amountDebit: 100, + encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) .request() @@ -85,8 +87,8 @@ describe('testing methods', () => { test('CancelAuthorize', async () => { await method .cancelAuthorize({ - originalTransactionKey: 'sad', - amountCredit: 10, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountCredit: 100, name: 'Visa', }) .request() @@ -97,8 +99,8 @@ describe('testing methods', () => { test('Capture', async () => { await method .capture({ - originalTransactionKey: 'sad', - amountDebit: 10, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100, name: 'Visa', }) .request() @@ -109,8 +111,8 @@ describe('testing methods', () => { test('PayRecurrent', async () => { await method .payRecurrent({ - originalTransactionKey: 'sad', - amountDebit: 10, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100, name: 'Visa', }) .request() diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index 0171df35..9b105c68 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('creditclick'); @@ -6,12 +7,12 @@ describe('Testing CreditClick methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 31, + amountDebit: 100, person: { - firstName: 'test', - lastName: 'test', + firstName: 'Test', + lastName: 'Acceptatie', }, - email: 't.tester@test.nl', + email: 'test@buckaroo.nl', }) .request() .then((response) => { @@ -21,9 +22,10 @@ describe('Testing CreditClick methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 31, - originalTransactionKey: 'C85BABFCCA2D4921B9CFBA0EBDF82C70', - description: 'test', + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + invoice: uniqid(), + description: 'refund', refundReason: 'Fraudulent', }) .request() diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index 980f74f2..c12e7707 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -19,15 +19,15 @@ describe('Testing Credit Management', () => { await creditManagement .createInvoice( creditManagementTestInvoice({ - invoice: 'Billingtest101', + invoice: uniqid(), description: 'buckaroo_schema_test_PDF', invoiceAmount: 217.8, invoiceDate: '2022-01-01', - dueDate: '1990-01-01', - schemeKey: '2amq34', - poNumber: 'PO-12345', + dueDate: '2024-01-01', + schemeKey: 'XXXXXXX', + poNumber: 'XX-XXXXX', debtor: { - code: 'johnsmith4', + code: 'XXXXXXXX', }, articles: [ { @@ -74,7 +74,7 @@ describe('Testing Credit Management', () => { }); test('Pause Invoice', async () => { await creditManagement - .pauseInvoice({ invoice: 'Testinvoice184915' }) + .pauseInvoice({ invoice: uniqid() }) .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); @@ -82,7 +82,7 @@ describe('Testing Credit Management', () => { }); test('UnPause Invoice', async () => { await creditManagement - .unpauseInvoice({ invoice: 'Testinvoice184915' }) + .unpauseInvoice({ invoice: uniqid() }) .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); @@ -91,7 +91,7 @@ describe('Testing Credit Management', () => { test('Invoice Info', async () => { await creditManagement .invoiceInfo({ - invoice: 'INV001', + invoice: uniqid(), invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }], }) .request() @@ -103,7 +103,7 @@ describe('Testing Credit Management', () => { await creditManagement .debtorInfo({ debtor: { - code: 'TestDebtor123123', + code: 'XXXXXXXX', }, }) .request() @@ -114,7 +114,7 @@ describe('Testing Credit Management', () => { test('AddOrUpdateProductLines', async () => { await creditManagement .addOrUpdateProductLines({ - invoiceKey: 'd42', + invoiceKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', articles: [ { type: 'Regular', @@ -161,13 +161,15 @@ describe('Testing Credit Management', () => { }); test('addOrUpdateDebtor', async () => { await creditManagement - .addOrUpdateDebtor( - creditManagementTestInvoice({ - addressUnreachable: false, - emailUnreachable: false, - mobileUnreachable: false, - }) - ) + .addOrUpdateDebtor({ + debtor: { + code: 'XXXXXXXX', + }, + person: { + culture: 'nl-NL', + lastName: 'Acceptatie', + }, + }) .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); @@ -179,14 +181,14 @@ describe('Testing Credit Management', () => { .method('sepadirectdebit') .combine(combinedInvoice.data) .pay({ - iban: 'NL39RABO0300065264', - bic: 'RABONL2U', - mandateReference: 'TestMandateReference', + iban: 'NLXXTESTXXXXXXXXXX', + bic: 'XXXXXXXXX', + mandateReference: 'XXXXXXXXXXXXXXX', mandateDate: '2020-01-01', collectDate: '2020-07-03', - amountDebit: 10.1, + amountDebit: 100, customer: { - name: 'John Smith', + name: 'Test Acceptatie', }, invoice: uniqid('TestInvoice'), }) @@ -199,15 +201,15 @@ describe('Testing Credit Management', () => { await creditManagement .createPaymentPlan({ description: 'Payment in two intstallments', - includedInvoiceKey: '20D09973FB5C4DBC9A33DB0F4F707xxx', - dossierNumber: 'PaymentplanJohnsmith123', + includedInvoiceKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + dossierNumber: 'XXXXXXXXXXXXXXXXXXXXXX', installmentCount: 2, initialAmount: 100, startDate: '2030-01-01', interval: CreditManagementInstallmentInterval.MONTH, paymentPlanCostAmount: 3.5, paymentPlanCostAmountVat: 1.2, - recipientEmail: 'test@buckaroo.nl', + recipientemail: 'test@buckaroo.nl', }) .request() .then((data) => { @@ -217,7 +219,7 @@ describe('Testing Credit Management', () => { test('pauseInvoice', async () => { await creditManagement .pauseInvoice({ - invoice: 'd42', + invoice: uniqid(), }) .request() .then((data) => { @@ -227,20 +229,21 @@ describe('Testing Credit Management', () => { }); export const creditManagementTestInvoice = (append: object = {}): IInvoice => { return { + invoice: uniqid(), applyStartRecurrent: false, invoiceAmount: 10, invoiceAmountVAT: 1, invoiceDate: '2022-01-01', dueDate: '2030-01-01', - schemeKey: '2amq34', + schemeKey: 'XXXXXX', maxStepIndex: 1, allowedServices: 'ideal,mastercard', debtor: { - code: 'johnsmith4', + code: 'XXXXXXXX', }, - email: 'youremail@example.nl', + email: 'test@buckaroo.nl', phone: { - mobile: '06198765432', + mobile: '0612345678', }, person: { culture: 'nl-NL', @@ -248,20 +251,20 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { initials: 'JS', firstName: 'Test', lastNamePrefix: 'Jones', - lastName: 'Aflever', + lastName: 'Acceptatie', gender: Gender.MALE, }, company: { culture: 'nl-NL', - name: 'My Company Corporation', + name: 'Buckaroo B.V.', vatApplicable: true, - vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741', + vatNumber: 'NLXXXXXXXXXXB01', + chamberOfCommerce: 'XXXXXX41', }, address: { - street: 'Hoofdtraat', - houseNumber: '90', - houseNumberAdditional: 'A', + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', zipcode: '8441ER', city: 'Heerenveen', state: 'Friesland', diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index ac7d08dd..2c747572 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -1,11 +1,12 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('eps'); describe('Testing Eps methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10.1, + amountDebit: 100, }) .request() .then((response) => { @@ -15,8 +16,9 @@ describe('Testing Eps methods', () => { test('Refund', async () => { method .refund({ - amountCredit: 10.1, - originalTransactionKey: '1234567890', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((response) => { diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index bc4fb9e2..20cc3945 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { ServiceCode } from '../../src'; const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { @@ -13,10 +14,10 @@ describe('Testing Emandates methods', () => { test('CreateMandate', async () => { method .createMandate({ - debtorReference: 'klant1234', + debtorReference: 'XXXXXXXXX', language: 'nl', continueOnIncomplete: true, - purchaseId: 'purchaseid1234', + purchaseId: 'XXXXXXXXXXXXXX', sequenceType: 0, }) .request() @@ -26,7 +27,7 @@ describe('Testing Emandates methods', () => { }); test('GetStatus', async () => { method - .status({ mandateId: '1DC014098EC5C1F40AD803B83A425153BBC' }) + .status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) .request() .then((response) => { expect(response.isSuccess()).toBeTruthy(); @@ -35,7 +36,7 @@ describe('Testing Emandates methods', () => { test('ModifyMandate', async () => { method .modifyMandate({ - originalMandateId: '1DC014098EC5C1F40AD803B83A425153BBC', + originalMandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', continueOnIncomplete: true, }) .request() @@ -45,9 +46,10 @@ describe('Testing Emandates methods', () => { }); test('CancelMandate', async () => { method + .setPaymentName('emandateb2b' as ServiceCode) .cancelMandate({ - mandateId: '1DC014098EC5C1F40AD803B83A425153BBC', - purchaseId: 'purchaseid1234', + mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + purchaseId: 'XXXXXXXXXXXXXX', }) .request() .then((response) => { diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index 2f624487..222695dd 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('boekenbon'); @@ -6,8 +7,8 @@ describe('GiftCard methods', () => { test('Pay', async () => { const responsePay = await method .pay({ - amountDebit: 10, - intersolveCardnumber: '0000000000000000001', + amountDebit: 100, + intersolveCardnumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', intersolvePIN: '500', }) .request(); @@ -15,7 +16,7 @@ describe('GiftCard methods', () => { const responseRemainderPay = await buckarooClientTest .method('ideal') .payRemainder({ - amountDebit: 10.1, + amountDebit: 100, issuer: 'ABNANL2A', invoice: responsePay.data.invoice, originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, @@ -26,10 +27,11 @@ describe('GiftCard methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 5, - originalTransactionKey: '9F99B530DA5449EB919D27351D28BDF2', - email: '', - lastName: '', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + email: 'test@buckaroo.nl', + lastName: 'Acceptatie', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index 5a3b8a4c..4f1eee34 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -6,8 +6,8 @@ describe('Testing Giropay methods', () => { test('Pay', async () => { await method .pay({ - bic: 'GENODETT488', - amountDebit: 10.1, + bic: 'XXXXXXXXX', + amountDebit: 100, }) .request() .then((response) => { @@ -17,9 +17,9 @@ describe('Testing Giropay methods', () => { test('Refund', async () => { await method .refund({ - amountCredit: 10, + amountCredit: 0.01, invoice: uniqid(), - originalTransactionKey: '2D04704995B74D679AACC59F87XXXXXX', + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((response) => { diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index 80c3b7e0..bcebb901 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -11,7 +11,7 @@ describe('testing Ideal methods', () => { test('Pay Simple Payload', () => { return ideal .pay({ - amountDebit: 10.1, + amountDebit: 100, issuer: 'ABNANL2A', continueOnIncomplete: false, additionalParameters: { @@ -29,8 +29,8 @@ describe('testing Ideal methods', () => { .refund({ order: uniqid(), invoice: uniqid(), - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', - amountCredit: 4.23, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountCredit: 0.01, clientIP: getIPAddress(), additionalParameters: { initiated_by_magento: '1', @@ -45,8 +45,9 @@ describe('testing Ideal methods', () => { test('InstantRefund', () => { return ideal .instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/Idin.test.ts b/tests/PaymentMethods/Idin.test.ts new file mode 100644 index 00000000..711a15f1 --- /dev/null +++ b/tests/PaymentMethods/Idin.test.ts @@ -0,0 +1,38 @@ +import buckarooClientTest from '../BuckarooClient.test'; + +const method = buckarooClientTest.method('idin'); + +describe('Idin methods', () => { + test('Verify', async () => { + await method + .verify({ + issuer: 'BANKNL2Y', + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + + test('Identify', async () => { + await method + .identify({ + issuer: 'BANKNL2Y', + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); + + test('Login', async () => { + await method + .login({ + issuer: 'BANKNL2Y', + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); +}); \ No newline at end of file diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 0d0a848a..4ecd1abd 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; import { IPay } from '../../src/PaymentMethods/In3/Models/Pay'; import RecipientCategory from '../../src/Constants/RecipientCategory'; @@ -17,11 +17,9 @@ describe('Testing In3 methods', () => { test('Refund', async () => { await in3 .refund({ - amountCredit: 42, - originalTransactionKey: '', - merchantImageUrl: '', - summaryImageUrl: '', - articles: [], + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -31,32 +29,32 @@ describe('Testing In3 methods', () => { }); const payload: IPay = { - amountDebit: 52.3, + amountDebit: 100, description: 'in3 pay', order: uniqid(), invoice: uniqid(), - clientIP: '127.0.0.1', + clientIP: getIPAddress(), billing: { recipient: { category: RecipientCategory.PERSON, - initials: 'J', - firstName: 'John', - lastName: 'Dona', + initials: 'TA', + firstName: 'Test', + lastName: 'Acceptatie', birthDate: '1990-01-01', - customerNumber: '12345', - companyName: 'Buckaroo', - chamberOfCommerce: '123456', + customerNumber: 'XXXXX', + companyName: 'Buckaroo B.V.', + chamberOfCommerce: 'XXXXXX41', }, address: { street: 'Hoofdstraat', - houseNumber: '13', + houseNumber: '80', houseNumberAdditional: 'a', - zipcode: '1234AB', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, phone: { - mobile: '0698765433', + mobile: '0612345678', }, email: 'test@buckaroo.nl', }, @@ -64,16 +62,16 @@ const payload: IPay = { recipient: { category: RecipientCategory.PERSON, careOf: 'J', - firstName: 'John', - lastName: 'Dona', - chamberOfCommerce: '123456', + firstName: 'Test', + lastName: 'Acceptatie', + chamberOfCommerce: 'XXXXXX41', }, address: { - street: 'Kalverstraat', - houseNumber: '13', - houseNumberAdditional: 'b', - zipcode: '4321EB', - city: 'Amsterdam', + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', + zipcode: '8441ER', + city: 'Heerenveen', country: 'NL', }, }, diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index f7e6c4a1..0c6e22a3 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -1,6 +1,7 @@ import buckarooClientTest from '../BuckarooClient.test'; import Gender from '../../src/Constants/Gender'; import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { getIPAddress, uniqid } from '../../src/Utils/Functions'; const capayable = buckarooClientTest.method('capayable'); @@ -16,8 +17,9 @@ describe('Testing capayable methods', () => { test('Refund', async () => { await capayable .refund({ - amountCredit: 42, - originalTransactionKey: '', + invoice: uniqid(), + amountCredit: paymentPayload.amountDebit, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { @@ -35,27 +37,27 @@ describe('Testing capayable methods', () => { }); const paymentPayload = { - clientIP: '127.0.0.0', - description: 'fdsfsdfdsf', - amountDebit: 32, + clientIP: getIPAddress(), + description: 'Test', + amountDebit: 100, customerType: RecipientCategory.COMPANY, invoiceDate: '22-01-2018', customer: { gender: Gender.FEMALE, culture: 'nl-NL', - initials: 'J.S.', - lastName: 'Aflever', + initials: 'TA', + lastName: 'Acceptatie', birthDate: '1990-01-01', }, company: { - companyName: 'My Company B.V.', - chamberOfCommerce: '123456', + companyName: 'Buckaroo B.V.', + chamberOfCommerce: 'XXXXXX41', }, address: { street: 'Hoofdstraat', - houseNumber: '2', + houseNumber: '80', houseNumberSuffix: 'a', - zipcode: '8441EE', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index 8bb76688..afc4ae43 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('KBCPaymentButton'); @@ -6,7 +7,7 @@ describe('Testing KBC methods', () => { test('Pay', async () => { await method .pay({ - amountDebit: 10, + amountDebit: 100, }) .request() .then((response) => { @@ -16,8 +17,9 @@ describe('Testing KBC methods', () => { test('Refund', async () => { method .refund({ - amountCredit: 10, - originalTransactionKey: 'B5675356904444F3965C33D280591C74', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((response) => { diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index a21696d0..d2b4fab0 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -14,8 +14,11 @@ describe('Testing Klarna methods', () => { }); }); test('PayInInstallments', async () => { + const clonedPayload = JSON.parse(JSON.stringify(payload)); + clonedPayload.currency = 'GBP'; + clonedPayload.billing.address.country = 'GB'; await klarna - .payInInstallments(payload) + .payInInstallments(clonedPayload) .request() .then((res) => { expect(res).toBeDefined(); @@ -24,27 +27,27 @@ describe('Testing Klarna methods', () => { }); let payload: IPay = { - amountDebit: 50.3, + amountDebit: 100, invoice: uniqid(), order: uniqid(), billing: { recipient: { category: RecipientCategory.PERSON, gender: 'female', - firstName: 'John', - lastName: 'Do', + firstName: 'Test', + lastName: 'Acceptatie', birthDate: '1990-01-01', }, address: { street: 'Hoofdstraat', - houseNumber: '13', + houseNumber: '80', houseNumberAdditional: 'a', - zipcode: '1234AB', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, phone: { - mobile: '0698765433', + mobile: '0612345678', }, email: 'test@buckaroo.nl', }, @@ -52,16 +55,16 @@ let payload: IPay = { recipient: { category: RecipientCategory.COMPANY, gender: 'male', - firstName: 'John', - lastName: 'Do', + firstName: 'Test', + lastName: 'Acceptatie', birthDate: '1990-01-01', }, address: { - street: 'Kalverstraat', - houseNumber: '13', - houseNumberAdditional: 'b', - zipcode: '4321EB', - city: 'Amsterdam', + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', + zipcode: '8441ER', + city: 'Heerenveen', country: 'NL', }, email: 'test@buckaroo.nl', diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 7a5e2294..b2d836d5 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import gender from '../../src/Constants/Gender'; +import Gender from '../../src/Constants/Gender'; const klarnaKp = buckarooClientTest.method('klarnakp'); @@ -7,8 +7,8 @@ describe('KlarnaKp', () => { test('Pay', async () => { await klarnaKp .pay({ - amountDebit: 50.3, - reservationNumber: '2377577452', + amountDebit: 100, + reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((info) => { @@ -18,38 +18,23 @@ describe('KlarnaKp', () => { test('Reserve', async () => { await klarnaKp .reserve({ - gender: gender.MALE, + gender: Gender.MALE, operatingCountry: 'NL', pno: '01011990', billing: { recipient: { - firstName: 'John', - lastName: 'Do', + firstName: 'Test', + lastName: 'Acceptatie', }, address: { - street: 'Neherkade', - houseNumber: '1', - zipcode: '2521VA', - city: 'Gravenhage', + street: 'Hoofdstraat', + zipcode: '8441ER', + city: 'Heerenveen', country: 'NL', }, phone: { mobile: '0612345678', }, - email: 'youremail@example.nl', - }, - shipping: { - recipient: { - firstName: 'John', - lastName: 'Do', - }, - address: { - street: 'Rosenburglaan', - houseNumber: '216', - zipcode: '4385 JM', - city: 'Vlissingen', - country: 'NL', - }, email: 'test@buckaroo.nl', }, articles: [ @@ -68,10 +53,6 @@ describe('KlarnaKp', () => { price: 10.1, }, ], - additionalParameters: { - initiated_by_magento: '1', - service_action: 'something', - }, }) .request() .then((info) => { @@ -80,7 +61,9 @@ describe('KlarnaKp', () => { }); test('Cancel', async () => { await klarnaKp - .cancel({}) + .cancel({ + reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', + }) .request() .then((info) => { expect(info).toBeDefined(); diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index ac906c36..e66606e7 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,4 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const marketplaces = buckarooClientTest.method('marketplaces'); const ideal = buckarooClientTest.method('ideal'); @@ -14,22 +15,22 @@ describe('Testing Marketplaces methods', () => { }, sellers: [ { - accountId: '789C60F316D24B088ACD471', + accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', amount: 50, description: '', }, { - accountId: '369C60F316D24B088ACD238', + accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', amount: 45, description: '', }, ], }); return ideal - .combine(marketplaces.getPayload()) + .combine(marketplaces) .pay({ issuer: 'ABNANL2A', - amountDebit: 95, + amountDebit: 100, }) .request() .then((response) => { @@ -39,14 +40,14 @@ describe('Testing Marketplaces methods', () => { test('transfer', async () => { marketplaces .transfer({ - originalTransactionKey: 'D3732474ED0', + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', marketplace: { amount: 10, description: 'INV0001 Commission Marketplace', }, sellers: [ { - accountId: '789C60F316D24B088ACD471', + accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', amount: 50, description: 'INV001 Payout Make-Up Products BV', }, @@ -61,14 +62,18 @@ describe('Testing Marketplaces methods', () => { marketplaces.refundSupplementary({ sellers: [ { - accountId: '789C60F316D24B088ACD471', + accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', description: 'INV001 Payout Make-Up Products BV', }, ], }); ideal .combine(marketplaces) - .refund({ originalTransactionKey: 'dasda', amountCredit: 10 }) + .refund({ + invoice: uniqid(), + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountCredit: 0.01, + }) .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts index 573be726..65f0de6e 100644 --- a/tests/PaymentMethods/Mbway.test.ts +++ b/tests/PaymentMethods/Mbway.test.ts @@ -5,7 +5,7 @@ describe('Mbway methods', () => { test('Pay', () => { return method .pay({ - amountDebit: 0.1, + amountDebit: 100, }) .request() .then((response) => { diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts index b9260887..3d7dd2c8 100644 --- a/tests/PaymentMethods/Multibanco.test.ts +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -5,7 +5,7 @@ describe('Multibanco methods', () => { await buckarooClientTest .method('multibanco') .pay({ - amountDebit: 50.3, + amountDebit: 100, }) .request() .then((info) => { diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts new file mode 100644 index 00000000..e453734f --- /dev/null +++ b/tests/PaymentMethods/NoService.test.ts @@ -0,0 +1,21 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; + +const method = buckarooClientTest.method('noservice'); + +describe('NoService methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 100, + invoice: uniqid(), + servicesSelectableByClient: 'ideal,bancontactmrcash,paypal', + servicesExcludedForClient: 'ideal', + continueOnIncomplete: true, + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); +}); \ No newline at end of file diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 3e7cec9e..737d5f5d 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -8,18 +8,19 @@ describe('PayPerEmail methods', () => { test('paymentInvitation', async () => { await method .paymentInvitation({ - amountDebit: 10, + currency: 'EUR', + amountDebit: 100, order: uniqid(), invoice: uniqid(), merchantSendsEmail: false, - email: 'johnsmith@gmail.com', + email: 'test@buckaroo.nl', expirationDate: '2030-01-01', paymentMethodsAllowed: 'ideal,mastercard,paypal', attachment: '', customer: { gender: Gender.FEMALE, - firstName: 'John', - lastName: 'Smith', + firstName: 'Test', + lastName: 'Acceptatie', }, }) .request() diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index f911b78a..a10f52d6 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,12 +1,13 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const payconiq = buckarooClientTest.method('payconiq'); describe('Payconiq', () => { test('Pay', async () => { await payconiq .pay({ - amountDebit: 50.3, - order: '123456', + amountDebit: 100, + order: uniqid(), }) .request() .then((info) => { @@ -16,8 +17,9 @@ describe('Payconiq', () => { test('Refund', async () => { await payconiq .refund({ - amountCredit: 50.3, - originalTransactionKey: '123456', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((info) => { @@ -27,8 +29,9 @@ describe('Payconiq', () => { test('InstantRefund', async () => { await payconiq .instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((data) => { diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 3070cf01..d14541ce 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,15 +1,18 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; + require('../BuckarooClient.test'); -import PayByBank from '../../src/PaymentMethods/PayByBank'; -const paymentInitiation = new PayByBank('PayByBank'); +const method = buckarooClientTest.method('PayByBank'); -describe('PayByBank methods', () => { +describe('PaymentInitiation methods', () => { test('Pay', async () => { - await paymentInitiation + await method .pay({ - amountDebit: 50.3, - order: '123456', - issuer: 'INGBNL2A', + issuer: 'RABONL2U', + amountDebit: 100, + order: uniqid(), + invoice: uniqid(), countryCode: 'NL', }) .request() @@ -18,10 +21,11 @@ describe('PayByBank methods', () => { }); }); test('Refund', async () => { - await paymentInitiation + await method .refund({ - amountCredit: 50.3, - originalTransactionKey: '123456', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((info) => { diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 72845d26..1e960c10 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,5 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import Paypal from '../../src/PaymentMethods/Paypal'; +import { uniqid } from '../../src/Utils/Functions'; require('../BuckarooClient.test'); @@ -9,7 +10,7 @@ describe('Paypal', () => { test('Pay', async () => { await method .pay({ - amountDebit: 50.3, + amountDebit: 100, }) .request() .then((info) => { @@ -19,8 +20,9 @@ describe('Paypal', () => { test('Refund', async () => { await method .refund({ - amountCredit: 50.3, - originalTransactionKey: '123456', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((info) => { @@ -31,17 +33,17 @@ describe('Paypal', () => { buckarooClientTest.method('subscriptions').createCombined({}); await method .extraInfo({ - amountDebit: 50.3, + amountDebit: 100, address: { - street: 'Hoofstraat 90', + street: 'Hoofdstraat', street2: 'Street 2', city: 'Heerenveen', state: 'Friesland', - zipcode: '8441AB', + zipcode: '8441ER', country: 'NL', }, addressOverride: false, - costumer: { name: 'John' }, + customer: { name: 'Test Acceptatie' }, noShipping: '0', phone: { mobile: '0612345678' }, }) diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index f1f444d4..5e0c2e6c 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -1,12 +1,34 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import Gender from '../../src/Constants/Gender'; + require('../BuckarooClient.test'); -import PiM from '../../src/PaymentMethods/PiM'; -const pim = new PiM(); +const method = buckarooClientTest.method('pim'); describe('PiM', () => { test('generate', async () => { - await pim.generate().then((info) => { - expect(info).toBeDefined(); - }); + await method + .generate({ + amountDebit: 100, + description: 'Omschrijving', + title: 'Titel', + return: { + nickname: 'test', + initials: 'TA', + firstName: 'Test', + lastName: 'Acceptatie', + birthDate: '01-01-1990', + gender: Gender.MALE, + email: 'test@buckaroo.nl', + }, + result: { + title: 'success', + text: 'bedankt', + }, + }) + .request() + .then((info) => { + expect(info).toBeDefined(); + }); }); }); diff --git a/tests/PaymentMethods/Pos.test.ts b/tests/PaymentMethods/Pos.test.ts new file mode 100644 index 00000000..7cb03f6b --- /dev/null +++ b/tests/PaymentMethods/Pos.test.ts @@ -0,0 +1,19 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; + +const method = buckarooClientTest.method('pospayment'); + +describe('POS methods', () => { + test('Pay', async () => { + await method + .pay({ + amountDebit: 100, + invoice: uniqid(), + terminalId: '50000001', + }) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); + }); +}); \ No newline at end of file diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 3482c22b..29a607a8 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,18 +1,20 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; + require('../BuckarooClient.test'); -import Przelewy24 from '../../src/PaymentMethods/Przelewy24'; -const method = new Przelewy24('Przelewy24'); +const method = buckarooClientTest.method('przelewy24'); describe('Przelewy24', () => { test('Pay', async () => { method .pay({ - amountDebit: 50.3, + amountDebit: 100, customer: { - firstName: 'test', - lastName: 'test', + firstName: 'Test', + lastName: 'Acceptatie', }, - email: 'test@hotmail.com', + email: 'test@buckaroo.nl', }) .request() .then((res) => { @@ -22,8 +24,9 @@ describe('Przelewy24', () => { test('Refund', async () => { await method .refund({ - amountCredit: 50.3, - originalTransactionKey: '123456', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((info) => { diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index 42295c05..f5645bc4 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -1,40 +1,29 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; +import { IPay } from '../../src/PaymentMethods/SEPA/Models/Pay'; + require('../BuckarooClient.test'); -import SEPA from '../../src/PaymentMethods/SEPA'; -const method = new SEPA(); +const method = buckarooClientTest.method('sepadirectdebit'); + +const paymentPayload: IPay = { + invoice: uniqid(), + amountDebit: 100, + iban: 'NLXXTESTXXXXXXXXXX', + bic: 'XXXXXXXXX', + collectdate: '2022-12-01', + mandateReference: 'XXXXXXXXXXXXXXX', + mandateDate: '2022-07-03', + customer: { + name: 'Test Acceptatie', + }, +}; -describe('SEPA', () => { +describe('SEPA methods', () => { test('Pay', async () => { await method - .pay({ - additionalParameters: undefined, - amountDebit: 0, - clientIP: undefined, - collectDate: '', - continueOnIncomplete: 0, - culture: '', - currency: '', - customParameters: undefined, - customerBIC: '', - customerIBAN: '', - customeraccountname: '', - description: '', - invoice: '', - mandateDate: '', - mandateReference: '', - order: '', - originalTransactionKey: '', - originalTransactionReference: '', - pushURL: '', - pushURLFailure: '', - returnURL: '', - returnURLCancel: '', - returnURLError: '', - returnURLReject: '', - servicesExcludedForClient: '', - servicesSelectableByClient: '', - startRecurrent: false, - }) + .pay(paymentPayload) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -42,21 +31,18 @@ describe('SEPA', () => { test('Refund', async () => { await method .refund({ - amountCredit: 50.3, - originalTransactionKey: '', + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); }); test('Authorize', async () => { await method - .authorize({ - amountDebit: 0, - collectDate: '', - customerIBAN: '', - customeraccountname: '', - }) + .authorize(paymentPayload) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -64,10 +50,12 @@ describe('SEPA', () => { test('PayRecurrent', async () => { await method .payRecurrent({ - collectDate: '', - amountDebit: 50.3, - originalTransactionKey: '', + invoice: uniqid(), + collectDate: '2030-07-03', + amountDebit: 100, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -75,44 +63,26 @@ describe('SEPA', () => { test('ExtraInfo', async () => { await method .extraInfo({ - additionalParameters: undefined, - amountDebit: 0, - city: '', - clientIP: undefined, - collectDate: '', - contractID: '', - country: '', - culture: '', - currency: '', - customParameters: undefined, - customerBIC: '', - customerCode: '', - customerIBAN: '', - customerName: '', - customerReferencePartyCode: '', - customerReferencePartyName: '', - customeraccountname: '', - description: '', - houseNumber: '', - houseNumberSuffix: '', - invoice: '', - mandateDate: '', - mandateReference: '', - order: '', - originalTransactionKey: '', - originalTransactionReference: '', - pushURL: '', - pushURLFailure: '', - returnURL: '', - returnURLCancel: '', - returnURLError: '', - returnURLReject: '', - servicesExcludedForClient: '', - servicesSelectableByClient: '', - startRecurrent: false, - street: '', - zipcode: '', + amountDebit: 100, + invoice: uniqid(), + iban: 'NLXXTESTXXXXXXXXXX', + bic: 'XXXXXXXXX', + contractID: 'Test', + mandateDate: '2022-07-03', + customerReferencePartyName: 'Test', + customer: { + name: 'Test Acceptatie', + }, + address: { + street: 'Hoofdstraat', + houseNumber: '80', + houseNumberAdditional: 'a', + zipcode: '8441ER', + city: 'Heerenveen', + country: 'NL', + }, }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -120,9 +90,12 @@ describe('SEPA', () => { test('Emandates', async () => { await method .payWithEmandate({ - mandateReference: '', - amountDebit: 50.3, + order: uniqid(), + invoice: uniqid(), + mandateReference: 'XXXXXXXXXXXXXXX', + amountDebit: 100, }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index a5de8680..efa7a387 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -1,15 +1,18 @@ +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; + require('../BuckarooClient.test'); -import Sofort from '../../src/PaymentMethods/Sofort'; -const method = new Sofort(); +const method = buckarooClientTest.method('sofortueberweisung'); describe('Sofort', () => { test('Pay', async () => { - await method + return await method .pay({ - amountDebit: 50.3, - order: '123456', + amountDebit: 100, + order: uniqid(), }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -17,9 +20,11 @@ describe('Sofort', () => { test('Refund', async () => { await method .refund({ - amountCredit: 50.3, - originalTransactionKey: '123456', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -28,9 +33,11 @@ describe('Sofort', () => { test('InstantRefund', async () => { await method .instantRefund({ - amountCredit: 4.23, - originalTransactionKey: '97DC0A03BBDF4DAAAC694D7FEC8785E1', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 081401d7..c78e1157 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,5 +1,4 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { describe } from 'node:test'; const subscription = buckarooClientTest.method('subscriptions'); @@ -8,25 +7,25 @@ describe('Subscription methods', () => { return subscription .create({ additionalParameters: { - signature: '123213', + signature: 'XXXXXXXX', }, ratePlans: { add: { startDate: '2024-07-23', - ratePlanCode: 'zfv59mmy', + ratePlanCode: 'XXXXXXXX', }, }, ratePlanCharges: { add: { - ratePlanChargeCode: 'test', + ratePlanChargeCode: 'XXXXXXXX', }, }, - configurationCode: 'gfyh9fe4', + configurationCode: 'XXXXXXXX', configuration: { - name: 'owiejr', + name: 'XXXXXXXX', }, debtor: { - code: 'johnsmith4', + code: 'XXXXXXXX', }, }) .request() @@ -38,11 +37,11 @@ describe('Subscription methods', () => { subscription .update({ email: 'test@buckaroo.nl', - subscriptionGuid: 'FC512FC9CC3A485D8CF3D1804FF6xxxx', - configurationCode: '9wqe32ew', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + configurationCode: 'XXXXXXXX', ratePlan: { update: { - ratePlanGuid: 'F075470B1BB24B9291943A888A2Fxxxx', + ratePlanGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', startDate: '2022-01-01', endDate: '2030-01-01', }, @@ -58,30 +57,30 @@ describe('Subscription methods', () => { pushURL: 'https://buckaroo.dev/push', includeTransaction: false, transactionVatPercentage: 5, - configurationCode: 'gfyh9fe4', + configurationCode: 'XXXXXXXX', email: 'test@buckaroo.nl', ratePlans: { add: { startDate: '2033-01-01', - ratePlanCode: '9863hdcj', + ratePlanCode: 'XXXXXXXX', }, }, phone: { mobile: '0612345678', }, debtor: { - code: 'johnsmith4', + code: 'XXXXXXXX', }, company: { culture: 'nl-NL', - companyName: 'My Company Coporation', + companyName: 'Buckaroo B.V.', vatApplicable: true, - vatNumber: 'NL140619562B01', - chamberOfCommerce: '20091741', + vatNumber: 'NLXXXXXXXXXXB01', + chamberOfCommerce: 'XXXXXX41', }, address: { street: 'Hoofdstraat', - houseNumber: '90', + houseNumber: '80', zipcode: '8441ER', city: 'Heerenveen', country: 'NL', @@ -91,7 +90,7 @@ describe('Subscription methods', () => { .combine('ideal') .pay({ issuer: 'ABNANL2A', - amountDebit: 10, + amountDebit: 100, startRecurrent: true, }) .request() @@ -102,13 +101,13 @@ describe('Subscription methods', () => { test('Update Combined Subscription', async () => { subscription.updateCombined({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }); subscription .combine('ideal') .pay({ issuer: 'ABNANL2A', - amountDebit: 10, + amountDebit: 100, }) .request() .then((data) => { @@ -118,29 +117,29 @@ describe('Subscription methods', () => { test('Stop Subscription', async () => { const stop = await subscription.stop({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }); expect(stop).toBeDefined(); }); test('Subscription Info', async () => { const info = await subscription.info({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }); expect(info).toBeDefined(); }); test('Delete Subscription Config', async () => { await subscription .deletePaymentConfig({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((res) => { - expect(res.httpResponse.statusCode === 200).toBeTruthy(); + expect(res.httpResponse.status === 200).toBeTruthy(); }); }); test('Subscription Pause', async () => { const pause = await subscription.pause({ - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', resumeDate: '2030-01-01', }); expect(pause).toBeDefined(); @@ -148,7 +147,7 @@ describe('Subscription methods', () => { test('Subscription Resume', async () => { const resume = await subscription.resume({ resumeDate: '2030-01-01', - subscriptionGuid: '515461997AD34C50881D74157E38A64D', + subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }); expect(resume).toBeDefined(); }); diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 5b5ee80d..8a29968b 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -1,14 +1,18 @@ -require('../BuckarooClient.test'); -import SurePay from '../../src/PaymentMethods/Surepay'; +import buckarooClientTest from '../BuckarooClient.test'; -const method = new SurePay(); +const method = buckarooClientTest.method('surepay'); -describe('Sofort', () => { +describe('SurePay methods', () => { test('Verify', async () => { await method .verify({ - customeraccountname: 'string', + amountDebit: 100, + bankAccount: { + iban: 'NLXXTESTXXXXXXXXXX', + accountName: 'Test Acceptatie', + }, }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index a560ee72..ecdfbbc4 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -1,28 +1,56 @@ -require('../BuckarooClient.test'); +import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; -import Thunes from '../../src/PaymentMethods/Thunes'; - -const thunes = new Thunes(); +const method = buckarooClientTest.method('thunes'); describe('Thunes methods', () => { test('authorize', async () => { - thunes.authorize({ amountDebit: 0 }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .authorize({ + amountDebit: 100, + order: uniqid(), + invoice: uniqid(), + name: 'monizzeecovoucher', + articles: [ + { + identifier: 'Articlenumber1', + description: 'Articledesciption1', + price: '1', + }, + { + identifier: 'Articlenumber2', + description: 'Articledesciption2', + price: '2', + }, + ], + }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); test('capture', async () => { - thunes.capture({ amountDebit: 0, originalTransactionKey: '1' }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .capture({ amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); test('getStatus', async () => { - thunes.getStatus({ originalTransactionKey: '111111111111' }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); test('cancel', async () => { - thunes.cancel({ originalTransactionKey: '111111111111' }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); }); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 3ed45629..83b4f9e9 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,5 +1,6 @@ import Gender from '../../src/Constants/Gender'; import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('tinka'); describe('Tinka', () => { @@ -7,30 +8,27 @@ describe('Tinka', () => { await method .pay({ billing: { - recipient: { - lastNamePrefix: 'the', - }, - email: 'billingcustomer@buckaroo.nl', + email: 'test@buckaroo.nl', phone: { - mobile: '0109876543', + mobile: '0612345678', }, address: { street: 'Hoofdstraat', houseNumber: '80', - houseNumberAdditional: 'A', - zipcode: '8441EE', + houseNumberAdditional: 'a', + zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, }, customer: { gender: Gender.MALE, - firstName: 'Buck', - lastName: 'Aroo', + firstName: 'Test', + lastName: 'Acceptatie', initials: 'BA', birthDate: '1990-01-01', }, - amountDebit: 3.5, + amountDebit: 100, articles: [ { type: '1', @@ -56,8 +54,9 @@ describe('Tinka', () => { test('Refund', async () => { await method .refund({ - amountCredit: 3.5, - originalTransactionKey: '1234567890', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((res) => { diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 33ef22cb..495f016f 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -1,17 +1,16 @@ -require('../BuckarooClient.test'); -import Trustly from '../../src/PaymentMethods/Trustly'; +import buckarooClientTest from '../BuckarooClient.test'; -const method = new Trustly(); +const method = buckarooClientTest.method('trustly'); describe('Trustly', () => { test('Pay', async () => { await method .pay({ - amountDebit: 12, + amountDebit: 100, customer: { firstName: 'Test', lastName: 'Acceptatie', - country: 'NL', + countryCode: 'NL', }, }) .request() diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 7d213671..77764f34 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,11 +1,12 @@ import buckarooClientTest from '../BuckarooClient.test'; +import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('wechatpay'); describe('WechatPay', () => { test('Pay', async () => { await method .pay({ - amountDebit: 3.5, + amountDebit: 100, locale: 'en-US', }) .request() @@ -16,8 +17,9 @@ describe('WechatPay', () => { test('Refund', async () => { await method .refund({ - amountCredit: 3.5, - originalTransactionKey: '1234567890', + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) .request() .then((response) => { From ecb265e26c65c21e7f99031f6a7ecaf902462121 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 26 Oct 2023 10:26:33 +0200 Subject: [PATCH 26/52] fixed batch request test issue --- tests/Client.test.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/Client.test.ts b/tests/Client.test.ts index b7256733..ec4dad21 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -16,21 +16,22 @@ describe('Testing Buckaroo Client', () => { const creditManagement = client.method('CreditManagement3'); const sepaDirectDebit = client.method('sepadirectdebit'); for (let i = 0; i < 3; i++) { - creditManagement.createCombinedInvoice(creditManagementTestInvoice()); + const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); - sepaDirectDebit.combine(creditManagement).pay({ - invoice: uniqid(), - amountDebit: 10.1, - iban: 'NL13TEST0123456789', - bic: 'TESTNL2A', - collectdate: '2024-07-03', + const sepaRequest = sepaDirectDebit.combine(combinedInvoice.data).pay({ + iban: 'NL39RABO0300065264', + bic: 'RABONL2U', mandateReference: '1DCtestreference', mandateDate: '2022-07-03', + collectDate: '2020-07-03', + amountDebit: 10.1, customer: { name: 'John Smith', }, + invoice: uniqid('TestInvoice'), }); - transactionData.push(sepaDirectDebit.getPayload()); + + transactionData.push(sepaRequest.data); } await client.batch From ce31ed5d268ec43039febe14e32046c7e912f833 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 27 Oct 2023 15:48:39 +0200 Subject: [PATCH 27/52] few fixes --- src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts | 2 -- src/PaymentMethods/Klarna/index.ts | 3 ++- src/PaymentMethods/KlarnaKP/Models/IReserve.ts | 3 +-- src/PaymentMethods/Subscriptions/Models/ISubscription.ts | 4 ++-- tests/PaymentMethods/Billink.test.ts | 2 -- tests/PaymentMethods/PaymentInitiation.test.ts | 2 -- tests/PaymentMethods/Paypal.test.ts | 2 -- tests/PaymentMethods/PiM.test.ts | 2 -- tests/PaymentMethods/Przelewy24.test.ts | 2 -- tests/PaymentMethods/SEPA.test.ts | 2 -- tests/PaymentMethods/Sofort.test.ts | 2 -- tests/PaymentMethods/Trustly.test.ts | 2 +- 12 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts index 423b2e4b..3ab57cab 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -70,8 +70,6 @@ export class Pay extends ServiceParameter implements Omit { if (this.has(key + 'RatePlan')) { - this[key + 'RatePlan'] = val; + this.set(key + 'RatePlan', val); } }); } @@ -125,7 +125,7 @@ export class Subscription extends ServiceParameter implements ISubscription { set ratePlanCharges(value: IRatePlanCharges) { Object.entries(value).forEach(([key, val]) => { if (this.has(key + 'RatePlanCharge')) { - this[key + 'RatePlanCharge'] = val; + this.set(key + 'RatePlanCharge', val); } }); } diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index f64f79fd..ae5f9481 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -3,8 +3,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import RecipientCategory from '../../src/Constants/RecipientCategory'; import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('billink'); describe('Billink methods', () => { diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index d14541ce..9347690f 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,8 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('PayByBank'); describe('PaymentInitiation methods', () => { diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 1e960c10..e248fab5 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -2,8 +2,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import Paypal from '../../src/PaymentMethods/Paypal'; import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test'); - const method = new Paypal('paypal'); describe('Paypal', () => { diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index 5e0c2e6c..ad82d019 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -1,8 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import Gender from '../../src/Constants/Gender'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('pim'); describe('PiM', () => { diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 29a607a8..348d882e 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,8 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('przelewy24'); describe('Przelewy24', () => { diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index f5645bc4..b569a1ed 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -2,8 +2,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; import { IPay } from '../../src/PaymentMethods/SEPA/Models/Pay'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('sepadirectdebit'); const paymentPayload: IPay = { diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index efa7a387..e4913f91 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -1,8 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { uniqid } from '../../src/Utils/Functions'; -require('../BuckarooClient.test'); - const method = buckarooClientTest.method('sofortueberweisung'); describe('Sofort', () => { diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 495f016f..90ef3466 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -15,7 +15,7 @@ describe('Trustly', () => { }) .request() .then((response) => { - expect(response).toBeDefined(); + expect(response.isPendingProcessing()).toBeTruthy(); }); }); }); From cf687872dde95e8c9adf6a2c0b62fad2ba8547de Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 15:58:08 +0100 Subject: [PATCH 28/52] automatic API calls with optimal manual control --- src/PaymentMethods/Afterpay/index.ts | 5 +- .../AfterpayDigiAccept/index.ts | 5 +- src/PaymentMethods/Alipay/index.ts | 5 +- src/PaymentMethods/ApplePay/index.ts | 5 +- src/PaymentMethods/Bancontact/index.ts | 5 +- src/PaymentMethods/BankTransfer/index.ts | 5 +- src/PaymentMethods/Belfius/index.ts | 7 +- src/PaymentMethods/Billink/index.ts | 5 +- src/PaymentMethods/BuckarooVoucher/index.ts | 5 +- src/PaymentMethods/BuckarooWallet/index.ts | 5 +- src/PaymentMethods/CreditCard/index.ts | 5 +- src/PaymentMethods/CreditClick/index.ts | 5 +- src/PaymentMethods/CreditManagement/index.ts | 5 +- src/PaymentMethods/EPS/index.ts | 5 +- src/PaymentMethods/Emandates/index.ts | 5 +- src/PaymentMethods/GiftCard/index.ts | 5 +- src/PaymentMethods/Giropay/index.ts | 5 +- src/PaymentMethods/Ideal/index.ts | 25 +++--- src/PaymentMethods/IdealQR/index.ts | 5 +- src/PaymentMethods/Idin/index.ts | 2 +- src/PaymentMethods/In3/index.ts | 5 +- src/PaymentMethods/In3Old/index.ts | 5 +- src/PaymentMethods/KBC/index.ts | 5 +- src/PaymentMethods/Klarna/index.ts | 5 +- src/PaymentMethods/KlarnaKP/index.ts | 6 +- src/PaymentMethods/Marketplaces/index.ts | 9 +-- src/PaymentMethods/Mbway/index.ts | 5 +- src/PaymentMethods/Multibanco/index.ts | 5 +- src/PaymentMethods/NoService/index.ts | 5 +- src/PaymentMethods/PayByBank/index.ts | 6 +- src/PaymentMethods/PayPerEmail/index.ts | 5 +- src/PaymentMethods/Payconiq/index.ts | 5 +- src/PaymentMethods/Paypal/index.ts | 5 +- src/PaymentMethods/PiM/index.ts | 2 +- src/PaymentMethods/PointOfSale/index.ts | 5 +- src/PaymentMethods/Przelewy24/index.ts | 5 +- src/PaymentMethods/SEPA/index.ts | 5 +- src/PaymentMethods/Sofort/index.ts | 5 +- src/PaymentMethods/Subscriptions/index.ts | 5 +- src/PaymentMethods/Surepay/index.ts | 5 +- src/PaymentMethods/Thunes/index.ts | 5 +- src/PaymentMethods/Tinka/index.ts | 5 +- src/PaymentMethods/Trustly/index.ts | 5 +- src/PaymentMethods/WeChatPay/index.ts | 5 +- src/Request/Request.ts | 11 ++- src/Services/PayablePaymentMethod.ts | 6 +- src/Services/PaymentMethod.ts | 81 +++++++++++++------ src/Utils/MethodTypes.ts | 28 +++++-- src/buckaroo.ts | 12 +-- tests/PaymentMethods/AfterPay.test.ts | 21 ++--- .../PaymentMethods/AfterPayDigiAccept.test.ts | 27 +++---- tests/PaymentMethods/Alipay.test.ts | 2 - tests/PaymentMethods/ApplePay.test.ts | 3 - tests/PaymentMethods/Bancontact.test.ts | 15 +--- tests/PaymentMethods/BankTransfer.test.ts | 1 - tests/PaymentMethods/Belfius.test.ts | 2 + tests/PaymentMethods/Billink.test.ts | 21 ++--- tests/PaymentMethods/BuckarooVoucher.test.ts | 5 -- tests/PaymentMethods/BuckarooWallet.test.ts | 8 -- tests/PaymentMethods/CreditCard.test.ts | 10 --- tests/PaymentMethods/CreditClick.test.ts | 2 - tests/PaymentMethods/CreditManagment.test.ts | 55 ++++--------- tests/PaymentMethods/EPS.test.ts | 2 - tests/PaymentMethods/Emandate.test.ts | 23 ++---- tests/PaymentMethods/Giftcard.test.ts | 23 +++--- tests/PaymentMethods/GiroPay.test.ts | 2 - tests/PaymentMethods/Ideal.test.ts | 3 - tests/PaymentMethods/IdealQR.test.ts | 1 - tests/PaymentMethods/Idin.test.ts | 3 - tests/PaymentMethods/In3.test.ts | 8 +- tests/PaymentMethods/In3Old.test.ts | 19 ++--- tests/PaymentMethods/KBC.test.ts | 2 - tests/PaymentMethods/Klarna.test.ts | 24 +++--- tests/PaymentMethods/KlarnaKp.test.ts | 3 - tests/PaymentMethods/Marketplaces.test.ts | 11 +-- tests/PaymentMethods/Mbway.test.ts | 1 - tests/PaymentMethods/Multibanco.test.ts | 1 - tests/PaymentMethods/NoService.test.ts | 1 - tests/PaymentMethods/PayPerEmail.test.ts | 1 - tests/PaymentMethods/Payconiq.test.ts | 3 - .../PaymentMethods/PaymentInitiation.test.ts | 2 - tests/PaymentMethods/Paypal.test.ts | 3 - tests/PaymentMethods/PiM.test.ts | 1 - tests/PaymentMethods/Pos.test.ts | 1 - tests/PaymentMethods/Przelewy24.test.ts | 2 - tests/PaymentMethods/SEPA.test.ts | 22 ++--- tests/PaymentMethods/Sofort.test.ts | 3 - tests/PaymentMethods/Subscriptions.test.ts | 5 -- tests/PaymentMethods/SurePay.test.ts | 1 - tests/PaymentMethods/Thunes.test.ts | 20 ++--- tests/PaymentMethods/Tinka.test.ts | 4 +- tests/PaymentMethods/Trustly.test.ts | 1 - tests/PaymentMethods/WechatPay.test.ts | 2 - 93 files changed, 373 insertions(+), 377 deletions(-) diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 26f54931..81962288 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -3,7 +3,10 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefund, Refund } from './Model/Refund'; -export default class Afterpay extends PayablePaymentMethod { +export default class Afterpay extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Afterpay'; protected _serviceVersion = 1; diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 66efd936..386a7d7b 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -2,7 +2,10 @@ import IRequest, { IRefundRequest } from '../../Models/IRequest'; import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Model/Pay'; -export default class AfterpayDigiAccept extends PayablePaymentMethod { +export default class AfterpayDigiAccept< + Code extends 'afterpaydigiaccept', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'AfterpayDigiAccept'; protected _serviceVersion = 2; diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 8a8c1e00..dbe82363 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { ServiceParameter } from '../../Models/ServiceParameters'; -export default class Alipay extends PayablePaymentMethod { +export default class Alipay extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Alipay'; pay(payload: { useMobileView?: boolean } & IPaymentRequest) { diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 87fef5b0..4e6d1168 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -export default class ApplePay extends PayablePaymentMethod { +export default class ApplePay extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'ApplePay'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index a46aa9f1..8b2a0bb8 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models/IRequest'; -export default class Bancontact extends PayablePaymentMethod { +export default class Bancontact< + Code extends 'bancontactmrcash', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'Bancontact'; pay(payload: IPay) { diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 55266d8b..efb3f2e5 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models/IRequest'; -export default class BankTransfer extends PayablePaymentMethod { +export default class BankTransfer< + Code extends 'transfer', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'BankTransfer'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index fc4c1873..2ec0d8c9 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; -export default class Belfius extends PayablePaymentMethod { +export default class Belfius extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Belfius'; pay(payload: IPaymentRequest) { diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index d2819cbd..d9570082 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -3,7 +3,10 @@ import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; -export default class Billink extends PayablePaymentMethod { +export default class Billink extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Billink'; pay(payload: IPay) { diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index bdadccd6..04ea3b68 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -3,7 +3,10 @@ import { IPay, Pay } from './Models/Pay'; import IRequest from '../../Models/IRequest'; import { Create, ICreate } from './Models/Create'; -export default class BuckarooVoucher extends PayablePaymentMethod { +export default class BuckarooVoucher extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'BuckarooVoucher'; pay(payload: IPay) { diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 5ab90dfa..27ed1706 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IWallet, Wallet } from './Models/Wallet'; import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -export default class BuckarooWallet extends PayablePaymentMethod { +export default class BuckarooWallet< + Code extends 'BuckarooWalletCollecting', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'BuckarooWallet'; pay(payload: IWallet & IPaymentRequest) { diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index cfb3bfeb..66777918 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -3,7 +3,10 @@ import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest import { CardData, ICardData } from './Models/CardData'; import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; -export default class CreditCard extends PayablePaymentMethod { +export default class CreditCard< + Code extends 'CreditCard', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'CreditCard'; payEncrypted(payload: ICardData) { diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 894fdb37..c3078ab8 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; -export default class CreditClick extends PayablePaymentMethod { +export default class CreditClick< + Code extends 'creditclick', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'CreditClick'; pay(payload: IPay) { diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 735358f0..94ba0ca9 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -9,7 +9,10 @@ import IRequest from '../../Models/IRequest'; import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; import { ServiceParameter } from '../../Models/ServiceParameters'; -export default class CreditManagement extends PaymentMethod { +export default class CreditManagement< + Code extends 'CreditManagement3', + Manually extends boolean = false +> extends PaymentMethod { protected _paymentName = 'CreditManagement'; protected _serviceVersion = 1; protected _requiredFields = ['currency']; diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 8bfbd74d..70c0db6b 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,5 +1,8 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -export default class EPS extends PayablePaymentMethod { +export default class EPS extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'EPS'; } diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 0c25ad11..a272aef4 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -2,7 +2,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { IConfig } from '../../Utils/Types'; import { IMandate, Mandate } from './Models/Mandate'; -export default class Emandates extends PaymentMethod { +export default class Emandates extends PaymentMethod< + Code, + Manually +> { _requiredFields: Array = ['currency']; protected _paymentName = 'Emandates'; diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 24f8d181..c950c778 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import IPay, { Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; -export default class GiftCard extends PayablePaymentMethod { +export default class GiftCard extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'GiftCard'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 47746319..f15062a3 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; -export default class Giropay extends PayablePaymentMethod { +export default class Giropay extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Giropay'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index b73212aa..229a4b57 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -3,12 +3,15 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { RequestTypes } from '../../Constants/Endpoints'; import { IRefundRequest } from '../../Models/IRequest'; -export default class Ideal extends PayablePaymentMethod { +export default class Ideal extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Ideal'; protected _serviceVersion = 2; constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { - super(serviceCode); + super(serviceCode as Code); } pay(data: IPay) { @@ -20,16 +23,14 @@ export default class Ideal extends PayablePaymentMethod { } issuers() { - return this.specification(RequestTypes.Transaction) - .request() - .then((response) => { - return response - .getActionRequestParameters('Pay') - ?.find((item) => item.name === 'issuer') - ?.listItemDescriptions?.map((item) => { - return { [item.value]: item.description }; - }); - }); + return this.specification(RequestTypes.Transaction).then((response) => { + return response + .getActionRequestParameters('Pay') + ?.find((item) => item.name === 'issuer') + ?.listItemDescriptions?.map((item) => { + return { [item.value]: item.description }; + }); + }); } instantRefund(data: IRefundRequest) { diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 66ace8c0..8fc32238 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,7 +1,10 @@ import { Generate, IGenerate } from './Models/IGenerate'; import PaymentMethod from '../../Services/PaymentMethod'; -export default class IdealQR extends PaymentMethod { +export default class IdealQR extends PaymentMethod< + Code, + Manually +> { protected _paymentName = 'IdealQR'; generate(payload: IGenerate) { diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 5b78d8fa..d1724c52 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,7 +1,7 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { IPay, Pay } from './Models/Pay'; -export default class Idin extends PaymentMethod { +export default class Idin extends PaymentMethod { protected _paymentName = 'Idin'; identify(payload: IPay) { diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index 3144f2a9..a80a5c18 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import Pay from './Models/Pay'; -export default class In3 extends PayablePaymentMethod { +export default class In3 extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'In3'; pay(payload: IPaymentRequest) { diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index a1bd94df..0cd115ab 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; -export default class In3Old extends PayablePaymentMethod { +export default class In3Old extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'In3Old'; pay(payload: IPay) { diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 19451257..cf6dd080 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; -export default class KBC extends PayablePaymentMethod { +export default class KBC extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'KBC'; refund(payload: IRefundRequest) { diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 502fc8a0..c689478e 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,7 +1,10 @@ import { IPay, Pay } from './Models/Pay'; import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -export default class Klarna extends PayablePaymentMethod { +export default class Klarna extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Klarna'; pay(data: IPay) { diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index a0448cac..07bbeb49 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -2,8 +2,12 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/IPay'; import IRequest from '../../Models/IRequest'; import { IReserve, Reserve } from './Models/IReserve'; +import { ServiceCode } from '../../Utils'; -export default class KlarnaKP extends PayablePaymentMethod { +export default class KlarnaKP< + Code extends 'klarnakp', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'KlarnaKP'; protected _serviceVersion = 1; diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index f5657617..b9f6eb3f 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -2,11 +2,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; -export default class Marketplaces extends PaymentMethod { - get paymentName() { - return 'Marketplaces'; - } - +export default class Marketplaces extends PaymentMethod< + Code, + Manually +> { split(payload: ISplit) { this.setServiceList('Split', new Split(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index 4d4f4b2d..dbce0745 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,5 +1,8 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -export default class Mbway extends PayablePaymentMethod { +export default class Mbway extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'MB WAY'; } diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index 2b58b8c4..8900010c 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -1,5 +1,8 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -export default class MultiBanco extends PayablePaymentMethod { +export default class MultiBanco< + Code extends 'multibanco', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'MultiBanco'; } diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index fb717539..a249f287 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,6 +1,9 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -export default class NoService extends PayablePaymentMethod { +export default class NoService extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'noserivce'; get paymentName() { diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index a164bdff..baf7818e 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import IPay, { Pay } from './Models/IPay'; -export default class PayByBank extends PayablePaymentMethod { +export default class PayByBank extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'PayByBank'; pay(payload: IPay) { @@ -15,7 +18,6 @@ export default class PayByBank extends PayablePaymentMethod { issuers() { return this.specification() - .request() .then((response) => { return response .getActionRequestParameters('Pay') diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 700924b4..4cd98b5c 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,7 +1,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { IInvitation, Invitation } from './Models/Invitation'; -export default class PayPerEmail extends PaymentMethod { +export default class PayPerEmail extends PaymentMethod< + Code, + Manually +> { protected _paymentName = 'PayPerEmail'; paymentInvitation(payload: IInvitation) { diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index a7115888..46f79a6a 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; -export default class Payconiq extends PayablePaymentMethod { +export default class Payconiq extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Payconiq'; instantRefund(payload: IRefundRequest) { diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index f5453ca8..c093d85b 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -3,7 +3,10 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; -export default class Paypal extends PayablePaymentMethod { +export default class Paypal< + Code extends 'paypal', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'Paypal'; pay(payload: IPay) { diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index 78ec3d79..7d03e015 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,7 +1,7 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { Generate, IGenerate } from './Models/Generate'; -export default class PiM extends PaymentMethod { +export default class PiM extends PaymentMethod { protected _paymentName = 'pim'; protected _requiredFields = ['currency']; diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index a7c9ec23..157627a2 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/Pay'; -export default class PointOfSale extends PayablePaymentMethod { +export default class PointOfSale< + Code extends 'pospayment', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'PointOfSale'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 314a2d21..ac7ef150 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; -export default class Przelewy24 extends PayablePaymentMethod { +export default class Przelewy24< + Code extends 'przelewy24', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'Przelewy24'; pay(payload: IPay) { diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index e277cd8b..4687ad9b 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -5,7 +5,10 @@ import { IEmandate } from './Models/Emandate'; import { uniqid } from '../../Utils/Functions'; import { IPaymentRequest } from '../../Models/IRequest'; -export default class SEPA extends PayablePaymentMethod { +export default class SEPA< + Code extends 'sepadirectdebit', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'SEPA'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 404841ca..0a954d69 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,7 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -export default class Sofort extends PayablePaymentMethod { +export default class Sofort< + Code extends 'sofortueberweisung', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'Sofort'; protected _serviceVersion = 1; diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 833783f2..05d4c701 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -3,7 +3,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import IRequest from '../../Models/IRequest'; import { ResumeSubscription } from './Models/ResumeSubscription'; -export default class Subscriptions extends PaymentMethod { +export default class Subscriptions< + Code extends 'subscriptions', + Manually extends boolean = false +> extends PaymentMethod { protected _paymentName = 'Subscriptions'; protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 469fc45f..5f311422 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,7 +1,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { IVerify, Verify } from './Models/Verify'; -export default class Surepay extends PaymentMethod { +export default class Surepay extends PaymentMethod< + Code, + Manually +> { protected _paymentName = 'Surepay'; verify(payload: IVerify) { diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index ade4f9d3..6427ac88 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -2,7 +2,10 @@ import PaymentMethod from '../../Services/PaymentMethod'; import IRequest from '../../Models/IRequest'; type key = Required>; -export default class Thunes extends PaymentMethod { +export default class Thunes extends PaymentMethod< + Code, + Manually +> { protected _paymentName = 'Thunes'; getStatus(payload: key) { diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index 32cb8401..dac2e8d0 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; -export default class Tinka extends PayablePaymentMethod { +export default class Tinka extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Tinka'; pay(payload: IPay) { diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 215ab2cf..32eda03f 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; -export default class Trustly extends PayablePaymentMethod { +export default class Trustly extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Trustly'; pay(payload: IPay) { diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index f954063c..288fae1d 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -2,7 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; -export default class WeChatPay extends PayablePaymentMethod { +export default class WeChatPay< + Code extends 'wechatpay', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'WeChatPay'; pay(payload: IPay) { diff --git a/src/Request/Request.ts b/src/Request/Request.ts index f95e0b42..dd891adc 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -58,21 +58,26 @@ export default class Request< return new Request(RequestTypes.Data, HttpMethods.POST, new DataRequestData(payload), TransactionResponse); } - static Specification(type: RequestTypes.Data | RequestTypes.Transaction, data: IService[] | IService) { + static Specification( + type: RequestTypes.Data | RequestTypes.Transaction, + data: T + ): T extends IService[] + ? Request + : Request { if (Array.isArray(data)) { return new Request( type + `/Specifications`, HttpMethods.POST, new SpecificationRequestData(data), SpecificationRequestResponse - ); + ) as any; } return new Request( type + `/Specification/${data?.name}?serviceVersion=${data?.version}`, HttpMethods.GET, undefined, SpecificationRequestResponse - ); + ) as any; } static BatchTransaction(payload: IRequest[] = []) { diff --git a/src/Services/PayablePaymentMethod.ts b/src/Services/PayablePaymentMethod.ts index c13692dd..c29a5e89 100644 --- a/src/Services/PayablePaymentMethod.ts +++ b/src/Services/PayablePaymentMethod.ts @@ -3,8 +3,12 @@ import IRequest, { IPaymentRequest, IRefundRequest } from '../Models/IRequest'; import { uniqid } from '../Utils/Functions'; import { ServiceParameter } from '../Models/ServiceParameters'; import { IParameter } from '../Models/IParameters'; +import { ServiceCode } from '../Utils'; -export default abstract class PayablePaymentMethod extends PaymentMethod { +export default abstract class PayablePaymentMethod< + Code extends ServiceCode, + Manually extends boolean = false +> extends PaymentMethod { protected _requiredFields: Array = ['currency', 'returnURL', 'returnURLCancel', 'pushURL']; pay(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 8528d761..9262b43f 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -5,18 +5,21 @@ import Request from '../Request/Request'; import { IService, ServiceList } from '../Models/IServiceList'; import { ServiceParameter } from '../Models/ServiceParameters'; import { IParameter } from '../Models/IParameters'; -import { TransactionData } from '../Request/DataModels'; -import { PaymentMethodInstance, ServiceCode } from '../Utils/MethodTypes'; +import { DataRequestData, TransactionData } from '../Request/DataModels'; +import { PaymentMethodInstanceType, PaymentMethodRegistryType, ServiceCode } from '../Utils/MethodTypes'; +import { TransactionResponse } from '../Models/Response/TransactionResponse'; +import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; -export default abstract class PaymentMethod { +export default abstract class PaymentMethod { + public _isManually: Manually = false as Manually; protected _paymentName: string = ''; - protected _serviceCode?: ServiceCode; + protected _serviceCode?: Code; protected _serviceVersion: number = 0; protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; - constructor(serviceCode?: ServiceCode) { - this._serviceCode = serviceCode ?? (this.paymentName as ServiceCode); + constructor(serviceCode?: Code) { + this._serviceCode = (serviceCode ?? this.paymentName) as Code; } get serviceVersion() { @@ -27,17 +30,21 @@ export default abstract class PaymentMethod { this._serviceVersion = value; } - get serviceCode(): ServiceCode { - return this._serviceCode || 'noservice'; + get serviceCode(): Code { + return (this._serviceCode || 'noservice') as Code; } get paymentName() { return this._paymentName; } - setPaymentName(value: ServiceCode): this { - this._paymentName = value; - this._serviceCode = value; + public manually(): PaymentMethodRegistryType { + this._isManually = true as Manually; + return this as any; + } + + setServiceCode(value: ServiceCode): this { + this._serviceCode = value as Code; return this; } @@ -54,19 +61,15 @@ export default abstract class PaymentMethod { return this._payload.getServiceList(); } - public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { - return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); - } - - combine(data: Name): PaymentMethodInstance; + combine(data: Name): PaymentMethodInstanceType; combine(data: Payload): this; - combine(method: Method): this; + combine>(method: Method): this; combine(data: any): this { if (typeof data === 'string') { - const method: PaymentMethod = Buckaroo.Client.method(data as any); + const method: PaymentMethod = Buckaroo.Client.method(data as any); method.setPayload(this._payload); return method as any; } @@ -74,6 +77,18 @@ export default abstract class PaymentMethod { return this; } + public specification( + type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data + ): this['_isManually'] extends true ? any : Promise { + const request = Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); + + if (this._isManually) { + return request as any; + } + + return request.request() as any; + } + protected setRequiredFields(requiredFields: Array = this._requiredFields) { for (const fieldKey of requiredFields) { let field = this._payload[fieldKey] ?? (Buckaroo.Client.config as IRequest)[fieldKey]; @@ -106,13 +121,33 @@ export default abstract class PaymentMethod { return this; } - protected transactionRequest(payload?: IRequest) { + protected transactionRequest( + payload?: IRequest + ): this['_isManually'] extends true + ? Request + : Promise { this.setPayload(payload); - return Request.Transaction(this._payload); + const request = Request.Transaction(this._payload); + + if (this._isManually) { + return request as any; + } + + return request.request() as any; } - protected dataRequest(payload?: IRequest) { + protected dataRequest( + payload?: IRequest + ): this['_isManually'] extends true + ? Request + : Promise { this.setPayload(payload); - return Request.DataRequest(this._payload); + const request = Request.DataRequest(this._payload); + + if (this._isManually) { + return request as any; + } + + return request.request() as any; } -} +} \ No newline at end of file diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 62931520..47e0ef13 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,14 +1,26 @@ -import * as AllPaymentMethods from '../PaymentMethods/PaymentMethods'; +import * as AllRegisteredPaymentMethods from '../PaymentMethods/PaymentMethods'; -export type AvailablePaymentMethods = typeof AllPaymentMethods; -export type ServiceCode = keyof AvailablePaymentMethods; -export type PaymentMethodInstance = InstanceType; +type InstanceWithManualFlag = B extends true ? T & { _isManually: B } : T; -export function getMethod(code: Code): PaymentMethodInstance { - const methodClass = AllPaymentMethods[code]; +export type PaymentMethodTypeDictionary = typeof AllRegisteredPaymentMethods; +export type ServiceCode = keyof PaymentMethodTypeDictionary; + +export type PaymentMethodInstanceType = InstanceWithManualFlag< + InstanceType, + B +>; + +export type PaymentMethodRegistryType = { + [K in keyof PaymentMethodTypeDictionary]: PaymentMethodInstanceType; +}[K]; + +export function getMethod(code: Code): PaymentMethodInstanceType { + const methodClass = AllRegisteredPaymentMethods[code] as { + new (code: Code): PaymentMethodInstanceType; + }; if (!methodClass) { throw new Error(`Invalid payment method code: ${code}`); } - return new methodClass(code as any) as PaymentMethodInstance; -} + return new methodClass(code) as PaymentMethodInstanceType; +} \ No newline at end of file diff --git a/src/buckaroo.ts b/src/buckaroo.ts index ffe86f6e..7c46682b 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -1,4 +1,4 @@ -import { getMethod, IConfig, ICredentials, PaymentMethodInstance, ServiceCode } from './Utils'; +import { getMethod, IConfig, ICredentials, PaymentMethodInstanceType, ServiceCode } from './Utils'; import HttpsClient from './Request/HttpsClient'; import { Agent } from 'https'; import Request from './Request/Request'; @@ -49,13 +49,15 @@ export default class Buckaroo { return (this._client = new this(credentials, config, agent)); } - method(): NoService; - method(name: Name): PaymentMethodInstance; - method(name?: K) { + method(): NoService<'noservice', false>; + method( + name: Code + ): PaymentMethodInstanceType; + method(name?: Code) { if (!name) { return new NoService(); } - return getMethod(name); + return getMethod(name); } confirmCredentials() { diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index f053ebec..6d05f4f9 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -41,12 +41,9 @@ const paymentPayload: IPay = { const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { test('Pay', () => { - return method - .pay(paymentPayload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + return method.pay(paymentPayload).then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await method @@ -55,18 +52,14 @@ describe('AfterPay methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', //Set transaction key of the transaction to refund amountCredit: paymentPayload.amountDebit, }) - .request() .then((data) => { expect(data.isFailed()).toBeDefined(); }); }); test('Authorize', async () => { - await method - .authorize(paymentPayload) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + await method.authorize(paymentPayload).then((data) => { + expect(data).toBeDefined(); + }); }); test('CancelAuthorize', async () => { await method @@ -75,7 +68,6 @@ describe('AfterPay methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountCredit: 100, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -87,7 +79,6 @@ describe('AfterPay methods', () => { ...paymentPayload, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 022f8614..f0413916 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -81,27 +81,18 @@ const paymentPayload: IPay = { }; describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { - await method - .authorize(paymentPayload) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + await method.authorize(paymentPayload).then((data) => { + expect(data).toBeDefined(); + }); }); test('Pay', async () => { - await method - .pay(paymentPayload) - .request() - .then((data) => { - expect(data.data).toBeDefined(); - }); + await method.pay(paymentPayload).then((data) => { + expect(data.data).toBeDefined(); + }); }); test('Specification', async () => { - await method - .specification(RequestTypes.Transaction) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + await method.specification(RequestTypes.Transaction).then((data) => { + expect(data).toBeDefined(); + }); }); }); \ No newline at end of file diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index 6a8dd3f7..fe303856 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -10,7 +10,6 @@ describe('Alipay methods', () => { amountDebit: 100, useMobileView: false, }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -22,7 +21,6 @@ describe('Alipay methods', () => { invoice: uniqid(), originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index f6ded503..ef0b52be 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -12,7 +12,6 @@ describe('Applepay methods', () => { paymentData: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', customerCardName: 'XXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -25,7 +24,6 @@ describe('Applepay methods', () => { servicesSelectableByClient: 'applepay', continueOnIncomplete: true, }) - .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -37,7 +35,6 @@ describe('Applepay methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 44ae3fe4..7dcd9463 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -10,7 +10,6 @@ describe('BanContact methods', () => { amountDebit: 100, saveToken: true, }) - .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -22,18 +21,14 @@ describe('BanContact methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); }); test('Authenticate', async () => { - await method - .authenticate({ invoice: uniqid(), amountDebit: 100 }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeDefined(); - }); + await method.authenticate({ invoice: uniqid(), amountDebit: 100 }).then((data) => { + expect(data.isWaitingOnUserInput()).toBeDefined(); + }); }); test('PayOneClick', async () => { await method @@ -42,7 +37,6 @@ describe('BanContact methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountDebit: 100, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -53,7 +47,6 @@ describe('BanContact methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -65,7 +58,6 @@ describe('BanContact methods', () => { amountDebit: 100, encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -77,7 +69,6 @@ describe('BanContact methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 0d0ba553..98b6ace5 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -17,7 +17,6 @@ describe('Transfer methods', () => { sendMail: true, dateDue: '2024-10-10', }) - .request() .then((res) => { expect(res.isAwaitingConsumer()).toBeDefined(); }); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index c094b00d..0c8900ae 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -6,6 +6,7 @@ const method = buckarooClientTest.method('belfius'); describe('testing methods', () => { test('Pay Simple Payload', async () => { await method + .manually() .pay({ amountDebit: 100, }) @@ -16,6 +17,7 @@ describe('testing methods', () => { }); test('Refund', async () => { await method + .manually() .refund({ invoice: uniqid(), amountCredit: 0.01, diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index ae5f9481..61952a29 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -9,12 +9,9 @@ describe('Billink methods', () => { const invoiceId = uniqid(); test('Pay', async () => { - await method - .pay(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await method.manually().pay(payload).request().then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await method @@ -23,18 +20,14 @@ describe('Billink methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); }); test('Authorize', async () => { - await method - .authorize({ ...payload, invoice: invoiceId }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await method.authorize({ ...payload, invoice: invoiceId }).then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('CancelAuthorize', async () => { await method @@ -43,7 +36,6 @@ describe('Billink methods', () => { amountCredit: payload.amountDebit, invoice: invoiceId, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -56,7 +48,6 @@ describe('Billink methods', () => { amountDebit: payload.amountDebit, articles: payload.articles, }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 8b79be8e..97a644b9 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -10,7 +10,6 @@ describe('testing methods', () => { amountDebit: 100, voucherCode: 'XXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -22,7 +21,6 @@ describe('testing methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -32,7 +30,6 @@ describe('testing methods', () => { .getBalance({ voucherCode: 'XXXXXXX', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -45,7 +42,6 @@ describe('testing methods', () => { validFrom: '2021-01-01', validUntil: '2024-01-01', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -55,7 +51,6 @@ describe('testing methods', () => { .deactivate({ voucherCode: 'XXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index 3ad4d9d4..c75bb383 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -11,7 +11,6 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -23,7 +22,6 @@ describe('BuckarooWallet methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -36,7 +34,6 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, walletMutationGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -49,7 +46,6 @@ describe('BuckarooWallet methods', () => { amountCredit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -68,7 +64,6 @@ describe('BuckarooWallet methods', () => { iban: 'NLXXTESTXXXXXXXXXX', }, }) - .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); @@ -81,7 +76,6 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -99,7 +93,6 @@ describe('BuckarooWallet methods', () => { iban: 'NLXXTESTXXXXXXXXXX', }, }) - .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); @@ -109,7 +102,6 @@ describe('BuckarooWallet methods', () => { .getInfo({ walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index cb3f3b51..427a4193 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -9,7 +9,6 @@ describe('testing methods', () => { .pay({ amountDebit: 100, }) - .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -21,7 +20,6 @@ describe('testing methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -31,7 +29,6 @@ describe('testing methods', () => { .authorize({ amountDebit: 100, }) - .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -43,7 +40,6 @@ describe('testing methods', () => { name: 'Visa', encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -55,7 +51,6 @@ describe('testing methods', () => { encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -67,7 +62,6 @@ describe('testing methods', () => { encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -79,7 +73,6 @@ describe('testing methods', () => { encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -91,7 +84,6 @@ describe('testing methods', () => { amountCredit: 100, name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -103,7 +95,6 @@ describe('testing methods', () => { amountDebit: 100, name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -115,7 +106,6 @@ describe('testing methods', () => { amountDebit: 100, name: 'Visa', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index 9b105c68..be2307c3 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -14,7 +14,6 @@ describe('Testing CreditClick methods', () => { }, email: 'test@buckaroo.nl', }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -28,7 +27,6 @@ describe('Testing CreditClick methods', () => { description: 'refund', refundReason: 'Fraudulent', }) - .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index c12e7707..b55ab2b3 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -8,12 +8,9 @@ const creditManagement = buckarooClientTest.method('CreditManagement3'); describe('Testing Credit Management', () => { test('CreateInvoice', async () => { - await creditManagement - .createInvoice(creditManagementTestInvoice()) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement.createInvoice(creditManagementTestInvoice()).then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('CreateInvoice With Articles', async () => { await creditManagement @@ -67,26 +64,19 @@ describe('Testing Credit Management', () => { ], }) ) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); }); test('Pause Invoice', async () => { - await creditManagement - .pauseInvoice({ invoice: uniqid() }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement.pauseInvoice({ invoice: uniqid() }).then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('UnPause Invoice', async () => { - await creditManagement - .unpauseInvoice({ invoice: uniqid() }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement.unpauseInvoice({ invoice: uniqid() }).then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('Invoice Info', async () => { await creditManagement @@ -94,7 +84,6 @@ describe('Testing Credit Management', () => { invoice: uniqid(), invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }], }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -106,7 +95,6 @@ describe('Testing Credit Management', () => { code: 'XXXXXXXX', }, }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -138,26 +126,19 @@ describe('Testing Credit Management', () => { }, ], }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); }); test('resumeDebtorFile', async () => { - await creditManagement - .resumeDebtorFile({ debtorFileGuid: 'd42' }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement.resumeDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('pauseDebtorFile', async () => { - await creditManagement - .pauseDebtorFile({ debtorFileGuid: 'd42' }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement.pauseDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('addOrUpdateDebtor', async () => { await creditManagement @@ -170,15 +151,15 @@ describe('Testing Credit Management', () => { lastName: 'Acceptatie', }, }) - .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); }); test('CreateCombinedInvoice', async () => { - const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); + const combinedInvoice = creditManagement.manually().createCombinedInvoice(creditManagementTestInvoice()); buckarooClientTest .method('sepadirectdebit') + .manually() .combine(combinedInvoice.data) .pay({ iban: 'NLXXTESTXXXXXXXXXX', @@ -211,7 +192,6 @@ describe('Testing Credit Management', () => { paymentPlanCostAmountVat: 1.2, recipientemail: 'test@buckaroo.nl', }) - .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -221,7 +201,6 @@ describe('Testing Credit Management', () => { .pauseInvoice({ invoice: uniqid(), }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index 2c747572..a1a44740 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -8,7 +8,6 @@ describe('Testing Eps methods', () => { .pay({ amountDebit: 100, }) - .request() .then((response) => { expect(response.isSuccess()).toBeTruthy(); }); @@ -20,7 +19,6 @@ describe('Testing Eps methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 20cc3945..1381f24b 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -4,12 +4,9 @@ import { ServiceCode } from '../../src'; const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { - await method - .issuerList() - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + await method.issuerList().then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); }); test('CreateMandate', async () => { method @@ -20,18 +17,14 @@ describe('Testing Emandates methods', () => { purchaseId: 'XXXXXXXXXXXXXX', sequenceType: 0, }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); }); test('GetStatus', async () => { - method - .status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + method.status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); }); test('ModifyMandate', async () => { method @@ -39,19 +32,17 @@ describe('Testing Emandates methods', () => { originalMandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', continueOnIncomplete: true, }) - .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); }); test('CancelMandate', async () => { method - .setPaymentName('emandateb2b' as ServiceCode) + .setServiceCode('emandateb2b' as ServiceCode) .cancelMandate({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', purchaseId: 'XXXXXXXXXXXXXX', }) - .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index 222695dd..ee6a4674 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -8,20 +8,16 @@ describe('GiftCard methods', () => { const responsePay = await method .pay({ amountDebit: 100, - intersolveCardnumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - intersolvePIN: '500', - }) - .request(); + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '1000', + }); expect(responsePay.isSuccess()).toBeTruthy(); - const responseRemainderPay = await buckarooClientTest - .method('ideal') - .payRemainder({ - amountDebit: 100, - issuer: 'ABNANL2A', - invoice: responsePay.data.invoice, - originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, - }) - .request(); + const responseRemainderPay = await buckarooClientTest.method('ideal').payRemainder({ + amountDebit: 100, + issuer: 'ABNANL2A', + invoice: responsePay.data.invoice, + originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, + }); expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { @@ -33,7 +29,6 @@ describe('GiftCard methods', () => { email: 'test@buckaroo.nl', lastName: 'Acceptatie', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index 4f1eee34..1168e6dc 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -9,7 +9,6 @@ describe('Testing Giropay methods', () => { bic: 'XXXXXXXXX', amountDebit: 100, }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -21,7 +20,6 @@ describe('Testing Giropay methods', () => { invoice: uniqid(), originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index bcebb901..d1a7a734 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -19,7 +19,6 @@ describe('testing Ideal methods', () => { service_action: 'something', }, }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -37,7 +36,6 @@ describe('testing Ideal methods', () => { service_action: 'something', }, }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -49,7 +47,6 @@ describe('testing Ideal methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/IdealQR.test.ts b/tests/PaymentMethods/IdealQR.test.ts index 7ffeab00..05953ea8 100644 --- a/tests/PaymentMethods/IdealQR.test.ts +++ b/tests/PaymentMethods/IdealQR.test.ts @@ -24,7 +24,6 @@ describe('Testing IdealQR methods', () => { service_action: 'something', }, }) - .request() .then((response) => { expect(response.isSuccess()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Idin.test.ts b/tests/PaymentMethods/Idin.test.ts index 711a15f1..0bab9f5d 100644 --- a/tests/PaymentMethods/Idin.test.ts +++ b/tests/PaymentMethods/Idin.test.ts @@ -8,7 +8,6 @@ describe('Idin methods', () => { .verify({ issuer: 'BANKNL2Y', }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -19,7 +18,6 @@ describe('Idin methods', () => { .identify({ issuer: 'BANKNL2Y', }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -30,7 +28,6 @@ describe('Idin methods', () => { .login({ issuer: 'BANKNL2Y', }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 4ecd1abd..f2e758df 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -9,7 +9,6 @@ describe('Testing In3 methods', () => { test('Pay', async () => { await in3 .pay(payload) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -21,7 +20,6 @@ describe('Testing In3 methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isSuccess()).toBeFalsy(); }); @@ -83,7 +81,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 2, - price: 20.1, + price: 25, }, { identifier: 'Articlenumber2', @@ -92,7 +90,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 1, - price: 10.1, + price: 25, }, { identifier: 'USPShippingID', @@ -101,7 +99,7 @@ const payload: IPay = { category: 'test product', vatPercentage: 21, quantity: 1, - price: 2, + price: 25, }, ], }; diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index 0c6e22a3..267230a8 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -7,12 +7,9 @@ const capayable = buckarooClientTest.method('capayable'); describe('Testing capayable methods', () => { test('Pay', async () => { - await capayable - .pay(paymentPayload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await capayable.pay(paymentPayload).then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await capayable @@ -21,18 +18,14 @@ describe('Testing capayable methods', () => { amountCredit: paymentPayload.amountDebit, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); }); test('PayInInstallments', async () => { - await capayable - .payInInstallments(paymentPayload) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + await capayable.payInInstallments(paymentPayload).then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); }); }); diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index afc4ae43..df9bb658 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -9,7 +9,6 @@ describe('Testing KBC methods', () => { .pay({ amountDebit: 100, }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -21,7 +20,6 @@ describe('Testing KBC methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index d2b4fab0..3e6d8b17 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -6,23 +6,17 @@ import RecipientCategory from '../../src/Constants/RecipientCategory'; const klarna = buckarooClientTest.method('klarna'); describe('Testing Klarna methods', () => { test('Pay', async () => { - await klarna - .pay(payload) - .request() - .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy(); - }); + await klarna.pay(payload).then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); }); test('PayInInstallments', async () => { const clonedPayload = JSON.parse(JSON.stringify(payload)); clonedPayload.currency = 'GBP'; clonedPayload.billing.address.country = 'GB'; - await klarna - .payInInstallments(clonedPayload) - .request() - .then((res) => { - expect(res).toBeDefined(); - }); + await klarna.payInInstallments(clonedPayload).then((res) => { + expect(res).toBeDefined(); + }); }); }); @@ -74,15 +68,15 @@ let payload: IPay = { identifier: 'Articlenumber1', description: 'Blue Toy Car', vatPercentage: 21, - quantity: 2, - price: 20.1, + quantity: 1, + price: 50, }, { identifier: 'Articlenumber2', description: 'Red Toy Car', vatPercentage: 21, quantity: 1, - price: 10.1, + price: 50, }, ], }; diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index b2d836d5..6e17e485 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -10,7 +10,6 @@ describe('KlarnaKp', () => { amountDebit: 100, reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info.isFailed()).toBeTruthy(); }); @@ -54,7 +53,6 @@ describe('KlarnaKp', () => { }, ], }) - .request() .then((info) => { expect(info.isPendingProcessing()).toBeTruthy(); }); @@ -64,7 +62,6 @@ describe('KlarnaKp', () => { .cancel({ reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index e66606e7..b5344599 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -6,7 +6,7 @@ const ideal = buckarooClientTest.method('ideal'); describe('Testing Marketplaces methods', () => { test('Split', async () => { - marketplaces.split({ + const marketplacesResponse = marketplaces.manually().split({ description: 'INV0001', daysUntilTransfer: 2, marketplace: { @@ -27,12 +27,11 @@ describe('Testing Marketplaces methods', () => { ], }); return ideal - .combine(marketplaces) + .combine(marketplacesResponse.data) .pay({ issuer: 'ABNANL2A', amountDebit: 100, }) - .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); @@ -53,13 +52,12 @@ describe('Testing Marketplaces methods', () => { }, ], }) - .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); }); test('refundSupplementary', async () => { - marketplaces.refundSupplementary({ + const marketplacesResponse = marketplaces.manually().refundSupplementary({ sellers: [ { accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', @@ -68,13 +66,12 @@ describe('Testing Marketplaces methods', () => { ], }); ideal - .combine(marketplaces) + .combine(marketplacesResponse.data) .refund({ invoice: uniqid(), originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountCredit: 0.01, }) - .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts index 65f0de6e..9888a32e 100644 --- a/tests/PaymentMethods/Mbway.test.ts +++ b/tests/PaymentMethods/Mbway.test.ts @@ -7,7 +7,6 @@ describe('Mbway methods', () => { .pay({ amountDebit: 100, }) - .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts index 3d7dd2c8..cbbeaec4 100644 --- a/tests/PaymentMethods/Multibanco.test.ts +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -7,7 +7,6 @@ describe('Multibanco methods', () => { .pay({ amountDebit: 100, }) - .request() .then((info) => { expect(info.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts index e453734f..49f34925 100644 --- a/tests/PaymentMethods/NoService.test.ts +++ b/tests/PaymentMethods/NoService.test.ts @@ -13,7 +13,6 @@ describe('NoService methods', () => { servicesExcludedForClient: 'ideal', continueOnIncomplete: true, }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 737d5f5d..cda59a9e 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -23,7 +23,6 @@ describe('PayPerEmail methods', () => { lastName: 'Acceptatie', }, }) - .request() .then((response) => { expect(response).toBeDefined(); }); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index a10f52d6..510297c3 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -9,7 +9,6 @@ describe('Payconiq', () => { amountDebit: 100, order: uniqid(), }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -21,7 +20,6 @@ describe('Payconiq', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -33,7 +31,6 @@ describe('Payconiq', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 9347690f..d86cb20f 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -13,7 +13,6 @@ describe('PaymentInitiation methods', () => { invoice: uniqid(), countryCode: 'NL', }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -25,7 +24,6 @@ describe('PaymentInitiation methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index e248fab5..1891b289 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -10,7 +10,6 @@ describe('Paypal', () => { .pay({ amountDebit: 100, }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -22,7 +21,6 @@ describe('Paypal', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -45,7 +43,6 @@ describe('Paypal', () => { noShipping: '0', phone: { mobile: '0612345678' }, }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index ad82d019..c04a7709 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -24,7 +24,6 @@ describe('PiM', () => { text: 'bedankt', }, }) - .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Pos.test.ts b/tests/PaymentMethods/Pos.test.ts index 7cb03f6b..e16c896d 100644 --- a/tests/PaymentMethods/Pos.test.ts +++ b/tests/PaymentMethods/Pos.test.ts @@ -11,7 +11,6 @@ describe('POS methods', () => { invoice: uniqid(), terminalId: '50000001', }) - .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 348d882e..946a2288 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -14,7 +14,6 @@ describe('Przelewy24', () => { }, email: 'test@buckaroo.nl', }) - .request() .then((res) => { expect(res.isPendingProcessing()).toBeTruthy(); }); @@ -26,7 +25,6 @@ describe('Przelewy24', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index b569a1ed..fd3ce8a7 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -19,12 +19,9 @@ const paymentPayload: IPay = { describe('SEPA methods', () => { test('Pay', async () => { - await method - .pay(paymentPayload) - .request() - .then((info) => { - expect(info).toBeDefined(); - }); + await method.pay(paymentPayload).then((info) => { + expect(info).toBeDefined(); + }); }); test('Refund', async () => { await method @@ -32,18 +29,14 @@ describe('SEPA methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info).toBeDefined(); }); }); test('Authorize', async () => { - await method - .authorize(paymentPayload) - .request() - .then((info) => { - expect(info).toBeDefined(); - }); + await method.authorize(paymentPayload).then((info) => { + expect(info).toBeDefined(); + }); }); test('PayRecurrent', async () => { await method @@ -53,7 +46,6 @@ describe('SEPA methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info).toBeDefined(); }); @@ -80,7 +72,6 @@ describe('SEPA methods', () => { country: 'NL', }, }) - .request() .then((info) => { expect(info).toBeDefined(); }); @@ -93,7 +84,6 @@ describe('SEPA methods', () => { mandateReference: 'XXXXXXXXXXXXXXX', amountDebit: 100, }) - .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index e4913f91..83618e3c 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -10,7 +10,6 @@ describe('Sofort', () => { amountDebit: 100, order: uniqid(), }) - .request() .then((info) => { expect(info).toBeDefined(); }); @@ -22,7 +21,6 @@ describe('Sofort', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((info) => { expect(info).toBeDefined(); }); @@ -35,7 +33,6 @@ describe('Sofort', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index c78e1157..9c1da533 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -28,7 +28,6 @@ describe('Subscription methods', () => { code: 'XXXXXXXX', }, }) - .request() .then((data) => { expect(data.hasError()).toBeTruthy(); }); @@ -47,7 +46,6 @@ describe('Subscription methods', () => { }, }, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -93,7 +91,6 @@ describe('Subscription methods', () => { amountDebit: 100, startRecurrent: true, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -109,7 +106,6 @@ describe('Subscription methods', () => { issuer: 'ABNANL2A', amountDebit: 100, }) - .request() .then((data) => { expect(data).toBeDefined(); }); @@ -132,7 +128,6 @@ describe('Subscription methods', () => { .deletePaymentConfig({ subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((res) => { expect(res.httpResponse.status === 200).toBeTruthy(); }); diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 8a29968b..5b64bfcc 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -12,7 +12,6 @@ describe('SurePay methods', () => { accountName: 'Test Acceptatie', }, }) - .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index ecdfbbc4..d7741ef7 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -24,7 +24,6 @@ describe('Thunes methods', () => { }, ], }) - .request() .then((res) => { expect(res.data).toBeDefined(); }); @@ -32,25 +31,18 @@ describe('Thunes methods', () => { test('capture', async () => { await method .capture({ amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() .then((res) => { expect(res.data).toBeDefined(); }); }); test('getStatus', async () => { - await method - .getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((res) => { - expect(res.data).toBeDefined(); - }); + await method.getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((res) => { + expect(res.data).toBeDefined(); + }); }); test('cancel', async () => { - await method - .cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((res) => { - expect(res.data).toBeDefined(); - }); + await method.cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((res) => { + expect(res.data).toBeDefined(); + }); }); }); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 83b4f9e9..63030ddd 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -38,7 +38,7 @@ describe('Tinka', () => { color: 'Red', size: 'Small', quantity: 1, - price: 3.5, + price: 100, unitCode: 'test', }, ], @@ -46,7 +46,6 @@ describe('Tinka', () => { deliveryMethod: 'CompanyStore', paymentMethod: 'Credit', }) - .request() .then((res) => { expect(res.isPendingProcessing()).toBeTruthy(); }); @@ -58,7 +57,6 @@ describe('Tinka', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((res) => { expect(res.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 90ef3466..493c96af 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -13,7 +13,6 @@ describe('Trustly', () => { countryCode: 'NL', }, }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 77764f34..7d740904 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -9,7 +9,6 @@ describe('WechatPay', () => { amountDebit: 100, locale: 'en-US', }) - .request() .then((response) => { expect(response.isPendingProcessing()).toBeDefined(); }); @@ -21,7 +20,6 @@ describe('WechatPay', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) - .request() .then((response) => { expect(response.data).toBeDefined(); }); From 1f20a37d468dbc38716f2c6b30b3ebea56e9494d Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 16:05:19 +0100 Subject: [PATCH 29/52] rename some ts properties --- src/Utils/MethodTypes.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 47e0ef13..4ff15fd2 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,22 +1,22 @@ import * as AllRegisteredPaymentMethods from '../PaymentMethods/PaymentMethods'; -type InstanceWithManualFlag = B extends true ? T & { _isManually: B } : T; +type InstanceWithManualFlag = Manually extends true ? Method & { _isManually: Manually } : Method; export type PaymentMethodTypeDictionary = typeof AllRegisteredPaymentMethods; export type ServiceCode = keyof PaymentMethodTypeDictionary; -export type PaymentMethodInstanceType = InstanceWithManualFlag< +export type PaymentMethodInstanceType = InstanceWithManualFlag< InstanceType, - B + Manually >; -export type PaymentMethodRegistryType = { - [K in keyof PaymentMethodTypeDictionary]: PaymentMethodInstanceType; +export type PaymentMethodRegistryType = { + [K in keyof PaymentMethodTypeDictionary]: PaymentMethodInstanceType; }[K]; -export function getMethod(code: Code): PaymentMethodInstanceType { +export function getMethod(code: Code): PaymentMethodInstanceType { const methodClass = AllRegisteredPaymentMethods[code] as { - new (code: Code): PaymentMethodInstanceType; + new (code: Code): PaymentMethodInstanceType; }; if (!methodClass) { throw new Error(`Invalid payment method code: ${code}`); From a5a85b2e7c3d9d63b19bde1ee82527bb9b67a5a1 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 16:06:27 +0100 Subject: [PATCH 30/52] Update MethodTypes.ts --- src/Utils/MethodTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 4ff15fd2..925403ec 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -22,5 +22,5 @@ export function getMethod(co throw new Error(`Invalid payment method code: ${code}`); } - return new methodClass(code) as PaymentMethodInstanceType; + return new methodClass(code) as PaymentMethodInstanceType; } \ No newline at end of file From bcf24f64e8444ea00bbe168793eab939766db1c4 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 16:11:43 +0100 Subject: [PATCH 31/52] code format --- src/PaymentMethods/BuckarooVoucher/index.ts | 8 ++++---- src/PaymentMethods/KBC/index.ts | 8 ++++---- src/PaymentMethods/KlarnaKP/index.ts | 9 ++++----- src/PaymentMethods/Paypal/index.ts | 8 ++++---- src/PaymentMethods/WeChatPay/index.ts | 8 ++++---- src/Utils/MethodTypes.ts | 18 ++++++++++++------ tests/PaymentMethods/Billink.test.ts | 10 +++++++--- tests/PaymentMethods/Giftcard.test.ts | 11 +++++------ tests/PaymentMethods/In3.test.ts | 8 +++----- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 04ea3b68..1004b558 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -3,10 +3,10 @@ import { IPay, Pay } from './Models/Pay'; import IRequest from '../../Models/IRequest'; import { Create, ICreate } from './Models/Create'; -export default class BuckarooVoucher extends PayablePaymentMethod< - Code, - Manually -> { +export default class BuckarooVoucher< + Code extends 'buckaroovoucher', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'BuckarooVoucher'; pay(payload: IPay) { diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index cf6dd080..d8b85c49 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,10 +1,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; -export default class KBC extends PayablePaymentMethod< - Code, - Manually -> { +export default class KBC< + Code extends 'KBCPaymentButton', + Manually extends boolean = false +> extends PayablePaymentMethod { protected _paymentName = 'KBC'; refund(payload: IRefundRequest) { diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 07bbeb49..5b1f7502 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -2,12 +2,11 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IPay, Pay } from './Models/IPay'; import IRequest from '../../Models/IRequest'; import { IReserve, Reserve } from './Models/IReserve'; -import { ServiceCode } from '../../Utils'; -export default class KlarnaKP< - Code extends 'klarnakp', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class KlarnaKP extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'KlarnaKP'; protected _serviceVersion = 1; diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index c093d85b..60853413 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -3,10 +3,10 @@ import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; -export default class Paypal< - Code extends 'paypal', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class Paypal extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'Paypal'; pay(payload: IPay) { diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 288fae1d..f9cfb2d9 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -2,10 +2,10 @@ import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefundRequest } from '../../Models/IRequest'; import { IPay, Pay } from './Models/Pay'; -export default class WeChatPay< - Code extends 'wechatpay', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class WeChatPay extends PayablePaymentMethod< + Code, + Manually +> { protected _paymentName = 'WeChatPay'; pay(payload: IPay) { diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 925403ec..642c03b9 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,20 +1,26 @@ import * as AllRegisteredPaymentMethods from '../PaymentMethods/PaymentMethods'; -type InstanceWithManualFlag = Manually extends true ? Method & { _isManually: Manually } : Method; +type InstanceWithManualFlag = Manually extends true + ? Method & { + _isManually: Manually; + } + : Method; export type PaymentMethodTypeDictionary = typeof AllRegisteredPaymentMethods; export type ServiceCode = keyof PaymentMethodTypeDictionary; -export type PaymentMethodInstanceType = InstanceWithManualFlag< - InstanceType, - Manually ->; +export type PaymentMethodInstanceType< + Code extends ServiceCode, + Manually extends boolean = false +> = InstanceWithManualFlag, Manually>; export type PaymentMethodRegistryType = { [K in keyof PaymentMethodTypeDictionary]: PaymentMethodInstanceType; }[K]; -export function getMethod(code: Code): PaymentMethodInstanceType { +export function getMethod( + code: Code +): PaymentMethodInstanceType { const methodClass = AllRegisteredPaymentMethods[code] as { new (code: Code): PaymentMethodInstanceType; }; diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index 61952a29..b1ffa530 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -9,9 +9,13 @@ describe('Billink methods', () => { const invoiceId = uniqid(); test('Pay', async () => { - await method.manually().pay(payload).request().then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await method + .manually() + .pay(payload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await method diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index ee6a4674..13896a86 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -5,12 +5,11 @@ const method = buckarooClientTest.method('boekenbon'); describe('GiftCard methods', () => { test('Pay', async () => { - const responsePay = await method - .pay({ - amountDebit: 100, - intersolveCardnumber: '0000000000000000001', - intersolvePIN: '1000', - }); + const responsePay = await method.pay({ + amountDebit: 100, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '1000', + }); expect(responsePay.isSuccess()).toBeTruthy(); const responseRemainderPay = await buckarooClientTest.method('ideal').payRemainder({ amountDebit: 100, diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index f2e758df..bf8b9d48 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -7,11 +7,9 @@ const in3 = buckarooClientTest.method('In3'); describe('Testing In3 methods', () => { test('Pay', async () => { - await in3 - .pay(payload) - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + await in3.pay(payload).then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); }); test('Refund', async () => { await in3 From 7a882a7b04e9f037788487dff09dc5a82ccc8193 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 16:25:18 +0100 Subject: [PATCH 32/52] improvements of manually method --- src/Services/PaymentMethod.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 9262b43f..5e9b45f2 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -38,8 +38,14 @@ export default abstract class PaymentMethod { - this._isManually = true as Manually; + public manually(value?: true): PaymentMethodRegistryType; + public manually(value: false): PaymentMethodRegistryType; + public manually(value?: boolean): PaymentMethodRegistryType { + if (value === undefined) { + this._isManually = true as Manually; + } else { + this._isManually = value as Manually; + } return this as any; } From 904f257d9c1c50e3e3cd7c116d051ce54003b7b8 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 30 Oct 2023 16:29:31 +0100 Subject: [PATCH 33/52] update client tests --- tests/Client.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Client.test.ts b/tests/Client.test.ts index ec4dad21..9f8cdb99 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -16,9 +16,9 @@ describe('Testing Buckaroo Client', () => { const creditManagement = client.method('CreditManagement3'); const sepaDirectDebit = client.method('sepadirectdebit'); for (let i = 0; i < 3; i++) { - const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); + const combinedInvoice = creditManagement.manually().createCombinedInvoice(creditManagementTestInvoice()); - const sepaRequest = sepaDirectDebit.combine(combinedInvoice.data).pay({ + const sepaRequest = sepaDirectDebit.manually().combine(combinedInvoice.data).pay({ iban: 'NL39RABO0300065264', bic: 'RABONL2U', mandateReference: '1DCtestreference', From f0082d236e85a1d3a0dbef2666cb57bd86b8e44f Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 1 Nov 2023 15:40:29 +0100 Subject: [PATCH 34/52] remove unnecessary `_paymentName` from payment methods --- src/PaymentMethods/Afterpay/index.ts | 1 - src/PaymentMethods/AfterpayDigiAccept/index.ts | 1 - src/PaymentMethods/Alipay/index.ts | 1 - src/PaymentMethods/ApplePay/index.ts | 1 - src/PaymentMethods/Bancontact/index.ts | 1 - src/PaymentMethods/BankTransfer/index.ts | 1 - src/PaymentMethods/Belfius/index.ts | 1 - src/PaymentMethods/Billink/index.ts | 2 -- src/PaymentMethods/BuckarooVoucher/index.ts | 1 - src/PaymentMethods/BuckarooWallet/index.ts | 1 - src/PaymentMethods/CreditCard/index.ts | 1 - src/PaymentMethods/CreditClick/index.ts | 2 -- src/PaymentMethods/CreditManagement/index.ts | 1 - src/PaymentMethods/EPS/index.ts | 1 - src/PaymentMethods/Emandates/index.ts | 1 - src/PaymentMethods/GiftCard/index.ts | 2 -- src/PaymentMethods/Giropay/index.ts | 2 -- src/PaymentMethods/Ideal/index.ts | 1 - src/PaymentMethods/IdealQR/index.ts | 2 -- src/PaymentMethods/Idin/index.ts | 2 -- src/PaymentMethods/In3/index.ts | 2 -- src/PaymentMethods/In3Old/index.ts | 2 -- src/PaymentMethods/KBC/index.ts | 2 -- src/PaymentMethods/Klarna/index.ts | 2 -- src/PaymentMethods/KlarnaKP/index.ts | 1 - src/PaymentMethods/Mbway/index.ts | 1 - src/PaymentMethods/Multibanco/index.ts | 1 - src/PaymentMethods/NoService/index.ts | 6 ------ src/PaymentMethods/PayByBank/index.ts | 2 -- src/PaymentMethods/PayPerEmail/index.ts | 2 -- src/PaymentMethods/Payconiq/index.ts | 2 -- src/PaymentMethods/Paypal/index.ts | 2 -- src/PaymentMethods/PiM/index.ts | 1 - src/PaymentMethods/PointOfSale/index.ts | 2 -- src/PaymentMethods/Przelewy24/index.ts | 2 -- src/PaymentMethods/SEPA/index.ts | 2 -- src/PaymentMethods/Sofort/index.ts | 1 - src/PaymentMethods/Subscriptions/index.ts | 1 - src/PaymentMethods/Surepay/index.ts | 2 -- src/PaymentMethods/Thunes/index.ts | 2 -- src/PaymentMethods/Tinka/index.ts | 2 -- src/PaymentMethods/Trustly/index.ts | 2 -- src/PaymentMethods/WeChatPay/index.ts | 2 -- src/Services/PaymentMethod.ts | 7 +------ 44 files changed, 1 insertion(+), 76 deletions(-) diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 81962288..3d67cfb1 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -7,7 +7,6 @@ export default class Afterpay { - protected _paymentName = 'Afterpay'; protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 386a7d7b..7f59ee10 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -6,7 +6,6 @@ export default class AfterpayDigiAccept< Code extends 'afterpaydigiaccept', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'AfterpayDigiAccept'; protected _serviceVersion = 2; pay(payload: IPay) { diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index dbe82363..88642912 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -6,7 +6,6 @@ export default class Alipay { - protected _paymentName = 'Alipay'; pay(payload: { useMobileView?: boolean } & IPaymentRequest) { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 4e6d1168..0154a6bd 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -6,7 +6,6 @@ export default class ApplePay { - protected _paymentName = 'ApplePay'; pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 8b2a0bb8..f70f832b 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -6,7 +6,6 @@ export default class Bancontact< Code extends 'bancontactmrcash', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'Bancontact'; pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index efb3f2e5..30a39a60 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -6,7 +6,6 @@ export default class BankTransfer< Code extends 'transfer', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'BankTransfer'; pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index 2ec0d8c9..e056d662 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -5,7 +5,6 @@ export default class Belfius { - protected _paymentName = 'Belfius'; pay(payload: IPaymentRequest) { return super.pay(payload); diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index d9570082..684708fe 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -7,8 +7,6 @@ export default class Billink { - protected _paymentName = 'Billink'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 1004b558..18a888d4 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -7,7 +7,6 @@ export default class BuckarooVoucher< Code extends 'buckaroovoucher', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'BuckarooVoucher'; pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 27ed1706..80d4e0ca 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -6,7 +6,6 @@ export default class BuckarooWallet< Code extends 'BuckarooWalletCollecting', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'BuckarooWallet'; pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 66777918..a26bdf12 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -7,7 +7,6 @@ export default class CreditCard< Code extends 'CreditCard', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'CreditCard'; payEncrypted(payload: ICardData) { this.setPayPayload(payload); diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index c3078ab8..55afeacf 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -6,8 +6,6 @@ export default class CreditClick< Code extends 'creditclick', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'CreditClick'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 94ba0ca9..22fe801f 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -13,7 +13,6 @@ export default class CreditManagement< Code extends 'CreditManagement3', Manually extends boolean = false > extends PaymentMethod { - protected _paymentName = 'CreditManagement'; protected _serviceVersion = 1; protected _requiredFields = ['currency']; diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 70c0db6b..dc4d45a9 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -4,5 +4,4 @@ export default class EPS e Code, Manually > { - protected _paymentName = 'EPS'; } diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index a272aef4..8eb14cde 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -7,7 +7,6 @@ export default class Emandates { _requiredFields: Array = ['currency']; - protected _paymentName = 'Emandates'; issuerList() { this.setServiceList('GetIssuerList'); diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index c950c778..642185a4 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -6,8 +6,6 @@ export default class GiftCard { - protected _paymentName = 'GiftCard'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index f15062a3..ead5a816 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -5,8 +5,6 @@ export default class Giropay { - protected _paymentName = 'Giropay'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index 229a4b57..adbec3a4 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -7,7 +7,6 @@ export default class Ideal { - protected _paymentName = 'Ideal'; protected _serviceVersion = 2; constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 8fc32238..8378462b 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -5,8 +5,6 @@ export default class IdealQR { - protected _paymentName = 'IdealQR'; - generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index d1724c52..6ce166eb 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -2,8 +2,6 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { IPay, Pay } from './Models/Pay'; export default class Idin extends PaymentMethod { - protected _paymentName = 'Idin'; - identify(payload: IPay) { this.setServiceList('Identify', new Pay(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index a80a5c18..d2b40c87 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -6,8 +6,6 @@ export default class In3 e Code, Manually > { - protected _paymentName = 'In3'; - pay(payload: IPaymentRequest) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 0cd115ab..7dc40a53 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -5,8 +5,6 @@ export default class In3Old { - protected _paymentName = 'In3Old'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index d8b85c49..881ce14c 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -5,8 +5,6 @@ export default class KBC< Code extends 'KBCPaymentButton', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'KBC'; - refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index c689478e..3102601b 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -5,8 +5,6 @@ export default class Klarna { - protected _paymentName = 'Klarna'; - pay(data: IPay) { return super.pay(data, new Pay(data)); } diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 5b1f7502..11f44dc9 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -7,7 +7,6 @@ export default class KlarnaKP { - protected _paymentName = 'KlarnaKP'; protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index dbce0745..53928fdf 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -4,5 +4,4 @@ export default class Mbway { - protected _paymentName = 'MB WAY'; } diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index 8900010c..7e8d30e4 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -4,5 +4,4 @@ export default class MultiBanco< Code extends 'multibanco', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'MultiBanco'; } diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index a249f287..8a97f5c5 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -4,12 +4,6 @@ export default class NoService { - protected _paymentName = 'noserivce'; - - get paymentName() { - return 'NoService'; - } - protected setServiceList(): this { return this; } diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index baf7818e..8c91ff54 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -6,8 +6,6 @@ export default class PayByBank { - protected _paymentName = 'PayByBank'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 4cd98b5c..b239cce5 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -5,8 +5,6 @@ export default class PayPerEmail { - protected _paymentName = 'PayPerEmail'; - paymentInvitation(payload: IInvitation) { this.setServiceList('paymentInvitation', new Invitation(payload)); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index 46f79a6a..60102286 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -5,8 +5,6 @@ export default class Payconiq { - protected _paymentName = 'Payconiq'; - instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 60853413..748a03ff 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -7,8 +7,6 @@ export default class Paypal { - protected _paymentName = 'Paypal'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index 7d03e015..b90489d7 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -2,7 +2,6 @@ import PaymentMethod from '../../Services/PaymentMethod'; import { Generate, IGenerate } from './Models/Generate'; export default class PiM extends PaymentMethod { - protected _paymentName = 'pim'; protected _requiredFields = ['currency']; generate(payload: IGenerate) { diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index 157627a2..681da9af 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -5,8 +5,6 @@ export default class PointOfSale< Code extends 'pospayment', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'PointOfSale'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index ac7ef150..f2129556 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -6,8 +6,6 @@ export default class Przelewy24< Code extends 'przelewy24', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'Przelewy24'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 4687ad9b..0ec81aae 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -9,8 +9,6 @@ export default class SEPA< Code extends 'sepadirectdebit', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'SEPA'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 0a954d69..f9bb9fe5 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -5,7 +5,6 @@ export default class Sofort< Code extends 'sofortueberweisung', Manually extends boolean = false > extends PayablePaymentMethod { - protected _paymentName = 'Sofort'; protected _serviceVersion = 1; pay(payload: IPaymentRequest) { diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 05d4c701..aaa893e3 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -7,7 +7,6 @@ export default class Subscriptions< Code extends 'subscriptions', Manually extends boolean = false > extends PaymentMethod { - protected _paymentName = 'Subscriptions'; protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 5f311422..2be11dfe 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -5,8 +5,6 @@ export default class Surepay { - protected _paymentName = 'Surepay'; - verify(payload: IVerify) { this.setServiceList('Verify', new Verify(payload)); return super.dataRequest(payload); diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 6427ac88..3952327a 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -6,8 +6,6 @@ export default class Thunes { - protected _paymentName = 'Thunes'; - getStatus(payload: key) { this.setServiceList('getStatus'); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index dac2e8d0..d25ebf0c 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -6,8 +6,6 @@ export default class Tinka { - protected _paymentName = 'Tinka'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 32eda03f..0252a5c3 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -6,8 +6,6 @@ export default class Trustly { - protected _paymentName = 'Trustly'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index f9cfb2d9..dca83ed7 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -6,8 +6,6 @@ export default class WeChatPay { - protected _paymentName = 'WeChatPay'; - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 5e9b45f2..244f5bea 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -12,14 +12,13 @@ import { SpecificationRequestResponse } from '../Models/Response/SpecificationRe export default abstract class PaymentMethod { public _isManually: Manually = false as Manually; - protected _paymentName: string = ''; protected _serviceCode?: Code; protected _serviceVersion: number = 0; protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; constructor(serviceCode?: Code) { - this._serviceCode = (serviceCode ?? this.paymentName) as Code; + this._serviceCode = serviceCode ?? this._serviceCode as Code; } get serviceVersion() { @@ -34,10 +33,6 @@ export default abstract class PaymentMethod; public manually(value: false): PaymentMethodRegistryType; public manually(value?: boolean): PaymentMethodRegistryType { From ef9230852f8461c2c5f552f8d8c0f919ef161dcc Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 2 Nov 2023 09:01:02 +0100 Subject: [PATCH 35/52] Update PaymentMethod.ts --- src/Services/PaymentMethod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 244f5bea..3afe1e09 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -18,7 +18,7 @@ export default abstract class PaymentMethod = []; constructor(serviceCode?: Code) { - this._serviceCode = serviceCode ?? this._serviceCode as Code; + this._serviceCode = serviceCode; } get serviceVersion() { From 86d3e7f179f59937498173c89180a179c78bce06 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 2 Nov 2023 13:49:18 +0100 Subject: [PATCH 36/52] refactor imports and exports --- src/Constants/IPProtocolVersion.ts | 2 +- src/Constants/index.ts | 13 ++- src/Handlers/Credentials.ts | 6 +- src/Handlers/Reply/ReplyHandler.ts | 6 +- src/Models/IParameters.ts | 2 +- src/Models/IRequest.ts | 2 +- src/Models/Interfaces/ICustomer.ts | 11 +-- src/Models/Interfaces/IRecipient.ts | 3 +- src/Models/Interfaces/index.ts | 25 +++++- src/Models/Model.ts | 2 +- src/Models/Response/HttpClientResponse.ts | 4 +- .../Response/SpecificationRequestResponse.ts | 2 +- src/Models/Response/TransactionResponse.ts | 4 +- src/Models/Response/index.ts | 4 + src/Models/ServiceParameters.ts | 2 +- src/Models/index.ts | 10 ++- src/PaymentMethods/Afterpay/Model/Address.ts | 2 +- src/PaymentMethods/Afterpay/Model/Article.ts | 2 +- src/PaymentMethods/Afterpay/Model/Customer.ts | 8 +- src/PaymentMethods/Afterpay/Model/Pay.ts | 5 +- src/PaymentMethods/Afterpay/Model/Phone.ts | 2 +- .../Afterpay/Model/Recipient.ts | 2 +- src/PaymentMethods/Afterpay/Model/Refund.ts | 3 +- src/PaymentMethods/Afterpay/index.ts | 4 +- .../AfterpayDigiAccept/Model/Article.ts | 2 +- .../AfterpayDigiAccept/Model/Customer.ts | 3 +- .../AfterpayDigiAccept/Model/Pay.ts | 5 +- .../AfterpayDigiAccept/Model/Recipient.ts | 2 +- .../AfterpayDigiAccept/Services/Address.ts | 2 +- .../AfterpayDigiAccept/Services/Phone.ts | 2 +- .../AfterpayDigiAccept/index.ts | 4 +- src/PaymentMethods/Alipay/index.ts | 6 +- src/PaymentMethods/ApplePay/Models/Pay.ts | 3 +- src/PaymentMethods/ApplePay/index.ts | 5 +- src/PaymentMethods/Bancontact/Models/Pay.ts | 3 +- src/PaymentMethods/Bancontact/index.ts | 5 +- src/PaymentMethods/BankTransfer/Models/Pay.ts | 4 +- src/PaymentMethods/BankTransfer/index.ts | 5 +- src/PaymentMethods/Belfius/index.ts | 3 +- src/PaymentMethods/Billink/Models/Address.ts | 2 +- src/PaymentMethods/Billink/Models/Article.ts | 2 +- src/PaymentMethods/Billink/Models/Capture.ts | 3 +- src/PaymentMethods/Billink/Models/Customer.ts | 15 ++-- src/PaymentMethods/Billink/Models/Pay.ts | 4 +- src/PaymentMethods/Billink/Models/Phone.ts | 2 +- src/PaymentMethods/Billink/Models/Refund.ts | 3 +- src/PaymentMethods/Billink/index.ts | 2 +- .../BuckarooVoucher/Models/Create.ts | 3 +- .../BuckarooVoucher/Models/Pay.ts | 3 +- src/PaymentMethods/BuckarooVoucher/index.ts | 5 +- .../BuckarooWallet/Models/BankAccount.ts | 2 +- .../BuckarooWallet/Models/Customer.ts | 4 +- .../BuckarooWallet/Models/Wallet.ts | 5 +- src/PaymentMethods/BuckarooWallet/index.ts | 5 +- .../CreditCard/Models/CardData.ts | 3 +- .../CreditCard/Models/SecurityCode.ts | 3 +- src/PaymentMethods/CreditCard/index.ts | 5 +- src/PaymentMethods/CreditClick/Models/Pay.ts | 4 +- .../CreditClick/Models/Refund.ts | 3 +- src/PaymentMethods/CreditClick/index.ts | 2 +- .../Models/AddOrUpdateProductLines.ts | 3 +- .../CreditManagement/Models/Address.ts | 2 +- .../CreditManagement/Models/Article.ts | 2 +- .../CreditManagement/Models/CreditNote.ts | 3 +- .../CreditManagement/Models/Debtor.ts | 2 +- .../CreditManagement/Models/DebtorInfo.ts | 4 +- .../CreditManagement/Models/Invoice.ts | 7 +- .../CreditManagement/Models/PaymentPlan.ts | 5 +- .../Models/multiInfoInvoice.ts | 3 +- src/PaymentMethods/CreditManagement/index.ts | 5 +- src/PaymentMethods/EPS/index.ts | 5 +- .../Emandates/Models/Mandate.ts | 3 +- src/PaymentMethods/Emandates/index.ts | 4 +- src/PaymentMethods/GiftCard/Models/Pay.ts | 3 +- src/PaymentMethods/GiftCard/Models/Refund.ts | 3 +- src/PaymentMethods/GiftCard/index.ts | 2 +- src/PaymentMethods/Giropay/Models/Pay.ts | 3 +- src/PaymentMethods/Giropay/index.ts | 2 +- src/PaymentMethods/Ideal/Models/Pay.ts | 3 +- src/PaymentMethods/Ideal/index.ts | 6 +- .../IdealQR/Models/IGenerate.ts | 3 +- src/PaymentMethods/IdealQR/index.ts | 2 +- src/PaymentMethods/Idin/Models/Pay.ts | 2 +- src/PaymentMethods/Idin/index.ts | 2 +- src/PaymentMethods/In3/Models/Article.ts | 2 +- src/PaymentMethods/In3/Models/Pay.ts | 3 +- src/PaymentMethods/In3/Models/Phone.ts | 2 +- src/PaymentMethods/In3/Models/Recipient.ts | 8 +- src/PaymentMethods/In3/Models/Refund.ts | 2 +- src/PaymentMethods/In3/index.ts | 4 +- src/PaymentMethods/In3Old/Models/Address.ts | 2 +- src/PaymentMethods/In3Old/Models/Article.ts | 2 +- src/PaymentMethods/In3Old/Models/Company.ts | 2 +- src/PaymentMethods/In3Old/Models/Pay.ts | 18 ++-- src/PaymentMethods/In3Old/Models/Phone.ts | 2 +- src/PaymentMethods/In3Old/Models/Subtotal.ts | 2 +- src/PaymentMethods/In3Old/index.ts | 2 +- src/PaymentMethods/KBC/index.ts | 4 +- src/PaymentMethods/Klarna/Models/Article.ts | 2 +- src/PaymentMethods/Klarna/Models/Pay.ts | 5 +- src/PaymentMethods/Klarna/Models/Recipient.ts | 8 +- .../Klarna/Services/KlarnaAddress.ts | 2 +- .../Klarna/Services/KlarnaPhone.ts | 2 +- src/PaymentMethods/Klarna/index.ts | 2 +- src/PaymentMethods/KlarnaKP/Models/Address.ts | 2 +- src/PaymentMethods/KlarnaKP/Models/Article.ts | 2 +- .../KlarnaKP/Models/Customer.ts | 4 +- src/PaymentMethods/KlarnaKP/Models/IPay.ts | 4 +- .../KlarnaKP/Models/IReserve.ts | 7 +- src/PaymentMethods/KlarnaKP/Models/Phone.ts | 2 +- .../KlarnaKP/Models/Recipient.ts | 2 +- src/PaymentMethods/KlarnaKP/index.ts | 4 +- .../Marketplaces/Models/Marketplace.ts | 2 +- .../Marketplaces/Models/Seller.ts | 2 +- .../Marketplaces/Models/Split.ts | 3 +- .../Marketplaces/Models/Transfer.ts | 2 +- src/PaymentMethods/Marketplaces/index.ts | 2 +- src/PaymentMethods/Mbway/index.ts | 5 +- src/PaymentMethods/Multibanco/index.ts | 5 +- src/PaymentMethods/NoService/index.ts | 2 +- src/PaymentMethods/PayByBank/Models/IPay.ts | 3 +- src/PaymentMethods/PayByBank/index.ts | 4 +- .../PayPerEmail/Models/Attachments.ts | 2 +- .../PayPerEmail/Models/Invitation.ts | 4 +- src/PaymentMethods/PayPerEmail/index.ts | 2 +- src/PaymentMethods/Payconiq/index.ts | 4 +- src/PaymentMethods/PaymentMethods.ts | 86 ------------------ src/PaymentMethods/Paypal/Models/Address.ts | 2 +- src/PaymentMethods/Paypal/Models/ExtraInfo.ts | 5 +- src/PaymentMethods/Paypal/Models/Pay.ts | 3 +- src/PaymentMethods/Paypal/Models/Phone.ts | 2 +- src/PaymentMethods/Paypal/index.ts | 4 +- src/PaymentMethods/PiM/Models/Generate.ts | 4 +- src/PaymentMethods/PiM/index.ts | 2 +- src/PaymentMethods/PointOfSale/Models/Pay.ts | 3 +- src/PaymentMethods/PointOfSale/index.ts | 2 +- src/PaymentMethods/Przelewy24/Models/Pay.ts | 4 +- src/PaymentMethods/Przelewy24/index.ts | 4 +- src/PaymentMethods/SEPA/Models/Emandate.ts | 2 +- src/PaymentMethods/SEPA/Models/ExtraInfo.ts | 3 +- src/PaymentMethods/SEPA/Models/Pay.ts | 6 +- src/PaymentMethods/SEPA/index.ts | 6 +- src/PaymentMethods/Sofort/index.ts | 4 +- .../Subscriptions/Models/Company.ts | 2 +- .../Subscriptions/Models/Configuration.ts | 2 +- .../Subscriptions/Models/ISubscription.ts | 21 +++-- .../Subscriptions/Models/RatePlan.ts | 2 +- .../Subscriptions/Models/RatePlanCharge.ts | 2 +- src/PaymentMethods/Subscriptions/index.ts | 4 +- .../Surepay/Models/BankAccount.ts | 2 +- src/PaymentMethods/Surepay/Models/Verify.ts | 3 +- src/PaymentMethods/Surepay/index.ts | 2 +- src/PaymentMethods/Thunes/index.ts | 4 +- src/PaymentMethods/Tinka/Models/Address.ts | 2 +- src/PaymentMethods/Tinka/Models/Article.ts | 2 +- src/PaymentMethods/Tinka/Models/Pay.ts | 4 +- src/PaymentMethods/Tinka/Models/Person.ts | 4 +- src/PaymentMethods/Tinka/Models/Phone.ts | 2 +- src/PaymentMethods/Tinka/Models/Recipient.ts | 5 +- src/PaymentMethods/Tinka/index.ts | 4 +- src/PaymentMethods/Trustly/Models/Customer.ts | 2 +- src/PaymentMethods/Trustly/Models/Pay.ts | 4 +- src/PaymentMethods/Trustly/index.ts | 4 +- src/PaymentMethods/WeChatPay/Models/Pay.ts | 3 +- src/PaymentMethods/WeChatPay/index.ts | 4 +- src/PaymentMethods/index.ts | 87 ++++++++++++++++++- src/Request/DataModels.ts | 10 +-- src/Request/Hmac.ts | 2 +- src/Request/HttpsClient.ts | 4 +- src/Request/Request.ts | 20 +++-- src/Request/index.ts | 7 ++ src/Services/PayablePaymentMethod.ts | 7 +- src/Services/PaymentMethod.ts | 22 ++--- src/Services/TransactionService.ts | 7 +- src/Services/index.ts | 4 + src/Utils/Functions.ts | 2 +- src/Utils/MethodTypes.ts | 2 +- src/Utils/index.ts | 2 +- src/buckaroo.ts | 7 +- src/index.ts | 4 +- tests/Client.test.ts | 32 +++---- tests/Models/index.ts | 20 +++-- tests/PaymentMethods/AfterPay.test.ts | 3 +- .../PaymentMethods/AfterPayDigiAccept.test.ts | 4 +- tests/PaymentMethods/Alipay.test.ts | 2 +- tests/PaymentMethods/ApplePay.test.ts | 2 +- tests/PaymentMethods/Bancontact.test.ts | 2 +- tests/PaymentMethods/BankTransfer.test.ts | 2 +- tests/PaymentMethods/Belfius.test.ts | 2 +- tests/PaymentMethods/Billink.test.ts | 3 +- tests/PaymentMethods/BuckarooVoucher.test.ts | 2 +- tests/PaymentMethods/BuckarooWallet.test.ts | 2 +- tests/PaymentMethods/CreditCard.test.ts | 2 +- tests/PaymentMethods/CreditClick.test.ts | 2 +- tests/PaymentMethods/CreditManagment.test.ts | 4 +- tests/PaymentMethods/EPS.test.ts | 2 +- tests/PaymentMethods/Giftcard.test.ts | 2 +- tests/PaymentMethods/GiroPay.test.ts | 2 +- tests/PaymentMethods/Ideal.test.ts | 2 +- tests/PaymentMethods/In3.test.ts | 3 +- tests/PaymentMethods/In3Old.test.ts | 4 +- tests/PaymentMethods/KBC.test.ts | 2 +- tests/PaymentMethods/Klarna.test.ts | 3 +- tests/PaymentMethods/KlarnaKp.test.ts | 2 +- tests/PaymentMethods/Marketplaces.test.ts | 2 +- tests/PaymentMethods/NoService.test.ts | 2 +- tests/PaymentMethods/PayPerEmail.test.ts | 3 +- tests/PaymentMethods/Payconiq.test.ts | 2 +- .../PaymentMethods/PaymentInitiation.test.ts | 2 +- tests/PaymentMethods/Paypal.test.ts | 5 +- tests/PaymentMethods/PiM.test.ts | 2 +- tests/PaymentMethods/Pos.test.ts | 2 +- tests/PaymentMethods/Przelewy24.test.ts | 2 +- tests/PaymentMethods/SEPA.test.ts | 2 +- tests/PaymentMethods/Sofort.test.ts | 2 +- tests/PaymentMethods/Thunes.test.ts | 2 +- tests/PaymentMethods/Tinka.test.ts | 3 +- tests/PaymentMethods/WechatPay.test.ts | 2 +- 218 files changed, 487 insertions(+), 549 deletions(-) create mode 100644 src/Models/Response/index.ts delete mode 100644 src/PaymentMethods/PaymentMethods.ts create mode 100644 src/Request/index.ts create mode 100644 src/Services/index.ts diff --git a/src/Constants/IPProtocolVersion.ts b/src/Constants/IPProtocolVersion.ts index 087cd59e..eb8f8d0d 100644 --- a/src/Constants/IPProtocolVersion.ts +++ b/src/Constants/IPProtocolVersion.ts @@ -1,6 +1,6 @@ import * as IpAddress from 'ip-address'; -import { getIPAddress } from '../Utils/Functions'; +import { getIPAddress } from '../Utils'; export class IPProtocolVersion { public static readonly IPV4: number = 0; diff --git a/src/Constants/index.ts b/src/Constants/index.ts index 04d1e6dd..c7dbcd7f 100644 --- a/src/Constants/index.ts +++ b/src/Constants/index.ts @@ -1,4 +1,11 @@ -export * from './Endpoints'; -export * from './Gender'; -export { default as RecipientCategory } from './RecipientCategory'; +import Endpoints, { RequestTypes } from './Endpoints'; + +export { default as CreditManagementInstallmentInterval } from './CreditManagementInstallmentInterval'; +export { default as Gender } from './Gender'; +export { default as HttpMethods } from './HttpMethods'; +export * from './IPProtocolVersion'; export * from './ResponseStatus'; +export { default as RecipientCategory } from './RecipientCategory'; +export { default as ResponseStatus } from './ResponseStatus'; + +export { Endpoints, RequestTypes }; \ No newline at end of file diff --git a/src/Handlers/Credentials.ts b/src/Handlers/Credentials.ts index c3f0a049..5accfd98 100644 --- a/src/Handlers/Credentials.ts +++ b/src/Handlers/Credentials.ts @@ -1,6 +1,6 @@ -import { ICredentials } from '../Utils/Types'; -import Request from '../Request/Request'; -import { RequestTypes } from '../Constants/Endpoints'; +import { ICredentials } from '../Utils'; +import { Request } from '../Request'; +import { RequestTypes } from '../Constants'; export class Credentials implements ICredentials { secretKey: string; diff --git a/src/Handlers/Reply/ReplyHandler.ts b/src/Handlers/Reply/ReplyHandler.ts index 47d071e5..9319088a 100644 --- a/src/Handlers/Reply/ReplyHandler.ts +++ b/src/Handlers/Reply/ReplyHandler.ts @@ -1,7 +1,7 @@ import crypto from 'crypto'; -import { ICredentials } from '../../Utils/Types'; -import { Hmac } from '../../Request/Hmac'; -import HttpMethods from '../../Constants/HttpMethods'; +import { ICredentials } from '../../Utils'; +import { Hmac } from '../../Request'; +import { HttpMethods } from '../../Constants'; export class ReplyHandler { private readonly _data: object; diff --git a/src/Models/IParameters.ts b/src/Models/IParameters.ts index 5158994e..91228beb 100644 --- a/src/Models/IParameters.ts +++ b/src/Models/IParameters.ts @@ -1,5 +1,5 @@ import { Model } from './Model'; -import { Str } from '../Utils/Functions'; +import { Str } from '../Utils'; export interface IParameter { name: string; diff --git a/src/Models/IRequest.ts b/src/Models/IRequest.ts index 1c7bae92..697d53d1 100644 --- a/src/Models/IRequest.ts +++ b/src/Models/IRequest.ts @@ -1,4 +1,4 @@ -import { ServiceCode } from '../Utils/MethodTypes'; +import { ServiceCode } from '../Utils'; import { IAdditionalParameters } from './IParameters'; export default interface IRequest { diff --git a/src/Models/Interfaces/ICustomer.ts b/src/Models/Interfaces/ICustomer.ts index 277a522b..6bec9001 100644 --- a/src/Models/Interfaces/ICustomer.ts +++ b/src/Models/Interfaces/ICustomer.ts @@ -1,8 +1,5 @@ -import IAddress, { Address } from './IAddress'; -import IPhone, { Phone } from './IPhone'; -import { Company, ICompany, IPerson, Person } from './IRecipient'; -import { Model } from '../Model'; -import recipientCategory from '../../Constants/RecipientCategory'; +import { Address, Company, IAddress, ICompany, IPerson, IPhone, Model, Person, Phone } from './../'; +import { RecipientCategory } from '../../Constants'; export interface ICustomer { phone?: Partial; @@ -25,9 +22,9 @@ export class Customer extends Model { } set recipient(recipient: IPerson | ICompany) { - if (recipient.category === recipientCategory.PERSON) { + if (recipient.category === RecipientCategory.PERSON) { this.set('recipient', new Person(recipient)); - } else if (recipient.category === recipientCategory.COMPANY) { + } else if (recipient.category === RecipientCategory.COMPANY) { this.set('recipient', new Company(recipient)); } } diff --git a/src/Models/Interfaces/IRecipient.ts b/src/Models/Interfaces/IRecipient.ts index 998ccd4f..382c5f83 100644 --- a/src/Models/Interfaces/IRecipient.ts +++ b/src/Models/Interfaces/IRecipient.ts @@ -1,6 +1,5 @@ -import RecipientCategory from '../../Constants/RecipientCategory'; +import { Gender, RecipientCategory } from '../../Constants'; import { Model } from '../Model'; -import Gender from '../../Constants/Gender'; export interface IRecipient { [key: string]: any; diff --git a/src/Models/Interfaces/index.ts b/src/Models/Interfaces/index.ts index eaee1753..c5f7ee8b 100644 --- a/src/Models/Interfaces/index.ts +++ b/src/Models/Interfaces/index.ts @@ -1,3 +1,24 @@ -import type IArticle from './IArticle'; +import IAddress, { Address } from './IAddress'; +import IArticle, { Article } from './IArticle'; +import IBankAccount, { BankAccount } from './IBankAccount'; +import IDebtor, { Debtor } from './IDebtor'; +import IEmail, { Email } from './IEmail'; +import IPhone, { Phone } from './IPhone'; -export { IArticle }; \ No newline at end of file +export * from './ICustomer'; + +export * from './IRecipient'; +export { + IArticle, + Article, + IAddress, + Address, + IBankAccount, + BankAccount, + IDebtor, + Debtor, + IEmail, + Email, + IPhone, + Phone, +}; \ No newline at end of file diff --git a/src/Models/Model.ts b/src/Models/Model.ts index 6b9a01ca..48f4456c 100644 --- a/src/Models/Model.ts +++ b/src/Models/Model.ts @@ -1,4 +1,4 @@ -import { Str } from '../Utils/Functions'; +import { Str } from '../Utils'; export class Model { [key: keyof any]: any; diff --git a/src/Models/Response/HttpClientResponse.ts b/src/Models/Response/HttpClientResponse.ts index a9b906bf..8f9ef95f 100644 --- a/src/Models/Response/HttpClientResponse.ts +++ b/src/Models/Response/HttpClientResponse.ts @@ -1,6 +1,6 @@ import { JsonModel } from '../Model'; -import { ReplyHandler } from '../../Handlers/Reply/ReplyHandler'; -import { ICredentials } from '../../Utils/Types'; +import { ReplyHandler } from '../../Handlers'; +import { ICredentials } from '../../Utils'; import { AxiosResponse } from 'axios'; export interface HttpResponseConstructor { diff --git a/src/Models/Response/SpecificationRequestResponse.ts b/src/Models/Response/SpecificationRequestResponse.ts index 7bc97141..59136652 100644 --- a/src/Models/Response/SpecificationRequestResponse.ts +++ b/src/Models/Response/SpecificationRequestResponse.ts @@ -1,4 +1,4 @@ -import { Str } from '../../Utils/Functions'; +import { Str } from '../../Utils'; import { HttpClientResponse } from './HttpClientResponse'; export class SpecificationRequestResponse extends HttpClientResponse { diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index 82273cd5..fc2617ea 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -1,5 +1,5 @@ -import ResponseStatus from '../../Constants/ResponseStatus'; -import { DataFormatter } from '../../Utils/Functions'; +import { ResponseStatus } from '../../Constants'; +import { DataFormatter } from '../../Utils'; import { HttpClientResponse } from './HttpClientResponse'; import { IFormattedParameter } from '../IParameters'; diff --git a/src/Models/Response/index.ts b/src/Models/Response/index.ts new file mode 100644 index 00000000..54fd2701 --- /dev/null +++ b/src/Models/Response/index.ts @@ -0,0 +1,4 @@ +export * from './BatchRequestResponse'; +export * from './HttpClientResponse'; +export * from './SpecificationRequestResponse'; +export * from './TransactionResponse'; diff --git a/src/Models/ServiceParameters.ts b/src/Models/ServiceParameters.ts index 1329deb7..87957fc5 100644 --- a/src/Models/ServiceParameters.ts +++ b/src/Models/ServiceParameters.ts @@ -1,5 +1,5 @@ import { Model } from './Model'; -import { DataFormatter } from '../Utils/Functions'; +import { DataFormatter } from '../Utils'; import { IParameter } from './IParameters'; export class ServiceParameter extends Model { diff --git a/src/Models/index.ts b/src/Models/index.ts index a2f1caaf..cbf65b91 100644 --- a/src/Models/index.ts +++ b/src/Models/index.ts @@ -1,2 +1,10 @@ +import IRequest, { IPaymentRequest, IRefundRequest } from './IRequest'; + export * from './Interfaces'; -export * from './IRequest'; +export * from './Response'; +export * from './IParameters'; +export * from './IServiceList'; +export * from './Model'; +export * from './ServiceParameters'; + +export { IRequest, IPaymentRequest, IRefundRequest }; \ No newline at end of file diff --git a/src/PaymentMethods/Afterpay/Model/Address.ts b/src/PaymentMethods/Afterpay/Model/Address.ts index 37fcef40..6bc27ee3 100644 --- a/src/PaymentMethods/Afterpay/Model/Address.ts +++ b/src/PaymentMethods/Afterpay/Model/Address.ts @@ -1,4 +1,4 @@ -import { Address as IAddress } from '../../../Models/Interfaces/IAddress'; +import { Address as IAddress } from '../../../Models'; export default class Address extends IAddress { get houseNumber(): string { diff --git a/src/PaymentMethods/Afterpay/Model/Article.ts b/src/PaymentMethods/Afterpay/Model/Article.ts index 04a81428..2dfb9da8 100644 --- a/src/PaymentMethods/Afterpay/Model/Article.ts +++ b/src/PaymentMethods/Afterpay/Model/Article.ts @@ -1,4 +1,4 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; +import { Article, IArticle } from '../../../Models'; export interface IAfterPayArticle extends Partial { type?: string; diff --git a/src/PaymentMethods/Afterpay/Model/Customer.ts b/src/PaymentMethods/Afterpay/Model/Customer.ts index 70a7a055..e330e248 100644 --- a/src/PaymentMethods/Afterpay/Model/Customer.ts +++ b/src/PaymentMethods/Afterpay/Model/Customer.ts @@ -1,12 +1,8 @@ -import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient'; -import IAddress from '../../../Models/Interfaces/IAddress'; -import IPhone from '../../../Models/Interfaces/IPhone'; -import { Model } from '../../../Models/Model'; -import RecipientCategory from '../../../Constants/RecipientCategory'; +import { IAddress, ICompany, ICustomer, IPerson, IPhone, Model } from '../../../Models'; +import { RecipientCategory } from '../../../Constants'; import Phone from './Phone'; import Address from './Address'; import { AfterPayCompany, AfterPayPerson } from './Recipient'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export default class Customer extends Model implements ICustomer { set recipient(recipient: IPerson | ICompany) { diff --git a/src/PaymentMethods/Afterpay/Model/Pay.ts b/src/PaymentMethods/Afterpay/Model/Pay.ts index 85518425..95e54098 100644 --- a/src/PaymentMethods/Afterpay/Model/Pay.ts +++ b/src/PaymentMethods/Afterpay/Model/Pay.ts @@ -1,9 +1,6 @@ import { AfterPayArticle, IAfterPayArticle } from './Article'; import Customer from './Customer'; -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; - -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { ICustomer, IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { clientIP: string; diff --git a/src/PaymentMethods/Afterpay/Model/Phone.ts b/src/PaymentMethods/Afterpay/Model/Phone.ts index 8e6adff8..ba2be7a1 100644 --- a/src/PaymentMethods/Afterpay/Model/Phone.ts +++ b/src/PaymentMethods/Afterpay/Model/Phone.ts @@ -1,4 +1,4 @@ -import { Phone as IPhone } from '../../../Models/Interfaces/IPhone'; +import { Phone as IPhone } from '../../../Models'; export default class Phone extends IPhone { get mobile(): string { diff --git a/src/PaymentMethods/Afterpay/Model/Recipient.ts b/src/PaymentMethods/Afterpay/Model/Recipient.ts index 8901d3a1..039787d4 100644 --- a/src/PaymentMethods/Afterpay/Model/Recipient.ts +++ b/src/PaymentMethods/Afterpay/Model/Recipient.ts @@ -1,4 +1,4 @@ -import { Company, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; +import { Company, IPerson, Person } from '../../../Models'; export class AfterPayCompany extends Company { set title(title: string) { diff --git a/src/PaymentMethods/Afterpay/Model/Refund.ts b/src/PaymentMethods/Afterpay/Model/Refund.ts index b3731b51..3ced4122 100644 --- a/src/PaymentMethods/Afterpay/Model/Refund.ts +++ b/src/PaymentMethods/Afterpay/Model/Refund.ts @@ -1,6 +1,5 @@ -import { IRefundRequest } from '../../../Models/IRequest'; +import { IRefundRequest, ServiceParameter } from '../../../Models'; import { AfterPayArticle, IAfterPayArticle } from './Article'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; export interface IRefund extends IRefundRequest { articles?: IAfterPayArticle[]; diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 3d67cfb1..9c793ef9 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -1,7 +1,7 @@ import { IPay, Pay } from './Model/Pay'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; import { IRefund, Refund } from './Model/Refund'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; +import { PayablePaymentMethod } from '../../Services'; export default class Afterpay extends PayablePaymentMethod< Code, diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts index a34dd393..6dbb5972 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Article.ts @@ -1,4 +1,4 @@ -import { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; +import { Article as ArticleClass } from '../../../Models'; export default class Article extends ArticleClass { get identifier(): string { diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts index ff964599..241983a9 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Customer.ts @@ -1,7 +1,6 @@ import { Address } from '../Services/Address'; -import { Model } from '../../../Models/Model'; +import { ICustomer, Model } from '../../../Models'; import { Phone } from '../Services/Phone'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; import { Recipient } from './Recipient'; export class Customer extends Model implements ICustomer { diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts index 3ab57cab..5f5bea13 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Pay.ts @@ -1,9 +1,6 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IArticle, ICustomer, IPaymentRequest, ServiceParameter } from '../../../Models'; import Article from './Article'; -import IArticle from '../../../Models/Interfaces/IArticle'; import { Customer } from './Customer'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IPay extends IPaymentRequest { b2b: boolean; diff --git a/src/PaymentMethods/AfterpayDigiAccept/Model/Recipient.ts b/src/PaymentMethods/AfterpayDigiAccept/Model/Recipient.ts index 35dc3bdd..9f9133e9 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Model/Recipient.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Model/Recipient.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Recipient extends Model { set prefix(value: string) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts index a64bcf6c..765438fc 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Address.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Address extends Model { set prefix(value: string) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts index 9b41160e..a63d0cc1 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/Services/Phone.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Phone extends Model { set prefix(value: string) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 7f59ee10..3a92cb36 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -1,5 +1,5 @@ -import IRequest, { IRefundRequest } from '../../Models/IRequest'; -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { IRefundRequest, IRequest } from '../../Models'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Model/Pay'; export default class AfterpayDigiAccept< diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 88642912..1ff2e18d 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,12 +1,10 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; -import { ServiceParameter } from '../../Models/ServiceParameters'; +import { PayablePaymentMethod } from '../../Services'; +import { IPaymentRequest, IRefundRequest, ServiceParameter } from '../../Models'; export default class Alipay extends PayablePaymentMethod< Code, Manually > { - pay(payload: { useMobileView?: boolean } & IPaymentRequest) { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); return super.pay(payload, serviceParameters); diff --git a/src/PaymentMethods/ApplePay/Models/Pay.ts b/src/PaymentMethods/ApplePay/Models/Pay.ts index a75b5132..30396b7a 100644 --- a/src/PaymentMethods/ApplePay/Models/Pay.ts +++ b/src/PaymentMethods/ApplePay/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { paymentData: string; diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 0154a6bd..c6c56ac0 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -1,12 +1,11 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; export default class ApplePay extends PayablePaymentMethod< Code, Manually > { - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Bancontact/Models/Pay.ts b/src/PaymentMethods/Bancontact/Models/Pay.ts index e78ea659..38f02d63 100644 --- a/src/PaymentMethods/Bancontact/Models/Pay.ts +++ b/src/PaymentMethods/Bancontact/Models/Pay.ts @@ -1,5 +1,4 @@ -import IRequest, { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, IRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { saveToken?: boolean; diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index f70f832b..547cb9e8 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -1,12 +1,11 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; -import { IRefundRequest } from '../../Models/IRequest'; +import { IRefundRequest } from '../../Models'; export default class Bancontact< Code extends 'bancontactmrcash', Manually extends boolean = false > extends PayablePaymentMethod { - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BankTransfer/Models/Pay.ts b/src/PaymentMethods/BankTransfer/Models/Pay.ts index a6502bd2..b4e6bee8 100644 --- a/src/PaymentMethods/BankTransfer/Models/Pay.ts +++ b/src/PaymentMethods/BankTransfer/Models/Pay.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, IPerson, Person, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { customer: Partial; diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 30a39a60..563a7d5d 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -1,12 +1,11 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -import { IRefundRequest } from '../../Models/IRequest'; +import { IRefundRequest } from '../../Models'; export default class BankTransfer< Code extends 'transfer', Manually extends boolean = false > extends PayablePaymentMethod { - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index e056d662..de9ebe66 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,11 +1,10 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; export default class Belfius extends PayablePaymentMethod< Code, Manually > { - pay(payload: IPaymentRequest) { return super.pay(payload); } diff --git a/src/PaymentMethods/Billink/Models/Address.ts b/src/PaymentMethods/Billink/Models/Address.ts index 69d34609..4bb28620 100644 --- a/src/PaymentMethods/Billink/Models/Address.ts +++ b/src/PaymentMethods/Billink/Models/Address.ts @@ -1,4 +1,4 @@ -import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; +import { Address as AddressClass } from '../../../Models'; export class Address extends AddressClass { set houseNumber(houseNumber: string) { diff --git a/src/PaymentMethods/Billink/Models/Article.ts b/src/PaymentMethods/Billink/Models/Article.ts index 974ed43e..cf4b5055 100644 --- a/src/PaymentMethods/Billink/Models/Article.ts +++ b/src/PaymentMethods/Billink/Models/Article.ts @@ -1,4 +1,4 @@ -import IArticle, { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; +import { Article as ArticleClass, IArticle } from '../../../Models'; export interface IBillinkArticle extends Partial { priceExcl: number; diff --git a/src/PaymentMethods/Billink/Models/Capture.ts b/src/PaymentMethods/Billink/Models/Capture.ts index 915c3f44..3f381150 100644 --- a/src/PaymentMethods/Billink/Models/Capture.ts +++ b/src/PaymentMethods/Billink/Models/Capture.ts @@ -1,6 +1,5 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; import { Article, IBillinkArticle } from './Article'; -import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface ICapture extends IPaymentRequest { articles?: IBillinkArticle[]; diff --git a/src/PaymentMethods/Billink/Models/Customer.ts b/src/PaymentMethods/Billink/Models/Customer.ts index 2745df8a..9caaf3f4 100644 --- a/src/PaymentMethods/Billink/Models/Customer.ts +++ b/src/PaymentMethods/Billink/Models/Customer.ts @@ -1,10 +1,7 @@ -import IPhone from '../../../Models/Interfaces/IPhone'; import { Phone } from './Phone'; -import IAddress from '../../../Models/Interfaces/IAddress'; import { Address } from './Address'; -import { Customer } from '../../../Models/Interfaces/ICustomer'; -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import recipientCategory from '../../../Constants/RecipientCategory'; +import { Company, Customer, IAddress, ICompany, IPerson, IPhone, Person } from '../../../Models'; +import { RecipientCategory } from '../../../Constants'; export class BillinkCustomer extends Customer { set address(address: IAddress) { @@ -16,16 +13,16 @@ export class BillinkCustomer extends Customer { } set recipient(recipient: IPerson | ICompany) { - if (recipient.category === recipientCategory.PERSON) { + if (recipient.category === RecipientCategory.PERSON) { this.set('recipient', new BillinkPerson(recipient)); - } else if (recipient.category === recipientCategory.COMPANY) { + } else if (recipient.category === RecipientCategory.COMPANY) { this.set('recipient', new BillinkCompany(recipient)); } else throw new Error('Invalid recipient category'); } } export class BillinkPerson extends Person { - set category(category: recipientCategory.PERSON) { + set category(category: RecipientCategory.PERSON) { this.set('category', 'B2C'); } @@ -35,7 +32,7 @@ export class BillinkPerson extends Person { } export class BillinkCompany extends Company { - set category(category: recipientCategory.COMPANY) { + set category(category: RecipientCategory.COMPANY) { this.set('category', 'B2B'); } diff --git a/src/PaymentMethods/Billink/Models/Pay.ts b/src/PaymentMethods/Billink/Models/Pay.ts index fd36a268..8ad8e807 100644 --- a/src/PaymentMethods/Billink/Models/Pay.ts +++ b/src/PaymentMethods/Billink/Models/Pay.ts @@ -1,7 +1,5 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; +import { ICustomer, IPaymentRequest, ServiceParameter } from '../../../Models'; import { Article, IBillinkArticle } from './Article'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; import { BillinkCustomer } from './Customer'; export interface IPay extends IPaymentRequest { diff --git a/src/PaymentMethods/Billink/Models/Phone.ts b/src/PaymentMethods/Billink/Models/Phone.ts index b42bd22b..a3200b00 100644 --- a/src/PaymentMethods/Billink/Models/Phone.ts +++ b/src/PaymentMethods/Billink/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; +import { Phone as PhoneClass } from '../../../Models'; export class Phone extends PhoneClass { set fax(fax: string) { diff --git a/src/PaymentMethods/Billink/Models/Refund.ts b/src/PaymentMethods/Billink/Models/Refund.ts index 64349d6f..b6b04cfd 100644 --- a/src/PaymentMethods/Billink/Models/Refund.ts +++ b/src/PaymentMethods/Billink/Models/Refund.ts @@ -1,5 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IRefundRequest } from '../../../Models/IRequest'; +import { IRefundRequest, ServiceParameter } from '../../../Models'; export interface IRefund extends IRefundRequest { refundReason?: string; diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 684708fe..0b7a0d27 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts index ccfe02fd..b83c9c3e 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Create.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Create.ts @@ -1,5 +1,4 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface ICreate extends IRequest { groupReference?: string; diff --git a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts index 88cbb0fe..043ab3d8 100644 --- a/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts +++ b/src/PaymentMethods/BuckarooVoucher/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { voucherCode: string; diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 18a888d4..9ed96fed 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -1,13 +1,12 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -import IRequest from '../../Models/IRequest'; +import { IRequest } from '../../Models'; import { Create, ICreate } from './Models/Create'; export default class BuckarooVoucher< Code extends 'buckaroovoucher', Manually extends boolean = false > extends PayablePaymentMethod { - pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts index 3f2c7f6f..479db4b8 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/BankAccount.ts @@ -1,4 +1,4 @@ -import { BankAccount as BankAccountClass } from '../../../Models/Interfaces/IBankAccount'; +import { BankAccount as BankAccountClass } from '../../../Models'; export class BankAccount extends BankAccountClass { set iban(value: string) { diff --git a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts index c501886a..59f504b4 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Customer.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Customer.ts @@ -1,5 +1,5 @@ -import { Person } from '../../../Models/Interfaces/IRecipient'; -import RecipientCategory from '../../../Constants/RecipientCategory'; +import { Person } from '../../../Models'; +import { RecipientCategory } from '../../../Constants'; export class Customer extends Person { set category(value: RecipientCategory.PERSON) {} diff --git a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts index a8b862a7..6603ca00 100644 --- a/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts +++ b/src/PaymentMethods/BuckarooWallet/Models/Wallet.ts @@ -1,8 +1,5 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { IBankAccount, IPerson, IRequest, ServiceParameter } from '../../../Models'; import { Customer } from './Customer'; -import IBankAccount from '../../../Models/Interfaces/IBankAccount'; import { BankAccount } from './BankAccount'; export interface IWallet extends IRequest { diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 80d4e0ca..74b83ad7 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -1,12 +1,11 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IWallet, Wallet } from './Models/Wallet'; -import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; export default class BuckarooWallet< Code extends 'BuckarooWalletCollecting', Manually extends boolean = false > extends PayablePaymentMethod { - pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); } diff --git a/src/PaymentMethods/CreditCard/Models/CardData.ts b/src/PaymentMethods/CreditCard/Models/CardData.ts index 56c160af..36e60c67 100644 --- a/src/PaymentMethods/CreditCard/Models/CardData.ts +++ b/src/PaymentMethods/CreditCard/Models/CardData.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface ICardData extends IPaymentRequest { encryptedCardData: string; diff --git a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts index 3409cfe2..62acc9ed 100644 --- a/src/PaymentMethods/CreditCard/Models/SecurityCode.ts +++ b/src/PaymentMethods/CreditCard/Models/SecurityCode.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface ISecurityCode extends IPaymentRequest { encryptedSecurityCode: string; diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index a26bdf12..3903eb3a 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import IRequest, { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; import { CardData, ICardData } from './Models/CardData'; import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; @@ -7,7 +7,6 @@ export default class CreditCard< Code extends 'CreditCard', Manually extends boolean = false > extends PayablePaymentMethod { - payEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('PayEncrypted', new CardData(payload)); diff --git a/src/PaymentMethods/CreditClick/Models/Pay.ts b/src/PaymentMethods/CreditClick/Models/Pay.ts index fd8506f2..f2afb8d4 100644 --- a/src/PaymentMethods/CreditClick/Models/Pay.ts +++ b/src/PaymentMethods/CreditClick/Models/Pay.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { IPerson } from '../../../Models/Interfaces/IRecipient'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, IPerson, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { person: Partial; diff --git a/src/PaymentMethods/CreditClick/Models/Refund.ts b/src/PaymentMethods/CreditClick/Models/Refund.ts index f52b79ef..3b45743a 100644 --- a/src/PaymentMethods/CreditClick/Models/Refund.ts +++ b/src/PaymentMethods/CreditClick/Models/Refund.ts @@ -1,5 +1,4 @@ -import { IRefundRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRefundRequest, ServiceParameter } from '../../../Models'; export interface IRefund extends IRefundRequest { description?: string; diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 55afeacf..8d05c5c0 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; diff --git a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts index 26a07561..3f9c0673 100644 --- a/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts +++ b/src/PaymentMethods/CreditManagement/Models/AddOrUpdateProductLines.ts @@ -1,6 +1,5 @@ import { CreditArticle, ICreditArticle } from './Article'; -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface IAddOrUpdateProductLines extends IRequest { invoiceKey: string; diff --git a/src/PaymentMethods/CreditManagement/Models/Address.ts b/src/PaymentMethods/CreditManagement/Models/Address.ts index 97bb968c..03e9a23c 100644 --- a/src/PaymentMethods/CreditManagement/Models/Address.ts +++ b/src/PaymentMethods/CreditManagement/Models/Address.ts @@ -1,4 +1,4 @@ -import { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; +import { Address as AddressClass } from '../../../Models'; export class Address extends AddressClass { set houseNumberAdditional(value: string) { diff --git a/src/PaymentMethods/CreditManagement/Models/Article.ts b/src/PaymentMethods/CreditManagement/Models/Article.ts index 66f0d1bc..9c25a403 100644 --- a/src/PaymentMethods/CreditManagement/Models/Article.ts +++ b/src/PaymentMethods/CreditManagement/Models/Article.ts @@ -1,4 +1,4 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; +import { Article, IArticle } from '../../../Models'; export interface ICreditArticle extends Partial { totalVat: number; diff --git a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts index ea547859..efc8b6d9 100644 --- a/src/PaymentMethods/CreditManagement/Models/CreditNote.ts +++ b/src/PaymentMethods/CreditManagement/Models/CreditNote.ts @@ -1,5 +1,4 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface ICreditNote extends IRequest { originalInvoiceNumber: string; diff --git a/src/PaymentMethods/CreditManagement/Models/Debtor.ts b/src/PaymentMethods/CreditManagement/Models/Debtor.ts index 7e84250e..ba26980d 100644 --- a/src/PaymentMethods/CreditManagement/Models/Debtor.ts +++ b/src/PaymentMethods/CreditManagement/Models/Debtor.ts @@ -1,4 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ServiceParameter } from '../../../Models'; import { IDebtorInfo } from './DebtorInfo'; export interface IDebtor extends IDebtorInfo { diff --git a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts index dedbd1fd..da1856b9 100644 --- a/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts +++ b/src/PaymentMethods/CreditManagement/Models/DebtorInfo.ts @@ -1,6 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import IDebtor, { Debtor as DebtorClass } from '../../../Models/Interfaces/IDebtor'; -import IRequest from '../../../Models/IRequest'; +import { Debtor as DebtorClass, IDebtor, IRequest, ServiceParameter } from '../../../Models'; export interface IDebtorInfo extends IRequest { debtor: IDebtor; diff --git a/src/PaymentMethods/CreditManagement/Models/Invoice.ts b/src/PaymentMethods/CreditManagement/Models/Invoice.ts index 18442db9..551c29f0 100644 --- a/src/PaymentMethods/CreditManagement/Models/Invoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/Invoice.ts @@ -1,10 +1,5 @@ -import IPhone from '../../../Models/Interfaces/IPhone'; -import IAddress from '../../../Models/Interfaces/IAddress'; +import { IAddress, ICompany, IDebtor, IPerson, IPhone, IRequest, ServiceParameter } from '../../../Models'; import { CreditArticle, ICreditArticle } from './Article'; -import IRequest from '../../../Models/IRequest'; -import { ICompany, IPerson } from '../../../Models/Interfaces/IRecipient'; -import IDebtor from '../../../Models/Interfaces/IDebtor'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; import { Address } from './Address'; export interface IInvoice extends IRequest { diff --git a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts index 2fcbdb10..19badb97 100644 --- a/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts +++ b/src/PaymentMethods/CreditManagement/Models/PaymentPlan.ts @@ -1,6 +1,5 @@ -import IRequest from '../../../Models/IRequest'; -import CreditManagementInstallmentInterval from '../../../Constants/CreditManagementInstallmentInterval'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { CreditManagementInstallmentInterval } from '../../../Constants'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface IPaymentPlan extends IRequest { includedInvoiceKey?: string; diff --git a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts index 4fff9b38..32acaaea 100644 --- a/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts +++ b/src/PaymentMethods/CreditManagement/Models/multiInfoInvoice.ts @@ -1,5 +1,4 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface IMultiInfoInvoice extends IRequest { invoice: string; diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 22fe801f..4af819f8 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -1,13 +1,12 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { IInvoice, Invoice } from './Models/Invoice'; import { CreditNote, ICreditNote } from './Models/CreditNote'; import { Debtor, IDebtor } from './Models/Debtor'; import { IPaymentPlan, PaymentPlan } from './Models/PaymentPlan'; import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice'; import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines'; -import IRequest from '../../Models/IRequest'; +import { IRequest, ServiceParameter } from '../../Models'; import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; -import { ServiceParameter } from '../../Models/ServiceParameters'; export default class CreditManagement< Code extends 'CreditManagement3', diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index dc4d45a9..21c36911 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,7 +1,6 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; export default class EPS extends PayablePaymentMethod< Code, Manually -> { -} +> {} diff --git a/src/PaymentMethods/Emandates/Models/Mandate.ts b/src/PaymentMethods/Emandates/Models/Mandate.ts index 7bb97195..b8106a90 100644 --- a/src/PaymentMethods/Emandates/Models/Mandate.ts +++ b/src/PaymentMethods/Emandates/Models/Mandate.ts @@ -1,5 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import IRequest from '../../../Models/IRequest'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface IMandate extends IRequest { mandateId?: string; diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 8eb14cde..1fd7ef18 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -1,5 +1,5 @@ -import PaymentMethod from '../../Services/PaymentMethod'; -import { IConfig } from '../../Utils/Types'; +import { PaymentMethod } from '../../Services'; +import { IConfig } from '../../Utils'; import { IMandate, Mandate } from './Models/Mandate'; export default class Emandates extends PaymentMethod< diff --git a/src/PaymentMethods/GiftCard/Models/Pay.ts b/src/PaymentMethods/GiftCard/Models/Pay.ts index 143ce712..aa527904 100644 --- a/src/PaymentMethods/GiftCard/Models/Pay.ts +++ b/src/PaymentMethods/GiftCard/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export default interface IPay extends IPaymentRequest { fashionChequeCardNumber?: string; diff --git a/src/PaymentMethods/GiftCard/Models/Refund.ts b/src/PaymentMethods/GiftCard/Models/Refund.ts index 7af6ceb4..bead79bf 100644 --- a/src/PaymentMethods/GiftCard/Models/Refund.ts +++ b/src/PaymentMethods/GiftCard/Models/Refund.ts @@ -1,5 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IRefundRequest } from '../../../Models/IRequest'; +import { IRefundRequest, ServiceParameter } from '../../../Models'; export interface IRefund extends IRefundRequest { email?: string; diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 642185a4..aec8a474 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import IPay, { Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; diff --git a/src/PaymentMethods/Giropay/Models/Pay.ts b/src/PaymentMethods/Giropay/Models/Pay.ts index c35c3b5c..e1908ee4 100644 --- a/src/PaymentMethods/Giropay/Models/Pay.ts +++ b/src/PaymentMethods/Giropay/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { bic?: string; diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index ead5a816..174bbb03 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; export default class Giropay extends PayablePaymentMethod< diff --git a/src/PaymentMethods/Ideal/Models/Pay.ts b/src/PaymentMethods/Ideal/Models/Pay.ts index e0fec08a..f6919862 100644 --- a/src/PaymentMethods/Ideal/Models/Pay.ts +++ b/src/PaymentMethods/Ideal/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { issuer?: string; diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index adbec3a4..f276e98e 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -1,7 +1,7 @@ import { IPay, Pay } from './Models/Pay'; -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { RequestTypes } from '../../Constants/Endpoints'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { RequestTypes } from '../../Constants'; +import { IRefundRequest } from '../../Models'; export default class Ideal extends PayablePaymentMethod< Code, diff --git a/src/PaymentMethods/IdealQR/Models/IGenerate.ts b/src/PaymentMethods/IdealQR/Models/IGenerate.ts index db98e238..4a11162e 100644 --- a/src/PaymentMethods/IdealQR/Models/IGenerate.ts +++ b/src/PaymentMethods/IdealQR/Models/IGenerate.ts @@ -1,5 +1,4 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; export interface IGenerate extends IRequest { amount: number; diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 8378462b..c764a1f8 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,5 +1,5 @@ import { Generate, IGenerate } from './Models/IGenerate'; -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; export default class IdealQR extends PaymentMethod< Code, diff --git a/src/PaymentMethods/Idin/Models/Pay.ts b/src/PaymentMethods/Idin/Models/Pay.ts index ec15d399..77eb2879 100644 --- a/src/PaymentMethods/Idin/Models/Pay.ts +++ b/src/PaymentMethods/Idin/Models/Pay.ts @@ -1,4 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ServiceParameter } from '../../../Models'; export interface IPay { issuer?: string; diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 6ce166eb..7978cda0 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; export default class Idin extends PaymentMethod { diff --git a/src/PaymentMethods/In3/Models/Article.ts b/src/PaymentMethods/In3/Models/Article.ts index 3f07a023..f645a66f 100644 --- a/src/PaymentMethods/In3/Models/Article.ts +++ b/src/PaymentMethods/In3/Models/Article.ts @@ -1,4 +1,4 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; +import { Article, IArticle } from '../../../Models'; export interface IIn3Article extends IArticle { category?: string; diff --git a/src/PaymentMethods/In3/Models/Pay.ts b/src/PaymentMethods/In3/Models/Pay.ts index d6a661d6..dad3ed92 100644 --- a/src/PaymentMethods/In3/Models/Pay.ts +++ b/src/PaymentMethods/In3/Models/Pay.ts @@ -1,5 +1,4 @@ -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; import { IIn3Article, In3Article } from './Article'; import { IIn3Recipient, In3Recipient } from './Recipient'; diff --git a/src/PaymentMethods/In3/Models/Phone.ts b/src/PaymentMethods/In3/Models/Phone.ts index b6485c7e..34c63b6c 100644 --- a/src/PaymentMethods/In3/Models/Phone.ts +++ b/src/PaymentMethods/In3/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Phone } from '../../../Models/Interfaces/IPhone'; +import { Phone } from '../../../Models'; export class In3Phone extends Phone { set landline(value: string) { diff --git a/src/PaymentMethods/In3/Models/Recipient.ts b/src/PaymentMethods/In3/Models/Recipient.ts index 4510e4a8..49aae8bc 100644 --- a/src/PaymentMethods/In3/Models/Recipient.ts +++ b/src/PaymentMethods/In3/Models/Recipient.ts @@ -1,10 +1,6 @@ -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; -import IPhone from '../../../Models/Interfaces/IPhone'; +import { Address, Company, IAddress, ICompany, ICustomer, IPerson, IPhone, Model, Person } from '../../../Models'; import { In3Phone } from './Phone'; -import RecipientCategory from '../../../Constants/RecipientCategory'; -import { Model } from '../../../Models/Model'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { RecipientCategory } from '../../../Constants'; export interface IIn3Recipient extends ICustomer { recipient: Partial; diff --git a/src/PaymentMethods/In3/Models/Refund.ts b/src/PaymentMethods/In3/Models/Refund.ts index 7735ec63..bbf6ac41 100644 --- a/src/PaymentMethods/In3/Models/Refund.ts +++ b/src/PaymentMethods/In3/Models/Refund.ts @@ -1,5 +1,5 @@ import { IIn3Article } from './Article'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { ServiceParameter } from '../../../Models'; export class Refund extends ServiceParameter { set merchantImageUrl(value: string) { diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index d2b40c87..d63304ce 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; import Pay from './Models/Pay'; export default class In3 extends PayablePaymentMethod< diff --git a/src/PaymentMethods/In3Old/Models/Address.ts b/src/PaymentMethods/In3Old/Models/Address.ts index 3b2a0618..c8b0332b 100644 --- a/src/PaymentMethods/In3Old/Models/Address.ts +++ b/src/PaymentMethods/In3Old/Models/Address.ts @@ -1,4 +1,4 @@ -import { Address } from '../../../Models/Interfaces/IAddress'; +import { Address } from '../../../Models'; export class In3OldAddress extends Address { set houseNumberAddition(houseNumberAddition: string) { diff --git a/src/PaymentMethods/In3Old/Models/Article.ts b/src/PaymentMethods/In3Old/Models/Article.ts index fe4f1d40..0bdd84d9 100644 --- a/src/PaymentMethods/In3Old/Models/Article.ts +++ b/src/PaymentMethods/In3Old/Models/Article.ts @@ -1,4 +1,4 @@ -import { Article } from '../../../Models/Interfaces/IArticle'; +import { Article } from '../../../Models'; export class In3OldArticle extends Article { set identifier(identifier: string) { diff --git a/src/PaymentMethods/In3Old/Models/Company.ts b/src/PaymentMethods/In3Old/Models/Company.ts index 71375ecc..decad29d 100644 --- a/src/PaymentMethods/In3Old/Models/Company.ts +++ b/src/PaymentMethods/In3Old/Models/Company.ts @@ -1,4 +1,4 @@ -import { Company } from '../../../Models/Interfaces/IRecipient'; +import { Company } from '../../../Models'; export class In3OldCompany extends Company { set companyName(companyName: string) { diff --git a/src/PaymentMethods/In3Old/Models/Pay.ts b/src/PaymentMethods/In3Old/Models/Pay.ts index 396b127b..a13e5690 100644 --- a/src/PaymentMethods/In3Old/Models/Pay.ts +++ b/src/PaymentMethods/In3Old/Models/Pay.ts @@ -1,11 +1,15 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import RecipientCategory from '../../../Constants/RecipientCategory'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import IArticle from '../../../Models/Interfaces/IArticle'; +import { + IAddress, + IArticle, + ICompany, + IPaymentRequest, + IPerson, + IPhone, + Person, + ServiceParameter, +} from '../../../Models'; +import { RecipientCategory } from '../../../Constants'; import { In3OldArticle } from './Article'; -import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import IAddress from '../../../Models/Interfaces/IAddress'; -import IPhone from '../../../Models/Interfaces/IPhone'; import { ISubtotal, Subtotal } from './Subtotal'; import { In3OldCompany } from './Company'; import { In3OldAddress } from './Address'; diff --git a/src/PaymentMethods/In3Old/Models/Phone.ts b/src/PaymentMethods/In3Old/Models/Phone.ts index b087822a..0cd27bed 100644 --- a/src/PaymentMethods/In3Old/Models/Phone.ts +++ b/src/PaymentMethods/In3Old/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Phone } from '../../../Models/Interfaces/IPhone'; +import { Phone } from '../../../Models'; export class In3OldPhone extends Phone { set mobile(number: string) { diff --git a/src/PaymentMethods/In3Old/Models/Subtotal.ts b/src/PaymentMethods/In3Old/Models/Subtotal.ts index 2882348b..57235b5f 100644 --- a/src/PaymentMethods/In3Old/Models/Subtotal.ts +++ b/src/PaymentMethods/In3Old/Models/Subtotal.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface ISubtotal { name: string; diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 7dc40a53..bb07c69b 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; export default class In3Old extends PayablePaymentMethod< diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 881ce14c..0133e063 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; export default class KBC< Code extends 'KBCPaymentButton', diff --git a/src/PaymentMethods/Klarna/Models/Article.ts b/src/PaymentMethods/Klarna/Models/Article.ts index cd78389e..d7a3837a 100644 --- a/src/PaymentMethods/Klarna/Models/Article.ts +++ b/src/PaymentMethods/Klarna/Models/Article.ts @@ -1,4 +1,4 @@ -import { Article } from '../../../Models/Interfaces/IArticle'; +import { Article } from '../../../Models'; export class KlarnaArticle extends Article { get price() { diff --git a/src/PaymentMethods/Klarna/Models/Pay.ts b/src/PaymentMethods/Klarna/Models/Pay.ts index 2310fc6e..f2fca527 100644 --- a/src/PaymentMethods/Klarna/Models/Pay.ts +++ b/src/PaymentMethods/Klarna/Models/Pay.ts @@ -1,9 +1,6 @@ import { KlarnaRecipient } from './Recipient'; -import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Article, IArticle, ICustomer, IPaymentRequest, ServiceParameter } from '../../../Models'; import { KlarnaArticle } from './Article'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; export interface IPay extends IPaymentRequest { billing: ICustomer; diff --git a/src/PaymentMethods/Klarna/Models/Recipient.ts b/src/PaymentMethods/Klarna/Models/Recipient.ts index 0b06dc4d..4bce0e31 100644 --- a/src/PaymentMethods/Klarna/Models/Recipient.ts +++ b/src/PaymentMethods/Klarna/Models/Recipient.ts @@ -1,11 +1,7 @@ -import IAddress from '../../../Models/Interfaces/IAddress'; -import IPhone from '../../../Models/Interfaces/IPhone'; -import { Model } from '../../../Models/Model'; +import { Company, IAddress, ICompany, ICustomer, IPerson, IPhone, Model, Person } from '../../../Models'; import { KlarnaAddress } from '../Services/KlarnaAddress'; -import { Company, ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; import { KlarnaPhone } from '../Services/KlarnaPhone'; -import RecipientCategory from '../../../Constants/RecipientCategory'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; +import { RecipientCategory } from '../../../Constants'; export class KlarnaRecipient extends Model implements ICustomer { set email(email: string) { diff --git a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts index 10d3aed2..3bfbf459 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaAddress.ts @@ -1,4 +1,4 @@ -import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; +import { Address, IAddress } from '../../../Models'; export class KlarnaAddress extends Address implements IAddress { get houseNumber(): string { diff --git a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts index 03b4a00f..10e8907f 100644 --- a/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts +++ b/src/PaymentMethods/Klarna/Services/KlarnaPhone.ts @@ -1,4 +1,4 @@ -import { Phone } from '../../../Models/Interfaces/IPhone'; +import { Phone } from '../../../Models'; export class KlarnaPhone extends Phone { get mobile(): string { diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 3102601b..52e73b0a 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,5 +1,5 @@ import { IPay, Pay } from './Models/Pay'; -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; export default class Klarna extends PayablePaymentMethod< Code, diff --git a/src/PaymentMethods/KlarnaKP/Models/Address.ts b/src/PaymentMethods/KlarnaKP/Models/Address.ts index 0a684773..635e1469 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Address.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Address.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Address extends Model { set prefix(value: string) { diff --git a/src/PaymentMethods/KlarnaKP/Models/Article.ts b/src/PaymentMethods/KlarnaKP/Models/Article.ts index cb58345f..c733df8a 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Article.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Article.ts @@ -1,4 +1,4 @@ -import { Article as ArticleClass } from '../../../Models/Interfaces/IArticle'; +import { Article as ArticleClass } from '../../../Models'; export default class Article extends ArticleClass { get description(): string { diff --git a/src/PaymentMethods/KlarnaKP/Models/Customer.ts b/src/PaymentMethods/KlarnaKP/Models/Customer.ts index ec3fe1ce..bbee8612 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Customer.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Customer.ts @@ -1,7 +1,5 @@ -import { Model } from '../../../Models/Model'; -import IAddress from '../../../Models/Interfaces/IAddress'; +import { IAddress, IRecipient, Model } from '../../../Models'; import { Address } from './Address'; -import { IRecipient } from '../../../Models/Interfaces/IRecipient'; import { Recipient } from './Recipient'; export class Customer extends Model { diff --git a/src/PaymentMethods/KlarnaKP/Models/IPay.ts b/src/PaymentMethods/KlarnaKP/Models/IPay.ts index 036e80eb..51239284 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IPay.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IPay.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { Person } from '../../../Models/Interfaces/IRecipient'; +import { IPaymentRequest, Person, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { reservationNumber?: string; diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts index d4b88c7b..64e3a112 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -1,8 +1,5 @@ -import Gender from '../../../Constants/Gender'; -import IRequest from '../../../Models/IRequest'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; -import IArticle from '../../../Models/Interfaces/IArticle'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { Gender } from '../../../Constants'; +import { IArticle, ICustomer, IRequest, ServiceParameter } from '../../../Models'; import { Customer } from './Customer'; import Article from './Article'; diff --git a/src/PaymentMethods/KlarnaKP/Models/Phone.ts b/src/PaymentMethods/KlarnaKP/Models/Phone.ts index 2b08fd98..4874b5c5 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Phone.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Person } from '../../../Models/Interfaces/IRecipient'; +import { Person } from '../../../Models'; export class Phone extends Person { set prefix(value: string) { diff --git a/src/PaymentMethods/KlarnaKP/Models/Recipient.ts b/src/PaymentMethods/KlarnaKP/Models/Recipient.ts index 3712c3bf..e911e2d5 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Recipient.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Recipient.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Recipient extends Model { set prefix(value: string) { diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 11f44dc9..07d24eba 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -1,6 +1,6 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/IPay'; -import IRequest from '../../Models/IRequest'; +import { IRequest } from '../../Models'; import { IReserve, Reserve } from './Models/IReserve'; export default class KlarnaKP extends PayablePaymentMethod< diff --git a/src/PaymentMethods/Marketplaces/Models/Marketplace.ts b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts index b96d3d33..ab3000d2 100644 --- a/src/PaymentMethods/Marketplaces/Models/Marketplace.ts +++ b/src/PaymentMethods/Marketplaces/Models/Marketplace.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface IMarketplace { amount: number; diff --git a/src/PaymentMethods/Marketplaces/Models/Seller.ts b/src/PaymentMethods/Marketplaces/Models/Seller.ts index 19703baa..aabc6703 100644 --- a/src/PaymentMethods/Marketplaces/Models/Seller.ts +++ b/src/PaymentMethods/Marketplaces/Models/Seller.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface ISeller { accountId?: string; diff --git a/src/PaymentMethods/Marketplaces/Models/Split.ts b/src/PaymentMethods/Marketplaces/Models/Split.ts index abff8adc..ced98610 100644 --- a/src/PaymentMethods/Marketplaces/Models/Split.ts +++ b/src/PaymentMethods/Marketplaces/Models/Split.ts @@ -1,5 +1,4 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IRequest, ServiceParameter } from '../../../Models'; import { IMarketplace, Marketplace } from './Marketplace'; import { ISeller, Seller } from './Seller'; diff --git a/src/PaymentMethods/Marketplaces/Models/Transfer.ts b/src/PaymentMethods/Marketplaces/Models/Transfer.ts index 83a82890..82df5874 100644 --- a/src/PaymentMethods/Marketplaces/Models/Transfer.ts +++ b/src/PaymentMethods/Marketplaces/Models/Transfer.ts @@ -1,4 +1,4 @@ -import IRequest from '../../../Models/IRequest'; +import { IRequest } from '../../../Models'; import { ISeller } from './Seller'; import { IMarketplace } from './Marketplace'; diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index b9f6eb3f..5cce3839 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index 53928fdf..f23b0fd3 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,7 +1,6 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; export default class Mbway extends PayablePaymentMethod< Code, Manually -> { -} +> {} diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index 7e8d30e4..a5e9270a 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -1,7 +1,6 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; export default class MultiBanco< Code extends 'multibanco', Manually extends boolean = false -> extends PayablePaymentMethod { -} +> extends PayablePaymentMethod {} diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index 8a97f5c5..bf1dba25 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; export default class NoService extends PayablePaymentMethod< Code, diff --git a/src/PaymentMethods/PayByBank/Models/IPay.ts b/src/PaymentMethods/PayByBank/Models/IPay.ts index e6a55706..019b03df 100644 --- a/src/PaymentMethods/PayByBank/Models/IPay.ts +++ b/src/PaymentMethods/PayByBank/Models/IPay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export default interface IPay extends IPaymentRequest { issuer: string; diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 8c91ff54..1001cadf 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; import IPay, { Pay } from './Models/IPay'; export default class PayByBank extends PayablePaymentMethod< diff --git a/src/PaymentMethods/PayPerEmail/Models/Attachments.ts b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts index cd55893e..58972a73 100644 --- a/src/PaymentMethods/PayPerEmail/Models/Attachments.ts +++ b/src/PaymentMethods/PayPerEmail/Models/Attachments.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface IAttachments { name: string; diff --git a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts index 17b70ef7..b41274d2 100644 --- a/src/PaymentMethods/PayPerEmail/Models/Invitation.ts +++ b/src/PaymentMethods/PayPerEmail/Models/Invitation.ts @@ -1,7 +1,5 @@ -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPerson, IRequest, Person, ServiceParameter } from '../../../Models'; import { Attachments, IAttachments } from './Attachments'; -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; export interface IInvitation extends IRequest { currency: string; diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index b239cce5..ea48ec22 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { IInvitation, Invitation } from './Models/Invitation'; export default class PayPerEmail extends PaymentMethod< diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index 60102286..fc9b7f1e 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; export default class Payconiq extends PayablePaymentMethod< Code, diff --git a/src/PaymentMethods/PaymentMethods.ts b/src/PaymentMethods/PaymentMethods.ts deleted file mode 100644 index 8e85fdd2..00000000 --- a/src/PaymentMethods/PaymentMethods.ts +++ /dev/null @@ -1,86 +0,0 @@ -export { default as ideal } from './Ideal'; -export { default as idealprocessing } from './Ideal'; -export { default as afterpay } from './Afterpay'; -export { default as afterpaydigiaccept } from './AfterpayDigiAccept'; -export { default as applepay } from './ApplePay'; -export { default as bancontactmrcash } from './Bancontact'; -export { default as transfer } from './BankTransfer'; -export { default as belfius } from './Belfius'; -export { default as billink } from './Billink'; -export { default as buckaroovoucher } from './BuckarooVoucher'; -export { default as BuckarooWalletCollecting } from './BuckarooWallet'; -export { default as CreditCard } from './CreditCard'; - -// Credit Cards -export { default as creditcard } from './CreditCard'; -export { default as mastercard } from './CreditCard'; -export { default as visa } from './CreditCard'; -export { default as amex } from './CreditCard'; -export { default as vpay } from './CreditCard'; -export { default as maestro } from './CreditCard'; -export { default as visaelectron } from './CreditCard'; -export { default as cartebleuevisa } from './CreditCard'; -export { default as cartebancaire } from './CreditCard'; -export { default as dankort } from './CreditCard'; -export { default as nexi } from './CreditCard'; -export { default as postepay } from './CreditCard'; - -export { default as creditclick } from './CreditClick'; -export { default as CreditManagement3 } from './CreditManagement'; -export { default as emandate } from './Emandates'; -export { default as eps } from './EPS'; - -// Gift Cards -export { default as giftcard } from './GiftCard'; -export { default as westlandbon } from './GiftCard'; -export { default as babygiftcard } from './GiftCard'; -export { default as babyparkgiftcard } from './GiftCard'; -export { default as beautywellness } from './GiftCard'; -export { default as boekenbon } from './GiftCard'; -export { default as boekenvoordeel } from './GiftCard'; -export { default as designshopsgiftcard } from './GiftCard'; -export { default as fashioncheque } from './GiftCard'; -export { default as fashionucadeaukaart } from './GiftCard'; -export { default as fijncadeau } from './GiftCard'; -export { default as koffiecadeau } from './GiftCard'; -export { default as kokenzo } from './GiftCard'; -export { default as kookcadeau } from './GiftCard'; -export { default as nationaleentertainmentcard } from './GiftCard'; -export { default as naturesgift } from './GiftCard'; -export { default as podiumcadeaukaart } from './GiftCard'; -export { default as shoesaccessories } from './GiftCard'; -export { default as webshopgiftcard } from './GiftCard'; -export { default as wijncadeau } from './GiftCard'; -export { default as wonenzo } from './GiftCard'; -export { default as yourgift } from './GiftCard'; -export { default as vvvgiftcard } from './GiftCard'; -export { default as parfumcadeaukaart } from './GiftCard'; - -export { default as giropay } from './Giropay'; -export { default as idealqr } from './IdealQR'; -export { default as idin } from './Idin'; -export { default as capayable } from './In3Old'; -export { default as KBCPaymentButton } from './KBC'; -export { default as klarna } from './Klarna'; -export { default as klarnakp } from './KlarnaKP'; -export { default as marketplaces } from './Marketplaces'; -export { default as MBWay } from './Mbway'; -export { default as multibanco } from './Multibanco'; -export { default as payconiq } from './Payconiq'; -export { default as PayByBank } from './PayByBank'; -export { default as paypal } from './Paypal'; -export { default as payperemail } from './PayPerEmail'; -export { default as pim } from './PiM'; -export { default as pospayment } from './PointOfSale'; -export { default as przelewy24 } from './Przelewy24'; -export { default as sepadirectdebit } from './SEPA'; -export { default as sofortueberweisung } from './Sofort'; -export { default as subscriptions } from './Subscriptions'; -export { default as surepay } from './Surepay'; -export { default as thunes } from './Thunes'; -export { default as tinka } from './Tinka'; -export { default as alipay } from './Alipay'; -export { default as trustly } from './Trustly'; -export { default as wechatpay } from './WeChatPay'; -export { default as In3 } from './In3'; -export { default as noservice } from './NoService'; \ No newline at end of file diff --git a/src/PaymentMethods/Paypal/Models/Address.ts b/src/PaymentMethods/Paypal/Models/Address.ts index c9d4b634..ceb64659 100644 --- a/src/PaymentMethods/Paypal/Models/Address.ts +++ b/src/PaymentMethods/Paypal/Models/Address.ts @@ -1,4 +1,4 @@ -import IAddressGlobal, { Address as AddressClass } from '../../../Models/Interfaces/IAddress'; +import { Address as AddressClass, IAddress as IAddressGlobal } from '../../../Models'; export interface IAddress extends Partial { street: string; diff --git a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts index fec52da4..1da7e288 100644 --- a/src/PaymentMethods/Paypal/Models/ExtraInfo.ts +++ b/src/PaymentMethods/Paypal/Models/ExtraInfo.ts @@ -1,9 +1,6 @@ -import IPhone from '../../../Models/Interfaces/IPhone'; -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, IPerson, IPhone, Person, ServiceParameter } from '../../../Models'; import { Phone } from './Phone'; import { Address, IAddress } from './Address'; -import { IPaymentRequest } from '../../../Models/IRequest'; export interface IExtraInfo extends IPaymentRequest { address?: IAddress; diff --git a/src/PaymentMethods/Paypal/Models/Pay.ts b/src/PaymentMethods/Paypal/Models/Pay.ts index a4c361f8..ee555c6c 100644 --- a/src/PaymentMethods/Paypal/Models/Pay.ts +++ b/src/PaymentMethods/Paypal/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { buyerEmail?: string; diff --git a/src/PaymentMethods/Paypal/Models/Phone.ts b/src/PaymentMethods/Paypal/Models/Phone.ts index 7ea9effb..09de9088 100644 --- a/src/PaymentMethods/Paypal/Models/Phone.ts +++ b/src/PaymentMethods/Paypal/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Phone as PhoneClass } from '../../../Models/Interfaces/IPhone'; +import { Phone as PhoneClass } from '../../../Models'; export class Phone extends PhoneClass { set mobile(value: string) { diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 748a03ff..8c388b38 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; diff --git a/src/PaymentMethods/PiM/Models/Generate.ts b/src/PaymentMethods/PiM/Models/Generate.ts index 294b810c..74c91e64 100644 --- a/src/PaymentMethods/PiM/Models/Generate.ts +++ b/src/PaymentMethods/PiM/Models/Generate.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { IPaymentRequest, IPerson, ServiceParameter } from '../../../Models'; export interface IGenerate extends IPaymentRequest { description: string; diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index b90489d7..f2790ae7 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { Generate, IGenerate } from './Models/Generate'; export default class PiM extends PaymentMethod { diff --git a/src/PaymentMethods/PointOfSale/Models/Pay.ts b/src/PaymentMethods/PointOfSale/Models/Pay.ts index f37d2191..8d1a50ea 100644 --- a/src/PaymentMethods/PointOfSale/Models/Pay.ts +++ b/src/PaymentMethods/PointOfSale/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { terminalId: string; diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index 681da9af..dff761fb 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,4 +1,4 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; export default class PointOfSale< diff --git a/src/PaymentMethods/Przelewy24/Models/Pay.ts b/src/PaymentMethods/Przelewy24/Models/Pay.ts index 7e37a4ba..02e3b15d 100644 --- a/src/PaymentMethods/Przelewy24/Models/Pay.ts +++ b/src/PaymentMethods/Przelewy24/Models/Pay.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, IPerson, Person, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { email: string; diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index f2129556..9594d54b 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; export default class Przelewy24< diff --git a/src/PaymentMethods/SEPA/Models/Emandate.ts b/src/PaymentMethods/SEPA/Models/Emandate.ts index 22621021..2f4ad602 100644 --- a/src/PaymentMethods/SEPA/Models/Emandate.ts +++ b/src/PaymentMethods/SEPA/Models/Emandate.ts @@ -1,4 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; +import { IPaymentRequest } from '../../../Models'; export interface IEmandate extends IPaymentRequest { mandateReference: string; diff --git a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts index 8e286768..be3d5881 100644 --- a/src/PaymentMethods/SEPA/Models/ExtraInfo.ts +++ b/src/PaymentMethods/SEPA/Models/ExtraInfo.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import IAddress from '../../../Models/Interfaces/IAddress'; +import { IAddress, IPaymentRequest } from '../../../Models'; export interface IExtraInfo extends IPaymentRequest { bic?: string; diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index 0fe90397..2b3e91ed 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -1,7 +1,5 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { IPerson, Person } from '../../../Models/Interfaces/IRecipient'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import RecipientCategory from '../../../Constants/RecipientCategory'; +import { IPaymentRequest, IPerson, Person, ServiceParameter } from '../../../Models'; +import { RecipientCategory } from '../../../Constants'; export interface IPay extends IPaymentRequest { customer?: Partial; diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 0ec81aae..ce03d491 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -1,9 +1,9 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; +import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IExtraInfo } from './Models/ExtraInfo'; import { IEmandate } from './Models/Emandate'; -import { uniqid } from '../../Utils/Functions'; -import { IPaymentRequest } from '../../Models/IRequest'; +import { uniqid } from '../../Utils'; +import { IPaymentRequest } from '../../Models'; export default class SEPA< Code extends 'sepadirectdebit', diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index f9bb9fe5..b6e9b0c3 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IPaymentRequest, IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IPaymentRequest, IRefundRequest } from '../../Models'; export default class Sofort< Code extends 'sofortueberweisung', diff --git a/src/PaymentMethods/Subscriptions/Models/Company.ts b/src/PaymentMethods/Subscriptions/Models/Company.ts index eb35983f..90f0c9cb 100644 --- a/src/PaymentMethods/Subscriptions/Models/Company.ts +++ b/src/PaymentMethods/Subscriptions/Models/Company.ts @@ -1,4 +1,4 @@ -import { Company as CompanyClass } from '../../../Models/Interfaces/IRecipient'; +import { Company as CompanyClass } from '../../../Models'; export default class Company extends CompanyClass { set companyName(companyName: string) { diff --git a/src/PaymentMethods/Subscriptions/Models/Configuration.ts b/src/PaymentMethods/Subscriptions/Models/Configuration.ts index 27b25839..9f7f877d 100644 --- a/src/PaymentMethods/Subscriptions/Models/Configuration.ts +++ b/src/PaymentMethods/Subscriptions/Models/Configuration.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export type IConfiguration = { name?: string; diff --git a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts index 21b64f9e..cfa52ee3 100644 --- a/src/PaymentMethods/Subscriptions/Models/ISubscription.ts +++ b/src/PaymentMethods/Subscriptions/Models/ISubscription.ts @@ -1,14 +1,21 @@ -import IPhone, { Phone } from '../../../Models/Interfaces/IPhone'; -import IAddress, { Address } from '../../../Models/Interfaces/IAddress'; +import { + Address, + BankAccount, + IAddress, + IBankAccount, + ICompany, + IDebtor, + IPerson, + IPhone, + IRequest, + Person, + Phone, + ServiceParameter, +} from '../../../Models'; import { IRatePlan, IRatePlans, RatePlan } from './RatePlan'; import { IRatePlanCharge, IRatePlanCharges, RatePlanCharge } from './RatePlanCharge'; import { Configuration, IConfiguration } from './Configuration'; -import IRequest from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { ICompany, IPerson, Person } from '../../../Models/Interfaces/IRecipient'; import Company from './Company'; -import IDebtor from '../../../Models/Interfaces/IDebtor'; -import IBankAccount, { BankAccount } from '../../../Models/Interfaces/IBankAccount'; export interface ISubscription extends IRequest { address?: Partial; diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts index 45492901..2988fff2 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlan.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlan.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface IRatePlans { add?: IRatePlan; diff --git a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts index ddde8073..4b6e53a4 100644 --- a/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts +++ b/src/PaymentMethods/Subscriptions/Models/RatePlanCharge.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface IRatePlanCharge { ratePlanChargeCode?: string; diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index aaa893e3..81a76803 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -1,6 +1,6 @@ import { ISubscription, Subscription } from './Models/ISubscription'; -import PaymentMethod from '../../Services/PaymentMethod'; -import IRequest from '../../Models/IRequest'; +import { PaymentMethod } from '../../Services'; +import { IRequest } from '../../Models'; import { ResumeSubscription } from './Models/ResumeSubscription'; export default class Subscriptions< diff --git a/src/PaymentMethods/Surepay/Models/BankAccount.ts b/src/PaymentMethods/Surepay/Models/BankAccount.ts index ac1a2758..1179cbc6 100644 --- a/src/PaymentMethods/Surepay/Models/BankAccount.ts +++ b/src/PaymentMethods/Surepay/Models/BankAccount.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export interface IBankAccount { iban: string; diff --git a/src/PaymentMethods/Surepay/Models/Verify.ts b/src/PaymentMethods/Surepay/Models/Verify.ts index 5e0fabaf..89da27fb 100644 --- a/src/PaymentMethods/Surepay/Models/Verify.ts +++ b/src/PaymentMethods/Surepay/Models/Verify.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; import { BankAccount, IBankAccount } from './BankAccount'; export interface IVerify extends IPaymentRequest { diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 2be11dfe..2c212087 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,4 +1,4 @@ -import PaymentMethod from '../../Services/PaymentMethod'; +import { PaymentMethod } from '../../Services'; import { IVerify, Verify } from './Models/Verify'; export default class Surepay extends PaymentMethod< diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 3952327a..915bcba9 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -1,5 +1,5 @@ -import PaymentMethod from '../../Services/PaymentMethod'; -import IRequest from '../../Models/IRequest'; +import { PaymentMethod } from '../../Services'; +import { IRequest } from '../../Models'; type key = Required>; export default class Thunes extends PaymentMethod< diff --git a/src/PaymentMethods/Tinka/Models/Address.ts b/src/PaymentMethods/Tinka/Models/Address.ts index 60775cdd..2fe31d7a 100644 --- a/src/PaymentMethods/Tinka/Models/Address.ts +++ b/src/PaymentMethods/Tinka/Models/Address.ts @@ -1,4 +1,4 @@ -import { Address } from '../../../Models/Interfaces/IAddress'; +import { Address } from '../../../Models'; export class TinkaAddress extends Address { set houseNumber(value: string) { diff --git a/src/PaymentMethods/Tinka/Models/Article.ts b/src/PaymentMethods/Tinka/Models/Article.ts index 0d49aa99..f2a70b09 100644 --- a/src/PaymentMethods/Tinka/Models/Article.ts +++ b/src/PaymentMethods/Tinka/Models/Article.ts @@ -1,4 +1,4 @@ -import IArticle, { Article } from '../../../Models/Interfaces/IArticle'; +import { Article, IArticle } from '../../../Models'; export interface ITinkaArticle extends IArticle { color?: string; diff --git a/src/PaymentMethods/Tinka/Models/Pay.ts b/src/PaymentMethods/Tinka/Models/Pay.ts index f13829ca..8f92909b 100644 --- a/src/PaymentMethods/Tinka/Models/Pay.ts +++ b/src/PaymentMethods/Tinka/Models/Pay.ts @@ -1,7 +1,5 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; +import { ICustomer, IPaymentRequest, ServiceParameter } from '../../../Models'; import { ITinkaArticle, TinkaArticle } from './Article'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { ICustomer } from '../../../Models/Interfaces/ICustomer'; import { ITinkaPerson, TinkaPerson } from './Person'; import { Recipient } from './Recipient'; diff --git a/src/PaymentMethods/Tinka/Models/Person.ts b/src/PaymentMethods/Tinka/Models/Person.ts index 4058874e..aedd6667 100644 --- a/src/PaymentMethods/Tinka/Models/Person.ts +++ b/src/PaymentMethods/Tinka/Models/Person.ts @@ -1,5 +1,5 @@ -import { Person } from '../../../Models/Interfaces/IRecipient'; -import Gender from '../../../Constants/Gender'; +import { Person } from '../../../Models'; +import { Gender } from '../../../Constants'; export interface ITinkaPerson { gender: Gender; diff --git a/src/PaymentMethods/Tinka/Models/Phone.ts b/src/PaymentMethods/Tinka/Models/Phone.ts index ada84db2..def298e4 100644 --- a/src/PaymentMethods/Tinka/Models/Phone.ts +++ b/src/PaymentMethods/Tinka/Models/Phone.ts @@ -1,4 +1,4 @@ -import { Phone } from '../../../Models/Interfaces/IPhone'; +import { Phone } from '../../../Models'; export class TinkaPhone extends Phone { set mobile(value: string) { diff --git a/src/PaymentMethods/Tinka/Models/Recipient.ts b/src/PaymentMethods/Tinka/Models/Recipient.ts index 7d880228..a2ea1618 100644 --- a/src/PaymentMethods/Tinka/Models/Recipient.ts +++ b/src/PaymentMethods/Tinka/Models/Recipient.ts @@ -1,10 +1,7 @@ -import { Customer } from '../../../Models/Interfaces/ICustomer'; -import IAddress from '../../../Models/Interfaces/IAddress'; +import { Customer, IAddress, IPerson, IPhone } from '../../../Models'; import { TinkaAddress } from './Address'; -import IPhone from '../../../Models/Interfaces/IPhone'; import { TinkaPhone } from './Phone'; import { TinkaPerson } from './Person'; -import { IPerson } from '../../../Models/Interfaces/IRecipient'; export class Recipient extends Customer { set address(value: IAddress) { diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index d25ebf0c..ad76da22 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; export default class Tinka extends PayablePaymentMethod< diff --git a/src/PaymentMethods/Trustly/Models/Customer.ts b/src/PaymentMethods/Trustly/Models/Customer.ts index 71260929..3fd8a54e 100644 --- a/src/PaymentMethods/Trustly/Models/Customer.ts +++ b/src/PaymentMethods/Trustly/Models/Customer.ts @@ -1,4 +1,4 @@ -import { Model } from '../../../Models/Model'; +import { Model } from '../../../Models'; export class Customer extends Model { set firstName(value: string) { diff --git a/src/PaymentMethods/Trustly/Models/Pay.ts b/src/PaymentMethods/Trustly/Models/Pay.ts index 594bd571..e7005b0d 100644 --- a/src/PaymentMethods/Trustly/Models/Pay.ts +++ b/src/PaymentMethods/Trustly/Models/Pay.ts @@ -1,6 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; -import { IPerson } from '../../../Models/Interfaces/IRecipient'; +import { IPaymentRequest, IPerson, ServiceParameter } from '../../../Models'; import { Customer } from './Customer'; export interface IPay extends IPaymentRequest { diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 0252a5c3..e9f1cb4d 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; export default class Trustly extends PayablePaymentMethod< diff --git a/src/PaymentMethods/WeChatPay/Models/Pay.ts b/src/PaymentMethods/WeChatPay/Models/Pay.ts index 4d47ac5e..9607d1a4 100644 --- a/src/PaymentMethods/WeChatPay/Models/Pay.ts +++ b/src/PaymentMethods/WeChatPay/Models/Pay.ts @@ -1,5 +1,4 @@ -import { IPaymentRequest } from '../../../Models/IRequest'; -import { ServiceParameter } from '../../../Models/ServiceParameters'; +import { IPaymentRequest, ServiceParameter } from '../../../Models'; export interface IPay extends IPaymentRequest { locale?: string; diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index dca83ed7..bf63ce6e 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,5 +1,5 @@ -import PayablePaymentMethod from '../../Services/PayablePaymentMethod'; -import { IRefundRequest } from '../../Models/IRequest'; +import { PayablePaymentMethod } from '../../Services'; +import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; export default class WeChatPay extends PayablePaymentMethod< diff --git a/src/PaymentMethods/index.ts b/src/PaymentMethods/index.ts index 220fc393..8e85fdd2 100644 --- a/src/PaymentMethods/index.ts +++ b/src/PaymentMethods/index.ts @@ -1 +1,86 @@ -export { default as PayablePaymentMethod } from '../Services/PayablePaymentMethod'; +export { default as ideal } from './Ideal'; +export { default as idealprocessing } from './Ideal'; +export { default as afterpay } from './Afterpay'; +export { default as afterpaydigiaccept } from './AfterpayDigiAccept'; +export { default as applepay } from './ApplePay'; +export { default as bancontactmrcash } from './Bancontact'; +export { default as transfer } from './BankTransfer'; +export { default as belfius } from './Belfius'; +export { default as billink } from './Billink'; +export { default as buckaroovoucher } from './BuckarooVoucher'; +export { default as BuckarooWalletCollecting } from './BuckarooWallet'; +export { default as CreditCard } from './CreditCard'; + +// Credit Cards +export { default as creditcard } from './CreditCard'; +export { default as mastercard } from './CreditCard'; +export { default as visa } from './CreditCard'; +export { default as amex } from './CreditCard'; +export { default as vpay } from './CreditCard'; +export { default as maestro } from './CreditCard'; +export { default as visaelectron } from './CreditCard'; +export { default as cartebleuevisa } from './CreditCard'; +export { default as cartebancaire } from './CreditCard'; +export { default as dankort } from './CreditCard'; +export { default as nexi } from './CreditCard'; +export { default as postepay } from './CreditCard'; + +export { default as creditclick } from './CreditClick'; +export { default as CreditManagement3 } from './CreditManagement'; +export { default as emandate } from './Emandates'; +export { default as eps } from './EPS'; + +// Gift Cards +export { default as giftcard } from './GiftCard'; +export { default as westlandbon } from './GiftCard'; +export { default as babygiftcard } from './GiftCard'; +export { default as babyparkgiftcard } from './GiftCard'; +export { default as beautywellness } from './GiftCard'; +export { default as boekenbon } from './GiftCard'; +export { default as boekenvoordeel } from './GiftCard'; +export { default as designshopsgiftcard } from './GiftCard'; +export { default as fashioncheque } from './GiftCard'; +export { default as fashionucadeaukaart } from './GiftCard'; +export { default as fijncadeau } from './GiftCard'; +export { default as koffiecadeau } from './GiftCard'; +export { default as kokenzo } from './GiftCard'; +export { default as kookcadeau } from './GiftCard'; +export { default as nationaleentertainmentcard } from './GiftCard'; +export { default as naturesgift } from './GiftCard'; +export { default as podiumcadeaukaart } from './GiftCard'; +export { default as shoesaccessories } from './GiftCard'; +export { default as webshopgiftcard } from './GiftCard'; +export { default as wijncadeau } from './GiftCard'; +export { default as wonenzo } from './GiftCard'; +export { default as yourgift } from './GiftCard'; +export { default as vvvgiftcard } from './GiftCard'; +export { default as parfumcadeaukaart } from './GiftCard'; + +export { default as giropay } from './Giropay'; +export { default as idealqr } from './IdealQR'; +export { default as idin } from './Idin'; +export { default as capayable } from './In3Old'; +export { default as KBCPaymentButton } from './KBC'; +export { default as klarna } from './Klarna'; +export { default as klarnakp } from './KlarnaKP'; +export { default as marketplaces } from './Marketplaces'; +export { default as MBWay } from './Mbway'; +export { default as multibanco } from './Multibanco'; +export { default as payconiq } from './Payconiq'; +export { default as PayByBank } from './PayByBank'; +export { default as paypal } from './Paypal'; +export { default as payperemail } from './PayPerEmail'; +export { default as pim } from './PiM'; +export { default as pospayment } from './PointOfSale'; +export { default as przelewy24 } from './Przelewy24'; +export { default as sepadirectdebit } from './SEPA'; +export { default as sofortueberweisung } from './Sofort'; +export { default as subscriptions } from './Subscriptions'; +export { default as surepay } from './Surepay'; +export { default as thunes } from './Thunes'; +export { default as tinka } from './Tinka'; +export { default as alipay } from './Alipay'; +export { default as trustly } from './Trustly'; +export { default as wechatpay } from './WeChatPay'; +export { default as In3 } from './In3'; +export { default as noservice } from './NoService'; \ No newline at end of file diff --git a/src/Request/DataModels.ts b/src/Request/DataModels.ts index 2e2dbcb2..81bb7d80 100644 --- a/src/Request/DataModels.ts +++ b/src/Request/DataModels.ts @@ -1,10 +1,6 @@ -import IRequest from '../Models/IRequest'; -import { Model } from '../Models/Model'; -import { ClientIP } from '../Constants/IPProtocolVersion'; -import { DataFormatter } from '../Utils/Functions'; -import { ServiceCode } from '../Utils/MethodTypes'; -import { IService, ServiceList } from '../Models/IServiceList'; -import { IAdditionalParameters } from '../Models/IParameters'; +import { IAdditionalParameters, IRequest, IService, Model, ServiceList } from '../Models'; +import { ClientIP } from '../Constants'; +import { DataFormatter, ServiceCode } from '../Utils'; export class TransactionData extends Model implements IRequest { constructor(data?: IRequest) { diff --git a/src/Request/Hmac.ts b/src/Request/Hmac.ts index 956244f0..137be5d0 100644 --- a/src/Request/Hmac.ts +++ b/src/Request/Hmac.ts @@ -1,4 +1,4 @@ -import { ICredentials } from '../Utils/Types'; +import { ICredentials } from '../Utils'; import md5 from 'crypto-js/md5'; import hmacSHA256 from 'crypto-js/hmac-sha256'; import Base64 from 'crypto-js/enc-base64'; diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index e9d25b0b..3d7de73e 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -1,7 +1,7 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; -import { HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; +import { HttpResponseConstructor } from '../Models'; import { RequestConfig } from './Headers'; -import HttpMethods from '../Constants/HttpMethods'; +import { HttpMethods } from '../Constants'; export default class HttpsClient { protected _options: AxiosRequestConfig = {}; diff --git a/src/Request/Request.ts b/src/Request/Request.ts index dd891adc..fa472e63 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -1,16 +1,18 @@ import Headers, { RequestConfig, RequestHeaders } from './Headers'; -import { HttpClientResponse, HttpResponseConstructor } from '../Models/Response/HttpClientResponse'; +import { + BatchRequestResponse, + HttpClientResponse, + HttpResponseConstructor, + IRequest, + IService, + SpecificationRequestResponse, + TransactionResponse, +} from '../Models'; import { DataRequestData, SpecificationRequestData, TransactionData } from './DataModels'; import Buckaroo from '../index'; -import Endpoints, { RequestTypes } from '../Constants/Endpoints'; -import { TransactionResponse } from '../Models/Response/TransactionResponse'; -import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; -import { BatchRequestResponse } from '../Models/Response/BatchRequestResponse'; -import HttpMethods from '../Constants/HttpMethods'; -import { ICredentials } from '../Utils/Types'; +import { Endpoints, HttpMethods, RequestTypes } from '../Constants'; +import { ICredentials } from '../Utils'; import { Hmac } from './Hmac'; -import { IService } from '../Models/IServiceList'; -import IRequest from '../Models/IRequest'; export default class Request< HttpResponse extends HttpResponseConstructor = HttpResponseConstructor, diff --git a/src/Request/index.ts b/src/Request/index.ts new file mode 100644 index 00000000..9dd74a9b --- /dev/null +++ b/src/Request/index.ts @@ -0,0 +1,7 @@ +import Headers, { RequestConfig, RequestHeaders } from './Headers'; + +export * from './DataModels'; +export * from './Hmac'; +export { default as HttpsClient } from './HttpsClient'; +export { default as Request } from './Request'; +export { Headers, RequestHeaders, RequestConfig }; \ No newline at end of file diff --git a/src/Services/PayablePaymentMethod.ts b/src/Services/PayablePaymentMethod.ts index c29a5e89..b4d1e2d9 100644 --- a/src/Services/PayablePaymentMethod.ts +++ b/src/Services/PayablePaymentMethod.ts @@ -1,9 +1,6 @@ import PaymentMethod from './PaymentMethod'; -import IRequest, { IPaymentRequest, IRefundRequest } from '../Models/IRequest'; -import { uniqid } from '../Utils/Functions'; -import { ServiceParameter } from '../Models/ServiceParameters'; -import { IParameter } from '../Models/IParameters'; -import { ServiceCode } from '../Utils'; +import { IParameter, IPaymentRequest, IRefundRequest, IRequest, ServiceParameter } from '../Models'; +import { ServiceCode, uniqid } from '../Utils'; export default abstract class PayablePaymentMethod< Code extends ServiceCode, diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 3afe1e09..2044e551 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -1,14 +1,16 @@ -import { RequestTypes } from '../Constants/Endpoints'; -import IRequest from '../Models/IRequest'; +import { RequestTypes } from '../Constants'; +import { + IParameter, + IRequest, + IService, + ServiceList, + ServiceParameter, + SpecificationRequestResponse, + TransactionResponse, +} from '../Models'; import Buckaroo from '../index'; -import Request from '../Request/Request'; -import { IService, ServiceList } from '../Models/IServiceList'; -import { ServiceParameter } from '../Models/ServiceParameters'; -import { IParameter } from '../Models/IParameters'; -import { DataRequestData, TransactionData } from '../Request/DataModels'; -import { PaymentMethodInstanceType, PaymentMethodRegistryType, ServiceCode } from '../Utils/MethodTypes'; -import { TransactionResponse } from '../Models/Response/TransactionResponse'; -import { SpecificationRequestResponse } from '../Models/Response/SpecificationRequestResponse'; +import { DataRequestData, Request, TransactionData } from '../Request'; +import { PaymentMethodInstanceType, PaymentMethodRegistryType, ServiceCode } from '../Utils'; export default abstract class PaymentMethod { public _isManually: Manually = false as Manually; diff --git a/src/Services/TransactionService.ts b/src/Services/TransactionService.ts index 7f80947c..595b75e6 100644 --- a/src/Services/TransactionService.ts +++ b/src/Services/TransactionService.ts @@ -1,7 +1,6 @@ -import Request from '../Request/Request'; -import HttpMethods from '../Constants/HttpMethods'; -import { TransactionResponse } from '../Models/Response/TransactionResponse'; -import { RequestTypes } from '../Constants/Endpoints'; +import { Request } from '../Request'; +import { HttpMethods, RequestTypes } from '../Constants'; +import { TransactionResponse } from '../Models'; export default class TransactionService { private readonly _key: string; diff --git a/src/Services/index.ts b/src/Services/index.ts new file mode 100644 index 00000000..283136e5 --- /dev/null +++ b/src/Services/index.ts @@ -0,0 +1,4 @@ +export * from './PayablePaymentMethod'; +export { default as PaymentMethod } from './PaymentMethod'; +export { default as PayablePaymentMethod } from './PayablePaymentMethod'; +export { default as TransactionService } from './TransactionService'; \ No newline at end of file diff --git a/src/Utils/Functions.ts b/src/Utils/Functions.ts index ae7a578f..d5bc2fbf 100644 --- a/src/Utils/Functions.ts +++ b/src/Utils/Functions.ts @@ -5,7 +5,7 @@ import { IParameter, IServiceParameters, ServiceParameterTypes, -} from '../Models/IParameters'; +} from '../Models'; export function uniqid(prefix: string = '', random: boolean = false) { const sec = Date.now() * 1000 + Math.random() * 1000; diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index 642c03b9..dde5ed32 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,4 +1,4 @@ -import * as AllRegisteredPaymentMethods from '../PaymentMethods/PaymentMethods'; +import * as AllRegisteredPaymentMethods from '../PaymentMethods'; type InstanceWithManualFlag = Manually extends true ? Method & { diff --git a/src/Utils/index.ts b/src/Utils/index.ts index 98568983..6ff6c310 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -1,3 +1,3 @@ export * from './MethodTypes'; export * from './Types'; -export { getIPAddress, DataFormatter } from './Functions'; \ No newline at end of file +export * from './Functions'; \ No newline at end of file diff --git a/src/buckaroo.ts b/src/buckaroo.ts index 7c46682b..8c77222c 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -1,10 +1,9 @@ import { getMethod, IConfig, ICredentials, PaymentMethodInstanceType, ServiceCode } from './Utils'; -import HttpsClient from './Request/HttpsClient'; +import { HttpsClient, Request } from './Request'; import { Agent } from 'https'; -import Request from './Request/Request'; import NoService from './PaymentMethods/NoService'; -import TransactionService from './Services/TransactionService'; -import { Credentials } from './Handlers/Credentials'; +import { TransactionService } from './Services'; +import { Credentials } from './Handlers'; export default class Buckaroo { private static _client: Buckaroo; diff --git a/src/index.ts b/src/index.ts index fd29aec5..1708bd9c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,10 @@ import Buckaroo from './buckaroo'; export * from './Constants'; export * from './Handlers'; export * from './Models'; -export * from './Utils'; export * from './PaymentMethods'; +export * from './Request'; +export * from './Services'; +export * from './Utils'; export default Buckaroo; export { Buckaroo }; \ No newline at end of file diff --git a/tests/Client.test.ts b/tests/Client.test.ts index 9f8cdb99..2f1d343e 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -1,9 +1,6 @@ import client from './BuckarooClient.test'; -import { TransactionResponse } from '../src/Models/Response/TransactionResponse'; -import { HttpClientResponse } from '../src/Models/Response/HttpClientResponse'; -import { uniqid } from '../src/Utils/Functions'; +import { HttpClientResponse, IRequest, TransactionResponse, uniqid } from '../src'; import { creditManagementTestInvoice } from './PaymentMethods/CreditManagment.test'; -import IRequest from '../src/Models/IRequest'; describe('Testing Buckaroo Client', () => { test('Credentials', () => { @@ -18,18 +15,21 @@ describe('Testing Buckaroo Client', () => { for (let i = 0; i < 3; i++) { const combinedInvoice = creditManagement.manually().createCombinedInvoice(creditManagementTestInvoice()); - const sepaRequest = sepaDirectDebit.manually().combine(combinedInvoice.data).pay({ - iban: 'NL39RABO0300065264', - bic: 'RABONL2U', - mandateReference: '1DCtestreference', - mandateDate: '2022-07-03', - collectDate: '2020-07-03', - amountDebit: 10.1, - customer: { - name: 'John Smith', - }, - invoice: uniqid('TestInvoice'), - }); + const sepaRequest = sepaDirectDebit + .manually() + .combine(combinedInvoice.data) + .pay({ + iban: 'NL39RABO0300065264', + bic: 'RABONL2U', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + collectDate: '2020-07-03', + amountDebit: 10.1, + customer: { + name: 'John Smith', + }, + invoice: uniqid('TestInvoice'), + }); transactionData.push(sepaRequest.data); } diff --git a/tests/Models/index.ts b/tests/Models/index.ts index 031937c4..bca7510f 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -1,11 +1,15 @@ -import { ICompany, IPerson } from '../../src/Models/Interfaces/IRecipient'; -import IAddress from '../../src/Models/Interfaces/IAddress'; -import IArticle from '../../src/Models/Interfaces/IArticle'; -import IPhone from '../../src/Models/Interfaces/IPhone'; -import IBankAccount from '../../src/Models/Interfaces/IBankAccount'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; -import Gender from '../../src/Constants/Gender'; +import { + Gender, + getIPAddress, + IAddress, + IArticle, + IBankAccount, + ICompany, + IPerson, + IPhone, + RecipientCategory, + uniqid, +} from '../../src'; export const TestPerson: IPerson = { birthDate: '1990-01-01', diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index 6d05f4f9..a87ad247 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -1,7 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import { getIPAddress, RecipientCategory, uniqid } from '../../src'; const paymentPayload: IPay = { invoice: uniqid(), diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index f0413916..178ae2a2 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,8 +1,6 @@ -import { RequestTypes } from '../../src/Constants/Endpoints'; +import { Gender, getIPAddress, RequestTypes, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay'; -import Gender from '../../src/Constants/Gender'; const method = buckarooClientTest.method('afterpaydigiaccept'); diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index fe303856..e48c22d7 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const alipay = buckarooClientTest.method('alipay'); diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index ef0b52be..b9d0a94f 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -1,4 +1,4 @@ -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; const method = buckarooClientTest.method('applepay'); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 7dcd9463..fc08a3d4 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('bancontactmrcash'); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 98b6ace5..80d2e4dc 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,4 +1,4 @@ -import Gender from '../../src/Constants/Gender'; +import { Gender } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; const method = buckarooClientTest.method('transfer'); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index 0c8900ae..3579e464 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('belfius'); diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index b1ffa530..4e835778 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,7 +1,6 @@ import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay'; import buckarooClientTest from '../BuckarooClient.test'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; -import { uniqid } from '../../src/Utils/Functions'; +import { RecipientCategory, uniqid } from '../../src'; const method = buckarooClientTest.method('billink'); diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 97a644b9..9c6de5e4 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('buckaroovoucher'); diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index c75bb383..81ac9552 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('BuckarooWalletCollecting'); diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index 427a4193..5198ac2c 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('visa'); diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index be2307c3..ea8f76bb 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('creditclick'); diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index b55ab2b3..0a9e7a05 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -1,8 +1,6 @@ import { IInvoice } from '../../src/PaymentMethods/CreditManagement/Models/Invoice'; -import Gender from '../../src/Constants/Gender'; -import CreditManagementInstallmentInterval from '../../src/Constants/CreditManagementInstallmentInterval'; +import { CreditManagementInstallmentInterval, Gender, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; const creditManagement = buckarooClientTest.method('CreditManagement3'); diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index a1a44740..eaeac3db 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('eps'); describe('Testing Eps methods', () => { diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index 13896a86..db9bf16e 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('boekenbon'); diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index 1168e6dc..265ba1c6 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('giropay'); describe('Testing Giropay methods', () => { diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index d1a7a734..8ffc6e8c 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,4 +1,4 @@ -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import { getIPAddress, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; const ideal = buckarooClientTest.method('ideal'); diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index bf8b9d48..036c456b 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -1,7 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import { getIPAddress, RecipientCategory, uniqid } from '../../src'; import { IPay } from '../../src/PaymentMethods/In3/Models/Pay'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; const in3 = buckarooClientTest.method('In3'); diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index 267230a8..27a66192 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -1,7 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import Gender from '../../src/Constants/Gender'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; -import { getIPAddress, uniqid } from '../../src/Utils/Functions'; +import { Gender, getIPAddress, RecipientCategory, uniqid } from '../../src'; const capayable = buckarooClientTest.method('capayable'); diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index df9bb658..18f7be92 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('KBCPaymentButton'); diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index 3e6d8b17..82e6ed64 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -1,7 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Klarna/Models/Pay'; -import { uniqid } from '../../src/Utils/Functions'; -import RecipientCategory from '../../src/Constants/RecipientCategory'; +import { RecipientCategory, uniqid } from '../../src'; const klarna = buckarooClientTest.method('klarna'); describe('Testing Klarna methods', () => { diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 6e17e485..28ccd43a 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import Gender from '../../src/Constants/Gender'; +import { Gender } from '../../src'; const klarnaKp = buckarooClientTest.method('klarnakp'); diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index b5344599..74576444 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const marketplaces = buckarooClientTest.method('marketplaces'); const ideal = buckarooClientTest.method('ideal'); diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts index 49f34925..e38f1a02 100644 --- a/tests/PaymentMethods/NoService.test.ts +++ b/tests/PaymentMethods/NoService.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('noservice'); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index cda59a9e..61ba3ed0 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -1,6 +1,5 @@ -import Gender from '../../src/Constants/Gender'; +import { Gender, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('payperemail'); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index 510297c3..17cb84cd 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const payconiq = buckarooClientTest.method('payconiq'); describe('Payconiq', () => { diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index d86cb20f..9f90746f 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('PayByBank'); diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 1891b289..07013940 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,8 +1,7 @@ import buckarooClientTest from '../BuckarooClient.test'; -import Paypal from '../../src/PaymentMethods/Paypal'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; -const method = new Paypal('paypal'); +const method = buckarooClientTest.method('paypal'); describe('Paypal', () => { test('Pay', async () => { diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index c04a7709..32a2f7af 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import Gender from '../../src/Constants/Gender'; +import { Gender } from '../../src'; const method = buckarooClientTest.method('pim'); diff --git a/tests/PaymentMethods/Pos.test.ts b/tests/PaymentMethods/Pos.test.ts index e16c896d..ec6dd990 100644 --- a/tests/PaymentMethods/Pos.test.ts +++ b/tests/PaymentMethods/Pos.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('pospayment'); diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 946a2288..ee6555ec 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('przelewy24'); diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index fd3ce8a7..19471754 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; import { IPay } from '../../src/PaymentMethods/SEPA/Models/Pay'; const method = buckarooClientTest.method('sepadirectdebit'); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index 83618e3c..ec5f2bdb 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('sofortueberweisung'); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index d7741ef7..05eb59dc 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('thunes'); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index 63030ddd..cfbee523 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -1,6 +1,5 @@ -import Gender from '../../src/Constants/Gender'; +import { Gender, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; const method = buckarooClientTest.method('tinka'); describe('Tinka', () => { diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 7d740904..0a9a8324 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,5 +1,5 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src/Utils/Functions'; +import { uniqid } from '../../src'; const method = buckarooClientTest.method('wechatpay'); describe('WechatPay', () => { From 9af132f7205d6c9c18d6ca803b4bb6742434b2a8 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 2 Nov 2023 14:37:54 +0100 Subject: [PATCH 37/52] Update index.ts --- src/Models/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/index.ts b/src/Models/index.ts index cbf65b91..69ee624b 100644 --- a/src/Models/index.ts +++ b/src/Models/index.ts @@ -1,10 +1,10 @@ import IRequest, { IPaymentRequest, IRefundRequest } from './IRequest'; +export * from './Model'; export * from './Interfaces'; export * from './Response'; export * from './IParameters'; export * from './IServiceList'; -export * from './Model'; export * from './ServiceParameters'; export { IRequest, IPaymentRequest, IRefundRequest }; \ No newline at end of file From 4484cdd71d80f8dde79e3d630211ce2198ad7b22 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 2 Nov 2023 15:10:53 +0100 Subject: [PATCH 38/52] revert manually functionality --- src/PaymentMethods/Afterpay/index.ts | 5 +- .../AfterpayDigiAccept/index.ts | 5 +- src/PaymentMethods/Alipay/index.ts | 5 +- src/PaymentMethods/ApplePay/index.ts | 5 +- src/PaymentMethods/Bancontact/index.ts | 5 +- src/PaymentMethods/BankTransfer/index.ts | 5 +- src/PaymentMethods/Belfius/index.ts | 5 +- src/PaymentMethods/Billink/index.ts | 5 +- src/PaymentMethods/BuckarooVoucher/index.ts | 5 +- src/PaymentMethods/BuckarooWallet/index.ts | 5 +- src/PaymentMethods/CreditCard/index.ts | 5 +- src/PaymentMethods/CreditClick/index.ts | 5 +- src/PaymentMethods/CreditManagement/index.ts | 5 +- src/PaymentMethods/EPS/index.ts | 5 +- src/PaymentMethods/Emandates/index.ts | 5 +- src/PaymentMethods/GiftCard/index.ts | 5 +- src/PaymentMethods/Giropay/index.ts | 5 +- src/PaymentMethods/Ideal/index.ts | 25 +++--- src/PaymentMethods/IdealQR/index.ts | 5 +- src/PaymentMethods/Idin/index.ts | 2 +- src/PaymentMethods/In3/index.ts | 5 +- src/PaymentMethods/In3Old/index.ts | 5 +- src/PaymentMethods/KBC/index.ts | 5 +- src/PaymentMethods/Klarna/index.ts | 5 +- src/PaymentMethods/KlarnaKP/index.ts | 5 +- src/PaymentMethods/Marketplaces/index.ts | 5 +- src/PaymentMethods/Mbway/index.ts | 5 +- src/PaymentMethods/Multibanco/index.ts | 5 +- src/PaymentMethods/NoService/index.ts | 5 +- src/PaymentMethods/PayByBank/index.ts | 6 +- src/PaymentMethods/PayPerEmail/index.ts | 5 +- src/PaymentMethods/Payconiq/index.ts | 5 +- src/PaymentMethods/Paypal/index.ts | 5 +- src/PaymentMethods/PiM/index.ts | 2 +- src/PaymentMethods/PointOfSale/index.ts | 5 +- src/PaymentMethods/Przelewy24/index.ts | 5 +- src/PaymentMethods/SEPA/index.ts | 5 +- src/PaymentMethods/Sofort/index.ts | 5 +- src/PaymentMethods/Subscriptions/index.ts | 5 +- src/PaymentMethods/Surepay/index.ts | 5 +- src/PaymentMethods/Thunes/index.ts | 5 +- src/PaymentMethods/Tinka/index.ts | 5 +- src/PaymentMethods/Trustly/index.ts | 5 +- src/PaymentMethods/WeChatPay/index.ts | 5 +- src/Services/PayablePaymentMethod.ts | 7 +- src/Services/PaymentMethod.ts | 88 +++++-------------- src/Utils/MethodTypes.ts | 34 ++----- src/buckaroo.ts | 12 ++- tests/Client.test.ts | 29 +++--- tests/PaymentMethods/AfterPay.test.ts | 21 +++-- .../PaymentMethods/AfterPayDigiAccept.test.ts | 27 ++++-- tests/PaymentMethods/Alipay.test.ts | 2 + tests/PaymentMethods/ApplePay.test.ts | 3 + tests/PaymentMethods/Bancontact.test.ts | 15 +++- tests/PaymentMethods/BankTransfer.test.ts | 1 + tests/PaymentMethods/Belfius.test.ts | 2 - tests/PaymentMethods/Billink.test.ts | 13 ++- tests/PaymentMethods/BuckarooVoucher.test.ts | 5 ++ tests/PaymentMethods/BuckarooWallet.test.ts | 8 ++ tests/PaymentMethods/CreditCard.test.ts | 10 +++ tests/PaymentMethods/CreditClick.test.ts | 2 + tests/PaymentMethods/CreditManagment.test.ts | 55 ++++++++---- tests/PaymentMethods/EPS.test.ts | 2 + tests/PaymentMethods/Emandate.test.ts | 21 +++-- tests/PaymentMethods/Giftcard.test.ts | 28 +++--- tests/PaymentMethods/GiroPay.test.ts | 2 + tests/PaymentMethods/Ideal.test.ts | 3 + tests/PaymentMethods/IdealQR.test.ts | 1 + tests/PaymentMethods/Idin.test.ts | 3 + tests/PaymentMethods/In3.test.ts | 10 ++- tests/PaymentMethods/In3Old.test.ts | 19 ++-- tests/PaymentMethods/KBC.test.ts | 2 + tests/PaymentMethods/Klarna.test.ts | 18 ++-- tests/PaymentMethods/KlarnaKp.test.ts | 3 + tests/PaymentMethods/Marketplaces.test.ts | 7 +- tests/PaymentMethods/Mbway.test.ts | 1 + tests/PaymentMethods/Multibanco.test.ts | 1 + tests/PaymentMethods/NoService.test.ts | 1 + tests/PaymentMethods/PayPerEmail.test.ts | 1 + tests/PaymentMethods/Payconiq.test.ts | 3 + .../PaymentMethods/PaymentInitiation.test.ts | 2 + tests/PaymentMethods/Paypal.test.ts | 3 + tests/PaymentMethods/PiM.test.ts | 1 + tests/PaymentMethods/Pos.test.ts | 1 + tests/PaymentMethods/Przelewy24.test.ts | 2 + tests/PaymentMethods/SEPA.test.ts | 22 +++-- tests/PaymentMethods/Sofort.test.ts | 3 + tests/PaymentMethods/Subscriptions.test.ts | 5 ++ tests/PaymentMethods/SurePay.test.ts | 1 + tests/PaymentMethods/Thunes.test.ts | 20 +++-- tests/PaymentMethods/Tinka.test.ts | 2 + tests/PaymentMethods/Trustly.test.ts | 1 + tests/PaymentMethods/WechatPay.test.ts | 2 + 93 files changed, 372 insertions(+), 388 deletions(-) diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 9c793ef9..51272a0a 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -3,10 +3,7 @@ import { IRefund, Refund } from './Model/Refund'; import { IPaymentRequest, IRefundRequest } from '../../Models'; import { PayablePaymentMethod } from '../../Services'; -export default class Afterpay extends PayablePaymentMethod< - Code, - Manually -> { +export default class Afterpay extends PayablePaymentMethod { protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index 3a92cb36..bc9b9cbe 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -2,10 +2,7 @@ import { IRefundRequest, IRequest } from '../../Models'; import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Model/Pay'; -export default class AfterpayDigiAccept< - Code extends 'afterpaydigiaccept', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class AfterpayDigiAccept extends PayablePaymentMethod { protected _serviceVersion = 2; pay(payload: IPay) { diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 1ff2e18d..ec8a4c7a 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest, ServiceParameter } from '../../Models'; -export default class Alipay extends PayablePaymentMethod< - Code, - Manually -> { +export default class Alipay extends PayablePaymentMethod { pay(payload: { useMobileView?: boolean } & IPaymentRequest) { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); return super.pay(payload, serviceParameters); diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index c6c56ac0..7128fe97 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IPaymentRequest, IRefundRequest } from '../../Models'; -export default class ApplePay extends PayablePaymentMethod< - Code, - Manually -> { +export default class ApplePay extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 547cb9e8..73dc0c80 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models'; -export default class Bancontact< - Code extends 'bancontactmrcash', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class Bancontact extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 563a7d5d..e26316a2 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models'; -export default class BankTransfer< - Code extends 'transfer', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class BankTransfer extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index de9ebe66..0c6eb5eb 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; -export default class Belfius extends PayablePaymentMethod< - Code, - Manually -> { +export default class Belfius extends PayablePaymentMethod { pay(payload: IPaymentRequest) { return super.pay(payload); } diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 0b7a0d27..254b566f 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -3,10 +3,7 @@ import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; -export default class Billink extends PayablePaymentMethod< - Code, - Manually -> { +export default class Billink extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index 9ed96fed..ce8fbd4b 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -3,10 +3,7 @@ import { IPay, Pay } from './Models/Pay'; import { IRequest } from '../../Models'; import { Create, ICreate } from './Models/Create'; -export default class BuckarooVoucher< - Code extends 'buckaroovoucher', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class BuckarooVoucher extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 74b83ad7..077a6e55 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IWallet, Wallet } from './Models/Wallet'; import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; -export default class BuckarooWallet< - Code extends 'BuckarooWalletCollecting', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class BuckarooWallet extends PayablePaymentMethod { pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); } diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 3903eb3a..25632768 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -3,10 +3,7 @@ import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; import { CardData, ICardData } from './Models/CardData'; import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; -export default class CreditCard< - Code extends 'CreditCard', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class CreditCard extends PayablePaymentMethod { payEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('PayEncrypted', new CardData(payload)); diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 8d05c5c0..b8c2ad8e 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; -export default class CreditClick< - Code extends 'creditclick', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class CreditClick extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 4af819f8..9fb7c927 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -8,10 +8,7 @@ import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddO import { IRequest, ServiceParameter } from '../../Models'; import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; -export default class CreditManagement< - Code extends 'CreditManagement3', - Manually extends boolean = false -> extends PaymentMethod { +export default class CreditManagement extends PaymentMethod { protected _serviceVersion = 1; protected _requiredFields = ['currency']; diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 21c36911..29b1eb56 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,6 +1,3 @@ import { PayablePaymentMethod } from '../../Services'; -export default class EPS extends PayablePaymentMethod< - Code, - Manually -> {} +export default class EPS extends PayablePaymentMethod {} diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 1fd7ef18..801f6056 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -2,10 +2,7 @@ import { PaymentMethod } from '../../Services'; import { IConfig } from '../../Utils'; import { IMandate, Mandate } from './Models/Mandate'; -export default class Emandates extends PaymentMethod< - Code, - Manually -> { +export default class Emandates extends PaymentMethod { _requiredFields: Array = ['currency']; issuerList() { diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index aec8a474..4581f284 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import IPay, { Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; -export default class GiftCard extends PayablePaymentMethod< - Code, - Manually -> { +export default class GiftCard extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 174bbb03..0240847a 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -export default class Giropay extends PayablePaymentMethod< - Code, - Manually -> { +export default class Giropay extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index f276e98e..145a52bb 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -3,14 +3,11 @@ import { PayablePaymentMethod } from '../../Services'; import { RequestTypes } from '../../Constants'; import { IRefundRequest } from '../../Models'; -export default class Ideal extends PayablePaymentMethod< - Code, - Manually -> { +export default class Ideal extends PayablePaymentMethod { protected _serviceVersion = 2; constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { - super(serviceCode as Code); + super(serviceCode); } pay(data: IPay) { @@ -22,14 +19,16 @@ export default class Ideal { - return response - .getActionRequestParameters('Pay') - ?.find((item) => item.name === 'issuer') - ?.listItemDescriptions?.map((item) => { - return { [item.value]: item.description }; - }); - }); + return this.specification(RequestTypes.Transaction) + .request() + .then((response) => { + return response + .getActionRequestParameters('Pay') + ?.find((item) => item.name === 'issuer') + ?.listItemDescriptions?.map((item) => { + return { [item.value]: item.description }; + }); + }); } instantRefund(data: IRefundRequest) { diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index c764a1f8..7bed8538 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,10 +1,7 @@ import { Generate, IGenerate } from './Models/IGenerate'; import { PaymentMethod } from '../../Services'; -export default class IdealQR extends PaymentMethod< - Code, - Manually -> { +export default class IdealQR extends PaymentMethod { generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 7978cda0..1905bd88 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,7 +1,7 @@ import { PaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -export default class Idin extends PaymentMethod { +export default class Idin extends PaymentMethod { identify(payload: IPay) { this.setServiceList('Identify', new Pay(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index d63304ce..c78c05b9 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; import Pay from './Models/Pay'; -export default class In3 extends PayablePaymentMethod< - Code, - Manually -> { +export default class In3 extends PayablePaymentMethod { pay(payload: IPaymentRequest) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index bb07c69b..a3999753 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -export default class In3Old extends PayablePaymentMethod< - Code, - Manually -> { +export default class In3Old extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 0133e063..3562cedc 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; -export default class KBC< - Code extends 'KBCPaymentButton', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class KBC extends PayablePaymentMethod { refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index 52e73b0a..ab458ae1 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,10 +1,7 @@ import { IPay, Pay } from './Models/Pay'; import { PayablePaymentMethod } from '../../Services'; -export default class Klarna extends PayablePaymentMethod< - Code, - Manually -> { +export default class Klarna extends PayablePaymentMethod { pay(data: IPay) { return super.pay(data, new Pay(data)); } diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 07d24eba..b63b5cee 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -3,10 +3,7 @@ import { IPay, Pay } from './Models/IPay'; import { IRequest } from '../../Models'; import { IReserve, Reserve } from './Models/IReserve'; -export default class KlarnaKP extends PayablePaymentMethod< - Code, - Manually -> { +export default class KlarnaKP extends PayablePaymentMethod { protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 5cce3839..3ffbdb35 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -2,10 +2,7 @@ import { PaymentMethod } from '../../Services'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; -export default class Marketplaces extends PaymentMethod< - Code, - Manually -> { +export default class Marketplaces extends PaymentMethod { split(payload: ISplit) { this.setServiceList('Split', new Split(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index f23b0fd3..81716588 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,6 +1,3 @@ import { PayablePaymentMethod } from '../../Services'; -export default class Mbway extends PayablePaymentMethod< - Code, - Manually -> {} +export default class Mbway extends PayablePaymentMethod {} diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index a5e9270a..fe1264f0 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -1,6 +1,3 @@ import { PayablePaymentMethod } from '../../Services'; -export default class MultiBanco< - Code extends 'multibanco', - Manually extends boolean = false -> extends PayablePaymentMethod {} +export default class MultiBanco extends PayablePaymentMethod {} diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index bf1dba25..4a58876f 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,9 +1,6 @@ import { PayablePaymentMethod } from '../../Services'; -export default class NoService extends PayablePaymentMethod< - Code, - Manually -> { +export default class NoService extends PayablePaymentMethod { protected setServiceList(): this { return this; } diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 1001cadf..7faeb1e9 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import IPay, { Pay } from './Models/IPay'; -export default class PayByBank extends PayablePaymentMethod< - Code, - Manually -> { +export default class PayByBank extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } @@ -16,6 +13,7 @@ export default class PayByBank { return response .getActionRequestParameters('Pay') diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index ea48ec22..12976f59 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,10 +1,7 @@ import { PaymentMethod } from '../../Services'; import { IInvitation, Invitation } from './Models/Invitation'; -export default class PayPerEmail extends PaymentMethod< - Code, - Manually -> { +export default class PayPerEmail extends PaymentMethod { paymentInvitation(payload: IInvitation) { this.setServiceList('paymentInvitation', new Invitation(payload)); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index fc9b7f1e..d01288b1 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; -export default class Payconiq extends PayablePaymentMethod< - Code, - Manually -> { +export default class Payconiq extends PayablePaymentMethod { instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 8c388b38..29bda515 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -3,10 +3,7 @@ import { IPaymentRequest, IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; -export default class Paypal extends PayablePaymentMethod< - Code, - Manually -> { +export default class Paypal extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index f2790ae7..b7394f1d 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,7 +1,7 @@ import { PaymentMethod } from '../../Services'; import { Generate, IGenerate } from './Models/Generate'; -export default class PiM extends PaymentMethod { +export default class PiM extends PaymentMethod { protected _requiredFields = ['currency']; generate(payload: IGenerate) { diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index dff761fb..e4f90acb 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; -export default class PointOfSale< - Code extends 'pospayment', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class PointOfSale extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 9594d54b..4812700f 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; -export default class Przelewy24< - Code extends 'przelewy24', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class Przelewy24 extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index ce03d491..9286501c 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -5,10 +5,7 @@ import { IEmandate } from './Models/Emandate'; import { uniqid } from '../../Utils'; import { IPaymentRequest } from '../../Models'; -export default class SEPA< - Code extends 'sepadirectdebit', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class SEPA extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index b6e9b0c3..b3033169 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,10 +1,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; -export default class Sofort< - Code extends 'sofortueberweisung', - Manually extends boolean = false -> extends PayablePaymentMethod { +export default class Sofort extends PayablePaymentMethod { protected _serviceVersion = 1; pay(payload: IPaymentRequest) { diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 81a76803..55aa85d0 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -3,10 +3,7 @@ import { PaymentMethod } from '../../Services'; import { IRequest } from '../../Models'; import { ResumeSubscription } from './Models/ResumeSubscription'; -export default class Subscriptions< - Code extends 'subscriptions', - Manually extends boolean = false -> extends PaymentMethod { +export default class Subscriptions extends PaymentMethod { protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 2c212087..d948fe64 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,10 +1,7 @@ import { PaymentMethod } from '../../Services'; import { IVerify, Verify } from './Models/Verify'; -export default class Surepay extends PaymentMethod< - Code, - Manually -> { +export default class Surepay extends PaymentMethod { verify(payload: IVerify) { this.setServiceList('Verify', new Verify(payload)); return super.dataRequest(payload); diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 915bcba9..6284721e 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -2,10 +2,7 @@ import { PaymentMethod } from '../../Services'; import { IRequest } from '../../Models'; type key = Required>; -export default class Thunes extends PaymentMethod< - Code, - Manually -> { +export default class Thunes extends PaymentMethod { getStatus(payload: key) { this.setServiceList('getStatus'); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index ad76da22..52c9df4d 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; -export default class Tinka extends PayablePaymentMethod< - Code, - Manually -> { +export default class Tinka extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index e9f1cb4d..1d617e03 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; -export default class Trustly extends PayablePaymentMethod< - Code, - Manually -> { +export default class Trustly extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index bf63ce6e..7c8c7557 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -2,10 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; -export default class WeChatPay extends PayablePaymentMethod< - Code, - Manually -> { +export default class WeChatPay extends PayablePaymentMethod { pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/Services/PayablePaymentMethod.ts b/src/Services/PayablePaymentMethod.ts index b4d1e2d9..fe1ebd1d 100644 --- a/src/Services/PayablePaymentMethod.ts +++ b/src/Services/PayablePaymentMethod.ts @@ -1,11 +1,8 @@ import PaymentMethod from './PaymentMethod'; import { IParameter, IPaymentRequest, IRefundRequest, IRequest, ServiceParameter } from '../Models'; -import { ServiceCode, uniqid } from '../Utils'; +import { uniqid } from '../Utils'; -export default abstract class PayablePaymentMethod< - Code extends ServiceCode, - Manually extends boolean = false -> extends PaymentMethod { +export default abstract class PayablePaymentMethod extends PaymentMethod { protected _requiredFields: Array = ['currency', 'returnURL', 'returnURLCancel', 'pushURL']; pay(payload: IPaymentRequest, serviceParameters?: ServiceParameter | IParameter[]) { diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 2044e551..ce21d8d4 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -1,25 +1,16 @@ import { RequestTypes } from '../Constants'; -import { - IParameter, - IRequest, - IService, - ServiceList, - ServiceParameter, - SpecificationRequestResponse, - TransactionResponse, -} from '../Models'; -import Buckaroo from '../index'; -import { DataRequestData, Request, TransactionData } from '../Request'; -import { PaymentMethodInstanceType, PaymentMethodRegistryType, ServiceCode } from '../Utils'; - -export default abstract class PaymentMethod { - public _isManually: Manually = false as Manually; - protected _serviceCode?: Code; +import { IParameter, IRequest, IService, ServiceList, ServiceParameter } from '../Models'; +import Buckaroo, { PaymentMethodInstance } from '../index'; +import { Request, TransactionData } from '../Request'; +import { ServiceCode } from '../Utils'; + +export default abstract class PaymentMethod { + protected _serviceCode?: ServiceCode; protected _serviceVersion: number = 0; protected _payload: TransactionData = new TransactionData(); protected _requiredFields: Array = []; - constructor(serviceCode?: Code) { + constructor(serviceCode?: ServiceCode) { this._serviceCode = serviceCode; } @@ -31,23 +22,12 @@ export default abstract class PaymentMethod; - public manually(value: false): PaymentMethodRegistryType; - public manually(value?: boolean): PaymentMethodRegistryType { - if (value === undefined) { - this._isManually = true as Manually; - } else { - this._isManually = value as Manually; - } - return this as any; + get serviceCode(): ServiceCode { + return this._serviceCode || 'noservice'; } setServiceCode(value: ServiceCode): this { - this._serviceCode = value as Code; + this._serviceCode = value; return this; } @@ -64,15 +44,15 @@ export default abstract class PaymentMethod(data: Name): PaymentMethodInstanceType; + combine(data: Name): PaymentMethodInstance; combine(data: Payload): this; - combine>(method: Method): this; + combine(method: Method): this; combine(data: any): this { if (typeof data === 'string') { - const method: PaymentMethod = Buckaroo.Client.method(data as any); + const method: PaymentMethod = Buckaroo.Client.method(data as any); method.setPayload(this._payload); return method as any; } @@ -80,16 +60,8 @@ export default abstract class PaymentMethod { - const request = Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); - - if (this._isManually) { - return request as any; - } - - return request.request() as any; + public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { + return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); } protected setRequiredFields(requiredFields: Array = this._requiredFields) { @@ -124,33 +96,13 @@ export default abstract class PaymentMethod - : Promise { + protected transactionRequest(payload?: IRequest) { this.setPayload(payload); - const request = Request.Transaction(this._payload); - - if (this._isManually) { - return request as any; - } - - return request.request() as any; + return Request.Transaction(this._payload); } - protected dataRequest( - payload?: IRequest - ): this['_isManually'] extends true - ? Request - : Promise { + protected dataRequest(payload?: IRequest) { this.setPayload(payload); - const request = Request.DataRequest(this._payload); - - if (this._isManually) { - return request as any; - } - - return request.request() as any; + return Request.DataRequest(this._payload); } } \ No newline at end of file diff --git a/src/Utils/MethodTypes.ts b/src/Utils/MethodTypes.ts index dde5ed32..ba3699de 100644 --- a/src/Utils/MethodTypes.ts +++ b/src/Utils/MethodTypes.ts @@ -1,32 +1,14 @@ -import * as AllRegisteredPaymentMethods from '../PaymentMethods'; +import * as AllPaymentMethods from '../PaymentMethods'; -type InstanceWithManualFlag = Manually extends true - ? Method & { - _isManually: Manually; - } - : Method; +export type AvailablePaymentMethods = typeof AllPaymentMethods; +export type ServiceCode = keyof AvailablePaymentMethods; +export type PaymentMethodInstance = InstanceType; -export type PaymentMethodTypeDictionary = typeof AllRegisteredPaymentMethods; -export type ServiceCode = keyof PaymentMethodTypeDictionary; - -export type PaymentMethodInstanceType< - Code extends ServiceCode, - Manually extends boolean = false -> = InstanceWithManualFlag, Manually>; - -export type PaymentMethodRegistryType = { - [K in keyof PaymentMethodTypeDictionary]: PaymentMethodInstanceType; -}[K]; - -export function getMethod( - code: Code -): PaymentMethodInstanceType { - const methodClass = AllRegisteredPaymentMethods[code] as { - new (code: Code): PaymentMethodInstanceType; - }; +export function getMethod(code: Code): PaymentMethodInstance { + const methodClass = AllPaymentMethods[code]; if (!methodClass) { throw new Error(`Invalid payment method code: ${code}`); } - return new methodClass(code) as PaymentMethodInstanceType; -} \ No newline at end of file + return new methodClass(code as any) as PaymentMethodInstance; +} diff --git a/src/buckaroo.ts b/src/buckaroo.ts index 8c77222c..03eb4b0f 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -1,4 +1,4 @@ -import { getMethod, IConfig, ICredentials, PaymentMethodInstanceType, ServiceCode } from './Utils'; +import { getMethod, IConfig, ICredentials, PaymentMethodInstance, ServiceCode } from './Utils'; import { HttpsClient, Request } from './Request'; import { Agent } from 'https'; import NoService from './PaymentMethods/NoService'; @@ -48,15 +48,13 @@ export default class Buckaroo { return (this._client = new this(credentials, config, agent)); } - method(): NoService<'noservice', false>; - method( - name: Code - ): PaymentMethodInstanceType; - method(name?: Code) { + method(): NoService; + method(name: Name): PaymentMethodInstance; + method(name?: K) { if (!name) { return new NoService(); } - return getMethod(name); + return getMethod(name); } confirmCredentials() { diff --git a/tests/Client.test.ts b/tests/Client.test.ts index 2f1d343e..d4880e4e 100644 --- a/tests/Client.test.ts +++ b/tests/Client.test.ts @@ -13,23 +13,20 @@ describe('Testing Buckaroo Client', () => { const creditManagement = client.method('CreditManagement3'); const sepaDirectDebit = client.method('sepadirectdebit'); for (let i = 0; i < 3; i++) { - const combinedInvoice = creditManagement.manually().createCombinedInvoice(creditManagementTestInvoice()); + const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); - const sepaRequest = sepaDirectDebit - .manually() - .combine(combinedInvoice.data) - .pay({ - iban: 'NL39RABO0300065264', - bic: 'RABONL2U', - mandateReference: '1DCtestreference', - mandateDate: '2022-07-03', - collectDate: '2020-07-03', - amountDebit: 10.1, - customer: { - name: 'John Smith', - }, - invoice: uniqid('TestInvoice'), - }); + const sepaRequest = sepaDirectDebit.combine(combinedInvoice.data).pay({ + iban: 'NL39RABO0300065264', + bic: 'RABONL2U', + mandateReference: '1DCtestreference', + mandateDate: '2022-07-03', + collectDate: '2020-07-03', + amountDebit: 10.1, + customer: { + name: 'John Smith', + }, + invoice: uniqid('TestInvoice'), + }); transactionData.push(sepaRequest.data); } diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index a87ad247..fc826fe8 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -40,9 +40,12 @@ const paymentPayload: IPay = { const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { test('Pay', () => { - return method.pay(paymentPayload).then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + return method + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await method @@ -51,14 +54,18 @@ describe('AfterPay methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', //Set transaction key of the transaction to refund amountCredit: paymentPayload.amountDebit, }) + .request() .then((data) => { expect(data.isFailed()).toBeDefined(); }); }); test('Authorize', async () => { - await method.authorize(paymentPayload).then((data) => { - expect(data).toBeDefined(); - }); + await method + .authorize(paymentPayload) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); }); test('CancelAuthorize', async () => { await method @@ -67,6 +74,7 @@ describe('AfterPay methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountCredit: 100, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -78,6 +86,7 @@ describe('AfterPay methods', () => { ...paymentPayload, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 178ae2a2..09eccb13 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -79,18 +79,27 @@ const paymentPayload: IPay = { }; describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { - await method.authorize(paymentPayload).then((data) => { - expect(data).toBeDefined(); - }); + await method + .authorize(paymentPayload) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); }); test('Pay', async () => { - await method.pay(paymentPayload).then((data) => { - expect(data.data).toBeDefined(); - }); + await method + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.data).toBeDefined(); + }); }); test('Specification', async () => { - await method.specification(RequestTypes.Transaction).then((data) => { - expect(data).toBeDefined(); - }); + await method + .specification(RequestTypes.Transaction) + .request() + .then((data) => { + expect(data).toBeDefined(); + }); }); }); \ No newline at end of file diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index e48c22d7..7a1ae36e 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -10,6 +10,7 @@ describe('Alipay methods', () => { amountDebit: 100, useMobileView: false, }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -21,6 +22,7 @@ describe('Alipay methods', () => { invoice: uniqid(), originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/ApplePay.test.ts b/tests/PaymentMethods/ApplePay.test.ts index b9d0a94f..aad65bfe 100644 --- a/tests/PaymentMethods/ApplePay.test.ts +++ b/tests/PaymentMethods/ApplePay.test.ts @@ -12,6 +12,7 @@ describe('Applepay methods', () => { paymentData: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', customerCardName: 'XXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -24,6 +25,7 @@ describe('Applepay methods', () => { servicesSelectableByClient: 'applepay', continueOnIncomplete: true, }) + .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -35,6 +37,7 @@ describe('Applepay methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index fc08a3d4..f75357ec 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -10,6 +10,7 @@ describe('BanContact methods', () => { amountDebit: 100, saveToken: true, }) + .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -21,14 +22,18 @@ describe('BanContact methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); }); test('Authenticate', async () => { - await method.authenticate({ invoice: uniqid(), amountDebit: 100 }).then((data) => { - expect(data.isWaitingOnUserInput()).toBeDefined(); - }); + await method + .authenticate({ invoice: uniqid(), amountDebit: 100 }) + .request() + .then((data) => { + expect(data.isWaitingOnUserInput()).toBeDefined(); + }); }); test('PayOneClick', async () => { await method @@ -37,6 +42,7 @@ describe('BanContact methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountDebit: 100, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -47,6 +53,7 @@ describe('BanContact methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -58,6 +65,7 @@ describe('BanContact methods', () => { amountDebit: 100, encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -69,6 +77,7 @@ describe('BanContact methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 80d2e4dc..cb0c00e4 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -17,6 +17,7 @@ describe('Transfer methods', () => { sendMail: true, dateDue: '2024-10-10', }) + .request() .then((res) => { expect(res.isAwaitingConsumer()).toBeDefined(); }); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index 3579e464..ed27185f 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -6,7 +6,6 @@ const method = buckarooClientTest.method('belfius'); describe('testing methods', () => { test('Pay Simple Payload', async () => { await method - .manually() .pay({ amountDebit: 100, }) @@ -17,7 +16,6 @@ describe('testing methods', () => { }); test('Refund', async () => { await method - .manually() .refund({ invoice: uniqid(), amountCredit: 0.01, diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index 4e835778..5f61a317 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -9,7 +9,6 @@ describe('Billink methods', () => { test('Pay', async () => { await method - .manually() .pay(payload) .request() .then((data) => { @@ -23,14 +22,18 @@ describe('Billink methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); }); test('Authorize', async () => { - await method.authorize({ ...payload, invoice: invoiceId }).then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await method + .authorize({ ...payload, invoice: invoiceId }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('CancelAuthorize', async () => { await method @@ -39,6 +42,7 @@ describe('Billink methods', () => { amountCredit: payload.amountDebit, invoice: invoiceId, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -51,6 +55,7 @@ describe('Billink methods', () => { amountDebit: payload.amountDebit, articles: payload.articles, }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 9c6de5e4..25857c12 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -10,6 +10,7 @@ describe('testing methods', () => { amountDebit: 100, voucherCode: 'XXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -21,6 +22,7 @@ describe('testing methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -30,6 +32,7 @@ describe('testing methods', () => { .getBalance({ voucherCode: 'XXXXXXX', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -42,6 +45,7 @@ describe('testing methods', () => { validFrom: '2021-01-01', validUntil: '2024-01-01', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -51,6 +55,7 @@ describe('testing methods', () => { .deactivate({ voucherCode: 'XXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index 81ac9552..2f3bffa7 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -11,6 +11,7 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -22,6 +23,7 @@ describe('BuckarooWallet methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -34,6 +36,7 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, walletMutationGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -46,6 +49,7 @@ describe('BuckarooWallet methods', () => { amountCredit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -64,6 +68,7 @@ describe('BuckarooWallet methods', () => { iban: 'NLXXTESTXXXXXXXXXX', }, }) + .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); @@ -76,6 +81,7 @@ describe('BuckarooWallet methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -93,6 +99,7 @@ describe('BuckarooWallet methods', () => { iban: 'NLXXTESTXXXXXXXXXX', }, }) + .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); @@ -102,6 +109,7 @@ describe('BuckarooWallet methods', () => { .getInfo({ walletId: 'XXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index 5198ac2c..848241aa 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -9,6 +9,7 @@ describe('testing methods', () => { .pay({ amountDebit: 100, }) + .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -20,6 +21,7 @@ describe('testing methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -29,6 +31,7 @@ describe('testing methods', () => { .authorize({ amountDebit: 100, }) + .request() .then((data) => { expect(data.isWaitingOnUserInput()).toBeTruthy(); }); @@ -40,6 +43,7 @@ describe('testing methods', () => { name: 'Visa', encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -51,6 +55,7 @@ describe('testing methods', () => { encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -62,6 +67,7 @@ describe('testing methods', () => { encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -73,6 +79,7 @@ describe('testing methods', () => { encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -84,6 +91,7 @@ describe('testing methods', () => { amountCredit: 100, name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -95,6 +103,7 @@ describe('testing methods', () => { amountDebit: 100, name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -106,6 +115,7 @@ describe('testing methods', () => { amountDebit: 100, name: 'Visa', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/CreditClick.test.ts b/tests/PaymentMethods/CreditClick.test.ts index ea8f76bb..43711b62 100644 --- a/tests/PaymentMethods/CreditClick.test.ts +++ b/tests/PaymentMethods/CreditClick.test.ts @@ -14,6 +14,7 @@ describe('Testing CreditClick methods', () => { }, email: 'test@buckaroo.nl', }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -27,6 +28,7 @@ describe('Testing CreditClick methods', () => { description: 'refund', refundReason: 'Fraudulent', }) + .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index 0a9e7a05..fb35a65f 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -6,9 +6,12 @@ const creditManagement = buckarooClientTest.method('CreditManagement3'); describe('Testing Credit Management', () => { test('CreateInvoice', async () => { - await creditManagement.createInvoice(creditManagementTestInvoice()).then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement + .createInvoice(creditManagementTestInvoice()) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('CreateInvoice With Articles', async () => { await creditManagement @@ -62,19 +65,26 @@ describe('Testing Credit Management', () => { ], }) ) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); }); test('Pause Invoice', async () => { - await creditManagement.pauseInvoice({ invoice: uniqid() }).then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement + .pauseInvoice({ invoice: uniqid() }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('UnPause Invoice', async () => { - await creditManagement.unpauseInvoice({ invoice: uniqid() }).then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement + .unpauseInvoice({ invoice: uniqid() }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('Invoice Info', async () => { await creditManagement @@ -82,6 +92,7 @@ describe('Testing Credit Management', () => { invoice: uniqid(), invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }], }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -93,6 +104,7 @@ describe('Testing Credit Management', () => { code: 'XXXXXXXX', }, }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -124,19 +136,26 @@ describe('Testing Credit Management', () => { }, ], }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); }); test('resumeDebtorFile', async () => { - await creditManagement.resumeDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement + .resumeDebtorFile({ debtorFileGuid: 'd42' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('pauseDebtorFile', async () => { - await creditManagement.pauseDebtorFile({ debtorFileGuid: 'd42' }).then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + await creditManagement + .pauseDebtorFile({ debtorFileGuid: 'd42' }) + .request() + .then((data) => { + expect(data.isValidationFailure()).toBeTruthy(); + }); }); test('addOrUpdateDebtor', async () => { await creditManagement @@ -149,15 +168,15 @@ describe('Testing Credit Management', () => { lastName: 'Acceptatie', }, }) + .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); }); }); test('CreateCombinedInvoice', async () => { - const combinedInvoice = creditManagement.manually().createCombinedInvoice(creditManagementTestInvoice()); + const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); buckarooClientTest .method('sepadirectdebit') - .manually() .combine(combinedInvoice.data) .pay({ iban: 'NLXXTESTXXXXXXXXXX', @@ -190,6 +209,7 @@ describe('Testing Credit Management', () => { paymentPlanCostAmountVat: 1.2, recipientemail: 'test@buckaroo.nl', }) + .request() .then((data) => { expect(data.isValidationFailure()).toBeTruthy(); }); @@ -199,6 +219,7 @@ describe('Testing Credit Management', () => { .pauseInvoice({ invoice: uniqid(), }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index eaeac3db..b24d018a 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -8,6 +8,7 @@ describe('Testing Eps methods', () => { .pay({ amountDebit: 100, }) + .request() .then((response) => { expect(response.isSuccess()).toBeTruthy(); }); @@ -19,6 +20,7 @@ describe('Testing Eps methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 1381f24b..84accb72 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -4,9 +4,12 @@ import { ServiceCode } from '../../src'; const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { - await method.issuerList().then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + await method + .issuerList() + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); }); test('CreateMandate', async () => { method @@ -17,14 +20,18 @@ describe('Testing Emandates methods', () => { purchaseId: 'XXXXXXXXXXXXXX', sequenceType: 0, }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); }); test('GetStatus', async () => { - method.status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + method + .status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((response) => { + expect(response.isSuccess()).toBeTruthy(); + }); }); test('ModifyMandate', async () => { method @@ -32,6 +39,7 @@ describe('Testing Emandates methods', () => { originalMandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', continueOnIncomplete: true, }) + .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); @@ -43,6 +51,7 @@ describe('Testing Emandates methods', () => { mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', purchaseId: 'XXXXXXXXXXXXXX', }) + .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index db9bf16e..c720a0da 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -5,18 +5,23 @@ const method = buckarooClientTest.method('boekenbon'); describe('GiftCard methods', () => { test('Pay', async () => { - const responsePay = await method.pay({ - amountDebit: 100, - intersolveCardnumber: '0000000000000000001', - intersolvePIN: '1000', - }); + const responsePay = await method + .pay({ + amountDebit: 100, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '1000', + }) + .request(); expect(responsePay.isSuccess()).toBeTruthy(); - const responseRemainderPay = await buckarooClientTest.method('ideal').payRemainder({ - amountDebit: 100, - issuer: 'ABNANL2A', - invoice: responsePay.data.invoice, - originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, - }); + const responseRemainderPay = await buckarooClientTest + .method('ideal') + .payRemainder({ + amountDebit: 100, + issuer: 'ABNANL2A', + invoice: responsePay.data.invoice, + originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, + }) + .request(); expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { @@ -28,6 +33,7 @@ describe('GiftCard methods', () => { email: 'test@buckaroo.nl', lastName: 'Acceptatie', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/GiroPay.test.ts b/tests/PaymentMethods/GiroPay.test.ts index 265ba1c6..acf2ede8 100644 --- a/tests/PaymentMethods/GiroPay.test.ts +++ b/tests/PaymentMethods/GiroPay.test.ts @@ -9,6 +9,7 @@ describe('Testing Giropay methods', () => { bic: 'XXXXXXXXX', amountDebit: 100, }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -20,6 +21,7 @@ describe('Testing Giropay methods', () => { invoice: uniqid(), originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index 8ffc6e8c..1b0b512c 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -19,6 +19,7 @@ describe('testing Ideal methods', () => { service_action: 'something', }, }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -36,6 +37,7 @@ describe('testing Ideal methods', () => { service_action: 'something', }, }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); @@ -47,6 +49,7 @@ describe('testing Ideal methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/IdealQR.test.ts b/tests/PaymentMethods/IdealQR.test.ts index 05953ea8..7ffeab00 100644 --- a/tests/PaymentMethods/IdealQR.test.ts +++ b/tests/PaymentMethods/IdealQR.test.ts @@ -24,6 +24,7 @@ describe('Testing IdealQR methods', () => { service_action: 'something', }, }) + .request() .then((response) => { expect(response.isSuccess()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Idin.test.ts b/tests/PaymentMethods/Idin.test.ts index 0bab9f5d..711a15f1 100644 --- a/tests/PaymentMethods/Idin.test.ts +++ b/tests/PaymentMethods/Idin.test.ts @@ -8,6 +8,7 @@ describe('Idin methods', () => { .verify({ issuer: 'BANKNL2Y', }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -18,6 +19,7 @@ describe('Idin methods', () => { .identify({ issuer: 'BANKNL2Y', }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); @@ -28,6 +30,7 @@ describe('Idin methods', () => { .login({ issuer: 'BANKNL2Y', }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 036c456b..a80c10cb 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -6,9 +6,12 @@ const in3 = buckarooClientTest.method('In3'); describe('Testing In3 methods', () => { test('Pay', async () => { - await in3.pay(payload).then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + await in3 + .pay(payload) + .request() + .then((data) => { + expect(data.isPendingProcessing()).toBeTruthy(); + }); }); test('Refund', async () => { await in3 @@ -17,6 +20,7 @@ describe('Testing In3 methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isSuccess()).toBeFalsy(); }); diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index 27a66192..b8d03976 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -5,9 +5,12 @@ const capayable = buckarooClientTest.method('capayable'); describe('Testing capayable methods', () => { test('Pay', async () => { - await capayable.pay(paymentPayload).then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + await capayable + .pay(paymentPayload) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); }); test('Refund', async () => { await capayable @@ -16,14 +19,18 @@ describe('Testing capayable methods', () => { amountCredit: paymentPayload.amountDebit, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data.isFailed()).toBeTruthy(); }); }); test('PayInInstallments', async () => { - await capayable.payInInstallments(paymentPayload).then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + await capayable + .payInInstallments(paymentPayload) + .request() + .then((response) => { + expect(response.isPendingProcessing()).toBeTruthy(); + }); }); }); diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index 18f7be92..f25e6e4b 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -9,6 +9,7 @@ describe('Testing KBC methods', () => { .pay({ amountDebit: 100, }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); @@ -20,6 +21,7 @@ describe('Testing KBC methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((response) => { expect(response.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index 82e6ed64..4d453789 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -5,17 +5,23 @@ import { RecipientCategory, uniqid } from '../../src'; const klarna = buckarooClientTest.method('klarna'); describe('Testing Klarna methods', () => { test('Pay', async () => { - await klarna.pay(payload).then((res) => { - expect(res.isPendingProcessing()).toBeTruthy(); - }); + await klarna + .pay(payload) + .request() + .then((res) => { + expect(res.isPendingProcessing()).toBeTruthy(); + }); }); test('PayInInstallments', async () => { const clonedPayload = JSON.parse(JSON.stringify(payload)); clonedPayload.currency = 'GBP'; clonedPayload.billing.address.country = 'GB'; - await klarna.payInInstallments(clonedPayload).then((res) => { - expect(res).toBeDefined(); - }); + await klarna + .payInInstallments(clonedPayload) + .request() + .then((res) => { + expect(res).toBeDefined(); + }); }); }); diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 28ccd43a..e8735dab 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -10,6 +10,7 @@ describe('KlarnaKp', () => { amountDebit: 100, reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info.isFailed()).toBeTruthy(); }); @@ -53,6 +54,7 @@ describe('KlarnaKp', () => { }, ], }) + .request() .then((info) => { expect(info.isPendingProcessing()).toBeTruthy(); }); @@ -62,6 +64,7 @@ describe('KlarnaKp', () => { .cancel({ reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index 74576444..a4a9170f 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -6,7 +6,7 @@ const ideal = buckarooClientTest.method('ideal'); describe('Testing Marketplaces methods', () => { test('Split', async () => { - const marketplacesResponse = marketplaces.manually().split({ + const marketplacesResponse = marketplaces.split({ description: 'INV0001', daysUntilTransfer: 2, marketplace: { @@ -32,6 +32,7 @@ describe('Testing Marketplaces methods', () => { issuer: 'ABNANL2A', amountDebit: 100, }) + .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); @@ -52,12 +53,13 @@ describe('Testing Marketplaces methods', () => { }, ], }) + .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); }); test('refundSupplementary', async () => { - const marketplacesResponse = marketplaces.manually().refundSupplementary({ + const marketplacesResponse = marketplaces.refundSupplementary({ sellers: [ { accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', @@ -72,6 +74,7 @@ describe('Testing Marketplaces methods', () => { originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', amountCredit: 0.01, }) + .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts index 9888a32e..65f0de6e 100644 --- a/tests/PaymentMethods/Mbway.test.ts +++ b/tests/PaymentMethods/Mbway.test.ts @@ -7,6 +7,7 @@ describe('Mbway methods', () => { .pay({ amountDebit: 100, }) + .request() .then((response) => { expect(response.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts index cbbeaec4..3d7dd2c8 100644 --- a/tests/PaymentMethods/Multibanco.test.ts +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -7,6 +7,7 @@ describe('Multibanco methods', () => { .pay({ amountDebit: 100, }) + .request() .then((info) => { expect(info.isValidationFailure()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts index e38f1a02..e4110748 100644 --- a/tests/PaymentMethods/NoService.test.ts +++ b/tests/PaymentMethods/NoService.test.ts @@ -13,6 +13,7 @@ describe('NoService methods', () => { servicesExcludedForClient: 'ideal', continueOnIncomplete: true, }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 61ba3ed0..49bde930 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -22,6 +22,7 @@ describe('PayPerEmail methods', () => { lastName: 'Acceptatie', }, }) + .request() .then((response) => { expect(response).toBeDefined(); }); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index 17cb84cd..38feedbb 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -9,6 +9,7 @@ describe('Payconiq', () => { amountDebit: 100, order: uniqid(), }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -20,6 +21,7 @@ describe('Payconiq', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -31,6 +33,7 @@ describe('Payconiq', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 9f90746f..9f2cc036 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -13,6 +13,7 @@ describe('PaymentInitiation methods', () => { invoice: uniqid(), countryCode: 'NL', }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -24,6 +25,7 @@ describe('PaymentInitiation methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index 07013940..e3828369 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -9,6 +9,7 @@ describe('Paypal', () => { .pay({ amountDebit: 100, }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -20,6 +21,7 @@ describe('Paypal', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); @@ -42,6 +44,7 @@ describe('Paypal', () => { noShipping: '0', phone: { mobile: '0612345678' }, }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index 32a2f7af..b1d90ced 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -24,6 +24,7 @@ describe('PiM', () => { text: 'bedankt', }, }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Pos.test.ts b/tests/PaymentMethods/Pos.test.ts index ec6dd990..87d48462 100644 --- a/tests/PaymentMethods/Pos.test.ts +++ b/tests/PaymentMethods/Pos.test.ts @@ -11,6 +11,7 @@ describe('POS methods', () => { invoice: uniqid(), terminalId: '50000001', }) + .request() .then((data) => { expect(data.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index ee6555ec..4b477a59 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -14,6 +14,7 @@ describe('Przelewy24', () => { }, email: 'test@buckaroo.nl', }) + .request() .then((res) => { expect(res.isPendingProcessing()).toBeTruthy(); }); @@ -25,6 +26,7 @@ describe('Przelewy24', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info.data).toBeDefined(); }); diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index 19471754..58ba5e25 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -19,9 +19,12 @@ const paymentPayload: IPay = { describe('SEPA methods', () => { test('Pay', async () => { - await method.pay(paymentPayload).then((info) => { - expect(info).toBeDefined(); - }); + await method + .pay(paymentPayload) + .request() + .then((info) => { + expect(info).toBeDefined(); + }); }); test('Refund', async () => { await method @@ -29,14 +32,18 @@ describe('SEPA methods', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); }); test('Authorize', async () => { - await method.authorize(paymentPayload).then((info) => { - expect(info).toBeDefined(); - }); + await method + .authorize(paymentPayload) + .request() + .then((info) => { + expect(info).toBeDefined(); + }); }); test('PayRecurrent', async () => { await method @@ -46,6 +53,7 @@ describe('SEPA methods', () => { amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -72,6 +80,7 @@ describe('SEPA methods', () => { country: 'NL', }, }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -84,6 +93,7 @@ describe('SEPA methods', () => { mandateReference: 'XXXXXXXXXXXXXXX', amountDebit: 100, }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Sofort.test.ts b/tests/PaymentMethods/Sofort.test.ts index ec5f2bdb..1d3a1741 100644 --- a/tests/PaymentMethods/Sofort.test.ts +++ b/tests/PaymentMethods/Sofort.test.ts @@ -10,6 +10,7 @@ describe('Sofort', () => { amountDebit: 100, order: uniqid(), }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -21,6 +22,7 @@ describe('Sofort', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((info) => { expect(info).toBeDefined(); }); @@ -33,6 +35,7 @@ describe('Sofort', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((data) => { expect(data).toBeDefined(); }); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 9c1da533..c78e1157 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -28,6 +28,7 @@ describe('Subscription methods', () => { code: 'XXXXXXXX', }, }) + .request() .then((data) => { expect(data.hasError()).toBeTruthy(); }); @@ -46,6 +47,7 @@ describe('Subscription methods', () => { }, }, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -91,6 +93,7 @@ describe('Subscription methods', () => { amountDebit: 100, startRecurrent: true, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -106,6 +109,7 @@ describe('Subscription methods', () => { issuer: 'ABNANL2A', amountDebit: 100, }) + .request() .then((data) => { expect(data).toBeDefined(); }); @@ -128,6 +132,7 @@ describe('Subscription methods', () => { .deletePaymentConfig({ subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((res) => { expect(res.httpResponse.status === 200).toBeTruthy(); }); diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 5b64bfcc..8a29968b 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -12,6 +12,7 @@ describe('SurePay methods', () => { accountName: 'Test Acceptatie', }, }) + .request() .then((info) => { expect(info).toBeDefined(); }); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index 05eb59dc..4f660f69 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -24,6 +24,7 @@ describe('Thunes methods', () => { }, ], }) + .request() .then((res) => { expect(res.data).toBeDefined(); }); @@ -31,18 +32,25 @@ describe('Thunes methods', () => { test('capture', async () => { await method .capture({ amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() .then((res) => { expect(res.data).toBeDefined(); }); }); test('getStatus', async () => { - await method.getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); test('cancel', async () => { - await method.cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).then((res) => { - expect(res.data).toBeDefined(); - }); + await method + .cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) + .request() + .then((res) => { + expect(res.data).toBeDefined(); + }); }); }); diff --git a/tests/PaymentMethods/Tinka.test.ts b/tests/PaymentMethods/Tinka.test.ts index cfbee523..43c9b0dd 100644 --- a/tests/PaymentMethods/Tinka.test.ts +++ b/tests/PaymentMethods/Tinka.test.ts @@ -45,6 +45,7 @@ describe('Tinka', () => { deliveryMethod: 'CompanyStore', paymentMethod: 'Credit', }) + .request() .then((res) => { expect(res.isPendingProcessing()).toBeTruthy(); }); @@ -56,6 +57,7 @@ describe('Tinka', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((res) => { expect(res.isFailed()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 493c96af..90ef3466 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -13,6 +13,7 @@ describe('Trustly', () => { countryCode: 'NL', }, }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeTruthy(); }); diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 0a9a8324..187cd06c 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -9,6 +9,7 @@ describe('WechatPay', () => { amountDebit: 100, locale: 'en-US', }) + .request() .then((response) => { expect(response.isPendingProcessing()).toBeDefined(); }); @@ -20,6 +21,7 @@ describe('WechatPay', () => { amountCredit: 0.01, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) + .request() .then((response) => { expect(response.data).toBeDefined(); }); From 2149964e75c84c1e0cd0ef0575909ef4b53f7cd5 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 2 Nov 2023 15:42:09 +0100 Subject: [PATCH 39/52] add service code property for every single payment method class --- src/PaymentMethods/Afterpay/index.ts | 2 ++ src/PaymentMethods/AfterpayDigiAccept/index.ts | 2 ++ src/PaymentMethods/Alipay/index.ts | 3 +++ src/PaymentMethods/ApplePay/index.ts | 3 +++ src/PaymentMethods/Bancontact/index.ts | 3 +++ src/PaymentMethods/BankTransfer/index.ts | 3 +++ src/PaymentMethods/Belfius/index.ts | 3 +++ src/PaymentMethods/Billink/index.ts | 3 +++ src/PaymentMethods/BuckarooVoucher/index.ts | 3 +++ src/PaymentMethods/BuckarooWallet/index.ts | 3 +++ src/PaymentMethods/CreditCard/index.ts | 3 +++ src/PaymentMethods/CreditClick/index.ts | 3 +++ src/PaymentMethods/CreditManagement/index.ts | 2 ++ src/PaymentMethods/EPS/index.ts | 5 ++++- src/PaymentMethods/Emandates/index.ts | 3 ++- src/PaymentMethods/GiftCard/index.ts | 3 +++ src/PaymentMethods/Giropay/index.ts | 3 +++ src/PaymentMethods/Ideal/index.ts | 2 ++ src/PaymentMethods/IdealQR/index.ts | 3 +++ src/PaymentMethods/Idin/index.ts | 3 +++ src/PaymentMethods/In3/index.ts | 3 +++ src/PaymentMethods/In3Old/index.ts | 3 +++ src/PaymentMethods/KBC/index.ts | 3 +++ src/PaymentMethods/Klarna/index.ts | 3 +++ src/PaymentMethods/KlarnaKP/index.ts | 2 ++ src/PaymentMethods/Marketplaces/index.ts | 3 +++ src/PaymentMethods/Mbway/index.ts | 5 ++++- src/PaymentMethods/Multibanco/index.ts | 5 ++++- src/PaymentMethods/NoService/index.ts | 3 +++ src/PaymentMethods/PayByBank/index.ts | 3 +++ src/PaymentMethods/PayPerEmail/index.ts | 3 +++ src/PaymentMethods/Payconiq/index.ts | 3 +++ src/PaymentMethods/Paypal/index.ts | 3 +++ src/PaymentMethods/PiM/index.ts | 2 ++ src/PaymentMethods/PointOfSale/index.ts | 3 +++ src/PaymentMethods/Przelewy24/index.ts | 3 +++ src/PaymentMethods/SEPA/index.ts | 4 +++- src/PaymentMethods/Sofort/index.ts | 2 ++ src/PaymentMethods/Subscriptions/index.ts | 2 ++ src/PaymentMethods/Surepay/index.ts | 3 +++ src/PaymentMethods/Thunes/index.ts | 4 ++++ src/PaymentMethods/Tinka/index.ts | 3 +++ src/PaymentMethods/Trustly/index.ts | 3 +++ src/PaymentMethods/WeChatPay/index.ts | 3 +++ src/Services/PaymentMethod.ts | 2 +- 45 files changed, 128 insertions(+), 6 deletions(-) diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index 51272a0a..ca6ac6b0 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -2,8 +2,10 @@ import { IPay, Pay } from './Model/Pay'; import { IRefund, Refund } from './Model/Refund'; import { IPaymentRequest, IRefundRequest } from '../../Models'; import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; export default class Afterpay extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'afterpay'; protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index bc9b9cbe..ce1cdf8b 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -1,8 +1,10 @@ import { IRefundRequest, IRequest } from '../../Models'; import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Model/Pay'; +import { ServiceCode } from '../../Utils'; export default class AfterpayDigiAccept extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'afterpaydigiaccept'; protected _serviceVersion = 2; pay(payload: IPay) { diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index ec8a4c7a..8e621cab 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest, ServiceParameter } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Alipay extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'alipay'; + pay(payload: { useMobileView?: boolean } & IPaymentRequest) { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); return super.pay(payload, serviceParameters); diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 7128fe97..4b575979 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IPaymentRequest, IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class ApplePay extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'applepay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 73dc0c80..768881c2 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, IPayComplete, IPayEncrypted, IPayOneClick, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Bancontact extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'bancontactmrcash'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index e26316a2..921e7981 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class BankTransfer extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'transfer'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index 0c6eb5eb..46f20cc3 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Belfius extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'belfius'; + pay(payload: IPaymentRequest) { return super.pay(payload); } diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 254b566f..8dccad45 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -2,8 +2,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; import { Capture, ICapture } from './Models/Capture'; +import { ServiceCode } from '../../Utils'; export default class Billink extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'billink'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index ce8fbd4b..ca41496e 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -2,8 +2,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRequest } from '../../Models'; import { Create, ICreate } from './Models/Create'; +import { ServiceCode } from '../../Utils'; export default class BuckarooVoucher extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'buckaroovoucher'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 077a6e55..4958fa18 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IWallet, Wallet } from './Models/Wallet'; import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class BuckarooWallet extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'BuckarooWalletCollecting'; + pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); } diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index 25632768..d539bc3e 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -2,8 +2,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; import { CardData, ICardData } from './Models/CardData'; import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; +import { ServiceCode } from '../../Utils'; export default class CreditCard extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'CreditCard'; + payEncrypted(payload: ICardData) { this.setPayPayload(payload); this.setServiceList('PayEncrypted', new CardData(payload)); diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index b8c2ad8e..8e06a394 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; +import { ServiceCode } from '../../Utils'; export default class CreditClick extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'creditclick'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index 9fb7c927..a7cdd96c 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -7,8 +7,10 @@ import { IMultiInfoInvoice, MultiInfoInvoice } from './Models/multiInfoInvoice'; import { AddOrUpdateProductLines, IAddOrUpdateProductLines } from './Models/AddOrUpdateProductLines'; import { IRequest, ServiceParameter } from '../../Models'; import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; +import { ServiceCode } from '../../Utils'; export default class CreditManagement extends PaymentMethod { + protected _serviceCode: ServiceCode = 'CreditManagement3'; protected _serviceVersion = 1; protected _requiredFields = ['currency']; diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index 29b1eb56..e6bf9a96 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -1,3 +1,6 @@ import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; -export default class EPS extends PayablePaymentMethod {} +export default class EPS extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'eps'; +} diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 801f6056..5b8cacdc 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -1,9 +1,10 @@ import { PaymentMethod } from '../../Services'; -import { IConfig } from '../../Utils'; +import { IConfig, ServiceCode } from '../../Utils'; import { IMandate, Mandate } from './Models/Mandate'; export default class Emandates extends PaymentMethod { _requiredFields: Array = ['currency']; + protected _serviceCode: ServiceCode = 'emandate'; issuerList() { this.setServiceList('GetIssuerList'); diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 4581f284..bfc148ef 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import IPay, { Pay } from './Models/Pay'; import { IRefund, Refund } from './Models/Refund'; +import { ServiceCode } from '../../Utils'; export default class GiftCard extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'giftcard'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 0240847a..939508f1 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class Giropay extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'giropay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index 145a52bb..530f18d6 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -2,8 +2,10 @@ import { IPay, Pay } from './Models/Pay'; import { PayablePaymentMethod } from '../../Services'; import { RequestTypes } from '../../Constants'; import { IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Ideal extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'ideal'; protected _serviceVersion = 2; constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 7bed8538..64379c79 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -1,7 +1,10 @@ import { Generate, IGenerate } from './Models/IGenerate'; import { PaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; export default class IdealQR extends PaymentMethod { + protected _serviceCode: ServiceCode = 'idealqr'; + generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 1905bd88..29b02403 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -1,7 +1,10 @@ import { PaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class Idin extends PaymentMethod { + protected _serviceCode: ServiceCode = 'idin'; + identify(payload: IPay) { this.setServiceList('Identify', new Pay(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index c78c05b9..160528ac 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; import Pay from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class In3 extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'In3'; + pay(payload: IPaymentRequest) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index a3999753..5ab13896 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class In3Old extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'capayable'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index 3562cedc..f2484fe2 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class KBC extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'KBCPaymentButton'; + refund(payload: IRefundRequest) { return super.refund(payload); } diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index ab458ae1..c8141b4e 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -1,7 +1,10 @@ import { IPay, Pay } from './Models/Pay'; import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; export default class Klarna extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'klarna'; + pay(data: IPay) { return super.pay(data, new Pay(data)); } diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index b63b5cee..32bfa483 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -2,8 +2,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/IPay'; import { IRequest } from '../../Models'; import { IReserve, Reserve } from './Models/IReserve'; +import { ServiceCode } from '../../Utils'; export default class KlarnaKP extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'klarnakp'; protected _serviceVersion = 1; pay(payload: IPay) { diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 3ffbdb35..49cb1779 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -1,8 +1,11 @@ import { PaymentMethod } from '../../Services'; import { ISplit, Split } from './Models/Split'; import { ITransfer } from './Models/Transfer'; +import { ServiceCode } from '../../Utils'; export default class Marketplaces extends PaymentMethod { + protected _serviceCode: ServiceCode = 'marketplaces'; + split(payload: ISplit) { this.setServiceList('Split', new Split(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index 81716588..b6ed8f72 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -1,3 +1,6 @@ import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; -export default class Mbway extends PayablePaymentMethod {} +export default class Mbway extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'MBWay'; +} diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index fe1264f0..fa39f12c 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -1,3 +1,6 @@ import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; -export default class MultiBanco extends PayablePaymentMethod {} +export default class MultiBanco extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'multibanco'; +} diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index 4a58876f..fa50228c 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -1,6 +1,9 @@ import { PayablePaymentMethod } from '../../Services'; +import { ServiceCode } from '../../Utils'; export default class NoService extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'noservice'; + protected setServiceList(): this { return this; } diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 7faeb1e9..4350673e 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import IPay, { Pay } from './Models/IPay'; +import { ServiceCode } from '../../Utils'; export default class PayByBank extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'PayByBank'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 12976f59..8f0aa59c 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -1,7 +1,10 @@ import { PaymentMethod } from '../../Services'; import { IInvitation, Invitation } from './Models/Invitation'; +import { ServiceCode } from '../../Utils'; export default class PayPerEmail extends PaymentMethod { + protected _serviceCode: ServiceCode = 'payperemail'; + paymentInvitation(payload: IInvitation) { this.setServiceList('paymentInvitation', new Invitation(payload)); return super.transactionRequest(payload); diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index d01288b1..d2f3c2dc 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Payconiq extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'payconiq'; + instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); return this.transactionRequest(payload); diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 29bda515..738cd8fe 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -2,8 +2,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; +import { ServiceCode } from '../../Utils'; export default class Paypal extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'paypal'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index b7394f1d..ae33f71c 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -1,7 +1,9 @@ import { PaymentMethod } from '../../Services'; import { Generate, IGenerate } from './Models/Generate'; +import { ServiceCode } from '../../Utils'; export default class PiM extends PaymentMethod { + protected _serviceCode: ServiceCode = 'pim'; protected _requiredFields = ['currency']; generate(payload: IGenerate) { diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index e4f90acb..ec2a2dc7 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -1,7 +1,10 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class PointOfSale extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'pospayment'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 4812700f..4fe673b3 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class Przelewy24 extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'przelewy24'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 9286501c..8e0963cb 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -2,10 +2,12 @@ import { PayablePaymentMethod } from '../../Services'; import { IPay, Pay } from './Models/Pay'; import { IExtraInfo } from './Models/ExtraInfo'; import { IEmandate } from './Models/Emandate'; -import { uniqid } from '../../Utils'; +import { ServiceCode, uniqid } from '../../Utils'; import { IPaymentRequest } from '../../Models'; export default class SEPA extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'sepadirectdebit'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index b3033169..742da6f8 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -1,7 +1,9 @@ import { PayablePaymentMethod } from '../../Services'; import { IPaymentRequest, IRefundRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; export default class Sofort extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'sofortueberweisung'; protected _serviceVersion = 1; pay(payload: IPaymentRequest) { diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 55aa85d0..9614f1cd 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -2,8 +2,10 @@ import { ISubscription, Subscription } from './Models/ISubscription'; import { PaymentMethod } from '../../Services'; import { IRequest } from '../../Models'; import { ResumeSubscription } from './Models/ResumeSubscription'; +import { ServiceCode } from '../../Utils'; export default class Subscriptions extends PaymentMethod { + protected _serviceCode: ServiceCode = 'subscriptions'; protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index d948fe64..6ce4c575 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -1,7 +1,10 @@ import { PaymentMethod } from '../../Services'; import { IVerify, Verify } from './Models/Verify'; +import { ServiceCode } from '../../Utils'; export default class Surepay extends PaymentMethod { + protected _serviceCode: ServiceCode = 'surepay'; + verify(payload: IVerify) { this.setServiceList('Verify', new Verify(payload)); return super.dataRequest(payload); diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 6284721e..70a755c7 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -1,8 +1,12 @@ import { PaymentMethod } from '../../Services'; import { IRequest } from '../../Models'; +import { ServiceCode } from '../../Utils'; type key = Required>; + export default class Thunes extends PaymentMethod { + protected _serviceCode: ServiceCode = 'thunes'; + getStatus(payload: key) { this.setServiceList('getStatus'); return this.dataRequest(payload); diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index 52c9df4d..de94950c 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class Tinka extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'tinka'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 1d617e03..52f4165e 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class Trustly extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'trustly'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 7c8c7557..6d6cf0ec 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -1,8 +1,11 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import { IPay, Pay } from './Models/Pay'; +import { ServiceCode } from '../../Utils'; export default class WeChatPay extends PayablePaymentMethod { + protected _serviceCode: ServiceCode = 'wechatpay'; + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index ce21d8d4..a6090991 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -11,7 +11,7 @@ export default abstract class PaymentMethod { protected _requiredFields: Array = []; constructor(serviceCode?: ServiceCode) { - this._serviceCode = serviceCode; + if (typeof serviceCode !== 'undefined') this._serviceCode = serviceCode; } get serviceVersion() { From 00b62d5722ac9a592f66be56f4583898a331d823 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 3 Nov 2023 09:57:55 +0100 Subject: [PATCH 40/52] reupdate service code on payment methods --- src/PaymentMethods/Afterpay/index.ts | 5 ++++- src/PaymentMethods/AfterpayDigiAccept/index.ts | 5 ++++- src/PaymentMethods/Alipay/index.ts | 4 +++- src/PaymentMethods/ApplePay/index.ts | 4 +++- src/PaymentMethods/Bancontact/index.ts | 4 +++- src/PaymentMethods/BankTransfer/index.ts | 4 +++- src/PaymentMethods/Belfius/index.ts | 4 +++- src/PaymentMethods/Billink/index.ts | 4 +++- src/PaymentMethods/BuckarooVoucher/index.ts | 4 +++- src/PaymentMethods/BuckarooWallet/index.ts | 4 +++- src/PaymentMethods/CreditCard/index.ts | 4 +++- src/PaymentMethods/CreditClick/index.ts | 4 +++- src/PaymentMethods/CreditManagement/index.ts | 5 ++++- src/PaymentMethods/EPS/index.ts | 4 +++- src/PaymentMethods/Emandates/index.ts | 5 ++++- src/PaymentMethods/GiftCard/index.ts | 4 +++- src/PaymentMethods/Giropay/index.ts | 4 +++- src/PaymentMethods/Ideal/index.ts | 5 ++++- src/PaymentMethods/IdealQR/index.ts | 4 +++- src/PaymentMethods/Idin/index.ts | 4 +++- src/PaymentMethods/In3/index.ts | 4 +++- src/PaymentMethods/In3Old/index.ts | 4 +++- src/PaymentMethods/KBC/index.ts | 4 +++- src/PaymentMethods/Klarna/index.ts | 4 +++- src/PaymentMethods/KlarnaKP/index.ts | 5 ++++- src/PaymentMethods/Marketplaces/index.ts | 4 +++- src/PaymentMethods/Mbway/index.ts | 4 +++- src/PaymentMethods/Multibanco/index.ts | 4 +++- src/PaymentMethods/NoService/index.ts | 4 +++- src/PaymentMethods/PayByBank/index.ts | 4 +++- src/PaymentMethods/PayPerEmail/index.ts | 4 +++- src/PaymentMethods/Payconiq/index.ts | 4 +++- src/PaymentMethods/Paypal/index.ts | 4 +++- src/PaymentMethods/PiM/index.ts | 5 ++++- src/PaymentMethods/PointOfSale/index.ts | 4 +++- src/PaymentMethods/Przelewy24/index.ts | 4 +++- src/PaymentMethods/SEPA/index.ts | 4 +++- src/PaymentMethods/Sofort/index.ts | 5 ++++- src/PaymentMethods/Subscriptions/index.ts | 5 ++++- src/PaymentMethods/Surepay/index.ts | 4 +++- src/PaymentMethods/Thunes/index.ts | 4 +++- src/PaymentMethods/Tinka/index.ts | 4 +++- src/PaymentMethods/Trustly/index.ts | 4 +++- src/PaymentMethods/WeChatPay/index.ts | 4 +++- src/Services/PaymentMethod.ts | 4 +++- 45 files changed, 144 insertions(+), 45 deletions(-) diff --git a/src/PaymentMethods/Afterpay/index.ts b/src/PaymentMethods/Afterpay/index.ts index ca6ac6b0..8fdb0ec8 100644 --- a/src/PaymentMethods/Afterpay/index.ts +++ b/src/PaymentMethods/Afterpay/index.ts @@ -5,9 +5,12 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class Afterpay extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'afterpay'; protected _serviceVersion = 1; + public defaultServiceCode(): ServiceCode { + return 'afterpay'; + } + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/AfterpayDigiAccept/index.ts b/src/PaymentMethods/AfterpayDigiAccept/index.ts index ce1cdf8b..368e87dd 100644 --- a/src/PaymentMethods/AfterpayDigiAccept/index.ts +++ b/src/PaymentMethods/AfterpayDigiAccept/index.ts @@ -4,9 +4,12 @@ import { IPay, Pay } from './Model/Pay'; import { ServiceCode } from '../../Utils'; export default class AfterpayDigiAccept extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'afterpaydigiaccept'; protected _serviceVersion = 2; + public defaultServiceCode(): ServiceCode { + return 'afterpaydigiaccept'; + } + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Alipay/index.ts b/src/PaymentMethods/Alipay/index.ts index 8e621cab..395d78e7 100644 --- a/src/PaymentMethods/Alipay/index.ts +++ b/src/PaymentMethods/Alipay/index.ts @@ -3,7 +3,9 @@ import { IPaymentRequest, IRefundRequest, ServiceParameter } from '../../Models' import { ServiceCode } from '../../Utils'; export default class Alipay extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'alipay'; + public defaultServiceCode(): ServiceCode { + return 'alipay'; + } pay(payload: { useMobileView?: boolean } & IPaymentRequest) { const serviceParameters = new ServiceParameter().set('useMobileView', payload.useMobileView); diff --git a/src/PaymentMethods/ApplePay/index.ts b/src/PaymentMethods/ApplePay/index.ts index 4b575979..9cba272c 100644 --- a/src/PaymentMethods/ApplePay/index.ts +++ b/src/PaymentMethods/ApplePay/index.ts @@ -4,7 +4,9 @@ import { IPaymentRequest, IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class ApplePay extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'applepay'; + public defaultServiceCode(): ServiceCode { + return 'applepay'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Bancontact/index.ts b/src/PaymentMethods/Bancontact/index.ts index 768881c2..02cbb37a 100644 --- a/src/PaymentMethods/Bancontact/index.ts +++ b/src/PaymentMethods/Bancontact/index.ts @@ -4,7 +4,9 @@ import { IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class Bancontact extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'bancontactmrcash'; + public defaultServiceCode(): ServiceCode { + return 'bancontactmrcash'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/BankTransfer/index.ts b/src/PaymentMethods/BankTransfer/index.ts index 921e7981..01c494b4 100644 --- a/src/PaymentMethods/BankTransfer/index.ts +++ b/src/PaymentMethods/BankTransfer/index.ts @@ -4,7 +4,9 @@ import { IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class BankTransfer extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'transfer'; + public defaultServiceCode(): ServiceCode { + return 'transfer'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Belfius/index.ts b/src/PaymentMethods/Belfius/index.ts index 46f20cc3..5dc756fb 100644 --- a/src/PaymentMethods/Belfius/index.ts +++ b/src/PaymentMethods/Belfius/index.ts @@ -3,7 +3,9 @@ import { IPaymentRequest, IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class Belfius extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'belfius'; + public defaultServiceCode(): ServiceCode { + return 'belfius'; + } pay(payload: IPaymentRequest) { return super.pay(payload); diff --git a/src/PaymentMethods/Billink/index.ts b/src/PaymentMethods/Billink/index.ts index 8dccad45..521456b3 100644 --- a/src/PaymentMethods/Billink/index.ts +++ b/src/PaymentMethods/Billink/index.ts @@ -5,7 +5,9 @@ import { Capture, ICapture } from './Models/Capture'; import { ServiceCode } from '../../Utils'; export default class Billink extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'billink'; + public defaultServiceCode(): ServiceCode { + return 'billink'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/BuckarooVoucher/index.ts b/src/PaymentMethods/BuckarooVoucher/index.ts index ca41496e..10e48575 100644 --- a/src/PaymentMethods/BuckarooVoucher/index.ts +++ b/src/PaymentMethods/BuckarooVoucher/index.ts @@ -5,7 +5,9 @@ import { Create, ICreate } from './Models/Create'; import { ServiceCode } from '../../Utils'; export default class BuckarooVoucher extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'buckaroovoucher'; + public defaultServiceCode(): ServiceCode { + return 'buckaroovoucher'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index 4958fa18..d9879bdf 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -4,7 +4,9 @@ import { IPaymentRequest, IRefundRequest, IRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class BuckarooWallet extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'BuckarooWalletCollecting'; + public defaultServiceCode(): ServiceCode { + return 'BuckarooWalletCollecting'; + } pay(payload: IWallet & IPaymentRequest) { return super.pay(payload, new Wallet(payload)); diff --git a/src/PaymentMethods/CreditCard/index.ts b/src/PaymentMethods/CreditCard/index.ts index d539bc3e..fcbcadf4 100644 --- a/src/PaymentMethods/CreditCard/index.ts +++ b/src/PaymentMethods/CreditCard/index.ts @@ -5,7 +5,9 @@ import { ISecurityCode, SecurityCode } from './Models/SecurityCode'; import { ServiceCode } from '../../Utils'; export default class CreditCard extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'CreditCard'; + public defaultServiceCode(): ServiceCode { + return 'CreditCard'; + } payEncrypted(payload: ICardData) { this.setPayPayload(payload); diff --git a/src/PaymentMethods/CreditClick/index.ts b/src/PaymentMethods/CreditClick/index.ts index 8e06a394..f6b73705 100644 --- a/src/PaymentMethods/CreditClick/index.ts +++ b/src/PaymentMethods/CreditClick/index.ts @@ -4,7 +4,9 @@ import { IRefund, Refund } from './Models/Refund'; import { ServiceCode } from '../../Utils'; export default class CreditClick extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'creditclick'; + public defaultServiceCode(): ServiceCode { + return 'creditclick'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/CreditManagement/index.ts b/src/PaymentMethods/CreditManagement/index.ts index a7cdd96c..e8cfc973 100644 --- a/src/PaymentMethods/CreditManagement/index.ts +++ b/src/PaymentMethods/CreditManagement/index.ts @@ -10,10 +10,13 @@ import { DebtorInfo, IDebtorInfo } from './Models/DebtorInfo'; import { ServiceCode } from '../../Utils'; export default class CreditManagement extends PaymentMethod { - protected _serviceCode: ServiceCode = 'CreditManagement3'; protected _serviceVersion = 1; protected _requiredFields = ['currency']; + public defaultServiceCode(): ServiceCode { + return 'CreditManagement3'; + } + createInvoice(payload: IInvoice) { this.setServiceList('CreateInvoice', new Invoice(payload)); return this.dataRequest(payload); diff --git a/src/PaymentMethods/EPS/index.ts b/src/PaymentMethods/EPS/index.ts index e6bf9a96..23367174 100644 --- a/src/PaymentMethods/EPS/index.ts +++ b/src/PaymentMethods/EPS/index.ts @@ -2,5 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class EPS extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'eps'; + public defaultServiceCode(): ServiceCode { + return 'eps'; + } } diff --git a/src/PaymentMethods/Emandates/index.ts b/src/PaymentMethods/Emandates/index.ts index 5b8cacdc..c9fe6548 100644 --- a/src/PaymentMethods/Emandates/index.ts +++ b/src/PaymentMethods/Emandates/index.ts @@ -4,7 +4,10 @@ import { IMandate, Mandate } from './Models/Mandate'; export default class Emandates extends PaymentMethod { _requiredFields: Array = ['currency']; - protected _serviceCode: ServiceCode = 'emandate'; + + public defaultServiceCode(): ServiceCode { + return 'emandate'; + } issuerList() { this.setServiceList('GetIssuerList'); diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index bfc148ef..e903b967 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -4,7 +4,9 @@ import { IRefund, Refund } from './Models/Refund'; import { ServiceCode } from '../../Utils'; export default class GiftCard extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'giftcard'; + public defaultServiceCode(): ServiceCode { + return 'giftcard'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Giropay/index.ts b/src/PaymentMethods/Giropay/index.ts index 939508f1..b5c1f1a4 100644 --- a/src/PaymentMethods/Giropay/index.ts +++ b/src/PaymentMethods/Giropay/index.ts @@ -3,7 +3,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class Giropay extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'giropay'; + public defaultServiceCode(): ServiceCode { + return 'giropay'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Ideal/index.ts b/src/PaymentMethods/Ideal/index.ts index 530f18d6..9663a282 100644 --- a/src/PaymentMethods/Ideal/index.ts +++ b/src/PaymentMethods/Ideal/index.ts @@ -5,13 +5,16 @@ import { IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class Ideal extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'ideal'; protected _serviceVersion = 2; constructor(serviceCode: 'ideal' | 'idealprocessing' = 'ideal') { super(serviceCode); } + public defaultServiceCode(): ServiceCode { + return 'ideal'; + } + pay(data: IPay) { return super.pay(data, new Pay(data)); } diff --git a/src/PaymentMethods/IdealQR/index.ts b/src/PaymentMethods/IdealQR/index.ts index 64379c79..22281d06 100644 --- a/src/PaymentMethods/IdealQR/index.ts +++ b/src/PaymentMethods/IdealQR/index.ts @@ -3,7 +3,9 @@ import { PaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class IdealQR extends PaymentMethod { - protected _serviceCode: ServiceCode = 'idealqr'; + public defaultServiceCode(): ServiceCode { + return 'idealqr'; + } generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); diff --git a/src/PaymentMethods/Idin/index.ts b/src/PaymentMethods/Idin/index.ts index 29b02403..4f1552cd 100644 --- a/src/PaymentMethods/Idin/index.ts +++ b/src/PaymentMethods/Idin/index.ts @@ -3,7 +3,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class Idin extends PaymentMethod { - protected _serviceCode: ServiceCode = 'idin'; + public defaultServiceCode(): ServiceCode { + return 'idin'; + } identify(payload: IPay) { this.setServiceList('Identify', new Pay(payload)); diff --git a/src/PaymentMethods/In3/index.ts b/src/PaymentMethods/In3/index.ts index 160528ac..270e6b98 100644 --- a/src/PaymentMethods/In3/index.ts +++ b/src/PaymentMethods/In3/index.ts @@ -4,7 +4,9 @@ import Pay from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class In3 extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'In3'; + public defaultServiceCode(): ServiceCode { + return 'In3'; + } pay(payload: IPaymentRequest) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/In3Old/index.ts b/src/PaymentMethods/In3Old/index.ts index 5ab13896..1dd95d22 100644 --- a/src/PaymentMethods/In3Old/index.ts +++ b/src/PaymentMethods/In3Old/index.ts @@ -3,7 +3,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class In3Old extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'capayable'; + public defaultServiceCode(): ServiceCode { + return 'capayable'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/KBC/index.ts b/src/PaymentMethods/KBC/index.ts index f2484fe2..fe9aef87 100644 --- a/src/PaymentMethods/KBC/index.ts +++ b/src/PaymentMethods/KBC/index.ts @@ -3,7 +3,9 @@ import { IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class KBC extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'KBCPaymentButton'; + public defaultServiceCode(): ServiceCode { + return 'KBCPaymentButton'; + } refund(payload: IRefundRequest) { return super.refund(payload); diff --git a/src/PaymentMethods/Klarna/index.ts b/src/PaymentMethods/Klarna/index.ts index c8141b4e..609aee49 100644 --- a/src/PaymentMethods/Klarna/index.ts +++ b/src/PaymentMethods/Klarna/index.ts @@ -3,7 +3,9 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class Klarna extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'klarna'; + public defaultServiceCode(): ServiceCode { + return 'klarna'; + } pay(data: IPay) { return super.pay(data, new Pay(data)); diff --git a/src/PaymentMethods/KlarnaKP/index.ts b/src/PaymentMethods/KlarnaKP/index.ts index 32bfa483..50336fae 100644 --- a/src/PaymentMethods/KlarnaKP/index.ts +++ b/src/PaymentMethods/KlarnaKP/index.ts @@ -5,9 +5,12 @@ import { IReserve, Reserve } from './Models/IReserve'; import { ServiceCode } from '../../Utils'; export default class KlarnaKP extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'klarnakp'; protected _serviceVersion = 1; + public defaultServiceCode(): ServiceCode { + return 'klarnakp'; + } + pay(payload: IPay) { return super.pay(payload, new Pay(payload)); } diff --git a/src/PaymentMethods/Marketplaces/index.ts b/src/PaymentMethods/Marketplaces/index.ts index 49cb1779..636fdec9 100644 --- a/src/PaymentMethods/Marketplaces/index.ts +++ b/src/PaymentMethods/Marketplaces/index.ts @@ -4,7 +4,9 @@ import { ITransfer } from './Models/Transfer'; import { ServiceCode } from '../../Utils'; export default class Marketplaces extends PaymentMethod { - protected _serviceCode: ServiceCode = 'marketplaces'; + public defaultServiceCode(): ServiceCode { + return 'marketplaces'; + } split(payload: ISplit) { this.setServiceList('Split', new Split(payload)); diff --git a/src/PaymentMethods/Mbway/index.ts b/src/PaymentMethods/Mbway/index.ts index b6ed8f72..a9f291fc 100644 --- a/src/PaymentMethods/Mbway/index.ts +++ b/src/PaymentMethods/Mbway/index.ts @@ -2,5 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class Mbway extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'MBWay'; + public defaultServiceCode(): ServiceCode { + return 'MBWay'; + } } diff --git a/src/PaymentMethods/Multibanco/index.ts b/src/PaymentMethods/Multibanco/index.ts index fa39f12c..cd7c4f9b 100644 --- a/src/PaymentMethods/Multibanco/index.ts +++ b/src/PaymentMethods/Multibanco/index.ts @@ -2,5 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class MultiBanco extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'multibanco'; + public defaultServiceCode(): ServiceCode { + return 'multibanco'; + } } diff --git a/src/PaymentMethods/NoService/index.ts b/src/PaymentMethods/NoService/index.ts index fa50228c..392be8bc 100644 --- a/src/PaymentMethods/NoService/index.ts +++ b/src/PaymentMethods/NoService/index.ts @@ -2,7 +2,9 @@ import { PayablePaymentMethod } from '../../Services'; import { ServiceCode } from '../../Utils'; export default class NoService extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'noservice'; + public defaultServiceCode(): ServiceCode { + return 'noservice'; + } protected setServiceList(): this { return this; diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 4350673e..6f3662cf 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -4,7 +4,9 @@ import IPay, { Pay } from './Models/IPay'; import { ServiceCode } from '../../Utils'; export default class PayByBank extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'PayByBank'; + public defaultServiceCode(): ServiceCode { + return 'PayByBank'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/PayPerEmail/index.ts b/src/PaymentMethods/PayPerEmail/index.ts index 8f0aa59c..a0d1b114 100644 --- a/src/PaymentMethods/PayPerEmail/index.ts +++ b/src/PaymentMethods/PayPerEmail/index.ts @@ -3,7 +3,9 @@ import { IInvitation, Invitation } from './Models/Invitation'; import { ServiceCode } from '../../Utils'; export default class PayPerEmail extends PaymentMethod { - protected _serviceCode: ServiceCode = 'payperemail'; + public defaultServiceCode(): ServiceCode { + return 'payperemail'; + } paymentInvitation(payload: IInvitation) { this.setServiceList('paymentInvitation', new Invitation(payload)); diff --git a/src/PaymentMethods/Payconiq/index.ts b/src/PaymentMethods/Payconiq/index.ts index d2f3c2dc..3daa55b8 100644 --- a/src/PaymentMethods/Payconiq/index.ts +++ b/src/PaymentMethods/Payconiq/index.ts @@ -3,7 +3,9 @@ import { IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class Payconiq extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'payconiq'; + public defaultServiceCode(): ServiceCode { + return 'payconiq'; + } instantRefund(payload: IRefundRequest) { this.setServiceList('InstantRefund'); diff --git a/src/PaymentMethods/Paypal/index.ts b/src/PaymentMethods/Paypal/index.ts index 738cd8fe..e0b20ad7 100644 --- a/src/PaymentMethods/Paypal/index.ts +++ b/src/PaymentMethods/Paypal/index.ts @@ -5,7 +5,9 @@ import { ExtraInfo, IExtraInfo } from './Models/ExtraInfo'; import { ServiceCode } from '../../Utils'; export default class Paypal extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'paypal'; + public defaultServiceCode(): ServiceCode { + return 'paypal'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/PiM/index.ts b/src/PaymentMethods/PiM/index.ts index ae33f71c..a5f92f89 100644 --- a/src/PaymentMethods/PiM/index.ts +++ b/src/PaymentMethods/PiM/index.ts @@ -3,9 +3,12 @@ import { Generate, IGenerate } from './Models/Generate'; import { ServiceCode } from '../../Utils'; export default class PiM extends PaymentMethod { - protected _serviceCode: ServiceCode = 'pim'; protected _requiredFields = ['currency']; + public defaultServiceCode(): ServiceCode { + return 'pim'; + } + generate(payload: IGenerate) { this.setServiceList('Generate', new Generate(payload)); return this.dataRequest(); diff --git a/src/PaymentMethods/PointOfSale/index.ts b/src/PaymentMethods/PointOfSale/index.ts index ec2a2dc7..eb80ee6a 100644 --- a/src/PaymentMethods/PointOfSale/index.ts +++ b/src/PaymentMethods/PointOfSale/index.ts @@ -3,7 +3,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class PointOfSale extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'pospayment'; + public defaultServiceCode(): ServiceCode { + return 'pospayment'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Przelewy24/index.ts b/src/PaymentMethods/Przelewy24/index.ts index 4fe673b3..70a6dd36 100644 --- a/src/PaymentMethods/Przelewy24/index.ts +++ b/src/PaymentMethods/Przelewy24/index.ts @@ -4,7 +4,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class Przelewy24 extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'przelewy24'; + public defaultServiceCode(): ServiceCode { + return 'przelewy24'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/SEPA/index.ts b/src/PaymentMethods/SEPA/index.ts index 8e0963cb..ab0f8927 100644 --- a/src/PaymentMethods/SEPA/index.ts +++ b/src/PaymentMethods/SEPA/index.ts @@ -6,7 +6,9 @@ import { ServiceCode, uniqid } from '../../Utils'; import { IPaymentRequest } from '../../Models'; export default class SEPA extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'sepadirectdebit'; + public defaultServiceCode(): ServiceCode { + return 'sepadirectdebit'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Sofort/index.ts b/src/PaymentMethods/Sofort/index.ts index 742da6f8..aae1ded4 100644 --- a/src/PaymentMethods/Sofort/index.ts +++ b/src/PaymentMethods/Sofort/index.ts @@ -3,9 +3,12 @@ import { IPaymentRequest, IRefundRequest } from '../../Models'; import { ServiceCode } from '../../Utils'; export default class Sofort extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'sofortueberweisung'; protected _serviceVersion = 1; + public defaultServiceCode(): ServiceCode { + return 'sofortueberweisung'; + } + pay(payload: IPaymentRequest) { return super.pay(payload); } diff --git a/src/PaymentMethods/Subscriptions/index.ts b/src/PaymentMethods/Subscriptions/index.ts index 9614f1cd..3a6c7dcb 100644 --- a/src/PaymentMethods/Subscriptions/index.ts +++ b/src/PaymentMethods/Subscriptions/index.ts @@ -5,10 +5,13 @@ import { ResumeSubscription } from './Models/ResumeSubscription'; import { ServiceCode } from '../../Utils'; export default class Subscriptions extends PaymentMethod { - protected _serviceCode: ServiceCode = 'subscriptions'; protected _serviceVersion = 1; protected _requiredFields: Array = ['currency']; + public defaultServiceCode(): ServiceCode { + return 'subscriptions'; + } + create(payload: ISubscription) { this.setPayload(payload); this.setServiceList('CreateSubscription', new Subscription(payload)); diff --git a/src/PaymentMethods/Surepay/index.ts b/src/PaymentMethods/Surepay/index.ts index 6ce4c575..40969745 100644 --- a/src/PaymentMethods/Surepay/index.ts +++ b/src/PaymentMethods/Surepay/index.ts @@ -3,7 +3,9 @@ import { IVerify, Verify } from './Models/Verify'; import { ServiceCode } from '../../Utils'; export default class Surepay extends PaymentMethod { - protected _serviceCode: ServiceCode = 'surepay'; + public defaultServiceCode(): ServiceCode { + return 'surepay'; + } verify(payload: IVerify) { this.setServiceList('Verify', new Verify(payload)); diff --git a/src/PaymentMethods/Thunes/index.ts b/src/PaymentMethods/Thunes/index.ts index 70a755c7..187ee5ed 100644 --- a/src/PaymentMethods/Thunes/index.ts +++ b/src/PaymentMethods/Thunes/index.ts @@ -5,7 +5,9 @@ import { ServiceCode } from '../../Utils'; type key = Required>; export default class Thunes extends PaymentMethod { - protected _serviceCode: ServiceCode = 'thunes'; + public defaultServiceCode(): ServiceCode { + return 'thunes'; + } getStatus(payload: key) { this.setServiceList('getStatus'); diff --git a/src/PaymentMethods/Tinka/index.ts b/src/PaymentMethods/Tinka/index.ts index de94950c..6a3961c5 100644 --- a/src/PaymentMethods/Tinka/index.ts +++ b/src/PaymentMethods/Tinka/index.ts @@ -4,7 +4,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class Tinka extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'tinka'; + public defaultServiceCode(): ServiceCode { + return 'tinka'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/Trustly/index.ts b/src/PaymentMethods/Trustly/index.ts index 52f4165e..333f21b5 100644 --- a/src/PaymentMethods/Trustly/index.ts +++ b/src/PaymentMethods/Trustly/index.ts @@ -4,7 +4,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class Trustly extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'trustly'; + public defaultServiceCode(): ServiceCode { + return 'trustly'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/PaymentMethods/WeChatPay/index.ts b/src/PaymentMethods/WeChatPay/index.ts index 6d6cf0ec..b08c4465 100644 --- a/src/PaymentMethods/WeChatPay/index.ts +++ b/src/PaymentMethods/WeChatPay/index.ts @@ -4,7 +4,9 @@ import { IPay, Pay } from './Models/Pay'; import { ServiceCode } from '../../Utils'; export default class WeChatPay extends PayablePaymentMethod { - protected _serviceCode: ServiceCode = 'wechatpay'; + public defaultServiceCode(): ServiceCode { + return 'wechatpay'; + } pay(payload: IPay) { return super.pay(payload, new Pay(payload)); diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index a6090991..43dda6c9 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -11,7 +11,7 @@ export default abstract class PaymentMethod { protected _requiredFields: Array = []; constructor(serviceCode?: ServiceCode) { - if (typeof serviceCode !== 'undefined') this._serviceCode = serviceCode; + this.setServiceCode((serviceCode ?? this._serviceCode) as ServiceCode); } get serviceVersion() { @@ -26,6 +26,8 @@ export default abstract class PaymentMethod { return this._serviceCode || 'noservice'; } + public abstract defaultServiceCode(): ServiceCode; + setServiceCode(value: ServiceCode): this { this._serviceCode = value; return this; From 9cb029269dda05666b954e5bbf91e7000b57d8c1 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 3 Nov 2023 10:19:59 +0100 Subject: [PATCH 41/52] few update --- src/Models/Interfaces/ICustomer.ts | 9 ++++----- src/Models/Response/SpecificationRequestResponse.ts | 6 +----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Models/Interfaces/ICustomer.ts b/src/Models/Interfaces/ICustomer.ts index 6bec9001..bf3c7ee5 100644 --- a/src/Models/Interfaces/ICustomer.ts +++ b/src/Models/Interfaces/ICustomer.ts @@ -22,10 +22,9 @@ export class Customer extends Model { } set recipient(recipient: IPerson | ICompany) { - if (recipient.category === RecipientCategory.PERSON) { - this.set('recipient', new Person(recipient)); - } else if (recipient.category === RecipientCategory.COMPANY) { - this.set('recipient', new Company(recipient)); - } + this.set( + 'recipient', + recipient.category === RecipientCategory.COMPANY ? new Company(recipient) : new Person(recipient) + ); } } diff --git a/src/Models/Response/SpecificationRequestResponse.ts b/src/Models/Response/SpecificationRequestResponse.ts index 59136652..7a43dea9 100644 --- a/src/Models/Response/SpecificationRequestResponse.ts +++ b/src/Models/Response/SpecificationRequestResponse.ts @@ -61,9 +61,5 @@ export interface ISpecificationRequestResponse { description: string; actions?: Action[]; supportedCurrencies?: SupportedCurrency[]; - customParameters?: { - description: string; - dataType: number; - name: string; - }[]; + customParameters?: Record; } From 36a1ce5fc14bcf25cd1e3f55e302bb161041b7fc Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 3 Nov 2023 13:03:45 +0100 Subject: [PATCH 42/52] fix sonarqube issues --- src/PaymentMethods/BuckarooWallet/index.ts | 2 +- src/PaymentMethods/SEPA/Models/Pay.ts | 3 --- src/Request/HttpsClient.ts | 4 ++-- src/Request/Request.ts | 2 +- src/Services/PaymentMethod.ts | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index d9879bdf..7257e0b4 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -43,7 +43,7 @@ export default class BuckarooWallet extends PayablePaymentMethod { cancel(payload: IPaymentRequest & { walletMutationGuid: string }) { this.setPayPayload(payload); - this.setServiceList('Withdrawal', new Wallet(payload)); + this.setServiceList('Cancel', new Wallet(payload)); return super.transactionRequest(); } diff --git a/src/PaymentMethods/SEPA/Models/Pay.ts b/src/PaymentMethods/SEPA/Models/Pay.ts index 2b3e91ed..ac933c7a 100644 --- a/src/PaymentMethods/SEPA/Models/Pay.ts +++ b/src/PaymentMethods/SEPA/Models/Pay.ts @@ -1,5 +1,4 @@ import { IPaymentRequest, IPerson, Person, ServiceParameter } from '../../../Models'; -import { RecipientCategory } from '../../../Constants'; export interface IPay extends IPaymentRequest { customer?: Partial; @@ -45,8 +44,6 @@ export class Pay extends ServiceParameter { } export class Customer extends Person { - set category(value: RecipientCategory.PERSON) {} - get name(): string { return this.get('customeraccountname'); } diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 3d7de73e..947b4970 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -16,8 +16,8 @@ export default class HttpsClient { public async sendRequest( url: URL, - data: object = {}, - options: RequestConfig = {}, + data: object, + options: RequestConfig, responseClass: R ): Promise> { try { diff --git a/src/Request/Request.ts b/src/Request/Request.ts index fa472e63..b531629a 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -103,7 +103,7 @@ export default class Request< data, { method: this._httpMethod, - headers: this.headers as RequestHeaders, + headers: this.headers, ...options, }, this.responseHandler diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 43dda6c9..6a0f7be2 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -23,7 +23,7 @@ export default abstract class PaymentMethod { } get serviceCode(): ServiceCode { - return this._serviceCode || 'noservice'; + return this._serviceCode ?? 'noservice'; } public abstract defaultServiceCode(): ServiceCode; From 372cf12314ea51a89a956385f73c0d33783a1b0a Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 3 Nov 2023 13:05:56 +0100 Subject: [PATCH 43/52] fix sonarqube issue --- src/Request/Request.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/Request.ts b/src/Request/Request.ts index b531629a..a16b2336 100644 --- a/src/Request/Request.ts +++ b/src/Request/Request.ts @@ -1,4 +1,4 @@ -import Headers, { RequestConfig, RequestHeaders } from './Headers'; +import Headers, { RequestConfig } from './Headers'; import { BatchRequestResponse, HttpClientResponse, From 6930190ec9bd21ee58667491ad412bf4c968c137 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 9 Nov 2023 09:32:15 +0100 Subject: [PATCH 44/52] fix bug and add test for paybybank issuers --- src/PaymentMethods/PayByBank/index.ts | 5 +++-- src/Services/PaymentMethod.ts | 7 +++++-- tests/PaymentMethods/PaymentInitiation.test.ts | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/PaymentMethods/PayByBank/index.ts b/src/PaymentMethods/PayByBank/index.ts index 6f3662cf..f429fc75 100644 --- a/src/PaymentMethods/PayByBank/index.ts +++ b/src/PaymentMethods/PayByBank/index.ts @@ -2,6 +2,7 @@ import { PayablePaymentMethod } from '../../Services'; import { IRefundRequest } from '../../Models'; import IPay, { Pay } from './Models/IPay'; import { ServiceCode } from '../../Utils'; +import { RequestTypes } from '../../Constants'; export default class PayByBank extends PayablePaymentMethod { public defaultServiceCode(): ServiceCode { @@ -17,12 +18,12 @@ export default class PayByBank extends PayablePaymentMethod { } issuers() { - return this.specification() + return this.specification(RequestTypes.Transaction, 1) .request() .then((response) => { return response .getActionRequestParameters('Pay') - ?.find((item) => item.name === 'issuer') + ?.find((item) => item.name === 'Issuer') ?.listItemDescriptions!.map((item) => { return { [item.value]: item.description }; }); diff --git a/src/Services/PaymentMethod.ts b/src/Services/PaymentMethod.ts index 6a0f7be2..bab92b8c 100644 --- a/src/Services/PaymentMethod.ts +++ b/src/Services/PaymentMethod.ts @@ -62,8 +62,11 @@ export default abstract class PaymentMethod { return this; } - public specification(type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data) { - return Request.Specification(type, { name: this.serviceCode, version: this.serviceVersion }); + public specification( + type: RequestTypes.Transaction | RequestTypes.Data = RequestTypes.Data, + serviceVersion: number = this.serviceVersion + ) { + return Request.Specification(type, { name: this.serviceCode, version: serviceVersion }); } protected setRequiredFields(requiredFields: Array = this._requiredFields) { diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 9f2cc036..1c719e4b 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -4,6 +4,13 @@ import { uniqid } from '../../src'; const method = buckarooClientTest.method('PayByBank'); describe('PaymentInitiation methods', () => { + test('Issuers', async () => { + await method + .issuers() + .then((response) => { + expect(Array.isArray(response)).toBeTruthy(); + }); + }); test('Pay', async () => { await method .pay({ From 82a74e8e5a7bdf9b94bad0d1a452474afa7f7131 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Tue, 14 Nov 2023 16:50:05 +0100 Subject: [PATCH 45/52] remove uneccessary BUCKAROO_ from response status --- src/Constants/ResponseStatus.ts | 28 +++++++++++----------- src/Models/Response/TransactionResponse.ts | 18 +++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Constants/ResponseStatus.ts b/src/Constants/ResponseStatus.ts index 4b91a7fd..81b2b57e 100644 --- a/src/Constants/ResponseStatus.ts +++ b/src/Constants/ResponseStatus.ts @@ -1,18 +1,18 @@ enum ResponseStatus { - BUCKAROO_STATUSCODE_SUCCESS = '190', - BUCKAROO_STATUSCODE_FAILED = '490', - BUCKAROO_STATUSCODE_VALIDATION_FAILURE = '491', - BUCKAROO_STATUSCODE_TECHNICAL_ERROR = '492', - BUCKAROO_STATUSCODE_REJECTED = '690', - BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT = '790', - BUCKAROO_STATUSCODE_PENDING_PROCESSING = '791', - BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER = '792', - BUCKAROO_STATUSCODE_PAYMENT_ON_HOLD = '793', - BUCKAROO_STATUSCODE_CANCELLED_BY_USER = '890', - BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT = '891', - BUCKAROO_AUTHORIZE_TYPE_CANCEL = 'I014', - BUCKAROO_AUTHORIZE_TYPE_ACCEPT = 'I013', - BUCKAROO_AUTHORIZE_TYPE_GROUP_TRANSACTION = 'I150', + STATUSCODE_SUCCESS = '190', + STATUSCODE_FAILED = '490', + STATUSCODE_VALIDATION_FAILURE = '491', + STATUSCODE_TECHNICAL_ERROR = '492', + STATUSCODE_REJECTED = '690', + STATUSCODE_WAITING_ON_USER_INPUT = '790', + STATUSCODE_PENDING_PROCESSING = '791', + STATUSCODE_WAITING_ON_CONSUMER = '792', + STATUSCODE_PAYMENT_ON_HOLD = '793', + STATUSCODE_CANCELLED_BY_USER = '890', + STATUSCODE_CANCELLED_BY_MERCHANT = '891', + AUTHORIZE_TYPE_CANCEL = 'I014', + AUTHORIZE_TYPE_ACCEPT = 'I013', + AUTHORIZE_TYPE_GROUP_TRANSACTION = 'I150', } export default ResponseStatus; diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index fc2617ea..a33c7a44 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -18,38 +18,38 @@ export class TransactionResponse extends HttpClientResponse { } isSuccess() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_SUCCESS; + return this.getStatusCode() === ResponseStatus.STATUSCODE_SUCCESS; } isFailed() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_FAILED; + return this.getStatusCode() === ResponseStatus.STATUSCODE_FAILED; } isCanceled() { return ( - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_USER || - this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT + this.getStatusCode() === ResponseStatus.STATUSCODE_CANCELLED_BY_USER || + this.getStatusCode() === ResponseStatus.STATUSCODE_CANCELLED_BY_MERCHANT ); } isAwaitingConsumer() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER; + return this.getStatusCode() === ResponseStatus.STATUSCODE_WAITING_ON_CONSUMER; } isPendingProcessing() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_PENDING_PROCESSING; + return this.getStatusCode() === ResponseStatus.STATUSCODE_PENDING_PROCESSING; } isWaitingOnUserInput() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_WAITING_ON_USER_INPUT; + return this.getStatusCode() === ResponseStatus.STATUSCODE_WAITING_ON_USER_INPUT; } isRejected() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_REJECTED; + return this.getStatusCode() === ResponseStatus.STATUSCODE_REJECTED; } isValidationFailure() { - return this.getStatusCode() === ResponseStatus.BUCKAROO_STATUSCODE_VALIDATION_FAILURE; + return this.getStatusCode() === ResponseStatus.STATUSCODE_VALIDATION_FAILURE; } hasRedirect() { From 3853279c77fd7d96cf0aed1cb5d1fd9a8f2ed0a6 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Tue, 14 Nov 2023 16:56:20 +0100 Subject: [PATCH 46/52] some refactor on afterpay customer model --- src/PaymentMethods/Afterpay/Model/Customer.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PaymentMethods/Afterpay/Model/Customer.ts b/src/PaymentMethods/Afterpay/Model/Customer.ts index e330e248..0dec620c 100644 --- a/src/PaymentMethods/Afterpay/Model/Customer.ts +++ b/src/PaymentMethods/Afterpay/Model/Customer.ts @@ -6,11 +6,12 @@ import { AfterPayCompany, AfterPayPerson } from './Recipient'; export default class Customer extends Model implements ICustomer { set recipient(recipient: IPerson | ICompany) { - if (recipient.category === RecipientCategory.PERSON) { - this.set('recipient', new AfterPayPerson(recipient)); - } else if (recipient.category === RecipientCategory.COMPANY) { - this.set('recipient', new AfterPayCompany(recipient)); - } + this.set( + 'recipient', + recipient.category === RecipientCategory.COMPANY + ? new AfterPayCompany(recipient) + : new AfterPayPerson(recipient) + ); } set address(address: IAddress) { From 9763fccfb5f65367bf3c419c84f323c16e4d8acf Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 15 Nov 2023 09:16:48 +0100 Subject: [PATCH 47/52] update examples --- .../additional_services/creditManagment.ts | 4 +-- example/additional_services/subscription.ts | 27 +++++++++---------- example/buckarooClient.ts | 22 ++++++++------- example/response/push.ts | 10 +++---- example/transaction/creditCard.ts | 20 ++++---------- example/transaction/ideal.ts | 8 +++--- 6 files changed, 40 insertions(+), 51 deletions(-) diff --git a/example/additional_services/creditManagment.ts b/example/additional_services/creditManagment.ts index c6237873..77cb68f0 100644 --- a/example/additional_services/creditManagment.ts +++ b/example/additional_services/creditManagment.ts @@ -49,8 +49,8 @@ const invoice = creditManagement.createCombinedInvoice({ }, }); -const sepadirectdebit = buckaroo.method('sepadirectdebit'); -sepadirectdebit +buckaroo + .method('sepadirectdebit') .combine(invoice.data) .pay({ invoice: '', diff --git a/example/additional_services/subscription.ts b/example/additional_services/subscription.ts index cd7e10ca..6b253898 100644 --- a/example/additional_services/subscription.ts +++ b/example/additional_services/subscription.ts @@ -1,8 +1,7 @@ -require('../buckarooClient'); -import Subscriptions from '../../src/PaymentMethods/Subscriptions'; -import Ideal from '../../src/PaymentMethods/Ideal'; +import buckaroo from '../buckarooClient'; + +const subscription = buckaroo.method('CreditManagement3'); -const subscription = new Subscriptions(); subscription.createCombined({ address: undefined, allowedServices: '', @@ -26,14 +25,12 @@ subscription.createCombined({ transactionVatPercentage: 0, }); -(async () => { - const combinedPayment = await new Ideal() - .combine(subscription) - .pay({ - amountDebit: 1, - currency: 'EUR', - description: 'test', - }) - .request(); - console.log(combinedPayment); -})(); +buckaroo + .method('ideal') + .combine(subscription) + .pay({ + amountDebit: 1, + currency: 'EUR', + description: 'test', + }) + .request(); diff --git a/example/buckarooClient.ts b/example/buckarooClient.ts index b8e9e243..5f276ac5 100644 --- a/example/buckarooClient.ts +++ b/example/buckarooClient.ts @@ -1,14 +1,16 @@ import Buckaroo from '@buckaroo/buckaroo_sdk'; -const buckaroo = Buckaroo.InitializeClient({ - secretKey: 'secret', - websiteKey: 'website', -}); +const buckaroo = Buckaroo.InitializeClient( + { + secretKey: process.env.BPE_SECRET_KEY || '', + websiteKey: process.env.BPE_WEBSITE_KEY || '', + }, + { + mode: 'TEST', + currency: 'EUR', + returnURL: 'https://example.com/return', + pushURL: 'https://example.com/push', + } +); -buckaroo.config = { - mode: 'TEST', - currency: 'EUR', - returnURL: 'https://example.com/return', - pushURL: 'https://example.com/push', -}; export default buckaroo; diff --git a/example/response/push.ts b/example/response/push.ts index 14a50969..17c9b2f5 100644 --- a/example/response/push.ts +++ b/example/response/push.ts @@ -1,5 +1,5 @@ -import buckaroo from "../buckarooClient"; -import { ReplyHandler } from "../../src/Handlers/Reply/ReplyHandler"; +import buckaroo from '../buckarooClient'; +import { ReplyHandler } from '../../src/Handlers/Reply/ReplyHandler'; //START HTTP POST PUSH let post_data = `{ @@ -32,10 +32,10 @@ reply_handler.isValid(); // Return either true or false //END HTTP POST PUSH //START JSON PUSH -const auth_header = "IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572"; +const auth_header = 'IBjihN7Fhp:0YvyjYAzDQ28W+hQi80f2nhe0Z1QFJLbz7IH//6LsAU=:cad1832100784f57a6e6de835d9f3638:1658227572'; post_data = - "{\"transaction\":{\"Key\":\"5340604668D74435AA344E1428ED1292\",\"Invoice\":\"62d68b6c8ab0c\",\"ServiceCode\":\"ideal\",\"Status\":{\"Code\":{\"Code\":190,\"Description\":\"Success\"},\"SubCode\":{\"Code\":\"S001\",\"Description\":\"transaction successfully processed\"},\"DateTime\":\"2022-07-19T12:46:12\"},\"IsTest\":true,\"Order\":\"ORDER_NO_62d68b6ca2df3\",\"Currency\":\"EUR\",\"AmountDebit\":10.1,\"TransactionType\":\"C021\",\"Services\":[{\"Name\":\"ideal\",\"Action\":null,\"Parameters\":[{\"Name\":\"consumerIssuer\",\"Value\":\"ABN AMRO\"},{\"Name\":\"transactionId\",\"Value\":\"0000000000000001\"},{\"Name\":\"consumerName\",\"Value\":\"J. de Tèster\"},{\"Name\":\"consumerIBAN\",\"Value\":\"NL44RABO0123456789\"},{\"Name\":\"consumerBIC\",\"Value\":\"RABONL2U\"}],\"VersionAsProperty\":2}],\"CustomParameters\":null,\"AdditionalParameters\":{\"List\":[{\"Name\":\"initiated_by_magento\",\"Value\":\"1\"},{\"Name\":\"service_action\",\"Value\":\"something\"}]},\"MutationType\":1,\"RelatedTransactions\":null,\"IsCancelable\":false,\"IssuingCountry\":null,\"StartRecurrent\":false,\"Recurring\":false,\"CustomerName\":\"J. de Tèster\",\"PayerHash\":\"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da\",\"PaymentKey\":\"AEC974D455FF4A4B9B4C21E437A04838\",\"Description\":null}}"; -const uri = "https://buckaroo.dev/push"; + '{"transaction":{"Key":"5340604668D74435AA344E1428ED1292","Invoice":"62d68b6c8ab0c","ServiceCode":"ideal","Status":{"Code":{"Code":190,"Description":"Success"},"SubCode":{"Code":"S001","Description":"transaction successfully processed"},"DateTime":"2022-07-19T12:46:12"},"IsTest":true,"Order":"ORDER_NO_62d68b6ca2df3","Currency":"EUR","AmountDebit":10.1,"TransactionType":"C021","Services":[{"Name":"ideal","Action":null,"Parameters":[{"Name":"consumerIssuer","Value":"ABN AMRO"},{"Name":"transactionId","Value":"0000000000000001"},{"Name":"consumerName","Value":"J. de Tèster"},{"Name":"consumerIBAN","Value":"NL44RABO0123456789"},{"Name":"consumerBIC","Value":"RABONL2U"}],"VersionAsProperty":2}],"CustomParameters":null,"AdditionalParameters":{"List":[{"Name":"initiated_by_magento","Value":"1"},{"Name":"service_action","Value":"something"}]},"MutationType":1,"RelatedTransactions":null,"IsCancelable":false,"IssuingCountry":null,"StartRecurrent":false,"Recurring":false,"CustomerName":"J. de Tèster","PayerHash":"2d26d34584a4eafeeaa97eed10cfdae22ae64cdce1649a80a55fafca8850e3e22cb32eb7c8fc95ef0c6f96669a21651d4734cc568816f9bd59c2092911e6c0da","PaymentKey":"AEC974D455FF4A4B9B4C21E437A04838","Description":null}}'; +const uri = 'https://buckaroo.dev/push'; reply_handler = new ReplyHandler(buckaroo.credentials, post_data, auth_header, uri); reply_handler.validate(); diff --git a/example/transaction/creditCard.ts b/example/transaction/creditCard.ts index a3cb0a17..505902fd 100644 --- a/example/transaction/creditCard.ts +++ b/example/transaction/creditCard.ts @@ -1,16 +1,6 @@ -require('../buckarooClient'); -import CreditCard from '../../src/PaymentMethods/CreditCard'; +import buckaroo from '../buckarooClient'; -const paymentMethod = new CreditCard('nexi'); - -(async () => { - try { - const info = await paymentMethod.pay({ - invoice: 'test1', - amountDebit: 12, - }); - console.log(info); - } catch (error) { - console.warn(error); - } -})(); +buckaroo.method('nexi').pay({ + invoice: 'test1', + amountDebit: 12, +}); diff --git a/example/transaction/ideal.ts b/example/transaction/ideal.ts index 71212fdc..b61ac5c9 100644 --- a/example/transaction/ideal.ts +++ b/example/transaction/ideal.ts @@ -6,16 +6,16 @@ const ideal = buckarooClient.method('ideal'); ideal .pay({ amountDebit: 10.1, - issuer: "ABNANL2A", - description: "Ideal Payment", + issuer: 'ABNANL2A', + description: 'Ideal Payment', }) .request(); //Refund ideal .refund({ - originalTransactionKey: "", + originalTransactionKey: '', amountCredit: 10.1, - invoice: "", + invoice: '', }) .request(); From d6ae5cafc897536363d0054aa69a044432a7cc26 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 15 Nov 2023 09:21:16 +0100 Subject: [PATCH 48/52] fix nullable on transaction request interface --- src/Models/Response/TransactionResponse.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index a33c7a44..8dca5fab 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -151,7 +151,7 @@ export declare interface ITransactionResponse { name: string; typeDeprecated: number; }; - services: { + services?: { action: string; name: string; value: string; @@ -164,33 +164,33 @@ export declare interface ITransactionResponse { additionalParameters?: { additionalParameter: IFormattedParameter[]; }; - requestErrors: { - channelErrors: { + requestErrors?: { + channelErrors?: { service: string; action: string; name: string; error: string; errorMessage: string; }[]; - serviceErrors: { + serviceErrors?: { name: string; error: string; errorMessage: string; }[]; - actionErrors: { + actionErrors?: { service: string; name: string; error: string; errorMessage: string; }[]; - parameterErrors: { + parameterErrors?: { service: string; action: string; name: string; error: string; errorMessage: string; }[]; - customParameterErrors: { + customParameterErrors?: { name: string; error: string; errorMessage: string; @@ -204,11 +204,11 @@ export declare interface ITransactionResponse { amountCredit: number; transactionType: string; mutationType: number; - relatedTransactions: { + relatedTransactions?: { relationType: string; relatedTransactionKey: string; }[]; - consumerMessage: { + consumerMessage?: { mustRead: boolean; cultureName: string; title: string; From 43bb0cf7068fe41558c9c6028ea3144ccd898a1f Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 15 Nov 2023 09:39:46 +0100 Subject: [PATCH 49/52] quick fix --- src/Models/Response/TransactionResponse.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Models/Response/TransactionResponse.ts b/src/Models/Response/TransactionResponse.ts index 8dca5fab..090f867f 100644 --- a/src/Models/Response/TransactionResponse.ts +++ b/src/Models/Response/TransactionResponse.ts @@ -105,11 +105,11 @@ export class TransactionResponse extends HttpClientResponse { return ( this.data.requestErrors && Object.keys(this.data.requestErrors).length > 0 && - (this.data.requestErrors.channelErrors.length > 0 || - this.data.requestErrors.serviceErrors.length > 0 || - this.data.requestErrors.actionErrors.length > 0 || - this.data.requestErrors.parameterErrors.length > 0 || - this.data.requestErrors.customParameterErrors.length > 0) + ((this.data.requestErrors.channelErrors?.length ?? 0) > 0 || + (this.data.requestErrors.serviceErrors?.length ?? 0) > 0 || + (this.data.requestErrors.actionErrors?.length ?? 0) > 0 || + (this.data.requestErrors.parameterErrors?.length ?? 0) > 0 || + (this.data.requestErrors.customParameterErrors?.length ?? 0) > 0) ); } From 409411e2089ce2a73c6bcd7ec0c2d942783258c9 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 15 Nov 2023 10:53:13 +0100 Subject: [PATCH 50/52] add agent on axios request --- src/Request/HttpsClient.ts | 8 +++++++- src/buckaroo.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 947b4970..0a3ad18b 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -2,15 +2,21 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; import { HttpResponseConstructor } from '../Models'; import { RequestConfig } from './Headers'; import { HttpMethods } from '../Constants'; +import { Agent } from 'https'; export default class HttpsClient { protected _options: AxiosRequestConfig = {}; private _axiosInstance: AxiosInstance; - constructor() { + constructor(agent?: Agent) { this._options.timeout = 10000; this._options.maxRedirects = 10; this._options.withCredentials = true; + + if (agent) { + this._options.httpsAgent = agent; + } + this._axiosInstance = axios.create(this._options); } diff --git a/src/buckaroo.ts b/src/buckaroo.ts index 03eb4b0f..fd92bc90 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -14,7 +14,7 @@ export default class Buckaroo { constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; - this._httpClient = new HttpsClient(); + this._httpClient = new HttpsClient(agent); } static get Client(): Buckaroo { From 45ead7972c84c6f113070709f04b4c50cdd10e42 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Fri, 17 Nov 2023 13:58:02 +0100 Subject: [PATCH 51/52] update rollup packages & fix build issue --- package.json | 7 ++++--- rollup.config.js | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 39600995..b98c9888 100644 --- a/package.json +++ b/package.json @@ -31,15 +31,16 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/preset-env": "^7.23.2", "@babel/preset-typescript": "^7.23.2", + "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-json": "^6.0.1", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-typescript": "^11.1.5", "@types/crypto-js": "^4.1.1", "@types/jest": "^29.4.0", "@types/node": "^18.11.18", "dotenv": "^16.0.3", "jest": "^29.4.2", "prettier": "^2.8.3", - "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-json": "^4.0.0", - "rollup-plugin-node-resolve": "^5.2.0", "ts-jest": "^29.0.5", "typescript": "^4.9.4" }, diff --git a/rollup.config.js b/rollup.config.js index bd98e43e..dfa12a13 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,8 @@ const { join } = require('path'); -const json = require('rollup-plugin-json'); -const resolve = require('rollup-plugin-node-resolve'); -const babel = require('rollup-plugin-babel'); +const json = require('@rollup/plugin-json'); +const resolve = require('@rollup/plugin-node-resolve'); +const babel = require('@rollup/plugin-babel'); +const typescript = require('@rollup/plugin-typescript'); module.exports = { input: join('src', 'index.ts'), @@ -20,12 +21,11 @@ module.exports = { { file: join('dist', 'buckaroo.esm.js'), format: 'es' }, ], plugins: [ + typescript(), json(), resolve({ extensions: ['.ts'], - customResolveOptions: { - moduleDirectory: 'src', - }, + moduleDirectories: ['src'], preferBuiltins: true, }), babel({ From edc296b2cb8073b8944aebe6ac071a43ee4e17f5 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Mon, 20 Nov 2023 10:12:24 +0100 Subject: [PATCH 52/52] Update README.md --- README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 130327d5..31bb1ada 100644 --- a/README.md +++ b/README.md @@ -48,32 +48,41 @@ npm install @buckaroo/buckaroo_sdk Initiate the buckaroo client with your website key and secret key. The keys can be retrieved from your [Buckaroo account](https://plaza.buckaroo.nl/Login). ```javascript -import { initializeBuckarooClient } from './BuckarooClient'; -initializeBuckarooClient({ websiteKey: 'KEY', secretKey: 'SECRET' }); +import Buckaroo from '@buckaroo/buckaroo_sdk'; + +const buckarooClient = Buckaroo.InitializeClient( + { + secretKey: 'KEY', + websiteKey: 'SECRET', + }, + { + mode: 'TEST', // OR 'LIVE' + currency: 'EUR', + returnURL: 'RETURN_URL', + pushURL: 'PUSH_URL', + } +) ``` Create a payment with all the available payment methods. In this example, we show how to create a credit card payment. Each payment has a slightly different payload. ```javascript -import creditCard from './PaymentMethods/CreditCard'; - -const payment = await creditCard().pay({ - amountDebit: 10, - name: 'Mastercard', - invoice: 'UNIQUE-INVOICE-NO', -}); +const payment = await buckarooClient + .method('mastercard') + .pay({ + amountDebit: 100, + }) + .request(); ``` After you create a transaction, you can retrieve several transaction information on demand. ```javascript -const transactionKey = payment.Key; - -import { buckarooClient } from './BuckarooClient'; +const transaction = buckarooClient.transaction(payment.getTransactionKey()); -buckarooClient().status(transactionKey); // Retrieve transaction status -buckarooClient().refundInfo(transactionKey); // Retrieve refund info -buckarooClient().cancelInfo(transactionKey); // Retrieve cancellation info +await transaction.status(); // Retrieve transaction status +await transaction.refundInfo(); // Retrieve refund info +await transaction.cancelInfo(); // Retrieve cancellation info ``` Find our full documentation online on [docs.buckaroo.io](https://docs.buckaroo.io/docs/node-sdk).