function regularPaymentFieldsFromAuthorisation()

in support-frontend/assets/helpers/forms/paymentIntegrations/readerRevenueApis.ts [248:300]


function regularPaymentFieldsFromAuthorisation(
	authorisation: PaymentAuthorisation,
	stripePublicKey: string,
	recaptchaToken: string,
): RegularPaymentFields {
	switch (authorisation.paymentMethod) {
		case Stripe:
			if (authorisation.paymentMethodId) {
				return {
					paymentType: Stripe,
					paymentMethod: authorisation.paymentMethodId,
					stripePaymentType: authorisation.stripePaymentMethod,
					stripePublicKey: stripePublicKey,
				};
			}

			throw new Error(
				'Neither token nor paymentMethod found in authorisation data for Stripe recurring contribution',
			);

		case PayPal:
			return {
				paymentType: PayPal,
				baid: authorisation.token,
			};

		case DirectDebit:
			return {
				paymentType: DirectDebit,
				accountHolderName: authorisation.accountHolderName,
				sortCode: authorisation.sortCode,
				accountNumber: authorisation.accountNumber,
				recaptchaToken,
			};

		case Sepa:
			if (authorisation.country && authorisation.streetName) {
				return {
					paymentType: Sepa,
					accountHolderName: authorisation.accountHolderName,
					iban: authorisation.iban.replace(/ /g, ''),
					country: authorisation.country,
					streetName: authorisation.streetName,
				};
			} else {
				return {
					paymentType: Sepa,
					accountHolderName: authorisation.accountHolderName,
					iban: authorisation.iban.replace(/ /g, ''),
				};
			}
	}
}