diff --git a/src/data/orders/OrderHelper.ts b/src/data/orders/OrderHelper.ts index 327e1847..11f401ec 100644 --- a/src/data/orders/OrderHelper.ts +++ b/src/data/orders/OrderHelper.ts @@ -98,6 +98,16 @@ export default class OrderHelper extends Helper { return this.links.checkout.href; } + /** + * Returns the direct link to the order in the Mollie Dashboard. + * + * @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/dashboard#response + * @since 4.0.0 + */ + public getDashboardUrl(): string { + return this.links.dashboard.href; + } + /** * Returns all payments created for the order. * diff --git a/src/data/orders/data.ts b/src/data/orders/data.ts index 43bd16d7..21101a7c 100644 --- a/src/data/orders/data.ts +++ b/src/data/orders/data.ts @@ -202,6 +202,12 @@ export interface OrderLinks extends Links { * @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/checkout#response */ checkout?: Url; + /** + * Direct link to the order in the Mollie Dashboard. + * + * @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=_links/dashboard#response + */ + dashboard: Url; } export enum OrderStatus { diff --git a/src/data/payments/PaymentHelper.ts b/src/data/payments/PaymentHelper.ts index 3465105a..0e796a8c 100644 --- a/src/data/payments/PaymentHelper.ts +++ b/src/data/payments/PaymentHelper.ts @@ -12,7 +12,6 @@ import { type ThrottlingParameter } from '../../types/parameters'; import Helper from '../Helper'; import type Chargeback from '../chargebacks/Chargeback'; import { type ChargebackData } from '../chargebacks/Chargeback'; -import { SequenceType, type Amount } from '../global'; import type Order from '../orders/Order'; import { type OrderData } from '../orders/data'; import type Refund from '../refunds/Refund'; @@ -20,7 +19,7 @@ import { type RefundData } from '../refunds/data'; import type Payment from './Payment'; import type Capture from './captures/Capture'; import { type CaptureData } from './captures/data'; -import { PaymentStatus, type BankTransferLinks, type PaymentData } from './data'; +import { type BankTransferLinks, type PaymentData } from './data'; export default class PaymentHelper extends Helper { constructor(networkClient: TransformingNetworkClient, protected readonly links: PaymentData['_links'], protected readonly embedded: Payment['_embedded']) { @@ -59,6 +58,16 @@ export default class PaymentHelper extends Helper { return this.links.checkout?.href ?? null; } + /** + * Returns the direct link to the payment in the Mollie Dashboard. + * + * @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/dashboard#response + * @since 4.0.0 + */ + public getDashboardUrl(): string { + return this.links.dashboard.href; + } + public canBeRefunded(this: PaymentData): boolean { return this.amountRemaining != undefined; } diff --git a/src/data/payments/data.ts b/src/data/payments/data.ts index 4483ff67..55615fe8 100644 --- a/src/data/payments/data.ts +++ b/src/data/payments/data.ts @@ -338,6 +338,12 @@ interface PaymentLinks extends Links { * @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/order#response */ order?: Url; + /** + * Direct link to the payment in the Mollie Dashboard. + * + * @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=_links/dashboard#response + */ + dashboard: Url; } export interface BancontactDetails { diff --git a/tests/unit/resources/orders.test.ts b/tests/unit/resources/orders.test.ts index aee6ddf2..3bf97c13 100644 --- a/tests/unit/resources/orders.test.ts +++ b/tests/unit/resources/orders.test.ts @@ -121,6 +121,10 @@ function composeOrderResponse(orderId, orderStatus = 'created', orderNumber = '1 href: 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', type: 'text/html', }, + dashboard: { + href: `https://www.mollie.com/dashboard/org_123456789/orders/${orderId}`, + type: 'text/html', + }, documentation: { href: 'https://docs.mollie.com/reference/v2/orders-api/get-order', type: 'text/html', @@ -198,6 +202,8 @@ function testOrder(order, orderId, orderStatus = 'created', orderNumber = '1337' href: 'https://docs.mollie.com/reference/v2/orders-api/get-order', type: 'text/html', }); + expect(order.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/select-method/7UhSN1zuXS'); + expect(order.getDashboardUrl()).toBe(`https://www.mollie.com/dashboard/org_123456789/orders/${orderId}`); expect(order.lines[0]).toEqual({ resource: 'orderline', @@ -545,6 +551,10 @@ test('getOrderIncludingPayments', () => { href: 'https://www.mollie.com/payscreen/order/checkout/pbjz8x', type: 'text/html', }, + dashboard: { + href: 'https://www.mollie.com/dashboard/org_123456789/orders/ord_pbjz8x', + type: 'text/html', + }, documentation: { href: 'https://docs.mollie.com/reference/v2/orders-api/get-order', type: 'text/html', @@ -585,6 +595,8 @@ test('getOrderIncludingPayments', () => { href: 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa', type: 'application/hal+json', }); + expect(order.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/order/checkout/pbjz8x'); + expect(order.getDashboardUrl()).toBe('https://www.mollie.com/dashboard/org_123456789/orders/ord_pbjz8x'); }); }); diff --git a/tests/unit/resources/payments.test.ts b/tests/unit/resources/payments.test.ts index d1de63d4..52658711 100644 --- a/tests/unit/resources/payments.test.ts +++ b/tests/unit/resources/payments.test.ts @@ -34,6 +34,10 @@ test('createPayment', () => { href: 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', type: 'text/html', }, + dashboard: { + href: 'https://www.mollie.com/dashboard/org_12345678/payments/tr_44aKxzEbr8', + type: 'text/html', + }, documentation: { href: 'https://docs.mollie.com/reference/v2/payments-api/create-payment', type: 'text/html', @@ -79,6 +83,10 @@ test('createPayment', () => { expect(payment._links.checkout).toEqual({ href: 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', type: 'text/html' }); expect(payment._links.documentation).toEqual({ href: 'https://docs.mollie.com/reference/v2/payments-api/create-payment', type: 'text/html' }); + + expect(payment.getCheckoutUrl()).toBe('https://www.mollie.com/payscreen/select-method/44aKxzEbr8'); + + expect(payment.getDashboardUrl()).toBe('https://www.mollie.com/dashboard/org_12345678/payments/tr_44aKxzEbr8'); }); });