Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -40,7 +40,14 @@ |
41 | 41 | $this->error_map = array( |
42 | 42 | 0 => 'globalcollect_gateway-response-default', |
43 | 43 | 430452 => 'globalcollect_gateway-response-default', // Not authorised :: This message was generated when trying to attempt a direct debit transaction from Belgium. |
44 | | - 430900 => 'globalcollect_gateway-response-default', // NO VALID PROVIDERS FOUND FOR COMBINATION MERCHANTID: NNNN, PAYMENTPRODUCT: NNN, COUNTRYCODE: XX, CURRENCYCODE: XXX |
| 44 | + 430900 => 'globalcollect_gateway-response-default', // NO VALID PROVIDERS FOUND FOR COMBINATION MERCHANTID: NNNN, PAYMENTPRODUCT: NNN, COUNTRYCODE: XX, CURRENCYCODE: XXX |
| 45 | + |
| 46 | + // Do bank validation messages |
| 47 | + //'dbv-50' => 'globalcollect_gateway-response-dbv-50', // Account number format incorrect |
| 48 | + //'dbv-80' => 'globalcollect_gateway-response-dbv-80', // Account details missing |
| 49 | + //'dbv-330' => 'globalcollect_gateway-response-dbv-330', // Check digit format is incorrect |
| 50 | + //'dbv-340' => 'globalcollect_gateway-response-dbv-340', // Branch code not submitted |
| 51 | + |
45 | 52 | ); |
46 | 53 | } |
47 | 54 | |
— | — | @@ -177,7 +184,7 @@ |
178 | 185 | * Please do not add more transactions to this array. |
179 | 186 | * |
180 | 187 | * @todo |
181 | | - * - Does DO_BANKVALIDATION need IPADDRESS? What about the other transactions. Is this the user's IPA? |
| 188 | + * - Does need IPADDRESS? What about the other transactions. Is this the user's IPA? |
182 | 189 | * - Does DO_BANKVALIDATION need HOSTEDINDICATOR? |
183 | 190 | * |
184 | 191 | * This method should define: |
— | — | @@ -427,6 +434,7 @@ |
428 | 435 | 'label' => 'Any', |
429 | 436 | 'group' => 'cc', |
430 | 437 | 'validation' => array( 'address' => true, 'amount' => true, 'email' => true, 'name' => true, ), |
| 438 | + 'keys' => array(), |
431 | 439 | ); |
432 | 440 | |
433 | 441 | /* |
— | — | @@ -439,6 +447,7 @@ |
440 | 448 | 'label' => 'Bank Transfer', |
441 | 449 | 'group' => 'bt', |
442 | 450 | 'validation' => array(), |
| 451 | + 'keys' => array(), |
443 | 452 | ); |
444 | 453 | |
445 | 454 | /* |
— | — | @@ -451,6 +460,7 @@ |
452 | 461 | 'label' => 'Visa', |
453 | 462 | 'group' => 'cc', |
454 | 463 | 'validation' => array(), |
| 464 | + 'keys' => array(), |
455 | 465 | ); |
456 | 466 | |
457 | 467 | // MasterCard |
— | — | @@ -459,6 +469,7 @@ |
460 | 470 | 'label' => 'MasterCard', |
461 | 471 | 'group' => 'cc', |
462 | 472 | 'validation' => array(), |
| 473 | + 'keys' => array(), |
463 | 474 | ); |
464 | 475 | |
465 | 476 | // American Express |
— | — | @@ -467,6 +478,7 @@ |
468 | 479 | 'label' => 'American Express', |
469 | 480 | 'group' => 'cc', |
470 | 481 | 'validation' => array(), |
| 482 | + 'keys' => array(), |
471 | 483 | ); |
472 | 484 | |
473 | 485 | // Maestro |
— | — | @@ -475,6 +487,7 @@ |
476 | 488 | 'label' => 'Maestro', |
477 | 489 | 'group' => 'cc', |
478 | 490 | 'validation' => array(), |
| 491 | + 'keys' => array(), |
479 | 492 | ); |
480 | 493 | |
481 | 494 | // Solo |
— | — | @@ -483,6 +496,7 @@ |
484 | 497 | 'label' => 'Solo', |
485 | 498 | 'group' => 'cc', |
486 | 499 | 'validation' => array(), |
| 500 | + 'keys' => array(), |
487 | 501 | ); |
488 | 502 | |
489 | 503 | // Laser |
— | — | @@ -491,6 +505,7 @@ |
492 | 506 | 'label' => 'Laser', |
493 | 507 | 'group' => 'cc', |
494 | 508 | 'validation' => array(), |
| 509 | + 'keys' => array(), |
495 | 510 | ); |
496 | 511 | |
497 | 512 | // JCB |
— | — | @@ -499,6 +514,7 @@ |
500 | 515 | 'label' => 'JCB', |
501 | 516 | 'group' => 'cc', |
502 | 517 | 'validation' => array(), |
| 518 | + 'keys' => array(), |
503 | 519 | ); |
504 | 520 | |
505 | 521 | // Discover |
— | — | @@ -507,6 +523,7 @@ |
508 | 524 | 'label' => 'Discover', |
509 | 525 | 'group' => 'cc', |
510 | 526 | 'validation' => array(), |
| 527 | + 'keys' => array(), |
511 | 528 | ); |
512 | 529 | |
513 | 530 | // CB |
— | — | @@ -515,6 +532,7 @@ |
516 | 533 | 'label' => 'CB', // Carte Bancaire OR Carte Bleue |
517 | 534 | 'group' => 'cc', |
518 | 535 | 'validation' => array(), |
| 536 | + 'keys' => array(), |
519 | 537 | ); |
520 | 538 | |
521 | 539 | /* |
— | — | @@ -540,7 +558,7 @@ |
541 | 559 | 'label' => 'Direct debit: BE', |
542 | 560 | 'group' => 'dd', |
543 | 561 | 'validation' => array(), |
544 | | - 'keys' => array( 'ACCOUNTNAME', 'ACCOUNTNUMBER', 'AUTHORIZATIONID', 'BANKNAME', 'DIRECTDEBITTEXT', ), |
| 562 | + 'keys' => array( 'ACCOUNTNAME', 'ACCOUNTNUMBER', 'AUTHORIZATIONID', 'BANKCHECKDIGIT', 'BANKCODE', 'BANKNAME', 'DIRECTDEBITTEXT', ), |
545 | 563 | ); |
546 | 564 | |
547 | 565 | // Direct debit: CH |
— | — | @@ -616,6 +634,7 @@ |
617 | 635 | 'label' => 'Nordea (Sweden)', |
618 | 636 | 'group' => 'rtbt', |
619 | 637 | 'validation' => array(), |
| 638 | + 'keys' => array(), |
620 | 639 | ); |
621 | 640 | |
622 | 641 | // Ideal |
— | — | @@ -624,6 +643,7 @@ |
625 | 644 | 'label' => 'Ideal', |
626 | 645 | 'group' => 'rtbt', |
627 | 646 | 'validation' => array(), |
| 647 | + 'keys' => array(), |
628 | 648 | 'issuerids' => array( |
629 | 649 | 771 => 'SNS Regio Bank', |
630 | 650 | 161 => 'Van Lanschot Bankiers', |
— | — | @@ -644,6 +664,7 @@ |
645 | 665 | 'label' => 'eNETS', |
646 | 666 | 'group' => 'rtbt', |
647 | 667 | 'validation' => array(), |
| 668 | + 'keys' => array(), |
648 | 669 | ); |
649 | 670 | |
650 | 671 | // Sofortuberweisung/DIRECTebanking |
— | — | @@ -652,6 +673,7 @@ |
653 | 674 | 'label' => 'Sofortuberweisung/DIRECTebanking', |
654 | 675 | 'group' => 'rtbt', |
655 | 676 | 'validation' => array(), |
| 677 | + 'keys' => array(), |
656 | 678 | ); |
657 | 679 | |
658 | 680 | // eps Online-Überweisung |
— | — | @@ -660,6 +682,7 @@ |
661 | 683 | 'label' => 'eps Online-Überweisung', |
662 | 684 | 'group' => 'rtbt', |
663 | 685 | 'validation' => array(), |
| 686 | + 'keys' => array(), |
664 | 687 | 'issuerids' => array( |
665 | 688 | 824 => 'Bankhaus Spängler', |
666 | 689 | 825 => 'Hypo Tirol Bank', |
— | — | @@ -955,7 +978,7 @@ |
956 | 979 | * When we set lookup error code ranges, we use GET_ORDERSTATUS as the key for search |
957 | 980 | * because they are only defined for that transaction type. |
958 | 981 | * |
959 | | - * @param array $response The response array |
| 982 | + * @param DOMDocument $response The response object |
960 | 983 | */ |
961 | 984 | public function getResponseData( $response ) { |
962 | 985 | $data = array( ); |
— | — | @@ -976,6 +999,19 @@ |
977 | 1000 | } |
978 | 1001 | |
979 | 1002 | break; |
| 1003 | + case 'DO_BANKVALIDATION': |
| 1004 | + $data = $this->xmlChildrenToArray( $response, 'RESPONSE' ); |
| 1005 | + unset( $data['META'] ); |
| 1006 | + $data['errors'] = array(); |
| 1007 | + $data['CHECKSPERFORMED'] = $this->xmlGetChecks( $response ); |
| 1008 | + $data['VALIDATIONID'] = $this->xmlChildrenToArray( $response, 'VALIDATIONID' ); |
| 1009 | + |
| 1010 | + // WMFStatus will already be set if the transaction was unable to communicate properly. |
| 1011 | + if ( $this->getTransactionStatus() ) { |
| 1012 | + $this->setTransactionWMFStatus( $this->checkDoBankValidation( $data ) ); |
| 1013 | + } |
| 1014 | + |
| 1015 | + break; |
980 | 1016 | case 'GET_ORDERSTATUS': |
981 | 1017 | $data = $this->xmlChildrenToArray( $response, 'STATUS' ); |
982 | 1018 | $this->setTransactionWMFStatus( $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ) ); |
— | — | @@ -985,8 +1021,185 @@ |
986 | 1022 | |
987 | 1023 | return $data; |
988 | 1024 | } |
| 1025 | + |
| 1026 | + /** |
| 1027 | + * Parse the response object for the checked validations |
| 1028 | + * |
| 1029 | + * @param DOMDocument $response The response object |
| 1030 | + */ |
| 1031 | + protected function xmlGetChecks( $response ) { |
| 1032 | + |
| 1033 | + $data = array( |
| 1034 | + 'CHECKS' => array(), |
| 1035 | + ); |
| 1036 | + |
| 1037 | + $checks = $response->getElementsByTagName( 'CHECK' ); |
| 1038 | + |
| 1039 | + foreach ( $checks as $check ) { |
| 1040 | + |
| 1041 | + // Get the check code |
| 1042 | + $checkCode = $check->getElementsByTagName('CHECKCODE')->item(0)->nodeValue; |
| 1043 | + |
| 1044 | + // Remove zero paddding |
| 1045 | + $checkCode = ltrim( $checkCode, '0'); |
| 1046 | + |
| 1047 | + // Convert it too an integer |
| 1048 | + settype( $checkCode, 'integer' ); |
| 1049 | + |
| 1050 | + $data['CHECKS'][ $checkCode ] = $check->getElementsByTagName('CHECKRESULT')->item(0)->nodeValue; |
| 1051 | + } |
| 1052 | + |
| 1053 | + // Sort the error codes |
| 1054 | + ksort( $data['CHECKS'] ); |
| 1055 | + |
| 1056 | + return $data; |
| 1057 | + } |
| 1058 | + |
| 1059 | + /** |
| 1060 | + * Interpret DO_BANKVALIDATION checks performed. |
| 1061 | + * |
| 1062 | + * The check results are returned as follows: |
| 1063 | + * |
| 1064 | + * <code> |
| 1065 | + * <RESPONSE> |
| 1066 | + * <RESULT>OK</RESULT> |
| 1067 | + * <META> |
| 1068 | + * <REQUESTID>207326</REQUESTID> |
| 1069 | + * <RESPONSEDATETIME>20111106054547</RESPONSEDATETIME> |
| 1070 | + * <CHECKSPERFORMED> |
| 1071 | + * <CHECK> |
| 1072 | + * <CHECKCODE>0030</CHECKCODE> |
| 1073 | + * <CHECKRESULT>NOTCHECKED</CHECKRESULT></CHECK> |
| 1074 | + * <CHECK> |
| 1075 | + * <CHECKCODE>0050</CHECKCODE> |
| 1076 | + * <CHECKRESULT>ERROR</CHECKRESULT></CHECK> |
| 1077 | + * <CHECK> |
| 1078 | + * <CHECKCODE>0051</CHECKCODE> |
| 1079 | + * <CHECKRESULT>NOTCHECKED</CHECKRESULT> |
| 1080 | + * </CHECK> |
| 1081 | + * </CHECKSPERFORMED> |
| 1082 | + * </RESPONSE> |
| 1083 | + * </code> |
| 1084 | + * |
| 1085 | + * This will use the error map. |
| 1086 | + * |
| 1087 | + * PASSED is a successful validation. |
| 1088 | + * |
| 1089 | + * ERROR is a validation failure. |
| 1090 | + * |
| 1091 | + * WARNING: For now, this will be treated as failed. |
| 1092 | + * |
| 1093 | + * NOTCHECKED does not need to be worried about in the check results. These |
| 1094 | + * are supposed to appear if a validation failed, rendering the other |
| 1095 | + * validations pointless to check. |
| 1096 | + * |
| 1097 | + * @todo |
| 1098 | + * - There is a problem with the manual for DO_BANKVALIDATION. Failure should return NOK. Is this only on development? |
| 1099 | + * - Messages are not being translated by the provider. |
| 1100 | + * - What do we do about WARNING? For now, it is fail? |
| 1101 | + * - Get the validation id |
| 1102 | + * |
| 1103 | + * @param array $data The data array |
| 1104 | + * |
| 1105 | + * @return boolean |
| 1106 | + */ |
| 1107 | + public function checkDoBankValidation( &$data ) { |
| 1108 | + |
| 1109 | + $checks = &$data['CHECKSPERFORMED']; |
| 1110 | + |
| 1111 | + $hasValidationId = false; |
| 1112 | + $isPass = 0; |
| 1113 | + $isError = 0; |
| 1114 | + $isWarning = 0; |
| 1115 | + $isNotChecked = 0; |
| 1116 | + |
| 1117 | + $return = 'failed'; |
| 1118 | + |
| 1119 | + if ( !is_array( $checks['CHECKS'] ) ) { |
| 1120 | + |
| 1121 | + // Should we trigger an error if no checks are performed? |
| 1122 | + // For now, just return failed. |
| 1123 | + return $return; |
| 1124 | + } |
| 1125 | + |
| 1126 | + // We only mark validation as a failure if we have warnings or errors. |
| 1127 | + $return = 'complete'; |
| 1128 | + |
| 1129 | + foreach ( $checks['CHECKS'] as $checkCode => $checkResult ) { |
| 1130 | + |
| 1131 | + // Prefix error codes with dbv for DO_BANKVALIDATION |
| 1132 | + $code = 'dbv-' . $checkCode; |
| 1133 | + |
| 1134 | + if ( $checkResult == 'ERROR' ) { |
| 1135 | + $isError++; |
| 1136 | + |
| 1137 | + // Message might need to be put somewhere else. |
| 1138 | + $data['errors'][ $code ] = $this->getErrorMap( $code ); |
| 1139 | + |
| 1140 | + } elseif ( $checkResult == 'NOTCHECKED' ) { |
| 1141 | + |
| 1142 | + $isNotChecked++; |
| 1143 | + |
| 1144 | + } elseif ( $checkResult == 'PASSED' ) { |
| 1145 | + |
| 1146 | + $isPass++; |
| 1147 | + |
| 1148 | + } elseif ( $checkResult == 'WARNING' ) { |
| 1149 | + |
| 1150 | + $isWarning++; |
| 1151 | + |
| 1152 | + // Message might need to be put somewhere else. |
| 1153 | + $data['errors'][ $code ] = $this->getErrorMap( $code ); |
| 1154 | + |
| 1155 | + } else { |
| 1156 | + |
| 1157 | + $message = 'Unknown check result: (' . $checkResult . ')'; |
| 1158 | + |
| 1159 | + throw new MWException( $message ); |
| 1160 | + } |
| 1161 | + } |
| 1162 | + |
| 1163 | + // The return text needs to match something in @see $this->defineGoToThankYouOn() |
| 1164 | + if ( $isPass ) { |
| 1165 | + $return = 'complete'; |
| 1166 | + } |
| 1167 | + |
| 1168 | + if ( $isWarning ) { |
| 1169 | + // This should be logged. |
| 1170 | + $return = 'failed'; |
| 1171 | + } |
| 1172 | + |
| 1173 | + if ( $isError ) { |
| 1174 | + $return = 'failed'; |
| 1175 | + } |
| 1176 | + |
| 1177 | + // Check to see if a validation id exists |
| 1178 | + $hasValidationId = isset( $data['VALIDATIONID'] ) ? (boolean) $data['VALIDATIONID'] : false; |
| 1179 | + |
| 1180 | + // Do we have a validation ID? |
| 1181 | + //$return = $hasValidationId ? $return : 'failed'; |
| 1182 | + |
| 1183 | + return $return; |
| 1184 | + } |
989 | 1185 | |
990 | 1186 | /** |
| 1187 | + * Set the bank validation error messages for the client. |
| 1188 | + * |
| 1189 | + * The messages have already been generated at this point. The purpose of |
| 1190 | + * this method is to pass them to the view. |
| 1191 | + */ |
| 1192 | + public function setBankValidationErrors() { |
| 1193 | + |
| 1194 | + $results = $this->getTransactionAllResults(); |
| 1195 | + |
| 1196 | + $checks = $results['data']; |
| 1197 | + |
| 1198 | + $errors = isset( $checks['errors'] ) ? $checks['errors'] : array(); |
| 1199 | + |
| 1200 | + $this->setTransactionResult( $errors, 'errors' ); |
| 1201 | + } |
| 1202 | + |
| 1203 | + /** |
991 | 1204 | * Gets all the currency codes appropriate for this gateway |
992 | 1205 | * @return array of currency codes |
993 | 1206 | */ |
— | — | @@ -1243,6 +1456,8 @@ |
1244 | 1457 | case 'rtbt_ideal': |
1245 | 1458 | $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid']; |
1246 | 1459 | $this->var_map['PAYMENTPRODUCTID'] = 'payment_product'; |
| 1460 | + |
| 1461 | + $this->addKeysToTransactionForSubmethod( $payment_submethod ); |
1247 | 1462 | |
1248 | 1463 | $this->addKeyToTransaction('ISSUERID'); |
1249 | 1464 | break; |
— | — | @@ -1260,8 +1475,15 @@ |
1261 | 1476 | * |
1262 | 1477 | */ |
1263 | 1478 | protected function addKeysToTransactionForSubmethod( $payment_submethod ) { |
| 1479 | + |
| 1480 | + // If there are no keys to add, do not proceed. |
| 1481 | + if ( !is_array( $this->payment_submethods[ $payment_submethod ]['keys'] ) ) { |
| 1482 | + |
| 1483 | + return; |
| 1484 | + } |
1264 | 1485 | |
1265 | 1486 | foreach ( $this->payment_submethods[ $payment_submethod ]['keys'] as $key ) { |
| 1487 | + |
1266 | 1488 | $this->addKeyToTransaction( $key ); |
1267 | 1489 | } |
1268 | 1490 | } |