mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
feat: ( payment ) add changing payment for booking
This commit is contained in:
@@ -77,8 +77,27 @@ export class IntentsService {
|
||||
request.referenceId,
|
||||
);
|
||||
if (existing) {
|
||||
const reusable = await this.reuseOrRetire(existing);
|
||||
if (reusable) return this.toSnapshot(reusable);
|
||||
// Payer switched method (e.g. Waafi → Telebirr) on an uncharged session: retire the
|
||||
// open intent and fall through to open a fresh one for the new provider. Only safe
|
||||
// while REQUIRES_ACTION — PROCESSING/SUCCEEDED intents may have money in flight, so
|
||||
// they keep the reuse path (the switch is silently refused until they resolve).
|
||||
const switchingProvider =
|
||||
existing.provider !== request.provider &&
|
||||
existing.status === ProviderPaymentStatus.REQUIRES_ACTION;
|
||||
if (switchingProvider) {
|
||||
await this.intentsRepository.update(existing.id, {
|
||||
status: ProviderPaymentStatus.CANCELLED,
|
||||
failureCode: "METHOD_CHANGED",
|
||||
failureMessage: `Payer switched from ${existing.provider} to ${request.provider}`,
|
||||
});
|
||||
this.logger.log(
|
||||
`intent ${existing.id} retired (METHOD_CHANGED ${existing.provider} → ${request.provider}) for ` +
|
||||
`${request.service}/${request.referenceType}/${request.referenceId}`,
|
||||
);
|
||||
} else {
|
||||
const reusable = await this.reuseOrRetire(existing);
|
||||
if (reusable) return this.toSnapshot(reusable);
|
||||
}
|
||||
}
|
||||
|
||||
const provider = this.providers.get(request.provider);
|
||||
|
||||
Reference in New Issue
Block a user