diff --git a/src/data/payments/Payment.ts b/src/data/payments/Payment.ts index b1c25bb2..b92f9c57 100644 --- a/src/data/payments/Payment.ts +++ b/src/data/payments/Payment.ts @@ -4,6 +4,8 @@ import type Chargeback from '../chargebacks/Chargeback'; import { transform as transformChargeback } from '../chargebacks/Chargeback'; import type Refund from '../refunds/Refund'; import { transform as transformRefund } from '../refunds/Refund'; +import type Capture from './captures/Capture'; +import { transform as transformCapture } from './captures/Capture'; import { type PaymentData } from './data'; import PaymentHelper from './PaymentHelper'; @@ -12,6 +14,7 @@ type Payment = Seal< _embedded?: { refunds?: Refund[]; chargebacks?: Chargeback[]; + captures?: Capture[]; }; }, PaymentHelper @@ -29,6 +32,9 @@ export function transform(networkClient: TransformingNetworkClient, input: Payme if (input._embedded.refunds != undefined) { _embedded.refunds = input._embedded.refunds.map(transformRefund.bind(undefined, networkClient)); } + if (input._embedded.captures != undefined) { + _embedded.captures = input._embedded.captures.map(transformCapture.bind(undefined, networkClient)); + } } return Object.assign(Object.create(new PaymentHelper(networkClient, input._links, _embedded)), input, { _embedded }); } diff --git a/src/data/payments/PaymentHelper.ts b/src/data/payments/PaymentHelper.ts index b071cfe3..348ff121 100644 --- a/src/data/payments/PaymentHelper.ts +++ b/src/data/payments/PaymentHelper.ts @@ -269,7 +269,11 @@ export default class PaymentHelper extends Helper { * @since 3.6.0 */ public getCaptures(parameters?: ThrottlingParameter): HelpfulIterator { - return runIf(this.links.captures, ({ href }) => this.networkClient.iterate(href, 'captures', undefined, parameters?.valuesPerMinute)) ?? emptyHelpfulIterator; + return ( + runIf(this.embedded?.captures, captures => new HelpfulIterator(makeAsync(captures[Symbol.iterator]()))) ?? + runIf(this.links.captures, ({ href }) => this.networkClient.iterate(href, 'captures', undefined, parameters?.valuesPerMinute)) ?? + emptyHelpfulIterator + ); } /** diff --git a/src/data/payments/data.ts b/src/data/payments/data.ts index c7b5df0f..99511b9d 100644 --- a/src/data/payments/data.ts +++ b/src/data/payments/data.ts @@ -3,6 +3,7 @@ import { type ChargebackData } from '../chargebacks/Chargeback'; import { type Address, type Amount, type ApiMode, type CardAudience, type CardFailureReason, type CardLabel, type FeeRegion, type HistoricPaymentMethod, type Links, type Locale, type PaymentMethod, type SequenceType, type Url } from '../global'; import type Model from '../Model'; import { type RefundData } from '../refunds/data'; +import { type CaptureData } from './captures/data' export interface PaymentData extends Model<'payment'> { /** @@ -254,6 +255,7 @@ export interface PaymentData extends Model<'payment'> { _embedded?: { refunds?: Omit[]; chargebacks?: Omit[]; + captures?: Omit[]; }; } @@ -849,6 +851,7 @@ export type PaymentInclude = 'details.qrCode'; export enum PaymentEmbed { refunds = 'refunds', chargebacks = 'chargebacks', + captures = 'captures', } export interface GiftCard {