r102341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102340‎ | r102341 | r102342 >
Date:22:49, 7 November 2011
Author:jpostlethwaite
Status:ok
Tags:fundraising 
Comment:
Added placeholder for Do bank validation error messages in $this->error_map. Added keys to payment_submethods. Updated getResponseData() to include DO_BANKVALIDATION. Added methods to help with direct debit: xmlGetChecks(), checkDoBankValidation(), setBankValidationErrors(). Updated addKeysToTransactionForSubmethod() to ignore payment_submethods without defined keys.
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -40,7 +40,14 @@
4141 $this->error_map = array(
4242 0 => 'globalcollect_gateway-response-default',
4343 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+
4552 );
4653 }
4754
@@ -177,7 +184,7 @@
178185 * Please do not add more transactions to this array.
179186 *
180187 * @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?
182189 * - Does DO_BANKVALIDATION need HOSTEDINDICATOR?
183190 *
184191 * This method should define:
@@ -427,6 +434,7 @@
428435 'label' => 'Any',
429436 'group' => 'cc',
430437 'validation' => array( 'address' => true, 'amount' => true, 'email' => true, 'name' => true, ),
 438+ 'keys' => array(),
431439 );
432440
433441 /*
@@ -439,6 +447,7 @@
440448 'label' => 'Bank Transfer',
441449 'group' => 'bt',
442450 'validation' => array(),
 451+ 'keys' => array(),
443452 );
444453
445454 /*
@@ -451,6 +460,7 @@
452461 'label' => 'Visa',
453462 'group' => 'cc',
454463 'validation' => array(),
 464+ 'keys' => array(),
455465 );
456466
457467 // MasterCard
@@ -459,6 +469,7 @@
460470 'label' => 'MasterCard',
461471 'group' => 'cc',
462472 'validation' => array(),
 473+ 'keys' => array(),
463474 );
464475
465476 // American Express
@@ -467,6 +478,7 @@
468479 'label' => 'American Express',
469480 'group' => 'cc',
470481 'validation' => array(),
 482+ 'keys' => array(),
471483 );
472484
473485 // Maestro
@@ -475,6 +487,7 @@
476488 'label' => 'Maestro',
477489 'group' => 'cc',
478490 'validation' => array(),
 491+ 'keys' => array(),
479492 );
480493
481494 // Solo
@@ -483,6 +496,7 @@
484497 'label' => 'Solo',
485498 'group' => 'cc',
486499 'validation' => array(),
 500+ 'keys' => array(),
487501 );
488502
489503 // Laser
@@ -491,6 +505,7 @@
492506 'label' => 'Laser',
493507 'group' => 'cc',
494508 'validation' => array(),
 509+ 'keys' => array(),
495510 );
496511
497512 // JCB
@@ -499,6 +514,7 @@
500515 'label' => 'JCB',
501516 'group' => 'cc',
502517 'validation' => array(),
 518+ 'keys' => array(),
503519 );
504520
505521 // Discover
@@ -507,6 +523,7 @@
508524 'label' => 'Discover',
509525 'group' => 'cc',
510526 'validation' => array(),
 527+ 'keys' => array(),
511528 );
512529
513530 // CB
@@ -515,6 +532,7 @@
516533 'label' => 'CB', // Carte Bancaire OR Carte Bleue
517534 'group' => 'cc',
518535 'validation' => array(),
 536+ 'keys' => array(),
519537 );
520538
521539 /*
@@ -540,7 +558,7 @@
541559 'label' => 'Direct debit: BE',
542560 'group' => 'dd',
543561 'validation' => array(),
544 - 'keys' => array( 'ACCOUNTNAME', 'ACCOUNTNUMBER', 'AUTHORIZATIONID', 'BANKNAME', 'DIRECTDEBITTEXT', ),
 562+ 'keys' => array( 'ACCOUNTNAME', 'ACCOUNTNUMBER', 'AUTHORIZATIONID', 'BANKCHECKDIGIT', 'BANKCODE', 'BANKNAME', 'DIRECTDEBITTEXT', ),
545563 );
546564
547565 // Direct debit: CH
@@ -616,6 +634,7 @@
617635 'label' => 'Nordea (Sweden)',
618636 'group' => 'rtbt',
619637 'validation' => array(),
 638+ 'keys' => array(),
620639 );
621640
622641 // Ideal
@@ -624,6 +643,7 @@
625644 'label' => 'Ideal',
626645 'group' => 'rtbt',
627646 'validation' => array(),
 647+ 'keys' => array(),
628648 'issuerids' => array(
629649 771 => 'SNS Regio Bank',
630650 161 => 'Van Lanschot Bankiers',
@@ -644,6 +664,7 @@
645665 'label' => 'eNETS',
646666 'group' => 'rtbt',
647667 'validation' => array(),
 668+ 'keys' => array(),
648669 );
649670
650671 // Sofortuberweisung/DIRECTebanking
@@ -652,6 +673,7 @@
653674 'label' => 'Sofortuberweisung/DIRECTebanking',
654675 'group' => 'rtbt',
655676 'validation' => array(),
 677+ 'keys' => array(),
656678 );
657679
658680 // eps Online-Überweisung
@@ -660,6 +682,7 @@
661683 'label' => 'eps Online-Überweisung',
662684 'group' => 'rtbt',
663685 'validation' => array(),
 686+ 'keys' => array(),
664687 'issuerids' => array(
665688 824 => 'Bankhaus Spängler',
666689 825 => 'Hypo Tirol Bank',
@@ -955,7 +978,7 @@
956979 * When we set lookup error code ranges, we use GET_ORDERSTATUS as the key for search
957980 * because they are only defined for that transaction type.
958981 *
959 - * @param array $response The response array
 982+ * @param DOMDocument $response The response object
960983 */
961984 public function getResponseData( $response ) {
962985 $data = array( );
@@ -976,6 +999,19 @@
9771000 }
9781001
9791002 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;
9801016 case 'GET_ORDERSTATUS':
9811017 $data = $this->xmlChildrenToArray( $response, 'STATUS' );
9821018 $this->setTransactionWMFStatus( $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ) );
@@ -985,8 +1021,185 @@
9861022
9871023 return $data;
9881024 }
 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+ }
9891185
9901186 /**
 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+ /**
9911204 * Gets all the currency codes appropriate for this gateway
9921205 * @return array of currency codes
9931206 */
@@ -1243,6 +1456,8 @@
12441457 case 'rtbt_ideal':
12451458 $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
12461459 $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 1460+
 1461+ $this->addKeysToTransactionForSubmethod( $payment_submethod );
12471462
12481463 $this->addKeyToTransaction('ISSUERID');
12491464 break;
@@ -1260,8 +1475,15 @@
12611476 *
12621477 */
12631478 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+ }
12641485
12651486 foreach ( $this->payment_submethods[ $payment_submethod ]['keys'] as $key ) {
 1487+
12661488 $this->addKeyToTransaction( $key );
12671489 }
12681490 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r102342Modified direct debit to properly check status. See r102341.jpostlethwaite22:53, 7 November 2011
r102732MFT r100644, r100785, r101785, r102120, r102318, r102332, r102341, r102342, r...awjrichards01:31, 11 November 2011

Status & tagging log