diff --git a/src/data/customers/mandates/MandateHelper.ts b/src/data/customers/mandates/MandateHelper.ts index 5387b6a7..2dd1b463 100644 --- a/src/data/customers/mandates/MandateHelper.ts +++ b/src/data/customers/mandates/MandateHelper.ts @@ -12,15 +12,6 @@ export default class MandateHelper extends Helper { super(networkClient, links); } - /** - * Returns whether the mandate is valid. - * - * @deprecated Use `mandate.status == MandateStatus.valid` instead. - */ - public isValid(this: MandateData): boolean { - return this.status === MandateStatus.valid; - } - /** * Returns the payments belonging to the customer. * diff --git a/src/data/onboarding/OnboardingHelper.ts b/src/data/onboarding/OnboardingHelper.ts index 6f60ffd0..d0772cc4 100644 --- a/src/data/onboarding/OnboardingHelper.ts +++ b/src/data/onboarding/OnboardingHelper.ts @@ -12,27 +12,6 @@ export default class OnboardingHelper extends Helper super(networkClient, links); } - /** - * @deprecated Use `onboarding.status == OnboardingStatus.needsData` instead. - */ - public needsData(this: OnboardingData) { - return this.status == OnboardingStatus.needsData; - } - - /** - * @deprecated Use `onboarding.status == OnboardingStatus.inReview` instead. - */ - public isInReview(this: OnboardingData) { - return this.status == OnboardingStatus.inReview; - } - - /** - * @deprecated Use `onboarding.status == OnboardingStatus.completed` instead. - */ - public isCompleted(this: OnboardingData) { - return this.status == OnboardingStatus.completed; - } - /** * Returns the organization. * diff --git a/src/data/payments/PaymentHelper.ts b/src/data/payments/PaymentHelper.ts index 348ff121..3465105a 100644 --- a/src/data/payments/PaymentHelper.ts +++ b/src/data/payments/PaymentHelper.ts @@ -27,51 +27,6 @@ export default class PaymentHelper extends Helper { super(networkClient, links); } - /** - * Returns whether the payment has been created, but nothing else has happened with it yet. - * - * @deprecated Use `payment.status == PaymentStatus.open` instead. - */ - public isOpen(this: PaymentData): boolean { - return this.status === PaymentStatus.open; - } - - /** - * Returns whether new captures can be created for this payment. - * - * @deprecated Use `payment.status == PaymentStatus.authorized` instead. - */ - public isAuthorized(this: PaymentData): boolean { - return this.status === PaymentStatus.authorized; - } - - /** - * Returns whether the payment is successfully paid. - * - * @deprecated Use `payment.status == PaymentStatus.paid` instead. - */ - public isPaid(this: PaymentData): boolean { - return this.paidAt != undefined; - } - - /** - * Returns whether the payment has been canceled by the customer. - * - * @deprecated Use `payment.status == PaymentStatus.canceled` instead. - */ - public isCanceled(this: PaymentData): boolean { - return this.status == PaymentStatus.canceled; - } - - /** - * Returns whether the payment has expired, e.g. the customer has abandoned the payment. - * - * @deprecated Use `payment.status == PaymentStatus.expired` instead. - */ - public isExpired(this: PaymentData): boolean { - return this.status == PaymentStatus.expired; - } - /** * Returns whether the payment is refundable. * @@ -81,34 +36,6 @@ export default class PaymentHelper extends Helper { return this.amountRemaining !== null; } - /** - * Returns the URL the customer should visit to make the payment. This is to where you should redirect the consumer. - * - * @deprecated Use `payment.getCheckoutUrl()` instead. - */ - public getPaymentUrl(): Nullable { - return this.getCheckoutUrl(); - } - - /** - * Returns whether the payment has failed and cannot be completed with a different payment method. - * - * @deprecated Use `payment.status == PaymentStatus.failed` instead. - */ - public isFailed(this: PaymentData): boolean { - return this.status == PaymentStatus.failed; - } - - /** - * Returns whether the payment is in this temporary status that can occur when the actual payment process has been - * started, but has not completed yet. - * - * @deprecated Use `payment.status == PaymentStatus.pending` instead. - */ - public isPending(this: PaymentData): boolean { - return this.status == PaymentStatus.pending; - } - /** * Returns whether there are refunds which belong to the payment. */ @@ -123,26 +50,6 @@ export default class PaymentHelper extends Helper { return this.links.chargebacks != undefined; } - /** - * Returns whether `sequenceType` is set to `'first'`. If a `'first'` payment has been completed successfully, the - * consumer's account may be charged automatically using recurring payments. - * - * @deprecated Use `payment.sequenceType == SequenceType.first` instead. - */ - public hasSequenceTypeFirst(this: PaymentData): boolean { - return this.sequenceType == SequenceType.first; - } - - /** - * Returns whether `sequenceType` is set to `'recurring'`. This type of payment is processed without involving the - * consumer. - * - * @deprecated Use `payment.sequenceType == SequenceType.recurring` instead. - */ - public hasSequenceTypeRecurring(this: PaymentData): boolean { - return this.sequenceType == SequenceType.recurring; - } - /** * The URL your customer should visit to make the payment. This is where you should redirect the consumer to. * @@ -160,41 +67,6 @@ export default class PaymentHelper extends Helper { return this.amountRemaining != undefined; } - /** - * Returns the total amount that is already refunded. For some payment methods, this amount may be higher than the - * payment amount, for example to allow reimbursement of the costs for a return shipment to the customer. - * - * @deprecated Use `payment.amountRefunded` instead. To obtain the value, use `payment.amountRefunded?.value`. - */ - public getAmountRefunded(this: PaymentData): Amount { - if (this.amountRefunded == undefined) { - return { - // Perhaps this zero-value should depend on the currency. If the currency is JPY (¥), for instance, the value - // should probably be "0"; not "0.00". - value: '0.00', - currency: this.amount.currency, - }; - } - return this.amountRefunded; - } - - /** - * Returns the remaining amount that can be refunded. - * - * @deprecated Use `payment.amountRemaining` instead. To obtain the value, use `payment.amountRemaining?.value`. - */ - public getAmountRemaining(this: PaymentData): Amount { - if (this.amountRemaining == undefined) { - return { - // Perhaps this zero-value should depend on the currency. If the currency is JPY (¥), for instance, the value - // should probably be "0"; not "0.00". - value: '0.00', - currency: this.amount.currency, - }; - } - return this.amountRemaining; - } - /** * Recurring payments do not have a checkout URL, because these payments are executed without any user interaction. This link is included for test mode recurring payments, and allows you to set the * final payment state for such payments. diff --git a/src/data/profiles/ProfileHelper.ts b/src/data/profiles/ProfileHelper.ts index b771a306..9b2aed69 100644 --- a/src/data/profiles/ProfileHelper.ts +++ b/src/data/profiles/ProfileHelper.ts @@ -23,27 +23,6 @@ export default class ProfileHelper extends Helper { super(networkClient, links); } - /** - * @deprecated Use `profile.status == ProfileStatus.unverified` instead. - */ - public isUnverified(this: ProfileData) { - return this.status == ProfileStatus.unverified; - } - - /** - * @deprecated Use `profile.status == ProfileStatus.verified` instead. - */ - public isVerified(this: ProfileData) { - return this.status == ProfileStatus.verified; - } - - /** - * @deprecated Use `profile.status == ProfileStatus.blocked` instead. - */ - public isBlocked(this: ProfileData) { - return this.status == ProfileStatus.blocked; - } - /** * The Checkout preview URL. You need to be logged in to access this page. * diff --git a/src/data/refunds/RefundHelper.ts b/src/data/refunds/RefundHelper.ts index 633af715..f2b271e9 100644 --- a/src/data/refunds/RefundHelper.ts +++ b/src/data/refunds/RefundHelper.ts @@ -18,51 +18,6 @@ export default class RefundHelper extends Helper { super(networkClient, links); } - /** - * Returns whether the refund is queued due to a lack of balance. A queued refund can be canceled. - * - * @deprecated Use `refund.status == RefundStatus.queued` instead. - */ - public isQueued(this: RefundData): boolean { - return this.status === RefundStatus.queued; - } - - /** - * Returns whether the refund is ready to be sent to the bank. You can still cancel the refund if you like. - * - * @deprecated Use `refund.status == RefundStatus.pending` instead. - */ - public isPending(this: RefundData): boolean { - return this.status === RefundStatus.pending; - } - - /** - * Returns whether the refund is being processed. Cancellation is no longer possible if so. - * - * @deprecated Use `refund.status == RefundStatus.processing` instead. - */ - public isProcessing(this: RefundData): boolean { - return this.status === RefundStatus.processing; - } - - /** - * Returns whether the refund has been settled to your customer. - * - * @deprecated Use `refund.status == RefundStatus.refunded` instead. - */ - public isRefunded(this: RefundData): boolean { - return this.status === RefundStatus.refunded; - } - - /** - * Returns whether the refund has failed after processing. - * - * @deprecated Use `refund.status == RefundStatus.failed` instead. - */ - public isFailed(this: RefundData): boolean { - return this.status === RefundStatus.failed; - } - /** * Returns the payment this refund was created for. * diff --git a/src/data/subscriptions/SubscriptionHelper.ts b/src/data/subscriptions/SubscriptionHelper.ts index 9f1dcd98..29c36a1d 100644 --- a/src/data/subscriptions/SubscriptionHelper.ts +++ b/src/data/subscriptions/SubscriptionHelper.ts @@ -29,41 +29,6 @@ export default class SubscriptionHelper extends Helper { const order = await orderExists; const payment: Payment = order._embedded.payments[0]; - if (!payment.isPaid()) { + if (payment.status != PaymentStatus.paid) { console.log('If you want to test the full flow, set the embedded order payment to paid:', order.redirectUrl); return; } diff --git a/tests/integration/payments.test.ts b/tests/integration/payments.test.ts index 3de4516e..06c1c7c6 100644 --- a/tests/integration/payments.test.ts +++ b/tests/integration/payments.test.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import { fail } from 'node:assert'; -import createMollieClient from '../..'; +import createMollieClient, { PaymentStatus } from '../..'; /** * Load the API_KEY environment variable @@ -16,7 +16,7 @@ describe('payments', () => { let paymentExists; - if (!payments.length || payments[0].isExpired()) { + if (!payments.length || payments[0].status == PaymentStatus.expired) { paymentExists = mollieClient.payments .create({ amount: { value: '10.00', currency: 'EUR' }, @@ -35,8 +35,8 @@ describe('payments', () => { const payment = await paymentExists; - if (!payment.isPaid()) { - console.log('If you want to test the full flow, set the payment to paid:', payment.getPaymentUrl()); + if (payment.status != PaymentStatus.paid) { + console.log('If you want to test the full flow, set the payment to paid:', payment.getCheckoutUrl()); return; } diff --git a/tests/unit/models/onboarding.test.ts b/tests/unit/models/onboarding.test.ts index b6817711..2a6e8d4d 100644 --- a/tests/unit/models/onboarding.test.ts +++ b/tests/unit/models/onboarding.test.ts @@ -36,22 +36,10 @@ function getOnboarding(status) { test('onboardingStatuses', () => { return Promise.all( - [ - ['needs-data', 'needsData', true], - ['needs-data', 'isInReview', false], - ['needs-data', 'isCompleted', false], - - ['in-review', 'needsData', false], - ['in-review', 'isInReview', true], - ['in-review', 'isCompleted', false], - - ['completed', 'needsData', false], - ['completed', 'isInReview', false], - ['completed', 'isCompleted', true], - ].map(async ([status, method, expectedResult]) => { + ['needs-data', 'in-review', 'completed'].map(async status => { const onboarding = await getOnboarding(status); - expect(onboarding[method as keyof Onboarding]()).toBe(expectedResult); + expect(onboarding.status).toBe(status); }), ); }); diff --git a/tests/unit/models/payment.test.ts b/tests/unit/models/payment.test.ts index 386be241..e4571280 100644 --- a/tests/unit/models/payment.test.ts +++ b/tests/unit/models/payment.test.ts @@ -1,4 +1,4 @@ -import { Payment } from '../../..'; +import { PaymentStatus, SequenceType } from '../../..'; import NetworkMocker, { getApiKeyClientProvider } from '../../NetworkMocker'; function getPayment(status, additionalProperties?: object, additionalLinks?: object) { @@ -63,59 +63,18 @@ function getPayment(status, additionalProperties?: object, additionalLinks?: obj test('paymentStatuses', () => { return Promise.all( [ - ['pending', 'isPending', true], - ['pending', 'isAuthorized', false], - ['pending', 'isFailed', false], - ['pending', 'isOpen', false], - ['pending', 'isCanceled', false], - ['pending', 'isPaid', false], - ['pending', 'isExpired', false], - - ['authorized', 'isPending', false], - ['authorized', 'isAuthorized', true], - ['authorized', 'isFailed', false], - ['authorized', 'isOpen', false], - ['authorized', 'isCanceled', false], - ['authorized', 'isPaid', false], - ['authorized', 'isExpired', false], - - ['failed', 'isPending', false], - ['failed', 'isAuthorized', false], - ['failed', 'isFailed', true], - ['failed', 'isOpen', false], - ['failed', 'isCanceled', false], - ['failed', 'isPaid', false], - ['failed', 'isExpired', false], - - ['open', 'isPending', false], - ['open', 'isAuthorized', false], - ['open', 'isFailed', false], - ['open', 'isOpen', true], - ['open', 'isCanceled', false], - ['open', 'isPaid', false], - ['open', 'isExpired', false], - + 'pending', + 'authorized', + 'failed', + 'open', // (Note that canceled payments usually have their canceledAt set.) - ['canceled', 'isPending', false], - ['canceled', 'isAuthorized', false], - ['canceled', 'isFailed', false], - ['canceled', 'isOpen', false], - ['canceled', 'isCanceled', true], - ['canceled', 'isPaid', false], - ['canceled', 'isExpired', false], - + 'canceled', // (Note that expired payments usually have their expiredAt set.) - ['expired', 'isPending', false], - ['expired', 'isAuthorized', false], - ['expired', 'isFailed', false], - ['expired', 'isOpen', false], - ['expired', 'isCanceled', false], - ['expired', 'isPaid', false], - ['expired', 'isExpired', true], - ].map(async ([status, method, expectedResult]) => { + 'expired', + ].map(async status => { const payment = await getPayment(status); - expect(payment[method as keyof Payment]()).toBe(expectedResult); + expect(payment.status).toBe(status); }), ); }); @@ -123,7 +82,7 @@ test('paymentStatuses', () => { test('paymentIsPaid', async () => { const payment = await getPayment('paid', { paidAt: '2016-10-24' }); - expect(payment.isPaid()).toBe(true); + expect(payment.status).toBe(PaymentStatus.paid); }); test('paymentHasRefunds', async () => { @@ -149,18 +108,18 @@ test('paymentHasChargebacks', async () => { test('paymentHasSequenceType', async () => { let payment = await getPayment('paid', { sequenceType: 'first' }); - expect(payment.hasSequenceTypeRecurring()).toBe(false); - expect(payment.hasSequenceTypeFirst()).toBe(true); + expect(payment.sequenceType).not.toBe(SequenceType.recurring); + expect(payment.sequenceType).toBe(SequenceType.first); payment = await getPayment('paid', { sequenceType: 'recurring' }); - expect(payment.hasSequenceTypeRecurring()).toBe(true); - expect(payment.hasSequenceTypeFirst()).toBe(false); + expect(payment.sequenceType).toBe(SequenceType.recurring); + expect(payment.sequenceType).not.toBe(SequenceType.first); payment = await getPayment('paid' /*, { sequenceType: 'oneoff' } */); - expect(payment.hasSequenceTypeRecurring()).toBe(false); - expect(payment.hasSequenceTypeFirst()).toBe(false); + expect(payment.sequenceType).not.toBe(SequenceType.recurring); + expect(payment.sequenceType).not.toBe(SequenceType.first); }); test('paymentGetCheckoutUrl', async () => { @@ -184,19 +143,19 @@ test('paymentCanBeRefunded', async () => { test('paymentGetAmountRefunded', async () => { let payment = await getPayment('paid', { amountRemaining: undefined, amountRefunded: { value: '20.00', currency: 'EUR' } }); - expect(payment.getAmountRefunded()).toEqual({ value: '20.00', currency: 'EUR' }); + expect(payment.amountRefunded).toEqual({ value: '20.00', currency: 'EUR' }); payment = await getPayment('paid', { /* amountRemaining: { value: '20.00', currency: 'EUR' }, */ amountRefunded: undefined }); - expect(payment.getAmountRefunded()).toEqual({ value: '0.00', currency: 'EUR' }); + expect(payment.amountRefunded).toBeUndefined(); }); test('paymentGetAmountRemaining', async () => { let payment = await getPayment('paid' /*, { amountRemaining: { value: '20.00', currency: 'EUR' } } */); - expect(payment.getAmountRemaining()).toEqual({ value: '20.00', currency: 'EUR' }); + expect(payment.amountRemaining).toEqual({ value: '20.00', currency: 'EUR' }); payment = await getPayment('paid', { amountRemaining: undefined, amountRefunded: { value: '20.00', currency: 'EUR' } }); - expect(payment.getAmountRemaining()).toEqual({ value: '0.00', currency: 'EUR' }); + expect(payment.amountRemaining).toBeUndefined(); }); diff --git a/tests/unit/models/profile.test.ts b/tests/unit/models/profile.test.ts index 4d90c3ce..e2648f77 100644 --- a/tests/unit/models/profile.test.ts +++ b/tests/unit/models/profile.test.ts @@ -51,22 +51,10 @@ function getProfile(status) { test('profileStatuses', () => { return Promise.all( - [ - ['blocked', 'isBlocked', true], - ['blocked', 'isVerified', false], - ['blocked', 'isUnverified', false], - - ['verified', 'isBlocked', false], - ['verified', 'isVerified', true], - ['verified', 'isUnverified', false], - - ['unverified', 'isBlocked', false], - ['unverified', 'isVerified', false], - ['unverified', 'isUnverified', true], - ].map(async ([status, method, expectedResult]) => { + ['blocked', 'verified', 'unverified'].map(async status => { const profile = await getProfile(status); - expect(profile[method as keyof Profile]()).toBe(expectedResult); + expect(profile.status).toBe(status); }), ); }); diff --git a/tests/unit/models/refund.test.ts b/tests/unit/models/refund.test.ts index 63203951..15f39983 100644 --- a/tests/unit/models/refund.test.ts +++ b/tests/unit/models/refund.test.ts @@ -55,26 +55,10 @@ function getRefund(status) { test('refundStatuses', () => { return Promise.all( - [ - ['pending', 'isPending', true], - ['pending', 'isProcessing', false], - ['pending', 'isQueued', false], - - ['processing', 'isPending', false], - ['processing', 'isProcessing', true], - ['processing', 'isQueued', false], - - ['queued', 'isPending', false], - ['queued', 'isProcessing', false], - ['queued', 'isQueued', true], - - ['refunded', 'isPending', false], - ['refunded', 'isProcessing', false], - ['refunded', 'isQueued', false], - ].map(async ([status, method, expectedResult]) => { + ['pending', 'processing', 'queued', 'refunded'].map(async status => { const refund = await getRefund(status); - expect(refund[method as keyof Refund]()).toBe(expectedResult); + expect(refund.status).toBe(status); }), ); }); diff --git a/tests/unit/models/subscription.test.ts b/tests/unit/models/subscription.test.ts index 49a62b57..5fad55f7 100644 --- a/tests/unit/models/subscription.test.ts +++ b/tests/unit/models/subscription.test.ts @@ -41,41 +41,10 @@ function getSubscription(status) { test('subscriptionStatuses', () => { return Promise.all( - [ - ['pending', 'isPending', true], - ['pending', 'isCanceled', false], - ['pending', 'isCompleted', false], - ['pending', 'isSuspended', false], - ['pending', 'isActive', false], - - // (Note that canceled subscriptions usually have their canceledAt set.) - ['canceled', 'isPending', false], - ['canceled', 'isCanceled', true], - ['canceled', 'isCompleted', false], - ['canceled', 'isSuspended', false], - ['canceled', 'isActive', false], - - ['completed', 'isPending', false], - ['completed', 'isCanceled', false], - ['completed', 'isCompleted', true], - ['completed', 'isSuspended', false], - ['completed', 'isActive', false], - - ['suspended', 'isPending', false], - ['suspended', 'isCanceled', false], - ['suspended', 'isCompleted', false], - ['suspended', 'isSuspended', true], - ['suspended', 'isActive', false], - - ['active', 'isPending', false], - ['active', 'isCanceled', false], - ['active', 'isCompleted', false], - ['active', 'isSuspended', false], - ['active', 'isActive', true], - ].map(async ([status, method, expectedResult]) => { + ['pending', 'canceled', 'completed', 'suspended', 'active'].map(async status => { const subscription = await getSubscription(status); - expect(subscription[method as keyof Subscription]()).toBe(expectedResult); + expect(subscription.status).toBe(status); }), ); });