AbcAeffchen / Sephpa

PHP class to create SEPA xml files for credit transfer and direct debit
GNU Lesser General Public License v3.0
71 stars 31 forks source link

PHP Fatal error: Uncaught Error: Class 'SephpaCreditTransfer' not found #19

Closed Johnny99211 closed 5 years ago

Johnny99211 commented 5 years ago

Ich habe per Composer alles installiert und vor dem Erstellen eines SephpaCreditTransfer's die autoload.php von Composer aus dem vendor Ordner required, jedoch funktioniert es immer noch nicht. Selbst eine manuelle Installation führt nicht zum gewünschten Erfolg.

Ich habe alle Pfade überprüft und die autoload.php wird geladen.

require_once get_home_path() . 'sepa-payment-xml-generator/vendor/autoload.php';
require 'admin/functions/generate-sepa-xml-file.php';

In der generate-sepa-xml-file.php erstelle ich meine SEPA-Überweisung und füge die einzelnen Zahlungsempfänger hinzu:

//DB
global $wpdb;

//Get all results from the wp_accepted_jobs table which are not payed out
$jobs = $wpdb->get_results( 'SELECT * FROM  wp_accepted_jobs WHERE paid_out = 0' );

//Loop over accepted jobs and add payments to the transfer file
if ( ! empty( $jobs ) ) {

    //Create new sepa transfer file
    $creditTransferFile = new SephpaCreditTransfer( get_option( 'wc_job_tab_email_shop_name' ), md5( uniqid( mt_rand(), true ) ), SephpaCreditTransfer::SEPA_PAIN_001_002_03 );

    //Add required information's about the debtor
    $creditTransferCollection = $creditTransferFile->addCollection( [
        'pmtInfId'    => md5( uniqid( mt_rand(), true ) ),          // ID of the payment collection
        'dbtr'        => get_option( 'wc_job_tab_email_shop_name' ),            // (max 70 characters)
        'iban'        => get_option( 'wc_job_tab_payment_company_iban' ),       // IBAN of the Debtor
        'bic'         => get_option( 'wc_job_tab_payment_company_bic' ),        // BIC of the Debtor
        // optional
        'ccy'         => 'EUR',                                                 // Currency. Default is 'EUR'
        'btchBookg'   => 'true',                                                // BatchBooking, only 'true' or 'false'
        //'ctgyPurp'      => ,                                                  // Category Purpose. Do not use this if you do not know how. For further information read the SEPA documentation
        'reqdExctnDt' => date( 'Y-m-d', strtotime( 'tomorrow' ) ), // Requested Execution Date: YYYY-MM-DD
        'ultmtDebtr'  => get_option( 'wc_job_tab_email_shop_name' )             // Just an information, this do not affect the payment (max 70 characters)
    ] );

    //Add payments
    foreach ( $jobs as $job ) {

        //Get userdata from developer
        $developer_info = get_userdata( $job->developer_id );

        //Add required information about the creditor
        $creditTransferCollection->addPayment( [
            'pmtId'     => md5( uniqid( mt_rand(), true ) ),            // ID of the payment (EndToEndId)
            'instdAmt'  => $job->job_pay,                                           // Amount
            'iban'      => get_user_meta( $job->developer_id, 'user_iban', true ),  // IBAN of the Creditor
            'bic'       => get_user_meta( $job->developer_id, 'user_bic', true ),   // BIC of the Creditor (only required for pain.001.002.03)
            'cdtr'      => $developer_info->first_name . ' ' . $developer_info->last_name,    // (max 70 characters)
            // optional
            'ultmtCdrt' => $developer_info->first_name . ' ' . $developer_info->last_name,    // Just an information, this do not affect the payment (max 70 characters)
            //'purp'      => ,                                                      // Do not use this if you do not know how. For further information read the SEPA documentation
            'rmtInf'    => 'Deine Entlohnung für den Auftrag: ' . $job->job_id      // unstructured information about the remittance (max 140 characters)
        ] );
    }

    //Download XML file
    $creditTransferFile->download();

} else {
    wp_send_json_error( null, 500 );
    wp_die();
}

