fix(payment): expose provider type for named gateways
This commit is contained in:
1 parent
2e770f7e3e
commit
1b470402c7
5 files changed
+8
-1
No files matched your search
@@ -50,6 +50,8 @@ export function validatePaymentConfig(config: PaymentConfig) {
|
|||||||
});
|
});
|
||||||
if (value.provider === "razorpay")
|
if (value.provider === "razorpay")
|
||||||
required(name, { keyId: value.keyId, keySecret: value.keySecret });
|
required(name, { keyId: value.keyId, keySecret: value.keySecret });
|
||||||
|
if (value.provider === "razorpay" && config.environment === "production")
|
||||||
|
required(name, { webhookSecret: value.webhookSecret });
|
||||||
if (value.provider === "paypal")
|
if (value.provider === "paypal")
|
||||||
required(name, {
|
required(name, {
|
||||||
clientId: value.clientId,
|
clientId: value.clientId,
|
||||||
@@ -64,7 +66,7 @@ export function validatePaymentConfig(config: PaymentConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function namedGateway(name: string, gateway: PaymentGateway): PaymentGateway {
|
function namedGateway(name: string, gateway: PaymentGateway): PaymentGateway {
|
||||||
return Object.freeze({ ...gateway, id: name });
|
return Object.freeze({ ...gateway, id: name, provider: gateway.provider ?? gateway.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function paymentOptionsFromConfig(
|
export function paymentOptionsFromConfig(
|
||||||
|
|||||||
@@ -419,6 +419,7 @@ export function definePayment(options: PaymentOptions) {
|
|||||||
providers: () =>
|
providers: () =>
|
||||||
[...adapters.values()].map((adapter) => ({
|
[...adapters.values()].map((adapter) => ({
|
||||||
id: adapter.id,
|
id: adapter.id,
|
||||||
|
provider: adapter.provider ?? adapter.id,
|
||||||
capabilities: adapter.capabilities,
|
capabilities: adapter.capabilities,
|
||||||
supports: adapter.supports,
|
supports: adapter.supports,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ export interface WebhookEvent {
|
|||||||
|
|
||||||
export interface PaymentGateway<TConfig = unknown> {
|
export interface PaymentGateway<TConfig = unknown> {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
/** Built-in provider type when the id is an application-defined gateway alias. */
|
||||||
|
readonly provider?: string;
|
||||||
readonly config?: TConfig;
|
readonly config?: TConfig;
|
||||||
readonly capabilities: GatewayCapabilities;
|
readonly capabilities: GatewayCapabilities;
|
||||||
readonly supports: GatewaySupport;
|
readonly supports: GatewaySupport;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ test("configuration creates any number of named provider gateways", () => {
|
|||||||
|
|
||||||
expect(options.default).toBe("india");
|
expect(options.default).toBe("india");
|
||||||
expect(options.adapters.map((adapter) => adapter.id)).toEqual(["india", "global"]);
|
expect(options.adapters.map((adapter) => adapter.id)).toEqual(["india", "global"]);
|
||||||
|
expect(options.adapters.map((adapter) => adapter.provider)).toEqual(["razorpay", "stripe"]);
|
||||||
expect(options.webhookSecrets).toEqual({ india: "razorpay-hook", global: "stripe-hook" });
|
expect(options.webhookSecrets).toEqual({ india: "razorpay-hook", global: "stripe-hook" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ test("package APIs use server subjects and never expose gateway secrets", async
|
|||||||
const providerBody = await providers.text();
|
const providerBody = await providers.text();
|
||||||
expect(providers.status).toBe(200);
|
expect(providers.status).toBe(200);
|
||||||
expect(providerBody).toContain("testGateway");
|
expect(providerBody).toContain("testGateway");
|
||||||
|
expect(providerBody).toContain('"provider":"sandbox"');
|
||||||
expect(providerBody).not.toContain("server-only");
|
expect(providerBody).not.toContain("server-only");
|
||||||
|
|
||||||
const denied = await POST({
|
const denied = await POST({
|
||||||
|
|||||||
Reference in new issue
Block a user