88if (application .environment eq " dev" ) {
99
1010 cfhttp ( url = variables .payrexxWebhookDev , result = " httpRes" , method = " GET" ) {}
11-
1211 if (isJSON (httpRes .filecontent )) {
1312 jsonData = deSerializeJSON (httpRes .filecontent );
1413 } else {
@@ -34,12 +33,17 @@ if (application.environment eq "dev") {
3433 }
3534
3635 jsonData = getHttpRequestData ().content ;
36+ if (! isJSON (jsonData )) {
37+ logWrite (" payrexx" , " warning" , " jsonData is not of type JSON!" );
38+ abort ;
39+ }
40+
3741 jsonData = deSerializeJSON (jsonData );
3842
3943}
4044
4145
42- if (structKeyExists (jsonData , " transaction" )) {
46+ if (isStruct ( jsonData ) and structKeyExists (jsonData , " transaction" )) {
4347
4448 webhookData = jsonData .transaction ;
4549
@@ -64,128 +68,135 @@ if (structKeyExists(jsonData, "transaction")) {
6468 customerID = listFirst (webhookData .referenceId , " @" );
6569 projectName = listLast (webhookData .referenceId , " @" );
6670 }
67- if (structKeyExists (webhookData , " id" )) {
68- internTransID = webhookData .id ;
69- }
70- if (structKeyExists (webhookData , " invoice" )) {
71- invoiceData = webhookData .invoice ;
72- if (structKeyExists (invoiceData , " paymentRequestId" ) and isNumeric (invoiceData .paymentRequestId )) {
73- gatewayID = invoiceData .paymentRequestId ;
71+
72+ if (isNumeric (customerID ) and customerID gt 0 ) {
73+
74+ if (structKeyExists (webhookData , " id" )) {
75+ internTransID = webhookData .id ;
7476 }
75- }
76- if (structKeyExists (webhookData , " amount" ) and isNumeric (webhookData .amount ) and webhookData .amount gt 0 ) {
77- paymentAmount = numberFormat (webhookData .amount / 100 , " __.__" );
78- }
79- if (structKeyExists (webhookData , " time" ) and isDate (webhookData .time )) {
80- objTime = new backend .core .com .time ();
81- dateTime = objTime .local2utc (webhookData .time , " Europe/Zurich" );
82- }
83- if (structKeyExists (webhookData , " status" )) {
84- status = webhookData .status ;
85- }
86- if (structKeyExists (webhookData , " lang" )) {
87- language = webhookData .lang ;
88- }
89- if (structKeyExists (webhookData , " psp" )) {
90- serviceProvider = webhookData .psp ;
91- }
92- if (structKeyExists (webhookData , " pspId" ) and isNumeric (webhookData .pspId ) and webhookData .pspId gt 0 ) {
93- serviceProviderID = webhookData .pspId ;
94- }
95- if (structKeyExists (webhookData , " payrexxFee" ) and isNumeric (webhookData .pspId ) and webhookData .pspId gt 0 ) {
96- payrexxFee = numberFormat (webhookData .payrexxFee / 100 , " __.__" );
97- }
98- if (structKeyExists (webhookData , " payment" )) {
99- if (structKeyExists (webhookData .payment , " brand" )) {
100- paymentBrand = webhookData .payment .brand ;
101- paymentBrand = left (uCase (paymentBrand ), 1 ) & right (paymentBrand , len (paymentBrand ) - 1 );
77+ if (structKeyExists (webhookData , " invoice" )) {
78+ invoiceData = webhookData .invoice ;
79+ if (structKeyExists (invoiceData , " paymentRequestId" ) and isNumeric (invoiceData .paymentRequestId )) {
80+ gatewayID = invoiceData .paymentRequestId ;
81+ }
10282 }
103- if (structKeyExists (webhookData .payment , " cardNumber" )) {
104- cardNumber = webhookData .payment .cardNumber ;
83+ if (structKeyExists (webhookData , " amount" ) and isNumeric (webhookData .amount ) and webhookData .amount gt 0 ) {
84+ paymentAmount = numberFormat (webhookData .amount / 100 , " _.__" );
85+ }
86+ if (structKeyExists (webhookData , " time" ) and isDate (webhookData .time )) {
87+ objTime = new backend .core .com .time ();
88+ dateTime = objTime .local2utc (webhookData .time , " Europe/Zurich" );
89+ }
90+ if (structKeyExists (webhookData , " status" )) {
91+ status = webhookData .status ;
92+ }
93+ if (structKeyExists (webhookData , " lang" )) {
94+ language = webhookData .lang ;
95+ }
96+ if (structKeyExists (webhookData , " psp" )) {
97+ serviceProvider = webhookData .psp ;
98+ }
99+ if (structKeyExists (webhookData , " pspId" ) and isNumeric (webhookData .pspId ) and webhookData .pspId gt 0 ) {
100+ serviceProviderID = webhookData .pspId ;
101+ }
102+ if (structKeyExists (webhookData , " payrexxFee" ) and isNumeric (webhookData .pspId ) and webhookData .pspId gt 0 ) {
103+ payrexxFee = numberFormat (webhookData .payrexxFee / 100 , " _.__" );
104+ }
105+ if (structKeyExists (webhookData , " payment" )) {
106+ if (structKeyExists (webhookData .payment , " brand" )) {
107+ paymentBrand = webhookData .payment .brand ;
108+ paymentBrand = left (uCase (paymentBrand ), 1 ) & right (paymentBrand , len (paymentBrand ) - 1 );
109+ }
110+ if (structKeyExists (webhookData .payment , " cardNumber" )) {
111+ cardNumber = webhookData .payment .cardNumber ;
112+ }
105113 }
106- }
107114
108- // Is there already a default payment method?
109- getWebhook = new backend .core .com .payrexx ().getWebhook (customerID , ' authorized' , 1 );
110- if (getWebhook .recordCount ) {
111- default = 0 ;
112- } else {
113- default = 1 ;
114- }
115+ // Is there already a default payment method?
116+ getWebhook = new backend .core .com .payrexx ().getWebhook (customerID , ' authorized' , 1 );
117+ if (getWebhook .recordCount ) {
118+ default = 0 ;
119+ } else {
120+ default = 1 ;
121+ }
115122
116- // Insert only if it's the correct webhook
117- if (projectName eq variables .applicationname ) {
118-
119- try {
120-
121- queryExecute (
122-
123- options = {datasource = application .datasource },
124- params = {
125- customerID : {type : " numeric" , value : customerID },
126- transID : {type : " numeric" , value : internTransID },
127- gatewayID : {type : " numeric" , value : gatewayID },
128- paymentAmount : {type : " decimal" , value : paymentAmount , scale : 2 },
129- dateTime : {type : " datetime" , value : dateTime },
130- status : {type : " varchar" , value : status },
131- language : {type : " varchar" , value : language },
132- serviceProvider : {type : " varchar" , value : serviceProvider },
133- serviceProviderID : {type : " numeric" , value : serviceProviderID },
134- payrexxFee : {type : " decimal" , value : payrexxFee , scale : 2 },
135- paymentBrand : {type : " nvarchar" , value : paymentBrand },
136- cardNumber : {type : " varchar" , value : cardNumber },
137- default : {type : " boolean" , value : default }
138- },
139- sql = "
140- INSERT INTO payrexx
141- (
142- intCustomerID,
143- dtmTimeUTC,
144- intGatewayID,
145- intTransactionID,
146- strStatus,
147- strLanguage,
148- strPSP,
149- intPSPID,
150- decAmount,
151- decPayrexxFee,
152- strPaymentBrand,
153- strCardNumber,
154- blnDefault
155- )
156- VALUES (
157- :customerID,
158- :dateTime,
159- :gatewayID,
160- :transID,
161- :status,
162- :language,
163- :serviceProvider,
164- :serviceProviderID,
165- :paymentAmount,
166- :payrexxFee,
167- :paymentBrand,
168- :cardNumber,
169- :default
170- )
171-
172- "
173- )
174-
175- logWrite (" payrexx" , " info" , " Webhook data successfully saved [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #]" );
176-
177-
178- } catch (any e ) {
179-
180- logWrite (" payrexx" , " error" , " Could not insert the webhook data into the payrexx table. [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #, Error: #e .message #]" , true );
123+ // Insert only if it's the correct webhook
124+ if (projectName eq variables .applicationname ) {
125+
126+ try {
127+
128+ queryExecute (
129+
130+ options = {datasource = application .datasource },
131+ params = {
132+ customerID : {type : " numeric" , value : customerID },
133+ transID : {type : " numeric" , value : internTransID },
134+ gatewayID : {type : " numeric" , value : gatewayID },
135+ paymentAmount : {type : " decimal" , value : paymentAmount , scale : 2 },
136+ dateTime : {type : " datetime" , value : dateTime },
137+ status : {type : " varchar" , value : status },
138+ language : {type : " varchar" , value : language },
139+ serviceProvider : {type : " varchar" , value : serviceProvider },
140+ serviceProviderID : {type : " numeric" , value : serviceProviderID },
141+ payrexxFee : {type : " decimal" , value : payrexxFee , scale : 2 },
142+ paymentBrand : {type : " nvarchar" , value : paymentBrand },
143+ cardNumber : {type : " varchar" , value : cardNumber },
144+ default : {type : " boolean" , value : default }
145+ },
146+ sql = "
147+ INSERT INTO payrexx
148+ (
149+ intCustomerID,
150+ dtmTimeUTC,
151+ intGatewayID,
152+ intTransactionID,
153+ strStatus,
154+ strLanguage,
155+ strPSP,
156+ intPSPID,
157+ decAmount,
158+ decPayrexxFee,
159+ strPaymentBrand,
160+ strCardNumber,
161+ blnDefault
162+ )
163+ VALUES (
164+ :customerID,
165+ :dateTime,
166+ :gatewayID,
167+ :transID,
168+ :status,
169+ :language,
170+ :serviceProvider,
171+ :serviceProviderID,
172+ :paymentAmount,
173+ :payrexxFee,
174+ :paymentBrand,
175+ :cardNumber,
176+ :default
177+ )
178+
179+ "
180+ )
181+
182+ logWrite (" payrexx" , " info" , " Webhook data successfully saved [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #]" );
183+
184+
185+ } catch (any e ) {
186+
187+ logWrite (" payrexx" , " error" , " Could not insert the webhook data into the payrexx table. [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #, Error: #e .message #]" , true );
188+
189+ }
190+
191+ } else {
192+
193+ logWrite (" payrexx" , " warning" , " Webhook could not be inserted because the application name does not match the project name. [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #, projectName: #projectName #, applicationName: #variables .applicationname #]" );
181194
182195 }
183196
184- } else {
197+ }
185198
186- logWrite (" payrexx" , " warning" , " Webhook could not be inserted because the application name does not match the project name. [CustomerID: #customerID #, TransactionID: #internTransID #, Payment: #paymentAmount #, projectName: #projectName #, applicationName: #variables .applicationname #]" );
187199
188- }
189200
190201 } else {
191202
0 commit comments