From 20bf7759b4c784992ab1b23af1326a05362e355e Mon Sep 17 00:00:00 2001 From: Joost ten Kattelaar <87014147+JoostMollie@users.noreply.github.com> Date: Fri, 8 Sep 2023 11:00:08 +0200 Subject: [PATCH 1/4] Added captures as embedded objects to payment --- src/data/payments/data.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/data/payments/data.ts b/src/data/payments/data.ts index c7b5df0f..ec35c519 100644 --- a/src/data/payments/data.ts +++ b/src/data/payments/data.ts @@ -254,6 +254,7 @@ export interface PaymentData extends Model<'payment'> { _embedded?: { refunds?: Omit[]; chargebacks?: Omit[]; + captures?: Omit[]; }; } @@ -849,6 +850,7 @@ export type PaymentInclude = 'details.qrCode'; export enum PaymentEmbed { refunds = 'refunds', chargebacks = 'chargebacks', + captures = 'captures', } export interface GiftCard { From 18b1e872b9cc4def20b6b750eb1d1ff6d4d6857b Mon Sep 17 00:00:00 2001 From: Joost ten Kattelaar <87014147+JoostMollie@users.noreply.github.com> Date: Fri, 8 Sep 2023 11:09:35 +0200 Subject: [PATCH 2/4] Added import for CaptureData --- src/data/payments/data.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/payments/data.ts b/src/data/payments/data.ts index ec35c519..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'> { /** From 88deca68930525b3082dbaeed19ffd6029565f5b Mon Sep 17 00:00:00 2001 From: "Pimm \"de Chinchilla\" Hogeling" Date: Wed, 20 Sep 2023 23:05:25 +0200 Subject: [PATCH 3/4] Add Payment._embedded.captures (to reflect PaymentData._embedded.captures). --- src/data/payments/Payment.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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 }); } From 81de71c101dbad6ccb50c03bf1f9579c48b72fab Mon Sep 17 00:00:00 2001 From: "Pimm \"de Chinchilla\" Hogeling" Date: Wed, 20 Sep 2023 23:06:04 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Use=20embedded=20captures=20=E2=80=92=20if?= =?UTF-8?q?=20present=20=E2=80=92=20in=20payment.getCaptures.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/payments/PaymentHelper.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 + ); } /**