Skip to content

Commit

Permalink
Merge pull request #364 from mollie/pimm/helper-cleanup
Browse files Browse the repository at this point in the history
Cleanup helpers.
  • Loading branch information
Pimm committed Sep 10, 2024
2 parents b3cfbff + 3a63056 commit e4466f3
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 405 deletions.
9 changes: 0 additions & 9 deletions src/data/customers/mandates/MandateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ export default class MandateHelper extends Helper<MandateData, Mandate> {
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.
*
Expand Down
21 changes: 0 additions & 21 deletions src/data/onboarding/OnboardingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@ export default class OnboardingHelper extends Helper<OnboardingData, Onboarding>
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.
*
Expand Down
128 changes: 0 additions & 128 deletions src/data/payments/PaymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,6 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
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.
*
Expand All @@ -81,34 +36,6 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
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<string> {
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.
*/
Expand All @@ -123,26 +50,6 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
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.
*
Expand All @@ -160,41 +67,6 @@ export default class PaymentHelper extends Helper<PaymentData, Payment> {
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.
Expand Down
21 changes: 0 additions & 21 deletions src/data/profiles/ProfileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ export default class ProfileHelper extends Helper<ProfileData, Profile> {
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.
*
Expand Down
45 changes: 0 additions & 45 deletions src/data/refunds/RefundHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,6 @@ export default class RefundHelper extends Helper<RefundData, Refund> {
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.
*
Expand Down
35 changes: 0 additions & 35 deletions src/data/subscriptions/SubscriptionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,6 @@ export default class SubscriptionHelper extends Helper<SubscriptionData, Subscri
return this.webhookUrl;
}

/**
* @deprecated Use `subscription.status == SubscriptionStatus.active` instead.
*/
public isActive(this: SubscriptionData): boolean {
return this.status === SubscriptionStatus.active;
}

/**
* @deprecated Use `subscription.status == SubscriptionStatus.pending` instead.
*/
public isPending(this: SubscriptionData): boolean {
return this.status === SubscriptionStatus.pending;
}

/**
* @deprecated Use `subscription.status == SubscriptionStatus.completed` instead.
*/
public isCompleted(this: SubscriptionData): boolean {
return this.status === SubscriptionStatus.completed;
}

/**
* @deprecated Use `subscription.status == SubscriptionStatus.suspended` instead.
*/
public isSuspended(this: SubscriptionData): boolean {
return this.status === SubscriptionStatus.suspended;
}

/**
* @deprecated Use `subscription.status == SubscriptionStatus.canceled` instead.
*/
public isCanceled(this: SubscriptionData): boolean {
return SubscriptionStatus.canceled == this.status;
}

/**
* Returns the customer the subscription is for.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/orders.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv';
import { fail } from 'node:assert';

import createMollieClient, { Locale, OrderEmbed, OrderLineType, Payment, PaymentMethod } from '../..';
import createMollieClient, { Locale, OrderEmbed, OrderLineType, Payment, PaymentMethod, PaymentStatus } from '../..';

/**
* Load the API_KEY environment variable
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('orders', () => {
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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/payments.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' },
Expand All @@ -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;
}

Expand Down
16 changes: 2 additions & 14 deletions tests/unit/models/onboarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
);
});
Loading

0 comments on commit e4466f3

Please sign in to comment.