/**
  * Looks up and updates orders for refund notifications.
  *
  * @return boolean
  */
 public function updateRefund()
 {
     $oOrder = $this->_getOrder();
     if ($this->_oNotification->getOriginOrderId() != null && $oOrder->oxorder__oxordernr->value != $this->_oNotification->getOriginOrderId()) {
         $this->_logIpnError("Order ID not valid for " . $this->_oNotification->getRefundTransactionId());
         return false;
     }
     $aRefunds = unserialize(str_replace(""", "\"", $oOrder->oxorder__bzrefunds->value));
     foreach ($aRefunds as $iKey => $aRefund) {
         if ($aRefund['refundid'] == $this->_oNotification->getRefundTransactionId()) {
             if ($aRefund['state'] != self::STATE_PENDING) {
                 $this->_logIpnError("Unable to change state of refund " . $this->_oNotification->getRefundTransactionId());
                 return false;
             }
             $aRefunds[$iKey]['state'] = str_replace("refund_", "", $this->_oNotification->getState());
             $oOrder->oxorder__bzrefunds = new oxField(serialize($aRefunds));
             $oOrder->save();
             return true;
         }
     }
     $this->_logIpnError("Refund not found for given ID: " . $this->_oNotification->getRefundTransactionId());
     return false;
 }
 /**
  * Test function with valid refund notification.
  */
 public function testValidateWithValidRefundNotification()
 {
     $params = array('state' => 'refund_completed', 'refund_transaction_id' => '1', 'origin_transaction_id' => '1', 'shop_id' => '10483', 'customer_email' => '*****@*****.**', 'amount' => '24.95', 'currency' => 'EUR', 'origin_order_id' => '1', 'custom_var_0' => 'PHP SDK', 'custom_var_1' => 'Euro 2012', 'custom_var_2' => 'Barzahlen v.1.3.3.7', 'hash' => '55b3b182caf79881f5ac9a4fd7ac4f84824267fc8ac8a18dcfd25535b48a646eb28a0acf864faaff006365fd5f0480c09341930bf15dbcbe3ad27e4fa0d5c9f5', 'page' => 'ipn/barzahlen');
     $notification = new Barzahlen_Notification(SHOPID, NOTIFICATIONKEY, $params);
     $this->assertEquals(null, $notification->getState());
     $this->assertEquals(null, $notification->getOriginTransactionId());
     $this->assertEquals(null, $notification->getShopId());
     $notification->validate();
     $this->assertTrue($notification->isValid());
     $this->assertEquals('refund', $notification->getNotificationType());
     $this->assertEquals('refund_completed', $notification->getState());
     $this->assertEquals('1', $notification->getRefundTransactionId());
     $this->assertEquals(null, $notification->getTransactionId());
     $this->assertEquals('1', $notification->getOriginTransactionId());
     $this->assertEquals('10483', $notification->getShopId());
     $this->assertEquals('*****@*****.**', $notification->getCustomerEmail());
     $this->assertEquals('24.95', $notification->getAmount());
     $this->assertEquals('EUR', $notification->getCurrency());
     $this->assertEquals(null, $notification->getOrderId());
     $this->assertEquals('1', $notification->getOriginOrderId());
     $this->assertEquals('PHP SDK', $notification->getCustomVar0());
     $this->assertEquals('Euro 2012', $notification->getCustomVar1());
     $this->assertEquals('Barzahlen v.1.3.3.7', $notification->getCustomVar2());
     $this->assertEquals(array('PHP SDK', 'Euro 2012', 'Barzahlen v.1.3.3.7'), $notification->getCustomVar());
     $this->assertEquals($params, $notification->getNotificationArray());
 }