Changeset 2711 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php
- Timestamp:
- 03/08/2016 05:05:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php
r2710 r2711 1161 1161 return ob_get_clean(); 1162 1162 } 1163 1164 /** 1165 * NACHA via JP Morgan 1166 * 1167 * @param array $args 1168 * 1169 * @return string 1170 */ 1171 public static function _generate_payment_report_jpm_ach( $args ) { 1172 $args = wp_parse_args( $args, array( 1173 'data' => array(), 1174 'status' => '', 1175 'post_type' => '', 1176 ) ); 1177 1178 $ach_options = apply_filters( 'wcb_payment_req_ach_options', array( 1179 'bank-routing-number' => '', // Immediate Destination (bank routing number) 1180 'company-id' => '', // Company ID 1181 'financial-inst' => '', // Originating Financial Institution 1182 ) ); 1183 1184 ob_start(); 1185 1186 // File Header Record 1187 1188 echo '1'; // Record Type Code 1189 echo '01'; // Priority Code 1190 echo ' ' . str_pad( substr( $ach_options['bank-routing-number'], 0, 9 ), 9, '0', STR_PAD_LEFT ); 1191 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10, '0', STR_PAD_LEFT ); // Immediate Origin (TIN) 1192 echo date( 'ymd' ); // Transmission Date 1193 echo date( 'Hi' ); // Transmission Time 1194 echo 'A'; // File ID Modifier 1195 echo '094'; // Record Size 1196 echo '10'; // Blocking Factor 1197 echo '1'; // Format Code 1198 echo str_pad( 'JPMORGANCHASE', 23 ); // Destination 1199 echo str_pad( 'WCEXPORT', 23 ); // Origin 1200 echo str_pad( '', 8 ); // Reference Code (optional) 1201 echo PHP_EOL; 1202 1203 // Batch Header Record 1204 1205 echo '5'; // Record Type Code 1206 echo '200'; // Service Type Code 1207 echo 'WordCamp Communi'; // Company Name 1208 echo str_pad( '', 20 ); // Blanks 1209 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company Identification 1210 1211 // Get the first one in the set. 1212 // @todo Split batches by account type. 1213 foreach ( $args['data'] as $entry ) { 1214 switch_to_blog( $entry->blog_id ); 1215 $post = get_post( $entry->post_id ); 1216 1217 if ( $args['status'] && $post->post_status != $args['status'] ) { 1218 restore_current_blog(); 1219 continue; 1220 } elseif ( $post->post_type != self::POST_TYPE ) { 1221 restore_current_blog(); 1222 continue; 1223 } elseif ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' ) { 1224 restore_current_blog(); 1225 continue; 1226 } 1227 1228 $account_type = get_post_meta( $post->ID, '_camppayments_ach_account_type', true ); 1229 restore_current_blog(); 1230 break; 1231 } 1232 1233 $entry_class = $account_type == 'Personal' ? 'PPD' : 'CCD'; 1234 echo $entry_class; // Standard Entry Class 1235 1236 echo 'Vendor Pay'; // Entry Description 1237 echo date( 'ymd', \WordCamp\Budgets_Dashboard\_next_business_day_timestamp() ); // Company Description Date 1238 echo date( 'ymd', \WordCamp\Budgets_Dashboard\_next_business_day_timestamp() ); // Effective Entry Date 1239 echo str_pad( '', 3 ); // Blanks 1240 echo '1'; // Originator Status Code 1241 echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution 1242 echo '0000001'; // Batch Number 1243 echo PHP_EOL; 1244 1245 $count = 0; 1246 $total = 0; 1247 $hash = 0; 1248 1249 foreach ( $args['data'] as $entry ) { 1250 switch_to_blog( $entry->blog_id ); 1251 $post = get_post( $entry->post_id ); 1252 1253 if ( $args['status'] && $post->post_status != $args['status'] ) { 1254 restore_current_blog(); 1255 continue; 1256 } elseif ( $post->post_type != self::POST_TYPE ) { 1257 restore_current_blog(); 1258 continue; 1259 } elseif ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' ) { 1260 restore_current_blog(); 1261 continue; 1262 } 1263 1264 $count++; 1265 1266 // Entry Detail Record 1267 1268 echo '6'; // Record Type Code 1269 1270 $transaction_code = $account_type == 'Personal' ? '27' : '22'; 1271 echo $transaction_code; // Transaction Code 1272 1273 // Transit/Routing Number of Destination Bank + Check digit 1274 $routing_number = get_post_meta( $post->ID, '_camppayments_ach_routing_number', true ); 1275 $routing_number = WCP_Encryption::maybe_decrypt( $routing_number ); 1276 $routing_number = substr( $routing_number, 0, 8 + 1 ); 1277 $routing_number = str_pad( $routing_number, 8 + 1 ); 1278 $hash += absint( substr( $routing_number, 0, 8 ) ); 1279 echo $routing_number; 1280 1281 // Bank Account Number 1282 $account_number = get_post_meta( $post->ID, '_camppayments_ach_account_number', true ); 1283 $account_number = WCP_Encryption::maybe_decrypt( $account_number ); 1284 $account_number = substr( $account_number, 0, 17 ); 1285 $account_number = str_pad( $account_number, 17 ); 1286 echo $account_number; 1287 1288 // Amount 1289 $amount = round( floatval( get_post_meta( $post->ID, '_camppayments_payment_amount', true ) ), 2 ); 1290 $total += $amount; 1291 $amount = str_pad( number_format( $amount, 2, '', '' ), 10, '0', STR_PAD_LEFT ); 1292 echo $amount; 1293 1294 // Individual Identification Number 1295 echo str_pad( sprintf( '%d-%d', $entry->blog_id, $entry->post_id ), 15 ); 1296 1297 // Individual Name 1298 $name = get_post_meta( $post->ID, '_camppayments_ach_account_holder_name', true ); 1299 $name = WCP_Encryption::maybe_decrypt( $name ); 1300 $name = substr( $name, 0, 22 ); 1301 $name = str_pad( $name, 22 ); 1302 echo $name; 1303 1304 echo ' '; // User Defined Data 1305 echo '0'; // Addenda Record Indicator 1306 1307 // Trace Number 1308 echo str_pad( substr( $ach_options['bank-routing-number'], 0, 8 ), 8, '0', STR_PAD_LEFT ); // routing number 1309 echo str_pad( $count, 7, '0', STR_PAD_LEFT ); // sequence number 1310 echo PHP_EOL; 1311 } 1312 1313 // Batch Trailer Record 1314 1315 echo '8'; // Record Type Code 1316 echo '200'; // Service Class Code 1317 echo str_pad( $count, 6, '0', STR_PAD_LEFT ); // Entry/Addenda Count 1318 echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash 1319 echo str_pad( number_format( $total, 2, '', '' ), 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount 1320 echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount 1321 echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company ID 1322 echo str_pad( '', 25 ); // Blanks 1323 echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution 1324 echo '0000001'; // Batch Number 1325 echo PHP_EOL; 1326 1327 1328 // File Trailer Record 1329 1330 echo '9'; // Record Type Code 1331 echo '000001'; // Batch Count 1332 echo str_pad( ceil( $count / 10 ), 6, '0', STR_PAD_LEFT ); // Block Count 1333 echo str_pad( $count, 8, '0', STR_PAD_LEFT ); // Entry/Addenda Count 1334 echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash 1335 echo str_pad( number_format( $total, 2, '', '' ), 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount 1336 echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount 1337 echo str_pad( '', 39 ); // Blanks 1338 echo PHP_EOL; 1339 1340 // The file must have a number of lines that is a multiple of 10 (e.g. 10, 20, 30). 1341 echo str_repeat( PHP_EOL, 10 - ( ( 4 + $count ) % 10 ) - 1 ); 1342 return ob_get_clean(); 1343 } 1163 1344 }
Note: See TracChangeset
for help on using the changeset viewer.