Skip to content

Commit

Permalink
fix: redundant class interface
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Interfaces are not exported anymore.
It is necessary to use class as a type directly, e.g. `Klarna` instead of `IKlarnaInstance`
  • Loading branch information
HormCodes committed Jan 6, 2022
1 parent 9ec7bbb commit e0b76bb
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 56 deletions.
8 changes: 1 addition & 7 deletions src/api/checkout-v3/checkout-v3.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { HttpRequest } from '../../http-request';
import { IOrderBody, IOrderResponse } from './interface';

export interface ICheckoutV3 {
createOrder(body: IOrderBody): Promise<IOrderResponse>;
retrieveOrder(orderId: string): Promise<IOrderResponse>;
updateOrder(orderId: string, body: IOrderBody): Promise<IOrderResponse>;
}

/*
* Documentation: https://developers.klarna.com/api/#checkout-api
*/
export class CheckoutV3 extends HttpRequest {
/*
Documentation: https://developers.klarna.com/api/#checkout-api-create-a-new-order
Documentation: https://developers.klarna.com/api/#checkout-api-create-a-new-order
*/
createOrder(body: IOrderBody): Promise<IOrderResponse> {
return this.invoke(`POST`, `/checkout/v3/orders`, body);
Expand Down
4 changes: 0 additions & 4 deletions src/api/customer-token-v1/customer-token-v1.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { HttpRequest, IResponse } from '../../http-request';
import { ICustomerTokenBody } from './interface';

export interface ICustomerTokenV1 {
order(token: string, body: ICustomerTokenBody): Promise<IResponse>;
}

/**
* Docs: https://developers.klarna.com/documentation/klarna-payments/integration-guide/place-order/#4-3-place-recurring-order-tokenization
*/
Expand Down
4 changes: 0 additions & 4 deletions src/api/order-management-v1/captures/captures.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { HttpRequest, IResponse } from '../../../http-request';
import { IOrderLine } from '../../checkout-v3';

export interface ICaptures {
capture(orderId: string, body: ICaptureBody): Promise<IResponse>;
}

interface ICaptureBody {
captured_amount: number;
description?: string;
Expand Down
18 changes: 6 additions & 12 deletions src/api/order-management-v1/order-management-v1.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { Orders, IOrders } from './orders';
import { Captures, ICaptures } from './captures';
import { Refunds, IRefunds } from './refunds';
import { Orders } from './orders';
import { Captures } from './captures';
import { Refunds } from './refunds';
import { IOptions } from '../../http-request';

export interface IOrderManagementV1 {
orders: IOrders;
captures: ICaptures;
refunds: IRefunds;
}

/**
* Docs: https://developers.klarna.com/api/#order-management-api
*/
export class OrderManagementV1 {
orders: IOrders;
captures: ICaptures;
refunds: IRefunds;
orders: Orders;
captures: Captures;
refunds: Refunds;

constructor(options: IOptions) {
this.orders = new Orders(options);
Expand Down
7 changes: 0 additions & 7 deletions src/api/order-management-v1/orders/orders.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { HttpRequest, IResponse } from '../../../http-request';

export interface IOrders {
acknowledge(orderId: string): Promise<IResponse>;
cancel(orderId: string): Promise<IResponse>;
releaseRemainingAuthorization(orderId: string): Promise<IResponse>;
getOrder(orderId: string): Promise<IResponse>;
}

interface IUpdateMerchantReferenceBody {
merchant_reference1: string;
merchant_reference2: string;
Expand Down
4 changes: 0 additions & 4 deletions src/api/order-management-v1/refunds/refunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ interface IRefundBody {
order_lines: Array<IOrderLine>;
}

export interface IRefunds {
create(orderId: string, body: IRefundBody): Promise<IResponse>;
}

export class Refunds extends HttpRequest {
/**
* https://developers.klarna.com/api/#order-management-api-create-a-refund
Expand Down
23 changes: 7 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IOptions } from './http-request';
import { CheckoutV3, ICheckoutV3 } from './api/checkout-v3';
import { CustomerTokenV1, ICustomerTokenV1 } from './api/customer-token-v1';
import {
IOrderManagementV1,
OrderManagementV1,
} from './api/order-management-v1';
import { CheckoutV3 } from './api/checkout-v3';
import { CustomerTokenV1 } from './api/customer-token-v1';
import { OrderManagementV1 } from './api/order-management-v1';
export * from './crystallize-helpers';

interface IConfig {
Expand All @@ -13,16 +10,10 @@ interface IConfig {
apiEndpoint?: string;
}

export interface IKlarnaInstance {
checkoutV3: ICheckoutV3;
customerTokenV1: ICustomerTokenV1;
orderManagementV1: IOrderManagementV1;
}

export class Klarna implements IKlarnaInstance {
checkoutV3: ICheckoutV3;
customerTokenV1: ICustomerTokenV1;
orderManagementV1: IOrderManagementV1;
export class Klarna {
checkoutV3: CheckoutV3;
customerTokenV1: CustomerTokenV1;
orderManagementV1: OrderManagementV1;

constructor(config: IConfig) {
let { apiEndpoint } = config;
Expand Down
4 changes: 2 additions & 2 deletions test/checkout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as dotenv from 'dotenv';
import { Klarna, IKlarnaInstance } from '../src';
import { Klarna } from '../src';

dotenv.config();

const username = process.env.KLARNA_USERNAME;
const password = process.env.KLARNA_PASSWORD;

describe('checkout v3', () => {
let klarna: IKlarnaInstance;
let klarna: Klarna;
let orderId: string;

beforeAll(done => {
Expand Down

0 comments on commit e0b76bb

Please sign in to comment.