feat: add gateway-neutral payment package
This commit is contained in:
1 parent
a9670c2a1c
commit
98e0813061
23 files changed
+1902
-6
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import type { PaymentGateway } from "./types.ts";
|
||||
|
||||
export interface GatewayContractReport {
|
||||
ok: boolean;
|
||||
issues: string[];
|
||||
}
|
||||
/** Structural half of the shared adapter suite, usable by third-party adapters in CI. */
|
||||
export function verifyGatewayContract(adapter: PaymentGateway): GatewayContractReport {
|
||||
const issues: string[] = [];
|
||||
const capability = (name: string, declared: boolean, present: boolean) => {
|
||||
if (declared !== present)
|
||||
issues.push(
|
||||
`${adapter.id}: capability '${name}' is ${declared ? "declared but not implemented" : "implemented but not declared"}`,
|
||||
);
|
||||
};
|
||||
capability(
|
||||
"authorizeThenCapture",
|
||||
adapter.capabilities.authorizeThenCapture,
|
||||
typeof adapter.capture === "function",
|
||||
);
|
||||
capability(
|
||||
"storedMethods",
|
||||
adapter.capabilities.storedMethods,
|
||||
typeof adapter.listMethods === "function" &&
|
||||
typeof adapter.attachMethod === "function" &&
|
||||
typeof adapter.detachMethod === "function",
|
||||
);
|
||||
capability(
|
||||
"customerVault",
|
||||
adapter.capabilities.customerVault,
|
||||
typeof adapter.createCustomer === "function",
|
||||
);
|
||||
if (!adapter.capabilities.hostedFields && !adapter.capabilities.hostedCheckout)
|
||||
issues.push(`${adapter.id}: a hosted payment surface is required`);
|
||||
if (!adapter.capabilities.webhookSignature)
|
||||
issues.push(`${adapter.id}: signed webhooks are required`);
|
||||
return { ok: issues.length === 0, issues };
|
||||
}
|
||||
Reference in new issue
Block a user