From 859b88968a14222a3819522d4b5a666278eb1be6 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Sat, 9 Nov 2024 20:13:16 +0100 Subject: [PATCH] - add ArticleProductUrl and ArticleImageUrl to KlarnaKP reserve payload - add missing invoice number on klarnakp test --- src/PaymentMethods/KlarnaKP/Models/Article.ts | 15 ++++++++++++++- src/PaymentMethods/KlarnaKP/Models/IReserve.ts | 8 ++++---- tests/PaymentMethods/KlarnaKp.test.ts | 7 ++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/PaymentMethods/KlarnaKP/Models/Article.ts b/src/PaymentMethods/KlarnaKP/Models/Article.ts index 45c21ac..5b84fb4 100644 --- a/src/PaymentMethods/KlarnaKP/Models/Article.ts +++ b/src/PaymentMethods/KlarnaKP/Models/Article.ts @@ -1,4 +1,9 @@ -import { Article as ArticleClass } from '../../../Models'; +import { Article as ArticleClass, IArticle } from '../../../Models'; + +export interface IKlarnaKpArticle extends IArticle { + imageUrl?: string; + productUrl?: string; +} export default class Article extends ArticleClass { get description(): string { @@ -25,6 +30,14 @@ export default class Article extends ArticleClass { this.set('number', identifier); } + set imageUrl(imageUrl: string) { + this.set('imageUrl', imageUrl); + } + + set productUrl(productUrl: string) { + this.set('productUrl', productUrl); + } + set(name: string, value: any, hidden: boolean = false): this { this.defineProperty(`article${name.charAt(0).toUpperCase() + name.slice(1)}`, value, hidden); return this; diff --git a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts index 63aadc6..f1a8726 100644 --- a/src/PaymentMethods/KlarnaKP/Models/IReserve.ts +++ b/src/PaymentMethods/KlarnaKP/Models/IReserve.ts @@ -1,13 +1,13 @@ import { Gender } from '../../../Constants'; -import { IArticle, ICustomer, IRequest, ServiceParameter } from '../../../Models'; +import { ICustomer, IRequest, ServiceParameter } from '../../../Models'; import { Customer } from './Customer'; -import Article from './Article'; +import Article, { IKlarnaKpArticle } from './Article'; export interface IReserve extends IRequest { gender?: Gender.MALE | Gender.FEMALE; billing?: ICustomer; shipping?: ICustomer; - articles?: Partial[]; + articles?: Partial[]; operatingCountry?: string; reservationNumber?: string; shippingSameAsBilling?: boolean; @@ -39,7 +39,7 @@ export class Reserve extends ServiceParameter implements IReserve { this.set('shipping', new Customer({ prefix: 'shipping', ...value })); } - set articles(value: IArticle[]) { + set articles(value: IKlarnaKpArticle[]) { this.set( 'articles', value.map((article) => new Article(article)) diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 3753cdb..07bdc11 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'; +import { Gender, uniqid } from '../../src'; const klarnaKp = buckarooClientTest.method('klarnakp'); @@ -18,6 +18,7 @@ describe('KlarnaKp', () => { test('Reserve', async () => { return klarnaKp .reserve({ + invoice: uniqid(), gender: Gender.MALE, operatingCountry: 'NL', pno: '01011990', @@ -44,6 +45,8 @@ describe('KlarnaKp', () => { vatPercentage: 21, quantity: 2, price: 20.1, + imageUrl: 'https://example.com/image', + productUrl: 'https://example.com/product', }, { identifier: 'Articlenumber2', @@ -51,6 +54,8 @@ describe('KlarnaKp', () => { vatPercentage: 21, quantity: 1, price: 10.1, + imageUrl: 'https://example.com/image', + productUrl: 'https://example.com/product', }, ], })