Exemplo n.º 1
0
 /**
  * Pay-Event
  * we will confirm the invoice with this method
  * 
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function sales_order_invoice_pay($observer)
 {
     // dont trigger if we are notifyed
     if (!empty($GLOBALS['isNotificationAction'])) {
         return $this;
     }
     // get invoice
     $invoice = $observer->getEvent()->getInvoice();
     $order = $invoice->getOrder();
     $payment = $order->getPayment();
     $addinfo = $payment->getAdditionalInformation();
     $invoices = $invoice->getOrder()->hasInvoices();
     $method = $payment->getMethod();
     if ($method != 'sofortrechnung') {
         return $this;
     }
     $transactionId = $payment->getAdditionalInformation('sofort_transaction');
     if (!empty($transactionId)) {
         $PnagInvoice = new PnagInvoice(Mage::getStoreConfig('payment/sofort/configkey'), $transactionId);
         $entity_type_model = Mage::getSingleton('eav/config')->getEntityType('invoice');
         $newInvoiceNumber = $entity_type_model->fetchNewIncrementId($invoice->getOrder()->getStoreId());
         $invoice->setIncrementId($newInvoiceNumber);
         $PnagInvoice->confirmInvoice($transactionId, $newInvoiceNumber);
         if ($PnagInvoice->isError()) {
             Mage::throwException($PnagInvoice->getError());
         } else {
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pnsofortueberweisung')->__('Successfully confirmed invoice: %s', $transactionId));
             $invoice->setTransactionId($transactionId);
             $payment->setAdditionalInformation("sofortrechnung_invoice_url", $PnagInvoice->getInvoiceUrl());
             $payment->save();
             return $this;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pnsofortueberweisung')->__('Could not confirm invoice.'));
     return $this;
 }
 * @author SOFORT AG http://www.sofort.com (integration@sofort.com)
 *
 */
require_once '../../../library/sofortLib.php';
define('CONFIGKEY', '1111:2222:6f3d938b65eb833e695393985e1r13z79c');
//your configkey or userid:projektid:apikey
$PnagInvoice = new PnagInvoice(CONFIGKEY);
$PnagInvoice->setVersion('MY_VERSION');
$PnagInvoice->addInvoiceAddress('John', 'Doe', 'Street', '15', '35578', 'City', 2, 'Max Mustermann', '3 Stock', 'Firma ABC');
//try firstname 'success' or 'decline' as firstname
$PnagInvoice->addShippingAddress('John', 'Doe', 'Street', '15', '35578', 'City', 2);
$PnagInvoice->setReason('Invoice', 'Invoice');
$PnagInvoice->setOrderId('213124');
$PnagInvoice->setCustomerId('213124');
$PnagInvoice->setDebitorVatNumber('DE325236');
$PnagInvoice->setEmailCustomer('*****@*****.**');
$PnagInvoice->addItemToInvoice(md5('unique'), 'Art01', 'a simple title', 1.2, 0, 'a simple description', 6, 19);
$PnagInvoice->setSuccessUrl('https://{website}/');
$PnagInvoice->setAbortUrl('https://{website}/');
$PnagInvoice->setTimeoutUrl('https://{website}/');
$PnagInvoice->setNotificationUrl('https://{website}/');
$err = $PnagInvoice->checkout();
$PnagInvoice->confirmInvoice($PnagInvoice->transactionId);
if ($PnagInvoice->isError()) {
    //PNAG-API didn't accept the data
    echo $PnagInvoice->getError();
} else {
    //buyer must be redirected to $paymentUrl else payment cannot be successfully completed!
    $paymentUrl = $PnagInvoice->getPaymentUrl();
    header('Location: ' . $paymentUrl);
}
 if ($_POST['sofort_action'] == 'sofort_comment') {
     shopSofortComment($_GET['oID'], $order, $_POST['status'], $_POST['comments'], $_POST['notify'], $_POST['notify_comments']);
 }
 if ($_POST['sofort_action'] == 'sofort_save' && $_POST['sofort_delete_all'] == '1') {
     $_POST['sofort_action'] = 'sofort_buttons';
     $_POST['sofort_button'] = 'cancel';
 }
 if ($_POST['sofort_action'] == 'sofort_buttons') {
     switch ($_POST['sofort_button']) {
         case 'invoice':
         case 'preview':
         case 'credit':
             $PnagInvoice->getInvoice();
             break;
         case 'confirm':
             $errors = $PnagInvoice->confirmInvoice();
             $warnings = $PnagInvoice->getWarnings();
             break;
         case 'cancel':
             $errors = $PnagInvoice->cancelInvoice();
             $warnings = $PnagInvoice->getWarnings();
             break;
         default:
             break;
     }
     $errorCodes = "";
     $successCodes = "";
     if ($errors) {
         $errorCodes .= "<div class='sofort_error'>";
         foreach ($errors as $oneError) {
             if (defined('MODULE_PAYMENT_SOFORT_MULTIPAY_XML_FAULT_' . $oneError['code'])) {
$PnagInvoice->addItemToInvoice(md5('unique'), 'Art01', 'a simple title', 1.2, 0, 'a simple description', 6, 19);
$PnagInvoice->setAbortUrl('http://127.0.0.1');
$PnagInvoice->setSuccessUrl('http://127.0.0.1');
$PnagInvoice->setTimeoutUrl('http://127.0.0.1');
$PnagInvoice->setNotificationUrl('http://127.0.0.1');
try {
    $err = $PnagInvoice->checkout();
    getWebPage($PnagInvoice->getPaymentUrl());
    // call sofort.com to 'activate' payment
} catch (XmlToArrayException $e) {
}
$transactionId = $PnagInvoice->getTransactionId();
$articles = array(array('articleId' => md5('unique'), 'articleNumber' => 'Art01', 'articleTitle' => 'a simple title', 'articlePrice' => 1.2, 'articleType' => 0, 'articleDescription' => 'a simple description', 'articleQuantity' => 2, 'articleTax' => 19));
$PnagInvoice = null;
$PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId);
$PnagInvoice->confirmInvoice();
$PnagInvoice = null;
$PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId);
$PnagInvoice->setTransactionId($transactionId);
$pnagArticles = array();
foreach ($articles as $article) {
    array_push($pnagArticles, array('itemId' => $article['articleId'], 'productNumber' => $article['articleNumber'], 'title' => $article['articleTitle'], 'description' => $article['articleDescription'], 'quantity' => $article['articleQuantity'], 'unitPrice' => number_format($article['articlePrice'], 2, '.', ''), 'tax' => number_format($article['articleTax'], 2, '.', '')));
}
try {
    $comment = 'must not be left empty for confirmed invoices, editing an invoice will result in refunded items';
    $PnagInvoice->updateInvoice($transactionId, $pnagArticles, $comment);
} catch (XmlToArrayException $e) {
}
/**
 * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
 * array containing the HTTP server response header fields and content.