diff --git a/src/client.ts b/src/client.ts index 26f946f..13c0017 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,6 +6,7 @@ import { BankAuthorisationService } from './services/bankAuthorisationService'; import { BankDetailsLookupService } from './services/bankDetailsLookupService'; import { BillingRequestService } from './services/billingRequestService'; import { BillingRequestFlowService } from './services/billingRequestFlowService'; +import { BillingRequestTemplateService } from './services/billingRequestTemplateService'; import { CreditorService } from './services/creditorService'; import { CreditorBankAccountService } from './services/creditorBankAccountService'; import { CurrencyExchangeRateService } from './services/currencyExchangeRateService'; @@ -37,6 +38,7 @@ export class GoCardlessClient { private _bankDetailsLookups: BankDetailsLookupService; private _billingRequests: BillingRequestService; private _billingRequestFlows: BillingRequestFlowService; + private _billingRequestTemplates: BillingRequestTemplateService; private _creditors: CreditorService; private _creditorBankAccounts: CreditorBankAccountService; private _currencyExchangeRates: CurrencyExchangeRateService; @@ -68,6 +70,7 @@ export class GoCardlessClient { this._bankDetailsLookups = undefined; this._billingRequests = undefined; this._billingRequestFlows = undefined; + this._billingRequestTemplates = undefined; this._creditors = undefined; this._creditorBankAccounts = undefined; this._currencyExchangeRates = undefined; @@ -125,6 +128,16 @@ export class GoCardlessClient { return this._billingRequestFlows; } + get billingRequestTemplates(): BillingRequestTemplateService { + if (!this._billingRequestTemplates) { + this._billingRequestTemplates = new BillingRequestTemplateService( + this._api + ); + } + + return this._billingRequestTemplates; + } + get creditors(): CreditorService { if (!this._creditors) { this._creditors = new CreditorService(this._api); diff --git a/src/services/billingRequestFlowService.ts b/src/services/billingRequestFlowService.ts index 092203a..71f5337 100644 --- a/src/services/billingRequestFlowService.ts +++ b/src/services/billingRequestFlowService.ts @@ -13,13 +13,22 @@ interface BillingRequestFlowListResponse extends Types.APIResponse { } interface BillingRequestFlowCreateRequest { + // Fulfil the Billing Request on completion of the flow (true by default) + + auto_fulfil?: boolean; + // Resources linked to this BillingRequestFlow. links: Types.BillingRequestFlowCreateRequestLinks; - // If true, the payer will not be able to edit their existing details (e.g. - // customer and bank account) within the billing request flow. + // If true, the payer will not be able to change their bank account within the + // flow + + lock_bank_account?: boolean; - lock_existing_details?: boolean; + // If true, the payer will not be able to edit their customer details within the + // flow + + lock_customer_details?: boolean; // URL that the payer can be redirected to after completing the request flow. @@ -58,4 +67,24 @@ export class BillingRequestFlowService { return formattedResponse; } + + async initialise(identity: string): Promise { + const urlParameters = [{ key: 'identity', value: identity }]; + const requestParams = { + path: '/billing_request_flows/:identity/actions/initialise', + method: 'post', + urlParameters, + + payloadKey: null, + fetch: null, + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestFlowResponse = { + ...response.body['billing_request_flows'], + __response__: response.__response__, + }; + + return formattedResponse; + } } diff --git a/src/services/billingRequestService.ts b/src/services/billingRequestService.ts index def62f9..388f429 100644 --- a/src/services/billingRequestService.ts +++ b/src/services/billingRequestService.ts @@ -47,10 +47,6 @@ interface BillingRequestListRequest { } interface BillingRequestCreateRequest { - // Should the billing request be fulfilled as soon as it's ready - - auto_fulfil?: boolean; - // Resources linked to this BillingRequest. links?: Types.BillingRequestCreateRequestLinks; @@ -74,7 +70,7 @@ interface BillingRequestCollectCustomerDetailsRequest { customer_billing_detail?: Types.BillingRequestCustomerBillingDetail; } -interface BillingRequestCollectBankAccountDetailsRequest { +interface BillingRequestCollectBankAccountRequest { // Name of the account holder, as known by the bank. Usually this is the same as // the name stored with the linked [creditor](#core-endpoints-creditors). This // field will be transliterated, upcased and truncated to 18 characters. This @@ -88,6 +84,11 @@ interface BillingRequestCollectBankAccountDetailsRequest { account_number?: string; + // Account number suffix (only for bank accounts denominated in NZD) - see + // [local details](#local-bank-details-new-zealand) for more information. + + account_number_suffix?: string; + // Bank account type. Required for USD-denominated bank accounts. Must not be // provided for bank accounts in other currencies. See [local // details](#local-bank-details-united-states) for more information. @@ -137,6 +138,13 @@ interface BillingRequestFulfilRequest { metadata?: Types.JsonMap; } +interface BillingRequestConfirmPayerDetailsRequest { + // Key-value store of custom data. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + metadata?: Types.JsonMap; +} + interface BillingRequestCancelRequest { // Key-value store of custom data. Up to 3 keys are permitted, with key names up // to 50 characters and values up to 500 characters. @@ -267,13 +275,13 @@ export class BillingRequestService { return formattedResponse; } - async collect_bank_account_details( + async collect_bank_account( identity: string, - requestParameters: BillingRequestCollectBankAccountDetailsRequest + requestParameters: BillingRequestCollectBankAccountRequest ): Promise { const urlParameters = [{ key: 'identity', value: identity }]; const requestParams = { - path: '/billing_requests/:identity/actions/collect_bank_account_details', + path: '/billing_requests/:identity/actions/collect_bank_account', method: 'post', urlParameters, requestParameters, @@ -313,6 +321,29 @@ export class BillingRequestService { return formattedResponse; } + async confirm_payer_details( + identity: string, + requestParameters: BillingRequestConfirmPayerDetailsRequest + ): Promise { + const urlParameters = [{ key: 'identity', value: identity }]; + const requestParams = { + path: '/billing_requests/:identity/actions/confirm_payer_details', + method: 'post', + urlParameters, + requestParameters, + payloadKey: null, + fetch: null, + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestResponse = { + ...response.body['billing_requests'], + __response__: response.__response__, + }; + + return formattedResponse; + } + async cancel( identity: string, requestParameters: BillingRequestCancelRequest diff --git a/src/services/billingRequestTemplateService.ts b/src/services/billingRequestTemplateService.ts new file mode 100644 index 0000000..c227e91 --- /dev/null +++ b/src/services/billingRequestTemplateService.ts @@ -0,0 +1,296 @@ +'use strict'; + +import { Api } from '../api/api'; +import * as Types from '../types/Types'; + +interface BillingRequestTemplateResponse + extends Types.BillingRequestTemplate, + Types.APIResponse {} + +interface BillingRequestTemplateListResponse extends Types.APIResponse { + billing_request_templates: Types.BillingRequestTemplate[]; + meta: Types.ListMeta; +} + +interface BillingRequestTemplateListRequest { + // Cursor pointing to the start of the desired set. + + after?: string; + + // Cursor pointing to the end of the desired set. + + before?: string; + + // Number of records to return. + + limit?: string; +} + +interface BillingRequestTemplateCreateRequest { + // Resources linked to this BillingRequestTemplate. + links?: Types.BillingRequestTemplateCreateRequestLinks; + + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. + // Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + + mandate_request_currency?: string; + + // Key-value store of custom data that will be applied to the mandate created + // when this request is fulfilled. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + mandate_request_metadata?: Types.JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + + mandate_request_scheme?: string; + + // Verification preference for the mandate. One of: + //
    + //
  • `minimum`: only verify if absolutely required, such as when part of + // scheme rules
  • + //
  • `recommended`: in addition to minimum, use the GoCardless risk engine + // to decide an appropriate level of verification
  • + //
  • `when_available`: if verification mechanisms are available, use + // them
  • + //
  • `always`: as `when_available`, but fail to create the Billing Request + // if a mechanism isn't available
  • + //
+ // + // If not provided, the `recommended` level is chosen. + + mandate_request_verify?: Types.BillingRequestTemplateMandateRequestVerify; + + // Key-value store of custom data. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + metadata?: Types.JsonMap; + + // Name for the template. Provides a friendly human name for the template, as it + // is shown in the dashboard. Must not exceed 255 characters. + + name?: string; + + // Amount in minor unit (e.g. pence in GBP, cents in EUR). + + payment_request_amount?: string; + + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. + // Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + + payment_request_currency?: string; + + // A human-readable description of the payment. This will be displayed to the + // payer when authorising the billing request. + // + + payment_request_description?: string; + + // Key-value store of custom data that will be applied to the payment created + // when this request is fulfilled. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + payment_request_metadata?: Types.JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + + payment_request_scheme?: string; + + // URL that the payer can be redirected to after completing the request flow. + + redirect_uri?: string; +} + +interface BillingRequestTemplateUpdateRequest { + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. + // Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + + mandate_request_currency?: string; + + // Key-value store of custom data that will be applied to the mandate created + // when this request is fulfilled. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + mandate_request_metadata?: Types.JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + + mandate_request_scheme?: string; + + // Verification preference for the mandate. One of: + //
    + //
  • `minimum`: only verify if absolutely required, such as when part of + // scheme rules
  • + //
  • `recommended`: in addition to minimum, use the GoCardless risk engine + // to decide an appropriate level of verification
  • + //
  • `when_available`: if verification mechanisms are available, use + // them
  • + //
  • `always`: as `when_available`, but fail to create the Billing Request + // if a mechanism isn't available
  • + //
+ // + // If not provided, the `recommended` level is chosen. + + mandate_request_verify?: Types.BillingRequestTemplateMandateRequestVerify; + + // Key-value store of custom data. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + metadata?: Types.JsonMap; + + // Name for the template. Provides a friendly human name for the template, as it + // is shown in the dashboard. Must not exceed 255 characters. + + name?: string; + + // Amount in minor unit (e.g. pence in GBP, cents in EUR). + + payment_request_amount?: string; + + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. + // Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + + payment_request_currency?: string; + + // A human-readable description of the payment. This will be displayed to the + // payer when authorising the billing request. + // + + payment_request_description?: string; + + // Key-value store of custom data that will be applied to the payment created + // when this request is fulfilled. Up to 3 keys are permitted, with key names up + // to 50 characters and values up to 500 characters. + + payment_request_metadata?: Types.JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + + payment_request_scheme?: string; + + // URL that the payer can be redirected to after completing the request flow. + + redirect_uri?: string; +} + +export class BillingRequestTemplateService { + private api: Api; + + constructor(api) { + this.api = api; + } + + async list( + requestParameters: BillingRequestTemplateListRequest + ): Promise { + const urlParameters = []; + const requestParams = { + path: '/billing_request_templates', + method: 'get', + urlParameters, + requestParameters, + payloadKey: null, + fetch: null, + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestTemplateListResponse = { + ...response.body, + __response__: response.__response__, + }; + + return formattedResponse; + } + + async *all( + requestParameters: BillingRequestTemplateListRequest + ): AsyncGenerator { + let cursor = undefined; + do { + const list = await this.list({ ...requestParameters, after: cursor }); + + for (const billingrequesttemplate of list.billing_request_templates) { + yield billingrequesttemplate; + } + + cursor = list.meta.cursors.after; + } while (cursor); + } + + async find(identity: string): Promise { + const urlParameters = [{ key: 'identity', value: identity }]; + const requestParams = { + path: '/billing_request_templates/:identity', + method: 'get', + urlParameters, + + payloadKey: null, + fetch: null, + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestTemplateResponse = { + ...response.body['billing_request_templates'], + __response__: response.__response__, + }; + + return formattedResponse; + } + + async create( + requestParameters: BillingRequestTemplateCreateRequest, + idempotencyKey = '', + customHeaders: Types.JsonMap = {} + ): Promise { + const urlParameters = []; + const requestParams = { + path: '/billing_request_templates', + method: 'post', + urlParameters, + requestParameters, + payloadKey: 'billing_request_templates', + idempotencyKey, + customHeaders, + fetch: async identity => this.find(identity), + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestTemplateResponse = { + ...(response.body?.['billing_request_templates'] ?? response), + __response__: response.__response__, + }; + + return formattedResponse; + } + + async update( + identity: string, + requestParameters: BillingRequestTemplateUpdateRequest + ): Promise { + const urlParameters = [{ key: 'identity', value: identity }]; + const requestParams = { + path: '/billing_request_templates/:identity', + method: 'put', + urlParameters, + requestParameters, + payloadKey: 'billing_request_templates', + fetch: null, + }; + + const response = await this.api.request(requestParams); + const formattedResponse: BillingRequestTemplateResponse = { + ...response.body['billing_request_templates'], + __response__: response.__response__, + }; + + return formattedResponse; + } +} diff --git a/src/services/customerService.ts b/src/services/customerService.ts index a079e78..f610a08 100644 --- a/src/services/customerService.ts +++ b/src/services/customerService.ts @@ -120,10 +120,21 @@ interface CustomerListRequest { limit?: string; // The direction to sort in. + // One of: + //
    + //
  • `asc`
  • + //
  • `desc`
  • + //
sort_direction?: Types.CustomerSortDirection; // Field by which to sort records. + // One of: + //
    + //
  • `name`
  • + //
  • `company_name`
  • + //
  • `created_at`
  • + //
sort_field?: Types.CustomerSortField; } diff --git a/src/services/eventService.ts b/src/services/eventService.ts index 8c65680..2d0b5ce 100644 --- a/src/services/eventService.ts +++ b/src/services/eventService.ts @@ -23,6 +23,11 @@ interface EventListRequest { before?: string; + // ID of a [billing request](#billing-requests-billing-requests). If specified, + // this endpoint will return all events for the given billing request. + + billing_request?: string; + // The creation date of this Event. created_at?: Types.CreatedAtFilter; @@ -37,6 +42,7 @@ interface EventListRequest { //
  • `subscription`
  • //
  • `instalment_schedule`
  • //
  • `creditor`
  • + //
  • `billing_request`<\li> // include?: Types.EventInclude; @@ -79,14 +85,15 @@ interface EventListRequest { // `subscription`, `instalment_schedule`, `creditor`, `refund` or `payout` // parameter. The type can be one of: //
      - //
    • `payments`
    • + //
    • `billing_requests`
    • + //
    • `creditors`
    • + //
    • `instalment_schedules`
    • //
    • `mandates`
    • //
    • `payer_authorisations`
    • + //
    • `payments`
    • //
    • `payouts`
    • - //
    • `subscriptions`
    • - //
    • `instalment_schedules`
    • - //
    • `creditors`
    • //
    • `refunds`
    • + //
    • `subscriptions`
    • //
    resource_type?: Types.EventResourceType; diff --git a/src/services/paymentService.ts b/src/services/paymentService.ts index 32845d2..9e3b492 100644 --- a/src/services/paymentService.ts +++ b/src/services/paymentService.ts @@ -113,10 +113,20 @@ interface PaymentListRequest { mandate?: string; // The direction to sort in. + // One of: + //
      + //
    • `asc`
    • + //
    • `desc`
    • + //
    sort_direction?: Types.PaymentSortDirection; // Field by which to sort records. + // One of: + //
      + //
    • `charge_date`
    • + //
    • `amount`
    • + //
    sort_field?: Types.PaymentSortField; diff --git a/src/services/scenarioSimulatorService.ts b/src/services/scenarioSimulatorService.ts index 34a8d4b..df5f5cb 100644 --- a/src/services/scenarioSimulatorService.ts +++ b/src/services/scenarioSimulatorService.ts @@ -13,13 +13,6 @@ interface ScenarioSimulatorListResponse extends Types.APIResponse { } interface ScenarioSimulatorRunRequest { - // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. - // Currently "AUD", "CAD", "DKK", "EUR", "GBP", "NZD", "SEK" and "USD" are - // supported. - // Only required when simulating `payout_create` - - currency?: Types.ScenarioSimulatorCurrency; - // Resources linked to this ScenarioSimulator. links?: Types.ScenarioSimulatorRunRequestLinks; } diff --git a/src/services/subscriptionService.ts b/src/services/subscriptionService.ts index acd2e0e..54422a6 100644 --- a/src/services/subscriptionService.ts +++ b/src/services/subscriptionService.ts @@ -84,7 +84,7 @@ interface SubscriptionCreateRequest { // created and will appear on your customer's bank statement. See the // documentation for // the [create payment endpoint](#payments-create-a-payment) for more details. - // + //
    //

    Restricted: You need your own // Service User Number to specify a payment reference for Bacs payments.

    @@ -97,7 +97,9 @@ interface SubscriptionCreateRequest { // The date on which the first payment should be charged. Must be on or after // the [mandate](#core-endpoints-mandates)'s `next_possible_charge_date`. When - // blank, this will be set as the mandate's `next_possible_charge_date`. + // left blank and `month` or `day_of_month` are provided, this will be set to + // the date of the first payment. If created without `month` or `day_of_month` + // this will be set as the mandate's `next_possible_charge_date` start_date?: string; } @@ -168,7 +170,7 @@ interface SubscriptionUpdateRequest { // created and will appear on your customer's bank statement. See the // documentation for // the [create payment endpoint](#payments-create-a-payment) for more details. - // + //
    //

    Restricted: You need your own // Service User Number to specify a payment reference for Bacs payments.

    diff --git a/src/types/Types.ts b/src/types/Types.ts index 3a32a30..cd798da 100644 --- a/src/types/Types.ts +++ b/src/types/Types.ts @@ -3,6 +3,10 @@ export interface BankAuthorisation { // Type of authorisation, can be either 'mandate' or 'payment'. authorisation_type: BankAuthorisationAuthorisationType; + // Fixed [timestamp](#api-usage-time-zones--dates), recording when the user + // has been authorised. + authorised_at?: string; + // Timestamp when the flow was created created_at: string; @@ -23,10 +27,6 @@ export interface BankAuthorisation { // URL that the payer can be redirected to after authorising the payment. redirect_uri: string; - // Short URL that redirects via GoCardless to the original URL, more suitable - // for encoding in a QR code - short_url: string; - // URL for an oauth flow that will allow the user to authorise the payment url: string; } @@ -98,14 +98,11 @@ export interface BillingRequest { // fulfilled. actions: BillingRequestAction[]; - // Should the billing request be fulfilled as soon as it's ready - auto_fulfil: boolean; - // Fixed [timestamp](#api-usage-time-zones--dates), recording when this // resource was created. created_at: string; - // Unique identifier, beginning with "PY". + // Unique identifier, beginning with "BRQ". id: string; // Resources linked to this BillingRequest. @@ -138,6 +135,10 @@ export interface BillingRequest { /** Type for a billingrequestcreaterequestlinks resource. */ export interface BillingRequestCreateRequestLinks { + // ID of the associated [creditor](#core-endpoints-creditors). Only required + // if your account manages multiple creditors. + creditor: string; + // ID of the [customer](#core-endpoints-customers) against which this request // should be made. customer: string; @@ -263,6 +264,13 @@ export enum BillingRequestNotificationType { /** Type for a billingrequestaction resource. */ export interface BillingRequestAction { + // Describes the behaviour of bank authorisations, for the bank_authorisation + // action + bank_authorisation: BillingRequestActionBankAuthorisation; + + // Additional parameters to help complete the collect_customer_details action + collect_customer_details: BillingRequestActionCollectCustomerDetails; + // Which other action types this action can complete. completes_actions: string[]; @@ -273,20 +281,66 @@ export interface BillingRequestAction { // Requires completing these actions before this action can be completed. requires_actions: string[]; + // Status of the action + status: BillingRequestActionStatus; + // Unique identifier for the action. type: BillingRequestActionType; } +/** Type for a billingrequestactionbankauthorisation resource. */ +export interface BillingRequestActionBankAuthorisation { + // Which authorisation adapter will be used to power these authorisations + // (GoCardless internal use only) + adapter: BillingRequestActionBankAuthorisationAdapter; + + // What type of bank authorisations are supported on this billing request + authorisation_type: BillingRequestActionBankAuthorisationAuthorisationType; + + // Whether an institution is a required field when creating this bank + // authorisation + requires_institution: boolean; +} + +export enum BillingRequestActionBankAuthorisationAdapter { + OpenBankingGatewayPis = 'open_banking_gateway_pis', + PlaidAis = 'plaid_ais', +} + +export enum BillingRequestActionBankAuthorisationAuthorisationType { + Payment = 'payment', + Mandate = 'mandate', +} + +/** Type for a billingrequestactioncollectcustomerdetails resource. */ +export interface BillingRequestActionCollectCustomerDetails { + // Default customer country code, as determined by scheme and payer location + default_country_code: string; +} + +export enum BillingRequestActionStatus { + Pending = 'pending', + Completed = 'completed', +} + export enum BillingRequestActionType { ChooseCurrency = 'choose_currency', CollectCustomerDetails = 'collect_customer_details', - CollectBankAccountDetails = 'collect_bank_account_details', - PaymentBankAuthorisation = 'payment_bank_authorisation', - MandateBankAuthorisation = 'mandate_bank_authorisation', + CollectBankAccount = 'collect_bank_account', + BankAuthorisation = 'bank_authorisation', + ConfirmPayerDetails = 'confirm_payer_details', } /** Type for a billingrequestlinks resource. */ export interface BillingRequestLinks { + // (Optional) ID of the [bank + // authorisation](#billing-requests-bank-authorisations) that was used to + // verify this request. + bank_authorisation: string; + + // ID of the associated [creditor](#core-endpoints-creditors). + creditor: string; + // ID of the [customer](#core-endpoints-customers) that will be used for this // request customer: string; @@ -299,15 +353,19 @@ export interface BillingRequestLinks { // ID of the customer billing detail that will be used for this request customer_billing_detail: string; - // (Optional) ID of the [mandate bank - // authorisation](#billing-requests-bank-authorisations) that was used to - // verify this request. - mandate_bank_authorisation: string; + // (Optional) ID of the associated mandate request + mandate_request: string; - // (Optional) ID of the [payment bank - // authorisation](#billing-requests-bank-authorisations) that was used to - // verify this request. - payment_bank_authorisation: string; + // (Optional) ID of the [mandate](#core-endpoints-mandates) that was created + // from this mandate request. this mandate request. + mandate_request_mandate: string; + + // (Optional) ID of the associated payment request + payment_request: string; + + // (Optional) ID of the [payment](#core-endpoints-payments) that was created + // from this payment request. + payment_request_payment: string; } /** Type for a billingrequestmandaterequest resource. */ @@ -323,6 +381,21 @@ export interface BillingRequestMandateRequest { // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. scheme?: string; + + // Verification preference for the mandate. One of: + //
      + //
    • `minimum`: only verify if absolutely required, such as when part of + // scheme rules
    • + //
    • `recommended`: in addition to minimum, use the GoCardless risk engine + // to decide an appropriate level of verification
    • + //
    • `when_available`: if verification mechanisms are available, use + // them
    • + //
    • `always`: as `when_available`, but fail to create the Billing Request + // if a mechanism isn't available
    • + //
    + // + // If not provided, the `recommended` level is chosen. + verify: BillingRequestMandateRequestVerify; } /** Type for a billingrequestmandaterequestlinks resource. */ @@ -333,11 +406,23 @@ export interface BillingRequestMandateRequestLinks { mandate: string; } +export enum BillingRequestMandateRequestVerify { + Minimum = 'minimum', + Recommended = 'recommended', + WhenAvailable = 'when_available', + Always = 'always', +} + /** Type for a billingrequestpaymentrequest resource. */ export interface BillingRequestPaymentRequest { // Amount in minor unit (e.g. pence in GBP, cents in EUR). amount: string; + // The amount to be deducted from the payment as an app fee, to be paid to the + // partner integration which created the billing request, in the lowest + // denomination for the currency (e.g. pence in GBP, cents in EUR). + app_fee?: string; + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency // code. Currently only "GBP" is supported as we only have one scheme that is // per_payment_authorised. @@ -511,6 +596,11 @@ export interface BillingRequestResourcesCustomerBillingDetail { // Unique identifier, beginning with "CU". id: string; + // For ACH customers only. Required for ACH customers. A string containing the + // IP address of the payer to whom the mandate belongs (i.e. as a result of + // their completion of a mandate setup flow in their browser). + ip_address?: string; + // The customer's postal code. postal_code?: string; @@ -542,17 +632,34 @@ export interface BillingRequestFlow { // billing request authorisation_url: string; + // Fulfil the Billing Request on completion of the flow (true by default) + auto_fulfil: boolean; + // Timestamp when the flow was created created_at: string; // Timestamp when the flow will expire. Each flow currently lasts for 7 days. expires_at: string; + // Unique identifier, beginning with "BRF". + id: string; + // Resources linked to this BillingRequestFlow. links: BillingRequestFlowLinks; + // If true, the payer will not be able to change their bank account within the + // flow + lock_bank_account: boolean; + + // If true, the payer will not be able to edit their customer details within + // the flow + lock_customer_details: boolean; + // URL that the payer can be redirected to after completing the request flow. - redirect_uri: string; + redirect_uri?: string; + + // Session token populated when responding to the initalise action + session_token?: string; } /** Type for a billingrequestflowcreaterequestlinks resource. */ @@ -569,6 +676,100 @@ export interface BillingRequestFlowLinks { billing_request: string; } +/** Type for a billingrequesttemplate resource. */ +export interface BillingRequestTemplate { + // Permanent URL that customers can visit to allow them to complete a flow + // based on this template, before being returned to the `redirect_uri`. + authorisation_url: string; + + // Fixed [timestamp](#api-usage-time-zones--dates), recording when this + // resource was created. + created_at: string; + + // Unique identifier, beginning with "BRT". + id: string; + + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency + // code. Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + mandate_request_currency: string; + + // Key-value store of custom data that will be applied to the mandate created + // when this request is fulfilled. Up to 3 keys are permitted, with key names + // up to 50 characters and values up to 500 characters. + mandate_request_metadata?: JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + mandate_request_scheme?: string; + + // Verification preference for the mandate. One of: + //
      + //
    • `minimum`: only verify if absolutely required, such as when part of + // scheme rules
    • + //
    • `recommended`: in addition to minimum, use the GoCardless risk engine + // to decide an appropriate level of verification
    • + //
    • `when_available`: if verification mechanisms are available, use + // them
    • + //
    • `always`: as `when_available`, but fail to create the Billing Request + // if a mechanism isn't available
    • + //
    + // + // If not provided, the `recommended` level is chosen. + mandate_request_verify: BillingRequestTemplateMandateRequestVerify; + + // Key-value store of custom data. Up to 3 keys are permitted, with key names + // up to 50 characters and values up to 500 characters. + metadata: JsonMap; + + // Name for the template. Provides a friendly human name for the template, as + // it is shown in the dashboard. Must not exceed 255 characters. + name: string; + + // Amount in minor unit (e.g. pence in GBP, cents in EUR). + payment_request_amount: string; + + // [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency + // code. Currently only "GBP" is supported as we only have one scheme that is + // per_payment_authorised. + payment_request_currency: string; + + // A human-readable description of the payment. This will be displayed to the + // payer when authorising the billing request. + // + payment_request_description?: string; + + // Key-value store of custom data that will be applied to the payment created + // when this request is fulfilled. Up to 3 keys are permitted, with key names + // up to 50 characters and values up to 500 characters. + payment_request_metadata?: JsonMap; + + // A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + // "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + payment_request_scheme?: string; + + // URL that the payer can be redirected to after completing the request flow. + redirect_uri?: string; + + // Dynamic [timestamp](#api-usage-time-zones--dates) recording when this + // resource was last updated. + updated_at: string; +} + +/** Type for a billingrequesttemplatecreaterequestlinks resource. */ +export interface BillingRequestTemplateCreateRequestLinks { + // ID of the associated [creditor](#core-endpoints-creditors). Only required + // if your account manages multiple creditors. + creditor: string; +} + +export enum BillingRequestTemplateMandateRequestVerify { + Minimum = 'minimum', + Recommended = 'recommended', + WhenAvailable = 'when_available', + Always = 'always', +} + /** Type for a creditor resource. */ export interface Creditor { // The first line of the creditor's address. @@ -1112,6 +1313,16 @@ export interface CustomerNotification { links: CustomerNotificationLinks; // The type of notification the customer shall receive. + // One of: + //
      + //
    • `payment_created`
    • + //
    • `payment_cancelled`
    • + //
    • `mandate_created`
    • + //
    • `subscription_created`
    • + //
    • `subscription_cancelled`
    • + //
    • `instalment_schedule_created`
    • + //
    • `instalment_schedule_cancelled`
    • + //
    type: CustomerNotificationType; } @@ -1152,7 +1363,8 @@ export enum CustomerNotificationType { /** Type for a event resource. */ export interface Event { - // What has happened to the resource. + // What has happened to the resource. See [Event Actions](#event-actions) for + // the possible actions. action: string; // Fixed [timestamp](#api-usage-time-zones--dates), recording when this @@ -1182,14 +1394,15 @@ export interface Event { // The resource type for this event. One of: //
      - //
    • `payments`
    • + //
    • `billing_requests`
    • + //
    • `creditors`
    • + //
    • `instalment_schedules`
    • //
    • `mandates`
    • //
    • `payer_authorisations`
    • + //
    • `payments`
    • //
    • `payouts`
    • //
    • `refunds`
    • //
    • `subscriptions`
    • - //
    • `instalment_schedules`
    • - //
    • `creditors`
    • //
    resource_type: EventResourceType; } @@ -1203,6 +1416,7 @@ export enum EventInclude { InstalmentSchedule = 'instalment_schedule', Creditor = 'creditor', PayerAuthorisation = 'payer_authorisation', + BillingRequest = 'billing_request', } /** Type for a eventcustomernotification resource. */ @@ -1217,6 +1431,16 @@ export interface EventCustomerNotification { mandatory: boolean; // The type of notification the customer shall receive. + // One of: + //
      + //
    • `payment_created`
    • + //
    • `payment_cancelled`
    • + //
    • `mandate_created`
    • + //
    • `subscription_created`
    • + //
    • `subscription_cancelled`
    • + //
    • `instalment_schedule_created`
    • + //
    • `instalment_schedule_cancelled`
    • + //
    type: EventCustomerNotificationType; } @@ -1372,15 +1596,16 @@ export interface EventLinks { } export enum EventResourceType { + BillingRequests = 'billing_requests', Creditors = 'creditors', InstalmentSchedules = 'instalment_schedules', Mandates = 'mandates', + Organisations = 'organisations', PayerAuthorisations = 'payer_authorisations', Payments = 'payments', Payouts = 'payouts', Refunds = 'refunds', Subscriptions = 'subscriptions', - Organisations = 'organisations', } /** Type for a instalmentschedule resource. */ @@ -1465,7 +1690,9 @@ export interface InstalmentScheduleInstalments { // The date on which the first payment should be charged. Must be on or after // the [mandate](#core-endpoints-mandates)'s `next_possible_charge_date`. When - // blank, this will be set as the mandate's `next_possible_charge_date`. + // left blank and `month` or `day_of_month` are provided, this will be set to + // the date of the first payment. If created without `month` or `day_of_month` + // this will be set as the mandate's `next_possible_charge_date` start_date?: string; } @@ -1581,6 +1808,8 @@ export interface Mandate { //
  • `expired`: the mandate has expired due to dormancy
  • //
  • `consumed`: the mandate has been consumed and cannot be reused (note // that this only applies to schemes that are per-payment authorised)
  • + //
  • `blocked`: the mandate has been blocked and payments cannot be + // created
  • // status: MandateStatus; } @@ -1623,6 +1852,7 @@ export enum MandateStatus { Cancelled = 'cancelled', Expired = 'expired', Consumed = 'consumed', + Blocked = 'blocked', } /** Type for a mandateimport resource. */ @@ -1641,20 +1871,16 @@ export interface MandateImport { // The status of the mandate import. //
      - //
    • New mandate imports report the `created` status.
    • - //
    • When the integrator has finished adding mandates and - // submitted the - // import, the status will report as `submitted`.
    • - //
    • If the integrator decided to - // cancel the mandate - // import, - // the status will report `cancelled`.
    • - //
    • Once a mandate import has been approved by a GoCardless team member, - // the status will - // initially report as `processing` (whilst the mandates are being - // imported).
    • - //
    • When the mandates have all been imported successfully, the status will - // report as `processed`.
    • + //
    • `created`: A new mandate import.
    • + //
    • `submitted`: After the integrator has finished adding mandates and submitted the + // import.
    • + //
    • `cancelled`: If the integrator cancelled the mandate + // import.
    • + //
    • `processing`: Once a mandate import has been approved by a GoCardless + // team member it will be in this state while mandates are imported.
    • + //
    • `processed`: When all mandates have been imported successfully.
    • //
    status: MandateImportStatus; } @@ -2345,14 +2571,14 @@ export interface Payout { // Fees that have already been deducted from the payout amount in minor unit // (e.g. pence in GBP, cents in EUR), inclusive of tax if applicable. - // + //
    // For each `late_failure_settled` or `chargeback_settled` action, we refund // the transaction fees in a payout. This means that a payout can have a // negative `deducted_fees` value. - // + //
    // This field is calculated as `(GoCardless fees + app fees + surcharge fees) // - (refunded fees)` - // + //
    // If the merchant is invoiced for fees separately from the payout, then // `deducted_fees` will be 0. deducted_fees: string; @@ -2908,6 +3134,11 @@ export interface ScenarioSimulator { //
  • `creditor_verification_status_successful`: Sets a creditor's // `verification status` to `successful`, meaning that the creditor is fully // verified and can receive payouts.
  • + //
  • `payment_confirmed`: Transitions a payment through to `confirmed`. It + // must start in the `pending_submission` state, and its mandate must be in + // the `activated` state (unless it is a payment for ACH, BECS, BECS_NZ or + // SEPA, in which cases the mandate may be `pending_submission`, since their + // mandates are submitted with their first payment).
  • //
  • `payment_paid_out`: Transitions a payment through to `paid_out`, having // been collected successfully and paid out to you. It must start in the // `pending_submission` state, and its mandate must be in the `activated` @@ -2962,8 +3193,8 @@ export interface ScenarioSimulator { //
  • `mandate_failed`: Transitions a mandate through to `failed`, having // been submitted to the banks but found to be invalid (for example due to // invalid bank details). It must start in the `pending_submission` or - // `submitted` states. Not compatible with ACH, BECS, BECS_NZ and SEPA - // mandates, which are submitted with their first payment.
  • + // `submitted` states. Not compatible with SEPA mandates, which are submitted + // with their first payment. //
  • `mandate_expired`: Transitions a mandate through to `expired`, having // been submitted to the banks, set up successfully and then expired because // no collection attempts were made against it for longer than the scheme's @@ -2984,29 +3215,35 @@ export interface ScenarioSimulator { // mandates.
  • //
  • `refund_paid`: Transitions a refund to `paid`. It must start in either // the `pending_submission` or `submitted` state.
  • + //
  • `refund_settled`: Transitions a refund to `paid`, if it's not already, + // then generates a payout that includes the refund, thereby settling the + // funds. It must start in one of `pending_submission`, `submitted` or `paid` + // states.
  • //
  • `refund_bounced`: Transitions a refund to `bounced`. It must start in // either the `pending_submission`, `submitted`, or `paid` state.
  • + //
  • `refund_returned`: Transitions a refund to `refund_returned`. The + // refund must start in `pending_submission`.
  • //
  • `payout_bounced`: Transitions a payout to `bounced`. It must start in // the `paid` state.
  • - //
  • `payout_create`: Creates a payout containing payments in `confirmed`, - // `failed` & `charged_back` states; refunds in `submitted` & `bounced`; and - // all related fees. Can only be used with a positive total payout balance and - // when some eligible items exist.
  • + //
  • `billing_request_fulfilled`: Authorises the billing request, fulfils + // it, and moves the associated payment to `failed`. The billing request must + // be in the `pending` state, with all actions completed except for + // `bank_authorisation`. Only billing requests with a `payment_request` are + // supported.
  • + //
  • `billing_request_fulfilled_and_payment_failed`: Authorises the billing + // request, fulfils it, and moves the associated payment to `failed`. The + // billing request must be in the `pending` state, with all actions completed + // except for `bank_authorisation`. Only billing requests with a + // `payment_request` are supported.
  • + //
  • `billing_request_fulfilled_and_payment_paid_out`: Authorises the + // billing request, fulfils it, and moves the associated payment to + // `paid_out`. The billing request must be in the `pending` state, with all + // actions completed except for `bank_authorisation`. Only billing requests + // with a `payment_request` are supported.
  • // id: string; } -export enum ScenarioSimulatorCurrency { - AUD = 'AUD', - CAD = 'CAD', - DKK = 'DKK', - EUR = 'EUR', - GBP = 'GBP', - NZD = 'NZD', - SEK = 'SEK', - USD = 'USD', -} - /** Type for a scenariosimulatorrunrequestlinks resource. */ export interface ScenarioSimulatorRunRequestLinks { // ID of the resource to run the simulation against. @@ -3157,7 +3394,7 @@ export interface Subscription { // created and will appear on your customer's bank statement. See the // documentation for // the [create payment endpoint](#payments-create-a-payment) for more details. - // + //
    //

    Restricted: You need your own // Service User Number to specify a payment reference for Bacs payments.

    payment_reference?: string; @@ -3168,7 +3405,9 @@ export interface Subscription { // The date on which the first payment should be charged. Must be on or after // the [mandate](#core-endpoints-mandates)'s `next_possible_charge_date`. When - // blank, this will be set as the mandate's `next_possible_charge_date`. + // left blank and `month` or `day_of_month` are provided, this will be set to + // the date of the first payment. If created without `month` or `day_of_month` + // this will be set as the mandate's `next_possible_charge_date` start_date?: string; // One of: