Skip to content

Commit f413229

Browse files
janpaepkePimm
authored andcommitted
add dashboard urls
1 parent f3ea3a2 commit f413229

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

src/data/orders/OrderHelper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ export default class OrderHelper extends Helper<OrderData, Order> {
9898
return this.links.checkout.href;
9999
}
100100

101+
/**
102+
* Returns the direct link to the order in the Mollie Dashboard.
103+
*
104+
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/dashboard#response
105+
* @since 4.0.0
106+
*/
107+
public getDashboardUrl(): string {
108+
return this.links.dashboard.href;
109+
}
110+
101111
/**
102112
* Returns all payments created for the order.
103113
*

src/data/orders/data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ export interface OrderLinks extends Links {
202202
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/checkout#response
203203
*/
204204
checkout?: Url;
205+
/**
206+
* Direct link to the order in the Mollie Dashboard.
207+
*
208+
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/dashboard#response
209+
*/
210+
dashboard: Url;
205211
}
206212

207213
export enum OrderStatus {

src/data/payments/PaymentHelper.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ import { type ThrottlingParameter } from '../../types/parameters';
1212
import Helper from '../Helper';
1313
import type Chargeback from '../chargebacks/Chargeback';
1414
import { type ChargebackData } from '../chargebacks/Chargeback';
15-
import { SequenceType, type Amount } from '../global';
1615
import type Order from '../orders/Order';
1716
import { type OrderData } from '../orders/data';
1817
import type Refund from '../refunds/Refund';
1918
import { type RefundData } from '../refunds/data';
2019
import type Payment from './Payment';
2120
import type Capture from './captures/Capture';
2221
import { type CaptureData } from './captures/data';
23-
import { PaymentStatus, type BankTransferLinks, type PaymentData } from './data';
22+
import { type BankTransferLinks, type PaymentData } from './data';
2423

2524
export default class PaymentHelper extends Helper<PaymentData, Payment> {
2625
constructor(networkClient: TransformingNetworkClient, protected readonly links: PaymentData['_links'], protected readonly embedded: Payment['_embedded']) {
@@ -59,6 +58,16 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
5958
return this.links.checkout?.href ?? null;
6059
}
6160

61+
/**
62+
* Returns the direct link to the payment in the Mollie Dashboard.
63+
*
64+
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/dashboard#response
65+
* @since 4.0.0
66+
*/
67+
public getDashboardUrl(): string {
68+
return this.links.dashboard.href;
69+
}
70+
6271
public canBeRefunded(this: PaymentData): boolean {
6372
return this.amountRemaining != undefined;
6473
}

src/data/payments/data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ interface PaymentLinks extends Links {
338338
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/order#response
339339
*/
340340
order?: Url;
341+
/**
342+
* Direct link to the payment in the Mollie Dashboard.
343+
*
344+
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/dashboard#response
345+
*/
346+
dashboard: Url;
341347
}
342348

343349
export interface BancontactDetails {

tests/unit/resources/orders.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ function composeOrderResponse(orderId, orderStatus = 'created', orderNumber = '1
121121
href: 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS',
122122
type: 'text/html',
123123
},
124+
dashboard: {
125+
href: `https://www.mollie.com/dashboard/org_123456789/orders/${orderId}`,
126+
type: 'text/html',
127+
},
124128
documentation: {
125129
href: 'https://docs.mollie.com/reference/v2/orders-api/get-order',
126130
type: 'text/html',
@@ -198,6 +202,8 @@ function testOrder(order, orderId, orderStatus = 'created', orderNumber = '1337'
198202
href: 'https://docs.mollie.com/reference/v2/orders-api/get-order',
199203
type: 'text/html',
200204
});
205+
expect(order.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/select-method/7UhSN1zuXS');
206+
expect(order.getDashboardUrl()).toBe(`https://www.mollie.com/dashboard/org_123456789/orders/${orderId}`);
201207

202208
expect(order.lines[0]).toEqual({
203209
resource: 'orderline',
@@ -545,6 +551,10 @@ test('getOrderIncludingPayments', () => {
545551
href: 'https://www.mollie.com/payscreen/order/checkout/pbjz8x',
546552
type: 'text/html',
547553
},
554+
dashboard: {
555+
href: 'https://www.mollie.com/dashboard/org_123456789/orders/ord_pbjz8x',
556+
type: 'text/html',
557+
},
548558
documentation: {
549559
href: 'https://docs.mollie.com/reference/v2/orders-api/get-order',
550560
type: 'text/html',
@@ -585,6 +595,8 @@ test('getOrderIncludingPayments', () => {
585595
href: 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa',
586596
type: 'application/hal+json',
587597
});
598+
expect(order.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/order/checkout/pbjz8x');
599+
expect(order.getDashboardUrl()).toBe('https://www.mollie.com/dashboard/org_123456789/orders/ord_pbjz8x');
588600
});
589601
});
590602

tests/unit/resources/payments.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ test('createPayment', () => {
3434
href: 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8',
3535
type: 'text/html',
3636
},
37+
dashboard: {
38+
href: 'https://www.mollie.com/dashboard/org_12345678/payments/tr_44aKxzEbr8',
39+
type: 'text/html',
40+
},
3741
documentation: {
3842
href: 'https://docs.mollie.com/reference/v2/payments-api/create-payment',
3943
type: 'text/html',
@@ -79,6 +83,10 @@ test('createPayment', () => {
7983
expect(payment._links.checkout).toEqual({ href: 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', type: 'text/html' });
8084

8185
expect(payment._links.documentation).toEqual({ href: 'https://docs.mollie.com/reference/v2/payments-api/create-payment', type: 'text/html' });
86+
87+
expect(payment.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/select-method/44aKxzEbr8');
88+
89+
expect(payment.getDashboardUrl()).toBe('https://www.mollie.com/dashboard/org_12345678/payments/tr_44aKxzEbr8');
8290
});
8391
});
8492

0 commit comments

Comments
 (0)