Skip to content

Commit

Permalink
Merge pull request #373 from janpaepke/feature/add-dashboard-urls
Browse files Browse the repository at this point in the history
Payments, Orders: add dashboard urls
  • Loading branch information
Pimm authored Sep 16, 2024
2 parents f3ea3a2 + f413229 commit 2f62b15
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/data/orders/OrderHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ export default class OrderHelper extends Helper<OrderData, Order> {
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.
*
Expand Down
6 changes: 6 additions & 0 deletions src/data/orders/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions src/data/payments/PaymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ 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';
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<PaymentData, Payment> {
constructor(networkClient: TransformingNetworkClient, protected readonly links: PaymentData['_links'], protected readonly embedded: Payment['_embedded']) {
Expand Down Expand Up @@ -59,6 +58,16 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/data/payments/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/resources/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
});
});

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/resources/payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
});
});

Expand Down

0 comments on commit 2f62b15

Please sign in to comment.