Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/classes/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ export class ChargilyClient {
);
}

// require either a non-empty items array or both amount and currency, This prevents empty items arrays from bypassing validation.
const hasItems =
Array.isArray(checkout_data.items) &&
checkout_data.items.length > 0;

const hasAmountAndCurrency =
typeof checkout_data.amount === 'number' &&
typeof checkout_data.currency === 'string';

if (!hasItems && !hasAmountAndCurrency) {
throw new Error(
'Either a non-empty items array or both amount and currency must be provided.'
);
}
return this.request('checkouts', 'POST', checkout_data);
}

Expand Down