Skip to content

Commit

Permalink
add cancelUrl to order and payment
Browse files Browse the repository at this point in the history
  • Loading branch information
schalterDev committed Aug 30, 2023
1 parent 7dec190 commit ce5e5d0
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/binders/orders/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type CreateParameters as PaymentCreateParameters } from '../payments/pa
import type PickOptional from '../../types/PickOptional';

export type CreateParameters = Pick<OrderData, 'amount' | 'orderNumber' | 'consumerDateOfBirth' | 'webhookUrl' | 'locale' | 'metadata' | 'expiresAt'> &
PickOptional<OrderData, 'billingAddress' | 'shippingAddress' | 'redirectUrl'> & {
PickOptional<OrderData, 'billingAddress' | 'shippingAddress' | 'redirectUrl' | 'cancelUrl'> & {
/**
* All order lines must have the same currency as the order. You cannot mix currencies within a single order.
*
Expand Down
2 changes: 1 addition & 1 deletion src/binders/payments/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type PaymentData, type PaymentEmbed, type PaymentInclude } from '../../
import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters';
import type PickOptional from '../../types/PickOptional';

export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'redirectUrl' | 'webhookUrl' | 'customerId' | 'mandateId'> &
export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'redirectUrl' | 'cancelUrl' | 'webhookUrl' | 'customerId' | 'mandateId'> &
PickOptional<PaymentData, 'locale' | 'metadata' | 'sequenceType'> & {
/**
* Normally, a payment method screen is shown. However, when using this parameter, you can choose a specific payment method and your customer will skip the selection screen and is sent directly to
Expand Down
8 changes: 8 additions & 0 deletions src/data/orders/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export interface OrderData extends Model<'order'> {
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=redirectUrl#response
*/
redirectUrl: Nullable<string>;
/**
* The optional redirect URL you provided during payment creation. Consumer that explicitly cancel the order will be redirected to this URL if provided, or otherwise to the `redirectUrl` instead — see above.
*
* The URL will be `null` for recurring orders.
*
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=cancelUrl#response
*/
cancelUrl: Nullable<string>;
/**
* An array of order line objects. Each object will have the properties listed below.
*
Expand Down
8 changes: 8 additions & 0 deletions src/data/payments/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ export interface PaymentData extends Model<'payment'> {
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=redirectUrl#response
*/
redirectUrl?: string;
/**
* The optional redirect URL you provided during payment creation. Consumer that explicitly cancel the payment will be redirected to this URL if provided, or otherwise to the `redirectUrl` instead — see above.
*
* The URL will be `null` for recurring payments.
*
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment?path=cancelUrl#response
*/
cancelUrl?: string;
/**
* The URL Mollie will call as soon an important status change takes place.
*
Expand Down
1 change: 1 addition & 0 deletions tests/unit/models/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function getOrder(status, additionalLinks?: object) {
method: 'klarnapaylater',
isCancelable: true,
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
lines: [
{
Expand Down
1 change: 1 addition & 0 deletions tests/unit/models/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function getPayment(status, additionalProperties?: object, additionalLinks
profileId: 'pfl_2A1gacu42V',
sequenceType: 'oneoff',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
settlementAmount: {
value: '20.00',
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/resources/customers/payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('createCustomerPayment', async () => {
profileId: 'pfl_2A1gacu42V',
sequenceType: 'oneoff',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
_links: {
self: {
Expand Down Expand Up @@ -53,6 +54,7 @@ test('createCustomerPayment', async () => {
customerId: 'cst_FhQJRw4s2n',
description: 'My first API payment',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
metadata: {
order_id: '1234',
Expand All @@ -75,6 +77,7 @@ test('createCustomerPayment', async () => {
expect(payment.profileId).toBe('pfl_2A1gacu42V');
expect(payment.sequenceType).toBe('oneoff');
expect(payment.redirectUrl).toBe('https://example.org/redirect');
expect(payment.cancelUrl).toBe('https://example.org/cancel');
expect(payment.webhookUrl).toBe('https://example.org/webhook');

expect(payment._links.self).toEqual({ href: 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', type: 'application/hal+json' });
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/resources/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function composeOrderResponse(orderId, orderStatus = 'created', orderNumber = '1
method: 'klarnapaylater',
isCancelable: true,
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
lines: [
{
Expand Down Expand Up @@ -182,6 +183,7 @@ function testOrder(order, orderId, orderStatus = 'created', orderNumber = '1337'
expect(order.locale).toBe('nl_NL');

expect(order.redirectUrl).toBe('https://example.org/redirect');
expect(order.cancelUrl).toBe('https://example.org/cancel');
expect(order.webhookUrl).toBe('https://example.org/webhook');

expect(order._links.self).toEqual({
Expand Down Expand Up @@ -275,6 +277,7 @@ test('createOrder', async () => {
locale: 'nl_NL',
orderNumber: '1337',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
method: 'klarnapaylater',
lines: [
Expand Down Expand Up @@ -380,6 +383,7 @@ test('getOrderIncludingPayments', async () => {
email: 'luke@skywalker.com',
},
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
lines: [
{
resource: 'orderline',
Expand Down Expand Up @@ -515,6 +519,7 @@ test('getOrderIncludingPayments', async () => {
orderId: 'ord_kEn1PlbGa',
sequenceType: 'oneoff',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
_links: {
self: {
href: 'https://api.mollie.com/v2/payments/tr_ncaPcAhuUV',
Expand Down Expand Up @@ -568,6 +573,7 @@ test('getOrderIncludingPayments', async () => {
expect(payment.orderId).toBe('ord_kEn1PlbGa');
expect(payment.sequenceType).toBe('oneoff');
expect(payment.redirectUrl).toBe('https://example.org/redirect');
expect(payment.cancelUrl).toBe('https://example.org/cancel');
expect(payment._links.self).toEqual({
href: 'https://api.mollie.com/v2/payments/tr_ncaPcAhuUV',
type: 'application/hal+json',
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/resources/payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('createPayment', async () => {
profileId: 'pfl_2A1gacu42V',
sequenceType: 'oneoff',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
_links: {
self: {
Expand All @@ -48,6 +49,7 @@ test('createPayment', async () => {
},
description: 'My first API payment',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
metadata: {
order_id: '1234',
Expand All @@ -70,6 +72,7 @@ test('createPayment', async () => {
expect(payment.profileId).toBe('pfl_2A1gacu42V');
expect(payment.sequenceType).toBe('oneoff');
expect(payment.redirectUrl).toBe('https://example.org/redirect');
expect(payment.cancelUrl).toBe('https://example.org/cancel');
expect(payment.webhookUrl).toBe('https://example.org/webhook');

expect(payment._links.self).toEqual({ href: 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', type: 'application/hal+json' });
Expand Down Expand Up @@ -190,6 +193,7 @@ test('getPayment', async () => {
profileId: 'pfl_2A1gacu42V',
sequenceType: 'oneoff',
redirectUrl: 'https://example.org/redirect',
cancelUrl: 'https://example.org/cancel',
webhookUrl: 'https://example.org/webhook',
settlementAmount: {
value: '20.00',
Expand Down Expand Up @@ -226,6 +230,7 @@ test('getPayment', async () => {
expect(payment.profileId).toBe('pfl_2A1gacu42V');
expect(payment.sequenceType).toBe('oneoff');
expect(payment.redirectUrl).toBe('https://example.org/redirect');
expect(payment.cancelUrl).toBe('https://example.org/cancel');
expect(payment.webhookUrl).toBe('https://example.org/webhook');

expect(payment._links.self).toEqual({ href: 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', type: 'application/hal+json' });
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/resources/subscriptions/payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test('listSubscriptionPayments', async () => {
subscriptionId: 'sub_8JfGzs6v3K',
sequenceType: 'recurring',
redirectUrl: null,
cancelUrl: null,
webhookUrl: 'https://example.org/webhook',
settlementAmount: {
value: '10.00',
Expand Down Expand Up @@ -84,6 +85,7 @@ test('listSubscriptionPayments', async () => {
subscriptionId: 'sub_8JfGzs6v3K',
sequenceType: 'recurring',
redirectUrl: null,
cancelUrl: null,
webhookUrl: 'https://example.org/webhook',
settlementAmount: {
value: '10.00',
Expand Down

0 comments on commit ce5e5d0

Please sign in to comment.