<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

class EPayNotifyRequestHandlerPayPalSPB extends EPayNotifyRequestHandler {

  public function getEPayInfo() {
    $input = RequestOperations::getJsonFromInputStream();
    $res = $input->resource;
    
    $epayInfo = new EPayInfo();
    $epayInfo->tid = $res->id;
    $epayInfo->tidMerchant = $this->getMerchantTransactionId($epayInfo->tid);
    $epayInfo->amount = MathOperations::floatToString($res->amount->value);
    $epayInfo->paymentState = $res->status;
    
    $epayInfo->paymentDate = DateTimeOperations::getDateTimeNow();
    return $epayInfo;
  }

  public function getEmailXML() {
    $emailxml = new EmailXML();
    return $emailxml;
  }

  public function getEmailXMLKurse() {
    $emailxmlkurse = new EmailXMLKurse(); 
    $emailxmlkurse->kursnummer = "dummykurs"; 
    return array($emailxmlkurse);
  }

  protected function validateRequestStructure() {
    return true;
  }

  protected function validateRequestContent() {
    return true;
  }

  private function getMerchantTransactionId($tid) {
    $dbw = DBWorkWebEpayTids::getDefaultInstance();
    return $dbw->getMerchantTransactionIdByTransactionId($tid);
  }
}