Skip to content

Commit

Permalink
add routing param for split payments
Browse files Browse the repository at this point in the history
  • Loading branch information
janpaepke committed Sep 27, 2024
1 parent 412104f commit 457080e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
58 changes: 56 additions & 2 deletions src/binders/payments/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Address, type Amount, type PaymentMethod } from '../../data/global';
import { type Address, type Amount, type DestinationType, type PaymentMethod } from '../../data/global';
import { type Issuer } from '../../data/Issuer';
import { type PaymentData, type PaymentEmbed, type PaymentInclude } from '../../data/payments/data';
import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters';
Expand Down Expand Up @@ -136,7 +136,12 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
profileId?: string;
testmode?: boolean;
/**
* Adding an application fee allows you to charge the merchant a small sum for the payment and transfer this to your own account.
* With Mollie Connect you can charge fees on payments that your app is processing on behalf of other Mollie merchants.
*
* If you use OAuth to create payments on a connected merchant's account, you can charge a fee using this applicationFee parameter.
* If the payment succeeds, the fee will be deducted from the merchant's balance and sent to your own account balance.
*
* If instead you want to split a payment on your own account between yourself and a connected merchant, refer to the `routing` parameter.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=applicationFee#mollie-connect-parameters
*/
Expand All @@ -159,6 +164,44 @@ export type CreateParameters = Pick<PaymentData, 'amount' | 'description' | 'red
*/
description: string;
};
/**
* _This functionality is not enabled by default. Reach out to our partner management team if you wish to use it._
*
* With Mollie Connect you can charge fees on payments that your app is processing on behalf of other Mollie merchants.
*
* If you create payments on your own account that you want to split between yourself and one or more connected merchants, you can use this `routing` parameter to route the payment accordingly.
*
* The `routing` parameter should contain an array of objects, with each object describing the destination for a specific portion of the payment.
*
* It is not necessary to indicate in the array which portion goes to yourself. After all portions of the total payment amount have been routed, the amount left will be routed to the current organization automatically.
*
* If instead you use OAuth to create payments on a connected merchant's account, refer to the applicationFee parameter.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=routing
*/
routing?: Array<{
/**
* The portion of the total payment amount being routed. Currently only `EUR` payments can be routed.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=routing/amount
*/
amount: Amount & { currency: 'EUR' };
/**
* The destination of this portion of the payment.
*
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=routing/destination
*/
destination: OrganisationDestination;
/**
* Optionally, schedule this portion of the payment to be transferred to its destination on a later date. The date must be given in `YYYY-MM-DD` format.
*
* If no date is given, the funds become available to the connected merchant as soon as the payment succeeds.
*
* @see https://docs.mollie.com/reference/v2/payments-api/create-payment?path=routing/releaseDate
*/
releaseDate?: string;
}>;
} & IdempotencyParameter;

export interface GetParameters {
Expand Down Expand Up @@ -194,3 +237,14 @@ export type UpdateParameters = Pick<PaymentData, 'redirectUrl' | 'cancelUrl' | '
export interface CancelParameters extends IdempotencyParameter {
testmode?: boolean;
}

type OrganisationDestination = {
/**
* The type of destination. Currently only the destination type `organization` is supported.
*/
type: DestinationType.organization;
/**
* Required for destination type `organization`. The ID of the connected organization the funds should be routed to.
*/
organizationId: string;
};
2 changes: 1 addition & 1 deletion src/createMollieClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function createMollieClient(options: Options) {

export { createMollieClient };

export { ApiMode, Locale, PaymentMethod, HistoricPaymentMethod, SequenceType } from './data/global';
export { ApiMode, Locale, PaymentMethod, HistoricPaymentMethod, SequenceType, DestinationType } from './data/global';
export { CaptureEmbed } from './data/payments/captures/data';
export { MandateMethod, MandateStatus } from './data/customers/mandates/data';
export { MethodImageSize, MethodInclude } from './data/methods/data';
Expand Down
4 changes: 4 additions & 0 deletions src/data/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ export enum SequenceType {
first = 'first',
recurring = 'recurring',
}

export enum DestinationType {
organization = 'organization',
}

0 comments on commit 457080e

Please sign in to comment.