Skip to content

Commit

Permalink
Merge branch 'master' into feature/split-payments
Browse files Browse the repository at this point in the history
  • Loading branch information
janpaepke authored Sep 30, 2024
2 parents 457080e + a73f311 commit 9429b00
Show file tree
Hide file tree
Showing 41 changed files with 424 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
env:
# Set the API key for the integration tests. In the future, all tests will rely on snapshots. An API key will
# then only be required to update those snapshots. The API key can then be removed from this file.
API_KEY: test_4kQQbBMEFh8QAuKVaWdpKuRpVSsdVG
API_KEY: ${{ secrets.TEST_API_KEY }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The `page` methods do not fit every use case. If you find yourself retrieving mu

```javascript
// Iterate over all payments.
for await (let payment in mollieClient.payments.iterate()) {
for await (const payment of mollieClient.payments.iterate()) {
// (Use break to end the loop prematurely.)
}
```
Expand Down
3 changes: 2 additions & 1 deletion src/Options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type MaybeArray from './types/MaybeArray';
import type Xor from './types/Xor';

type Options = Xor<
Expand All @@ -17,7 +18,7 @@ type Options = Xor<
/**
* One or an array of version strings of the software you are using, such as `'RockenbergCommerce/3.1.12'`.
*/
versionStrings?: string | string[];
versionStrings?: MaybeArray<string>;
/**
* The headers set in the requests sent to the Mollie API. `Authorization`, `User-Agent`, `Accept`,
* `Accept-Encoding`, and `Content-Type` are set by this library directly. Setting them here has no effect.
Expand Down
15 changes: 4 additions & 11 deletions src/binders/customers/CustomersBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../communication/TransformingNetw
import type Customer from '../../data/customers/Customer';
import { type CustomerData } from '../../data/customers/Customer';
import type Page from '../../data/page/Page';
import ApiError from '../../errors/ApiError';
import alias from '../../plumbing/alias';
import checkId from '../../plumbing/checkId';
import assertWellFormedId from '../../plumbing/assertWellFormedId';
import renege from '../../plumbing/renege';
import type Callback from '../../types/Callback';
import Binder from '../Binder';
Expand Down Expand Up @@ -42,9 +41,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public get(id: string, parameters: GetParameters, callback: Callback<Customer>): void;
public get(id: string, parameters?: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.get<CustomerData, Customer>(`${pathSegment}/${id}`, parameters);
}

Expand Down Expand Up @@ -86,9 +83,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public update(id: string, parameters: UpdateParameters, callback: Callback<Customer>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.patch<CustomerData, Customer>(`${pathSegment}/${id}`, parameters);
}

Expand All @@ -102,9 +97,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public delete(id: string, parameters: DeleteParameters, callback: Callback<true>): void;
public delete(id: string, parameters?: DeleteParameters) {
if (renege(this, this.delete, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.delete<CustomerData, true>(`${pathSegment}/${id}`, parameters);
}
}
31 changes: 8 additions & 23 deletions src/binders/customers/mandates/CustomerMandatesBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import { type MandateData } from '../../../data/customers/mandates/data';
import type Mandate from '../../../data/customers/mandates/Mandate';
import type Page from '../../../data/page/Page';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -34,9 +33,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<MandateData, Mandate>(getPathSegments(customerId), data);
}

Expand All @@ -50,13 +47,9 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public get(id: string, parameters: GetParameters, callback: Callback<Mandate>): void;
public get(id: string, parameters: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
assertWellFormedId(id, 'mandate');
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.get<MandateData, Mandate>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -73,9 +66,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -89,9 +80,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query, valuesPerMinute);
}

Expand All @@ -105,13 +94,9 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public revoke(id: string, parameters: RevokeParameters, callback: Callback<true>): void;
public revoke(id: string, parameters: RevokeParameters) {
if (renege(this, this.revoke, ...arguments)) return;
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
assertWellFormedId(id, 'mandate');
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.delete<MandateData, true>(`${getPathSegments(customerId)}/${id}`, context);
}
}
15 changes: 4 additions & 11 deletions src/binders/customers/payments/CustomerPaymentsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import type Page from '../../../data/page/Page';
import { type PaymentData } from '../../../data/payments/data';
import type Payment from '../../../data/payments/Payment';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -38,9 +37,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<PaymentData, Payment>(getPathSegments(customerId), data);
}

Expand All @@ -55,9 +52,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<PaymentData, Payment>(getPathSegments(customerId), 'payments', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -69,9 +64,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<PaymentData, Payment>(getPathSegments(customerId), 'payments', query, valuesPerMinute);
}
}
3 changes: 2 additions & 1 deletion src/binders/customers/payments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type PaymentMethod } from '../../../data/global';
import { type PaymentData } 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';

Expand All @@ -21,7 +22,7 @@ export type CreateParameters = ContextParameters &
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=method#parameters
*/
method?: PaymentMethod | PaymentMethod[];
method?: MaybeArray<PaymentMethod>;
} & IdempotencyParameter;

