Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
import test from 'node:test';import assert from 'node:assert/strict';
import {fixtureRequirements,normalizeImportedMerchants,verifyImportedMerchants,importFingerprint} from '../server/fixture-import.mjs';
const config={environment:'local',services:{router:'http://router',modular_pm:'http://pm/v2'},fixtures:{admin_api_key:'admin'},scenarios:[{scenario:'guest_payment',merchant_path:'modular',weight:100}],connectors:{mode:'real',mix:[{connector:'stripe',weight:100}]}};
const merchant={merchant_id:'merchant_1',profile_id:'pro_1',api_key:'secret-one',publishable_key:'pk_1',connector_accounts:{stripe:'mca_1'}};
const account={merchant_connector_id:'mca_1',connector_name:'stripe',profile_id:'pro_1',disabled:false,payment_methods_enabled:[{payment_method:'card',payment_method_types:[{payment_method_type:'credit',recurring_enabled:true}]}]};
function fetcher({connector=account,key='secret-one',pk='pk_1',profile='pro_1'}={}){return async(url,options)=>{
assert.equal(options.redirect,'manual');
if(url.endsWith('/connectors'))return options.headers['api-key']===key?Response.json([connector]):Response.json({error:'secret response MUST NOT escape'},{status:401});
if(url.includes('/business_profile/')){assert.equal(options.headers['api-key'],'secret-one');return Response.json({merchant_id:'merchant_1',profile_id:profile});}
return Response.json({merchant_id:'merchant_1',publishable_key:pk});
};}
test('valid imported merchant verifies read-only keys, profile and selected connector',async()=>{const result=await verifyImportedMerchants(config,[merchant],{fetcher:fetcher()});assert.equal(result.ok,true);assert.equal(result.checks.length,4);assert.ok(!JSON.stringify(result).includes('secret-one'));});
test('rejected API key and connector setup have separate actionable results without raw bodies',async()=>{const result=await verifyImportedMerchants(config,[merchant],{fetcher:fetcher({key:'other'})});assert.equal(result.ok,false);assert.match(result.checks[0].message,/401/);assert.ok(result.checks.every(c=>c.stage==='credentials'));assert.equal(result.stages.setup.status,'blocked');assert.ok(!JSON.stringify(result).includes('MUST NOT escape'));});
test('wrong publishable key, wrong profile and disabled connector fail independently',async()=>{const result=await verifyImportedMerchants(config,[merchant],{fetcher:fetcher({pk:'other',profile:'pro_other',connector:{...account,disabled:true}})});assert.equal(result.checks.filter(c=>!c.ok).length,2);});
test('connector account must match selected connector, profile, and enabled card configuration',async()=>{for(const changed of [{connector_name:'adyen'},{profile_id:'other'},{payment_methods_enabled:[]}]){const result=await verifyImportedMerchants(config,[merchant],{fetcher:fetcher({connector:{...account,...changed}})});assert.equal(result.checks.at(-1).ok,false);}});
test('import validates count, identities, duplicates and secrets; required publishable key is flow-dependent',()=>{assert.equal(normalizeImportedMerchants([merchant],1).length,1);assert.throws(()=>normalizeImportedMerchants([merchant],2),/exactly/);assert.throws(()=>normalizeImportedMerchants([merchant,merchant],2),/duplicate/);assert.throws(()=>normalizeImportedMerchants([{...merchant,api_key:'bad\nkey'}],1),/invalid/);assert.equal(fixtureRequirements(config).publishableKey,true);assert.equal(fixtureRequirements({...config,scenarios:[{scenario:'guest_payment',merchant_path:'legacy',weight:100}]}).publishableKey,false);});
test('verification fingerprint changes with credentials, destination and scenario requirements',()=>{const first=importFingerprint(config,[merchant]);for(const changed of [{...config,services:{...config.services,router:'http://other'}},{...config,environment:'gcp'},{...config,connectors:{mode:'real',mix:[{connector:'adyen',weight:100}]}}])assert.notEqual(importFingerprint(changed,[merchant]),first);assert.notEqual(importFingerprint(config,[{...merchant,api_key:'rotated'}]),first);});
test('aborted verification does not continue inspecting merchants',async()=>{const abort=new AbortController();abort.abort();await assert.rejects(verifyImportedMerchants(config,[merchant],{fetcher:fetcher(),signal:abort.signal}),/abort/i);});
test('recurring capability is required only for flows that need it',async()=>{const connector={...account,payment_methods_enabled:[{payment_method:'card',payment_method_types:[{payment_method_type:'credit',recurring_enabled:false}]}]};assert.equal((await verifyImportedMerchants(config,[merchant],{fetcher:fetcher({connector})})).ok,true);assert.equal((await verifyImportedMerchants({...config,scenarios:[{scenario:'cit_off_session',merchant_path:'modular',weight:100}]},[merchant],{fetcher:fetcher({connector})})).checks.at(-1).ok,false);});
test('bulk verification bounds concurrent inspections to four merchants',async()=>{let active=0,peak=0;const rows=Array.from({length:8},(_,i)=>({...merchant,merchant_id:`merchant_${i}`}));const result=await verifyImportedMerchants(config,rows,{fetcher:async(url,options)=>{active++;peak=Math.max(peak,active);await new Promise(r=>setTimeout(r,2));active--;const mid=url.match(/(?:account|accounts)\/(merchant_\d+)/)?.[1];if(url.endsWith('/connectors'))return Response.json([account]);if(url.includes('/business_profile/'))return Response.json({merchant_id:mid,profile_id:'pro_1'});return Response.json({merchant_id:mid,publishable_key:'pk_1'});}});assert.equal(result.ok,true);assert.equal(result.checks.length,32);assert.ok(peak>1&&peak<=4);});
test('progress reports real ordered credential and setup stages with completed counts',async()=>{const updates=[];await verifyImportedMerchants(config,[merchant],{fetcher:fetcher(),onProgress:(checks,state)=>updates.push(structuredClone(state))});assert.equal(updates[0].phase,'credentials');const setup=updates.find(v=>v.phase==='setup');assert.equal(setup.stages.credentials.status,'passed');assert.equal(setup.stages.credentials.completed,3);assert.equal(setup.stages.setup.completed,0);assert.equal(updates.at(-1).phase,'saving');assert.equal(updates.at(-1).stages.setup.completed,1);});
test('credential failure blocks connector validation for the entire import',async()=>{const result=await verifyImportedMerchants(config,[merchant],{fetcher:fetcher({pk:'wrong'})});assert.equal(result.phase,'failed');assert.equal(result.stages.setup.status,'blocked');assert.equal(result.stages.setup.completed,0);assert.ok(result.checks.every(c=>c.stage==='credentials'));});
test('cancellation at stage transition never runs connector validation',async()=>{const abort=new AbortController();await assert.rejects(verifyImportedMerchants(config,[merchant],{fetcher:fetcher(),signal:abort.signal,onProgress:(_,state)=>{if(state.phase==='setup')abort.abort();}}),/abort/i);});