Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Interface Types #397

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/binders/customers/subscriptions/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ContextParameters {
}

export type CreateParameters = ContextParameters &
Pick<SubscriptionData, 'amount' | 'interval' | 'description' | 'mandateId'> &
Pick<SubscriptionData, 'amount' | 'interval' | 'description' | 'mandateId' | 'applicationFee' | 'profileId'> &
PickOptional<SubscriptionData, 'times' | 'startDate' | 'method' | 'webhookUrl' | 'metadata'> &
IdempotencyParameter;

Expand Down
4 changes: 2 additions & 2 deletions src/binders/onboarding/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Address } from '../../data/global';
import type { OrganizationAdress } from '../../data/organizations/Organizations';
import { type IdempotencyParameter } from '../../types/parameters';

export interface SubmitParameters extends IdempotencyParameter {
Expand All @@ -15,7 +15,7 @@ export interface SubmitParameters extends IdempotencyParameter {
/**
* Address of the organization.
*/
address?: Address;
address?: OrganizationAdress;
/**
* The Chamber of Commerce registration number of the company.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/binders/payments/PaymentsBinder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { runIf } from 'ruply';
import type TransformingNetworkClient from '../../communication/TransformingNetworkClient';
import type Page from '../../data/page/Page';
import { type PaymentData } from '../../data/payments/data';
Expand Down Expand Up @@ -32,7 +33,7 @@ export default class PaymentsBinder extends Binder<PaymentData, Payment> {
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { include, ...data } = parameters;
const query = include != undefined ? { include } : undefined;
const query = runIf(include, include => ({ include }));
return this.networkClient.post<PaymentData, Payment>(pathSegment, data, query);
}

Expand Down
5 changes: 3 additions & 2 deletions src/binders/payments/captures/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type CaptureData, type CaptureInclude } from '../../../data/payments/captures/data';
import type MaybeArray from '../../../types/MaybeArray';
import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../../types/parameters';
import type PickOptional from '../../../types/PickOptional';

Expand All @@ -9,13 +10,13 @@ interface ContextParameters {
export type CreateParameters = ContextParameters & PickOptional<CaptureData, 'amount' | 'description' | 'metadata'> & IdempotencyParameter;

export type GetParameters = ContextParameters & {
include?: CaptureInclude;
include?: MaybeArray<CaptureInclude>;
testmode?: boolean;
};

export type PageParameters = ContextParameters &
PaginationParameters & {
include?: CaptureInclude;
include?: MaybeArray<CaptureInclude>;
testmode?: boolean;
};

Expand Down
49 changes: 28 additions & 21 deletions src/binders/payments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { type Address, type Amount, type PaymentMethod } from '../../data/global';
import { type Issuer } from '../../data/Issuer';
import { type Amount, type PaymentMethod } from '../../data/global';
import { type PaymentData, type PaymentEmbed, type PaymentInclude } from '../../data/payments/data';
import type MaybeArray from '../../types/MaybeArray';
import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters';
import type PickOptional from '../../types/PickOptional';

export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'redirectUrl' | 'cancelUrl' | 'webhookUrl' | 'customerId' | 'mandateId'> &
export type CreateParameters = Pick<
PaymentData,
| 'amount'
| 'description'
| 'redirectUrl'
| 'cancelUrl'
| 'webhookUrl'
| 'customerId'
| 'mandateId'
| 'lines'
| 'shippingAddress'
| 'billingAddress'
| 'routing'
| 'issuer'
| 'restrictPaymentMethodsToCountry'
> &
PickOptional<PaymentData, 'locale' | 'metadata' | 'sequenceType' | 'captureMode' | 'captureDelay'> & {
/**
* 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 Expand Up @@ -45,6 +59,9 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=applePayPaymentToken#apple-pay
*/
applePayPaymentToken?: string;
/**
* @deprecated use billingAddress.email instead
*/
billingEmail?: string;
/**
* The date the payment should expire, in `YYYY-MM-DD` format. **Note:** the minimum date is tomorrow and the maximum date is 100 days after tomorrow.
Expand All @@ -54,27 +71,12 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=dueDate#bank-transfer
*/
dueDate?: string;
/**
* The card holder's address details. We advise to provide these details to improve the credit card fraud protection, and thus improve conversion.
*
* If an address is provided, then the address has to be in a valid format. See the address object documentation for more information on which formats are accepted.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=billingAddress#credit-card
*/
billingAddress?: Address;
/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not actually removed, but picked from data (see above)

* The card token you got from Mollie Components. The token contains the card information (such as card holder, card number, and expiry date) needed to complete the payment.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=cardToken#credit-card
*/
cardToken?: string;
shippingAddress?: Address & {
// Note that this field is required for PayPal payments; but is disregarded for credit card payments.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not actually removed, but picked from data (see above)

givenName?: string;
// Note that this field is required for PayPal payments; but is disregarded for credit card payments.
familyName?: string;
};
issuer?: Issuer;
/**
* The card number on the gift card. You can supply this to prefill the card number.
*
Expand Down Expand Up @@ -133,7 +135,13 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=consumerAccount#sepa-direct-debit
*/
consumerAccount?: string;
include?: MaybeArray<PaymentInclude>;
/**
* This endpoint allows you to include additional information via the `include` query string parameter.
* * `details.qrCode`: Include a QR code object. Only available for iDEAL, Bancontact and bank transfer payments.
*
* __Note:__ In the REST API, this is not part of the request body, but a query Parameter. It is included here for consistency.
*/
include?: MaybeArray<PaymentInclude.qrCode>; // currently only one valid value, but making 'MaybeArray' for consistency
profileId?: string;
testmode?: boolean;
/**
Expand Down Expand Up @@ -163,13 +171,12 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
} & IdempotencyParameter;

export interface GetParameters {
include?: PaymentInclude;
include?: MaybeArray<PaymentInclude>;
embed?: MaybeArray<PaymentEmbed>;
testmode?: boolean;
}

export type PageParameters = PaginationParameters & {
profileId?: string;
testmode?: boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fjbender This param was not in the DOCS, which is why I assumed it does not exist and removed it.
If that is correct, the removal won't break anything since any current use wouldn't have worked anyway.

Can you confirm this Query Param is not available for list payments?

Copy link

@hreinberger hreinberger Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tried out listing my payments with this param set, and got this response:

{
    "status": 422,
    "title": "Unprocessable Entity",
    "detail": "Non-existent query parameter \"profileId\" for this API call. Did you mean: \"previous\"?",
    "field": "profileId",
    "_links": {
        "documentation": {
            "href": "https://docs.mollie.com/overview/handling-errors",
            "type": "text/html"
        }
    }
}

So yes, if it was ever possible to filter by profile ID, it's not possible anymore.

};

Expand Down
2 changes: 1 addition & 1 deletion src/createMollieClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export { MandateMethod, MandateStatus } from './data/customers/mandates/data';
export { MethodImageSize, MethodInclude } from './data/methods/data';
export { OrderEmbed, OrderStatus } from './data/orders/data';
export { OrderLineType } from './data/orders/orderlines/OrderLine';
export { PaymentEmbed, PaymentInclude, PaymentStatus, CaptureMethod } from './data/payments/data';
export { PaymentEmbed, PaymentInclude, PaymentStatus, CaptureMethod, PaymentLineType, PaymentLineCategory, RoutingType } from './data/payments/data';
export { RefundEmbed, RefundStatus } from './data/refunds/data';
export { SubscriptionStatus } from './data/subscriptions/data';
export { ProfileStatus } from './data/profiles/data';
Expand Down
28 changes: 27 additions & 1 deletion src/data/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ export interface Amount {
}

export interface Address {
/**
* The title of the person, for example _Mr._ or _Mrs._.
*
* @see https://docs.mollie.com/overview/common-data-types?path=title#address-object
*/
title?: string;
/**
* The given name (first name) of the person should be more than 1 character and cannot contain only numbers.
*
* @see https://docs.mollie.com/overview/common-data-types?path=givenName#address-object
*/
givenName?: string;
/**
* The family name (surname) of the person should be more than 1 character and cannot contain only numbers.
*
* @see https://docs.mollie.com/overview/common-data-types?path=familyName#address-object
*/
familyName?: string;
/**
* The street and street number of the address.
*
Expand All @@ -102,7 +120,13 @@ export interface Address {
*
* @see https://docs.mollie.com/overview/common-data-types?path=postalCode#address-object
*/
postalCode: string;
postalCode?: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only potentially breaking change, as for this was used for orders and is actually optional.
This means users, who consumed order.billingAddress.postalCode may now get a type error.

/**
* The customer's email address.
*
* @see https://docs.mollie.com/overview/common-data-types?path=email#address-object
*/
email?: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fjbender email is missing from the common type definition, but I think that's a mistake, as it is included where the address is used (payments/orders)

/**
* The city of the address.
*
Expand All @@ -112,6 +136,8 @@ export interface Address {
/**
* The region of the address.
*
* For certain PayPal payments the `region` field is required.
*
* @see https://docs.mollie.com/overview/common-data-types?path=region#address-object
*/
region?: string;
Expand Down
13 changes: 2 additions & 11 deletions src/data/orders/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface OrderData extends Model<'order'> {
*
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=billingAddress#response
*/
billingAddress: OrderAddress;
billingAddress: Address;
/**
* The date of birth of your customer, if available.
*
Expand All @@ -90,7 +90,7 @@ export interface OrderData extends Model<'order'> {
*
* @see https://docs.mollie.com/reference/v2/orders-api/get-order?path=shippingAddress#response
*/
shippingAddress: OrderAddress;
shippingAddress: Address;
/**
* The locale used during checkout. Note that the locale may have been changed by your customer during checkout.
*
Expand Down Expand Up @@ -221,15 +221,6 @@ export enum OrderStatus {
pending = 'pending',
}

export interface OrderAddress extends Address {
organizationName?: string;
title?: string;
givenName: string;
familyName: string;
email: string;
phone?: string;
}

export enum OrderEmbed {
payments = 'payments',
refunds = 'refunds',
Expand Down
4 changes: 3 additions & 1 deletion src/data/organizations/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface OrganizationData extends Model<'organization'> {
*
* @see https://docs.mollie.com/reference/v2/organizations-api/get-organization?path=address#response
*/
address: Address;
address: OrganizationAdress;
/**
* The registration number of the organization at the (local) chamber of commerce.
*
Expand All @@ -49,6 +49,8 @@ export interface OrganizationData extends Model<'organization'> {
_links: OrganizationLinks;
}

export type OrganizationAdress = Pick<Address, 'streetAndNumber' | 'postalCode' | 'city' | 'country'>;

type Organization = Seal<OrganizationData, Helper<OrganizationData, Organization>>;

export default Organization;
Expand Down
Loading
Loading