<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf 
 */
class EPayNotifierDMZSofortEinbuchen extends EPayNotifier {

  
  public function doNotify($pEmailXml, $pEPayInfo, $pKurse, $pDateiendung = '.xml', $pPayonline='') {
    $emailxml = $pEmailXml;
    $message = new XMLNode('EPAY');
    $emailxml->setValue2Var('epay_state', $pEPayInfo->paymentState);
    $emailxml->setValue2Var('epay_payment_date', $pEPayInfo->paymentDate);
    $emailxml->setValue2Var('epay_tid', $pEPayInfo->tid);
    $emailxml->setValue2Var('epay_tid_merchant', $pEPayInfo->tidMerchant);
    $emailxml->setValue2Var('epay_amount', $pEPayInfo->amount);
    $emailxml->setValue2Var('epay_payerid', $pEPayInfo->payerid);
    $emailxml->setValue2Var('epay_processing_mode', $pEPayInfo->processingMode);

    $emailxml->setValue2Var('epay_order_id', $pEPayInfo->order_id);
    $emailxml->setValue2Var('epay_authorizationid', $pEPayInfo->authorizationid);
    $emailxml->setValue2Var('epay_capture_id', $pEPayInfo->capture_id);

    $emailxml->setValue2Var('payonline', $pPayonline);
    $message->addChild($emailxml->getXMLNode());
    
    $kurse = new XMLNode('KURSE');
    $message->addChild($kurse);
    foreach( $pKurse as $kurs ) {
      $kurse->addChild($kurs->getXMLNode());
    }
    
    $operation = AbgleichAPI::ABGLEICH_EPAYSTATUSAENDERN;
    $abgleichAPI = new AbgleichAPI();
    $result = $abgleichAPI->sendeNachricht($operation, new Nutzlast($message));
    return $result->code == 0;
  }

}