@@ -1170,32 +1170,45 @@ Cypress.Commands.add(
1170
1170
} ) . then ( ( response ) => {
1171
1171
logRequestId ( response . headers [ "x-request-id" ] ) ;
1172
1172
expect ( response . headers [ "content-type" ] ) . to . include ( "application/json" ) ;
1173
- globalState . set ( "paymentID" , response . body . payment_id ) ;
1174
- if ( response . body . capture_method === "automatic" ) {
1175
- if ( response . body . authentication_type === "three_ds" ) {
1176
- expect ( response . body )
1177
- . to . have . property ( "next_action" )
1178
- . to . have . property ( "redirect_to_url" ) ;
1179
- const nextActionUrl = response . body . next_action . redirect_to_url ;
1180
- cy . log ( nextActionUrl ) ;
1181
- } else if ( response . body . authentication_type === "no_three_ds" ) {
1182
- expect ( response . body . status ) . to . equal ( "succeeded" ) ;
1183
- } else {
1184
- defaultErrorHandler ( response , res_data ) ;
1185
- }
1186
- } else if ( response . body . capture_method === "manual" ) {
1187
- if ( response . body . authentication_type === "three_ds" ) {
1188
- expect ( response . body )
1189
- . to . have . property ( "next_action" )
1190
- . to . have . property ( "redirect_to_url" ) ;
1191
- const nextActionUrl = response . body . next_action . redirect_to_url ;
1192
- cy . log ( response . body ) ;
1193
- cy . log ( nextActionUrl ) ;
1194
- } else if ( response . body . authentication_type === "no_three_ds" ) {
1195
- expect ( response . body . status ) . to . equal ( "requires_capture" ) ;
1173
+ if ( response . status === 200 ) {
1174
+ globalState . set ( "paymentID" , response . body . payment_id ) ;
1175
+ if ( response . body . capture_method === "automatic" ) {
1176
+ if ( response . body . authentication_type === "three_ds" ) {
1177
+ expect ( response . body )
1178
+ . to . have . property ( "next_action" )
1179
+ . to . have . property ( "redirect_to_url" ) ;
1180
+ const nextActionUrl = response . body . next_action . redirect_to_url ;
1181
+ cy . log ( nextActionUrl ) ;
1182
+ } else if ( response . body . authentication_type === "no_three_ds" ) {
1183
+ expect ( response . body . status ) . to . equal ( "succeeded" ) ;
1184
+ } else {
1185
+ throw new Error (
1186
+ `Invalid authentication type ${ response . body . authentication_type } `
1187
+ ) ;
1188
+ }
1189
+ } else if ( response . body . capture_method === "manual" ) {
1190
+ if ( response . body . authentication_type === "three_ds" ) {
1191
+ expect ( response . body )
1192
+ . to . have . property ( "next_action" )
1193
+ . to . have . property ( "redirect_to_url" ) ;
1194
+ const nextActionUrl = response . body . next_action . redirect_to_url ;
1195
+ cy . log ( nextActionUrl ) ;
1196
+ } else if ( response . body . authentication_type === "no_three_ds" ) {
1197
+ expect ( response . body . status ) . to . equal ( "requires_capture" ) ;
1198
+ } else {
1199
+ throw new Error (
1200
+ `Invalid authentication type ${ response . body . authentication_type } `
1201
+ ) ;
1202
+ }
1196
1203
} else {
1197
- defaultErrorHandler ( response , res_data ) ;
1204
+ throw new Error (
1205
+ `Invalid capture method ${ response . body . capture_method } `
1206
+ ) ;
1198
1207
}
1208
+ } else {
1209
+ throw new Error (
1210
+ `Error Response: ${ response . status } \n${ response . body . error . message } \n${ response . body . error . code } `
1211
+ ) ;
1199
1212
}
1200
1213
} ) ;
1201
1214
}
@@ -1221,33 +1234,45 @@ Cypress.Commands.add(
1221
1234
} ) . then ( ( response ) => {
1222
1235
logRequestId ( response . headers [ "x-request-id" ] ) ;
1223
1236
expect ( response . headers [ "content-type" ] ) . to . include ( "application/json" ) ;
1224
- globalState . set ( "paymentID" , response . body . payment_id ) ;
1225
- if ( response . body . capture_method === "automatic" ) {
1226
- if ( response . body . authentication_type === "three_ds" ) {
1227
- expect ( response . body )
1228
- . to . have . property ( "next_action" )
1229
- . to . have . property ( "redirect_to_url" ) ;
1230
- const nextActionUrl = response . body . next_action . redirect_to_url ;
1231
- cy . log ( response . body ) ;
1232
- cy . log ( nextActionUrl ) ;
1233
- } else if ( response . body . authentication_type === "no_three_ds" ) {
1234
- expect ( response . body . status ) . to . equal ( "succeeded" ) ;
1235
- } else {
1236
- defaultErrorHandler ( response , res_data ) ;
1237
- }
1238
- } else if ( response . body . capture_method === "manual" ) {
1239
- if ( response . body . authentication_type === "three_ds" ) {
1240
- expect ( response . body )
1241
- . to . have . property ( "next_action" )
1242
- . to . have . property ( "redirect_to_url" ) ;
1243
- const nextActionUrl = response . body . next_action . redirect_to_url ;
1244
- cy . log ( response . body ) ;
1245
- cy . log ( nextActionUrl ) ;
1246
- } else if ( response . body . authentication_type === "no_three_ds" ) {
1247
- expect ( response . body . status ) . to . equal ( "requires_capture" ) ;
1237
+ if ( response . status === 200 ) {
1238
+ globalState . set ( "paymentID" , response . body . payment_id ) ;
1239
+ if ( response . body . capture_method === "automatic" ) {
1240
+ if ( response . body . authentication_type === "three_ds" ) {
1241
+ expect ( response . body )
1242
+ . to . have . property ( "next_action" )
1243
+ . to . have . property ( "redirect_to_url" ) ;
1244
+ const nextActionUrl = response . body . next_action . redirect_to_url ;
1245
+ cy . log ( nextActionUrl ) ;
1246
+ } else if ( response . body . authentication_type === "no_three_ds" ) {
1247
+ expect ( response . body . status ) . to . equal ( "succeeded" ) ;
1248
+ } else {
1249
+ throw new Error (
1250
+ `Invalid authentication type ${ response . body . authentication_type } `
1251
+ ) ;
1252
+ }
1253
+ } else if ( response . body . capture_method === "manual" ) {
1254
+ if ( response . body . authentication_type === "three_ds" ) {
1255
+ expect ( response . body )
1256
+ . to . have . property ( "next_action" )
1257
+ . to . have . property ( "redirect_to_url" ) ;
1258
+ const nextActionUrl = response . body . next_action . redirect_to_url ;
1259
+ cy . log ( nextActionUrl ) ;
1260
+ } else if ( response . body . authentication_type === "no_three_ds" ) {
1261
+ expect ( response . body . status ) . to . equal ( "requires_capture" ) ;
1262
+ } else {
1263
+ throw new Error (
1264
+ `Invalid authentication type ${ response . body . authentication_type } `
1265
+ ) ;
1266
+ }
1248
1267
} else {
1249
- defaultErrorHandler ( response , res_data ) ;
1268
+ throw new Error (
1269
+ `Invalid capture method ${ response . body . capture_method } `
1270
+ ) ;
1250
1271
}
1272
+ } else {
1273
+ throw new Error (
1274
+ `Error Response: ${ response . status } \n${ response . body . error . message } \n${ response . body . error . code } `
1275
+ ) ;
1251
1276
}
1252
1277
} ) ;
1253
1278
}
0 commit comments