@@ -26,7 +26,6 @@ import {
2626 picklist ,
2727 pipe ,
2828 regex ,
29- safeParse ,
3029 string ,
3130 transform ,
3231 tuple ,
@@ -668,59 +667,37 @@ export const collectors: Address[] = (
668667 } [ chain . id ] ?? [ "0xDb90CDB64CfF03f254e4015C4F705C3F3C834400" ]
669668) . map ( ( address ) => parse ( Address , address ) ) ;
670669
671- const declineMessages : Record < string , string > = {
672- "account credit limit exceeded" : "transaction declined" ,
673- "block atm (mcc 6011) transaction exceeding 250.00 usd" : "atm limit reached. maximum 250 usd per transaction." ,
674- "blocked merchant" : "this merchant is not accepted" ,
675- "blocked mcc" : "this merchant is not accepted" ,
676- "card canceled" : "card canceled" ,
677- "card not activated" : "card not active" ,
678- "card spending limit exceeded" : "card limit exceeded" ,
679- "cvv mismatch" : "transaction declined" ,
680- "cvv2 match fail" : "transaction declined" ,
681- "expiry mismatch" : "transaction declined" ,
682- frozencard : "frozen card" , // cspell:ignore frozencard
683- "frozen card" : "frozen card" ,
684- insufficientaccountliquidity : "insufficient funds" , // cspell:ignore insufficientaccountliquidity
685- insufficient_funds : "insufficient funds" ,
686- "invalid pin" : "invalid pin" ,
687- "invalid pin attempt limit exceeded" : "too many invalid pin attempts" ,
688- merchant_blocked : "this merchant is not accepted" ,
689- "triggers for transactions from mcc 6050 and 6051" : "this merchant is not accepted" ,
690- "webhook declined" : "transaction declined" ,
691- } as const ;
692- const declinePatterns = [
693- [ "advertising services (mcc 7311) transaction velocity limit reached" , "advertising limit reached" ] ,
694- [ "atm (mcc 6011) transaction velocity limit reached" , "atm limit reached" ] ,
695- [ "automatic fuel dispenser velocity limit reached" , "fuel limit reached" ] ,
696- ] as const ;
697-
698- export function decline ( reason ?: null | string ) {
699- if ( ! reason ) return ;
700- const normalized = reason . toLowerCase ( ) ;
701- const message = declineMessages [ normalized ] ?? declinePatterns . find ( ( [ pattern ] ) => normalized . includes ( pattern ) ) ?. [ 1 ] ;
702- return { matched : message !== undefined , message : message ?? reason } ;
703- }
704-
705- export function requestedDeclineReason ( payload : unknown ) {
706- const parsed = safeParse (
707- object ( {
708- bodies : array (
709- looseObject ( {
710- action : string ( ) ,
711- body : looseObject ( { spend : looseObject ( { declinedReason : nullish ( string ( ) ) } ) } ) ,
712- reason : optional ( string ( ) ) ,
713- status : optional ( string ( ) ) ,
714- } ) ,
715- ) ,
716- } ) ,
717- payload ,
718- ) ;
719- if ( ! parsed . success ) return ;
720- const requested = parsed . output . bodies . findLast (
721- ( { action, status } ) => action === "requested" && status === "declined" ,
722- ) ;
723- return requested ?. body . spend . declinedReason ?? requested ?. reason ;
670+ export function declineMessage ( reason ?: null | string ) {
671+ return reason
672+ ? ( {
673+ "account credit limit exceeded" : "transaction declined" ,
674+ "block atm (mcc 6011) transaction exceeding 250.00 usd" : "atm limit reached. maximum 250 usd per transaction." ,
675+ "blocked merchant" : "this merchant is not accepted" ,
676+ "blocked mcc" : "this merchant is not accepted" ,
677+ "card canceled" : "card canceled" ,
678+ "card not activated" : "card not active" ,
679+ "card spending limit exceeded" : "card limit exceeded" ,
680+ "cvv mismatch" : "transaction declined" ,
681+ "cvv2 match fail" : "transaction declined" ,
682+ "expiry mismatch" : "transaction declined" ,
683+ frozencard : "frozen card" , // cspell:ignore frozencard
684+ "frozen card" : "frozen card" ,
685+ insufficientaccountliquidity : "insufficient funds" , // cspell:ignore insufficientaccountliquidity
686+ insufficient_funds : "insufficient funds" ,
687+ "invalid pin" : "invalid pin" ,
688+ "invalid pin attempt limit exceeded" : "too many invalid pin attempts" ,
689+ merchant_blocked : "this merchant is not accepted" ,
690+ "triggers for transactions from mcc 6050 and 6051" : "this merchant is not accepted" ,
691+ "webhook declined" : "transaction declined" ,
692+ } [ reason . toLowerCase ( ) ] ??
693+ (
694+ [
695+ [ "advertising services (mcc 7311) transaction velocity limit reached" , "advertising limit reached" ] ,
696+ [ "atm (mcc 6011) transaction velocity limit reached" , "atm limit reached" ] ,
697+ [ "automatic fuel dispenser velocity limit reached" , "fuel limit reached" ] ,
698+ ] as const
699+ ) . find ( ( [ pattern ] ) => reason . toLowerCase ( ) . includes ( pattern ) ) ?. [ 1 ] )
700+ : undefined ;
724701}
725702
726703// TODO remove code below
0 commit comments