Making WordPress.org

Changeset 2463


Ignore:
Timestamp:
02/04/2016 03:36:26 PM (8 years ago)
Author:
kovshenin
Message:

WordCamp.org: Add an option to export ACH payment requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php

    r2434 r2463  
    268268        }
    269269
     270        $type = in_array( $_POST['wcpn_export_type'], array( 'default', 'jpm_wires', 'jpm_ach' ) ) ? $_POST['wcpn_export_type'] : 'default';
     271        $mime_type = 'text/csv';
     272        $ext = 'csv';
     273
     274        if ( $type == 'jpm_ach' ) {
     275            $mime_type = 'text/plain';
     276            $ext = 'ach';
     277        }
     278
    270279        $start_date = strtotime( $_POST['wcpn_export_start_date'] . ' 00:00:00' );
    271280        $end_date   = strtotime( $_POST['wcpn_export_end_date']   . ' 23:59:59' );
    272         $filename   = sanitize_file_name( sprintf( 'wordcamp-payments-%s-to-%s.csv', date( 'Y-m-d', $start_date ), date( 'Y-m-d', $end_date ) ) );
    273 
    274         $type = in_array( $_POST['wcpn_export_type'], array( 'default', 'jpm_wires' ) ) ? $_POST['wcpn_export_type'] : 'default';
     281        $filename   = sanitize_file_name( sprintf( 'wordcamp-payments-%s-to-%s.%s',
     282            date( 'Y-m-d', $start_date ), date( 'Y-m-d', $end_date ), $ext ) );
    275283
    276284        $report = self::generate_payment_report( $_POST['wcpn_date_type'], $start_date, $end_date, $type );
     
    279287            add_settings_error( 'wcp-dashboard', $report->get_error_code(), $report->get_error_message() );
    280288        } else {
    281             header( 'Content-Type: text/csv' );
     289            header( sprintf( 'Content-Type: %s', $mime_type ) );
    282290            header( sprintf( 'Content-Disposition: attachment; filename="%s"', $filename ) );
    283291            header( 'Cache-control: private' );
     
    364372
    365373        fclose( $report );
     374        return ob_get_clean();
     375    }
     376
     377    /**
     378     * NACHA via JP Morgan
     379     *
     380     * @param array $args
     381     *
     382     * @return string
     383     */
     384    protected static function _generate_payment_report_jpm_ach( $args ) {
     385        $args = wp_parse_args( $args, array(
     386            'request_indexes' => array(),
     387        ) );
     388
     389        $ach_options = apply_filters( 'wcb_payment_req_ach_options', array(
     390            'immediate-origin'    => '', // Immediate Origin (TIN) 10 characters
     391            'bank-routing-number' => '', // Immediate Destination (bank routing number)
     392            'company-id'          => '', // 1NNNNNNNNN (Federal IRS Number)
     393            'financial-inst'      => '', // Originating Financial Institution
     394        ) );
     395
     396        ob_start();
     397
     398        // File Header Record
     399
     400        echo '1'; // Record Type Code
     401        echo '01'; // Priority Code
     402        echo ' ' . str_pad( substr( $ach_options['bank-routing-number'], 0, 9 ), 9, '0', STR_PAD_LEFT );
     403        echo str_pad( substr( $ach_options['immediate-origin'], 0, 10 ), 10 ); // Immediate Origin (TIN)
     404        echo date( 'ymd' ); // Transmission Date
     405        echo date( 'Hi' ); // Transmission Time
     406        echo '1'; // File ID Modifier
     407        echo '094'; // Record Size
     408        echo '10'; // Blocking Factor
     409        echo '1'; // Format Code
     410        echo str_pad( 'BANK ONE', 23 ); // Destination
     411        echo str_pad( 'WCEXPORT', 23 ); // Origin
     412        echo str_pad( '', 8 ); // Reference Code (optional)
     413        echo PHP_EOL;
     414
     415        // Batch Header Record
     416
     417        echo '5'; // Record Type Code
     418        echo '200'; // Service Type Code
     419        echo 'WordCamp Communi'; // Company Name
     420        echo str_pad( '', 20 ); // Blanks
     421        echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company Identification (Federal IRS Number)
     422        echo 'PPD'; // Standard Entry Class
     423        echo 'Vendor Pay'; // Entry Description
     424        echo date( 'ymd' ); // Company Description Date
     425        echo date( 'ymd' ); // Effective Entry Date
     426        echo str_pad( '', 3 ); // Blanks
     427        echo '1'; // Originator Status Code
     428        echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution
     429        echo '0000001'; // Batch Number
     430        echo PHP_EOL;
     431
     432        $count = 0;
     433        $total = 0;
     434        $hash = 0;
     435
     436        foreach ( $args['request_indexes'] as $index ) {
     437            switch_to_blog( $index->blog_id );
     438            $post = get_post( $index->post_id );
     439
     440            if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' )
     441                continue;
     442
     443            $count++;
     444
     445            // Entry Detail Record
     446
     447            echo '6'; // Record Type Code
     448            echo 'DDA'; // Transaction Code
     449
     450            // Transit/Routing Number of Destination Bank + Check digit
     451            $routing_number = get_post_meta( $post->ID, '_camppayments_ach_routing_number', true );
     452            $routing_number = WCP_Encryption::maybe_decrypt( $routing_number );
     453            $routing_number = substr( $routing_number, 0, 8 + 1 );
     454            $routing_number = str_pad( $routing_number, 8 + 1 );
     455            $hash += absint( substr( $routing_number, 0, 8 ) );
     456            echo $routing_number;
     457
     458            // Bank Account Number
     459            $account_number = get_post_meta( $post->ID, '_camppayments_ach_account_number', true );
     460            $account_number = WCP_Encryption::maybe_decrypt( $account_number );
     461            $account_number = substr( $account_number, 0, 17 );
     462            $account_number = str_pad( $account_number, 17 );
     463            echo $account_number;
     464
     465            // Amount
     466            $amount = round( floatval( get_post_meta( $post->ID, '_camppayments_payment_amount', true ) ), 2 );
     467            $total += $amount;
     468            $amount = str_pad( $amount, 10, '0', STR_PAD_LEFT );
     469            echo $amount;
     470
     471            // Individual Identification Number
     472            echo str_pad( sprintf( '%d-%d', $index->blog_id, $index->post_id ), 15 );
     473
     474            // Individual Name
     475            $name = get_post_meta( $post->ID, '_camppayments_ach_account_holder_name', true );
     476            $name = WCP_Encryption::maybe_decrypt( $name );
     477            $name = substr( $name, 0, 22 );
     478            $name = str_pad( $name, 22 );
     479            echo $name;
     480
     481            echo '  '; // User Defined Data
     482            echo '0'; // Addenda Record Indicator
     483
     484            // Trace Number
     485            echo str_pad( substr( $ach_options['bank-routing-number'], 0, 8 ), 8, '0', STR_PAD_LEFT ); // routing number
     486            echo str_pad( $count, 7, '0', STR_PAD_LEFT ); // sequence number
     487            echo PHP_EOL;
     488        }
     489
     490        // Batch Trailer Record
     491
     492        echo '8'; // Record Type Code
     493        echo '200'; // Service Class Code
     494        echo str_pad( $count, 6, '0', STR_PAD_LEFT ); // Entry/Addenda Count
     495        echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash
     496        echo str_pad( $total, 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount
     497        echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount
     498        echo str_pad( substr( $ach_options['company-id'], 0, 10 ), 10 ); // Company ID
     499        echo str_pad( '', 25 ); // Blanks
     500        echo str_pad( substr( $ach_options['financial-inst'], 0, 8 ), 8 ); // Originating Financial Institution
     501        echo '0000001'; // Batch Number
     502        echo PHP_EOL;
     503
     504
     505        // File Trailer Record
     506
     507        echo '9'; // Record Type Code
     508        echo '000001'; // Batch Count
     509        echo str_pad( ceil( $count / 10 ), 6, '0', STR_PAD_LEFT ); // Block Count
     510        echo str_pad( $count, 8, '0', STR_PAD_LEFT ); // Entry/Addenda Count
     511        echo str_pad( substr( $hash, -10 ), 10, '0', STR_PAD_LEFT ); // Entry Hash
     512        echo str_pad( $total, 12, '0', STR_PAD_LEFT ); // Total Debit Entry Dollar Amount
     513        echo str_pad( 0, 12, '0', STR_PAD_LEFT ); // Total Credit Entry Dollar Amount
     514        echo str_pad( '', 39 ); // Blanks
     515        echo PHP_EOL;
     516
     517        // The file must have a number of lines that is a multiple of 10 (e.g. 10, 20, 30).
     518        echo str_repeat( PHP_EOL, 10 - ( ( 4 + $count ) % 10 ) - 1 );
    366519        return ob_get_clean();
    367520    }
     
    701854                        <option value="default">Default</option>
    702855                        <option value="jpm_wires">JP Morgan Access - Wire Payments</option>
     856                        <option value="jpm_ach">JP Morgan - NACHA</option>
    703857                    </select>
    704858                </label>
Note: See TracChangeset for help on using the changeset viewer.