mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 10:10:57 +00:00
feat: dev and staging bypass
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
IntentStatusDto,
|
||||
PaymentPlatformDto,
|
||||
} from "./payments.dto";
|
||||
import { isBypassEnv } from "../../common/dev-bypass.util";
|
||||
|
||||
/** Everything the gateway needs to open an intent. Amount/currency are supplied by
|
||||
* the caller (billing) — this service never derives them from a domain record. */
|
||||
@@ -256,34 +257,52 @@ export class PaymentService {
|
||||
);
|
||||
}
|
||||
|
||||
const snapshot = await this.paymentClient.initiate({
|
||||
service: PaymentServiceEnum.FREIGHT,
|
||||
referenceType: PaymentReferenceType.SHIPMENT,
|
||||
referenceId: input.referenceId,
|
||||
orderRef: input.orderRef,
|
||||
// CBE_BILL must carry the REAL amount: /cbe/payment verifies what the customer was
|
||||
// debited against the intent amount, so the dev shortcut would break it.
|
||||
// CAC bank rejects amounts below 10 (DJF bounds 10–100,000), so its dev
|
||||
// shortcut floor is 10, not 1.
|
||||
// amountMinor: isCbeBill
|
||||
// ? input.amountMinor
|
||||
// : input.method === ProviderMethod.CAC_BANK
|
||||
// ? 10
|
||||
// : 1,
|
||||
amountMinor: input.amountMinor,
|
||||
currency: input.currency,
|
||||
provider: input.method as ProviderMethod,
|
||||
platform: input.platform,
|
||||
payerAccount: input.payerAccount,
|
||||
payerName: input.payerName,
|
||||
expiresAt: input.expiresAt,
|
||||
// bookingId lets the success page ack the redirect (→ PAYMENT_PROCESSING).
|
||||
returnUrl:
|
||||
input.returnUrl ??
|
||||
`https://edrfreight.triaplc.com/payment/success?bookingId=${encodeURIComponent(input.referenceId)}`,
|
||||
failureUrl:
|
||||
input.failureUrl ?? "https://edrfreight.triaplc.com/payment/failure",
|
||||
});
|
||||
// Dev/staging only: skip the real gateway call entirely and report an
|
||||
// immediate SUCCEEDED snapshot — everything below (upsert, settle,
|
||||
// billing notify) runs exactly as it would for a real synchronous
|
||||
// provider success.
|
||||
const snapshot: PaymentIntentSnapshot = isBypassEnv()
|
||||
? {
|
||||
intentId: `bypass-${input.referenceId}`,
|
||||
service: PaymentServiceEnum.FREIGHT,
|
||||
referenceType: PaymentReferenceType.SHIPMENT,
|
||||
referenceId: input.referenceId,
|
||||
merchantOrderId: input.orderRef,
|
||||
provider: input.method as ProviderMethod,
|
||||
status: ProviderPaymentStatus.SUCCEEDED,
|
||||
amountMinor: input.amountMinor,
|
||||
currency: input.currency,
|
||||
providerTxnId: `bypass-${input.referenceId}`,
|
||||
paidAt: new Date().toISOString(),
|
||||
}
|
||||
: await this.paymentClient.initiate({
|
||||
service: PaymentServiceEnum.FREIGHT,
|
||||
referenceType: PaymentReferenceType.SHIPMENT,
|
||||
referenceId: input.referenceId,
|
||||
orderRef: input.orderRef,
|
||||
// CBE_BILL must carry the REAL amount: /cbe/payment verifies what the customer was
|
||||
// debited against the intent amount, so the dev shortcut would break it.
|
||||
// CAC bank rejects amounts below 10 (DJF bounds 10–100,000), so its dev
|
||||
// shortcut floor is 10, not 1.
|
||||
// amountMinor: isCbeBill
|
||||
// ? input.amountMinor
|
||||
// : input.method === ProviderMethod.CAC_BANK
|
||||
// ? 10
|
||||
// : 1,
|
||||
amountMinor: input.amountMinor,
|
||||
currency: input.currency,
|
||||
provider: input.method as ProviderMethod,
|
||||
platform: input.platform,
|
||||
payerAccount: input.payerAccount,
|
||||
payerName: input.payerName,
|
||||
expiresAt: input.expiresAt,
|
||||
// bookingId lets the success page ack the redirect (→ PAYMENT_PROCESSING).
|
||||
returnUrl:
|
||||
input.returnUrl ??
|
||||
`https://edrfreight.triaplc.com/payment/success?bookingId=${encodeURIComponent(input.referenceId)}`,
|
||||
failureUrl:
|
||||
input.failureUrl ?? "https://edrfreight.triaplc.com/payment/failure",
|
||||
});
|
||||
|
||||
const immediateSuccess =
|
||||
snapshot.status === ProviderPaymentStatus.SUCCEEDED;
|
||||
|
||||
Reference in New Issue
Block a user