export type PageParameters = ContextParameters & PaginationParameters;
Expand Down
39 changes: 10 additions & 29 deletions src/binders/customers/subscriptions/CustomerSubscriptionsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import type Page from '../../../data/page/Page';
import { type SubscriptionData } from '../../../data/subscriptions/data';
import type Subscription from '../../../data/subscriptions/Subscription';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -41,9 +40,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<SubscriptionData, Subscription>(getPathSegments(customerId), data);
}

Expand All @@ -57,13 +54,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public get(id: string, parameters: GetParameters, callback: Callback<Subscription>): void;
public get(id: string, parameters: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.get<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -78,9 +71,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -92,9 +83,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query, valuesPerMinute);
}

Expand All @@ -110,13 +99,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public update(id: string, parameters: UpdateParameters, callback: Callback<Subscription>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.patch<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, data);
}

Expand All @@ -130,13 +115,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public cancel(id: string, parameters: CancelParameters, callback: Callback<Subscription>): void;
public cancel(id: string, parameters: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.delete<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, context);
}
}
5 changes: 3 additions & 2 deletions src/binders/methods/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Amount, type Locale, type SequenceType } from '../../data/global';
import { type MethodInclude } from '../../data/methods/data';
import type MaybeArray from '../../types/MaybeArray';

export interface GetParameters {
/**
Expand All @@ -10,7 +11,7 @@ export interface GetParameters {
* @see https://docs.mollie.com/reference/v2/methods-api/get-method?path=locale#parameters
*/
locale?: Locale;
include?: MethodInclude[] | MethodInclude;
include?: MaybeArray<MethodInclude>;
profileId?: string;
testmode?: boolean;
/**
Expand Down Expand Up @@ -103,7 +104,7 @@ export interface ListParameters {
* @see https://docs.mollie.com/reference/v2/methods-api/list-methods?path=orderLineCategories#parameters
*/
orderLineCategories?: string[];
include?: MethodInclude[] | MethodInclude;
include?: MaybeArray<MethodInclude>;
profileId?: string;
testmode?: boolean;
}
15 changes: 4 additions & 11 deletions src/binders/orders/OrdersBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type TransformingNetworkClient from '../../communication/TransformingNetw
import type Page from '../../data/page/Page';
import { type OrderData } from '../../data/orders/data';
import type Order from '../../data/orders/Order';
import ApiError from '../../errors/ApiError';
import checkId from '../../plumbing/checkId';
import assertWellFormedId from '../../plumbing/assertWellFormedId';
import renege from '../../plumbing/renege';
import type Callback from '../../types/Callback';
import Binder from '../Binder';
Expand Down Expand Up @@ -73,9 +72,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public get(id: string, parameters: GetParameters, callback: Callback<Order>): void;
public get(id: string, parameters?: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.get<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}

Expand Down Expand Up @@ -120,9 +117,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public update(id: string, parameters: UpdateParameters, callback: Callback<Order>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.patch<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}

Expand All @@ -148,9 +143,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public cancel(id: string, parameters: CancelParameters, callback: Callback<Order>): void;
public cancel(id: string, parameters?: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.delete<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}
}
Loading

0 comments on commit 9429b00

Please sign in to comment.