Merge pull request #553 from Tria-plc/alpha

Alpha
This commit is contained in:
Abubeker Yasin
2026-07-08 23:20:45 +03:00
committed by GitHub
3 changed files with 32 additions and 6 deletions

View File

@@ -338,7 +338,14 @@ export class PaymentsService {
};
return this.prisma.paymentIntent.upsert({
where: { bookingId },
update: data,
// amountMinor/currency are refreshed on update too: a cross-currency method switch
// (e.g. Waafi/USD → Telebirr/ETB) re-initiates over the same row, and the projection
// must reflect the currency the new provider actually charges — not the first one's.
update: {
...data,
amountMinor: snapshot.amountMinor,
currency: snapshot.currency,
},
create: {
bookingId,
amountMinor: snapshot.amountMinor,

View File

@@ -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);

View File

@@ -45,9 +45,9 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
return {
CAC_BASE_URL: this.baseUrl || "(empty)",
CAC_USERNAME: this.username || "(empty)",
CAC_PASSWORD: this.mask(this.password),
CAC_APP_KEY: this.mask(this.appKey),
CAC_API_KEY: this.mask(this.apiKey),
CAC_PASSWORD: this.password,
CAC_APP_KEY: this.appKey,
CAC_API_KEY: this.apiKey,
CAC_COMPANY_SERVICES_ID: this.companyServicesId,
CAC_CURRENCY: this.defaultCurrency,
CAC_TOKEN_TTL_MS: this.tokenTtlMs,