Es ist nicht die erste Library, welche ich an dieser Stelle einbinde und bei allen anderen hat es einwandfrei funktioniert. Mittlerweile gehen mir die Ideen aus.

Was kann ich tun?

AbcAeffchen commented 5 years ago

Das ist jetzt ein bisschen schwierig aus der Ferne zu debuggen. Wenn der Autoloader von Composer geladen wird sollte das eigentlich gehen. Ich bin nicht sicher ob ich hier die ganze Datei sehe. Wenn ja, könnte das Problem der fehlende Namespace sein. Alle Composerpakete müssen in einem Namespcae der Form author\package. In meinem Fall also AbcAeffchen\Sephpa. Die Klasse SephpaCreditTransfer heißt also vollständig AbcAeffchen\Sephpa\SephpaCreditTransfer. Hier muss entweder der volle Name verwendet werden oder der Namespace muss vorher importiert werden.

Johnny99211 commented 5 years ago

Eventuell habe ich auch die falsche composer.json. Wie müsste diese denn im Fall deiner Library aussehen, wenn ich diese in einem Ordner namens sepa-file-generator liegen habe?

AbcAeffchen commented 5 years ago

Also eigentlich hast du eine composer.json für dein Projekt in die du alle Abhängigkeiten rein schreibst. Es gibt da diesen Punkt required und da sollte irgendwo "abcaeffchen/sephpa": "~2.0.0" stehen oder auch "abcaeffchen/sephpa": "~1.3.0" wenn du eine ältere version willst. Mehr musst du nicht schreiben. Den rest sollte Composer machen.

Johnny99211 commented 5 years ago

Also ich habe in dem Ordner eine Date mit folgendem Inhalt:

{
  "require": {
    "abcaeffchen/sepa-utilities": "~1.2.4",
    "abcaeffchen/sephpa": "~2.0.0"
  }
}

Ich führe jetzt im Ordner composer install aus. Ich habe nicht direkt ein Projekt mit einer composer.json, weil ich in WordPress entwickel. Wenn ich jetzt composer install ausführe, bekomme ich einen Fehler:

Problem 1
    - The requested package abcaeffchen/sephpa ~2.0.0 is satisfiable by abcaeffchen/sephpa[2.0.0-beta1] but these conflict with your requirements or minimum-stability.
AbcAeffchen commented 5 years ago

Mit Wordpress kenne ich mich nicht aus. Der Fehler sagt aber nur, dass es mit Version 2.0.0 nicht geht. Das ist ein Beta Release. Versuche es mal mit 1.3.0. sepa-utilities musst du eigentlich nicht extra einbinden. Da wird die richtige Version schon von Sephpa verlangt.

Johnny99211 commented 5 years ago

Ich habe deinen Tipp befolgt, bekomme nun leider eine andere Fehlermeldung:

{
  "require": {
    "abcaeffchen/sepa-utilities": "~1.3.0",
    "abcaeffchen/sephpa": "~2.0.0"
  }
}
Problem 1
    - The requested package abcaeffchen/sepa-utilities ~1.3.0 exists as abcaeffchen/sepa-utilities[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, dev-master] but these are rejected by your constraint.
  Problem 2
    - The requested package abcaeffchen/sephpa ~2.0.0 is satisfiable by abcaeffchen/sephpa[2.0.0-beta1] but these conflict with your requirements or minimum-stability.
AbcAeffchen commented 5 years ago

Ich habe gesagt: 2.0.0 geht nicht -> versuche 1.3.0 und sepa-utilities musst du eigentlich gar nicht einbinden.

Johnny99211 commented 5 years ago

Jetzt gehts 👍 Danke dir!