Skip to content

Commit

Permalink
Merge pull request #75 from buckaroo-it/BA-590-klarna-add-articleProd…
Browse files Browse the repository at this point in the history
…uctUrl-articleImageUrl

BA-590: add ArticleProductUrl and ArticleImageUrl Parameters to KlarnaKP
  • Loading branch information
vildanbina authored Nov 11, 2024
2 parents 26d82e5 + 859b889 commit f803fae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/PaymentMethods/KlarnaKP/Models/Article.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/PaymentMethods/KlarnaKP/Models/IReserve.ts
Original file line number Diff line number Diff line change
@@ -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<IArticle>[];
articles?: Partial<IKlarnaKpArticle>[];
operatingCountry?: string;
reservationNumber?: string;
shippingSameAsBilling?: boolean;
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion tests/PaymentMethods/KlarnaKp.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buckarooClientTest from '../BuckarooClient.test';
import { Gender } from '../../src';
import { Gender, uniqid } from '../../src';

const klarnaKp = buckarooClientTest.method('klarnakp');

Expand All @@ -18,6 +18,7 @@ describe('KlarnaKp', () => {
test('Reserve', async () => {
return klarnaKp
.reserve({
invoice: uniqid(),
gender: Gender.MALE,
operatingCountry: 'NL',
pno: '01011990',
Expand All @@ -44,13 +45,17 @@ describe('KlarnaKp', () => {
vatPercentage: 21,
quantity: 2,
price: 20.1,
imageUrl: 'https://example.com/image',
productUrl: 'https://example.com/product',
},
{
identifier: 'Articlenumber2',
description: 'Red Toy Car',
vatPercentage: 21,
quantity: 1,
price: 10.1,
imageUrl: 'https://example.com/image',
productUrl: 'https://example.com/product',
},
],
})
Expand Down

0 comments on commit f803fae

Please sign in to comment.