Пример #1
0
 /**
  * Change Subscription State to Terminate.
  *
  * @throws WebsiteException
  */
 public function terminate()
 {
     global $_ARRAYLANG;
     if ($this->externalSubscriptionId) {
         \Cx\Core\Setting\Controller\Setting::init('MultiSite', '', 'FileSystem');
         $instanceName = \Cx\Core\Setting\Controller\Setting::getValue('payrexxAccount', 'MultiSite');
         $apiSecret = \Cx\Core\Setting\Controller\Setting::getValue('payrexxApiSecret', 'MultiSite');
         if (empty($instanceName) || empty($apiSecret)) {
             return;
         }
         $payrexx = new \Payrexx\Payrexx($instanceName, $apiSecret);
         $subscription = new \Payrexx\Models\Request\Subscription();
         $subscription->setId($this->externalSubscriptionId);
         try {
             $response = $payrexx->cancel($subscription);
             if (isset($response['status']) && $response['status'] != 'success' || isset($response['data']['status']) && $response['data']['status'] != 'cancelled') {
                 throw new SubscriptionException($_ARRAYLANG['TXT_MODULE_ORDER_SUBSCRIPTION_PAYREXX_CANCEL_FAILED']);
             }
         } catch (\Payrexx\PayrexxException $e) {
             throw new SubscriptionException($e->getMessage());
         }
     }
     //set state terminated.
     $this->setState(self::STATE_TERMINATED);
     //Set current date/time
     $this->setTerminationDate(new \DateTime());
     //Trigger the model event terminated on the subscription's product entity.
     \Env::get('cx')->getEvents()->triggerEvent('model/terminated', array(new \Doctrine\ORM\Event\LifecycleEventArgs($this, \Env::get('em'))));
 }
 /**
  * Verifies the parameters posted back by Payrexx
  * @return boolean True on success, false otherwise
  */
 public static function checkIn()
 {
     if (empty($_POST['transaction']['invoice']['paymentRequestId']) || empty($_POST['transaction']['status'])) {
         return false;
     }
     if ($_POST['transaction']['status'] === 'waiting') {
         die;
         // we don't want the shop to update the status to cancelled or confirmed
     }
     if ($_POST['transaction']['status'] !== 'confirmed') {
         return false;
     }
     $invoiceId = $_POST['transaction']['invoice']['paymentRequestId'];
     $arrSettings = \Cx\Core\Setting\Controller\Setting::getArray('Shop', 'config');
     if (empty($arrSettings)) {
         return false;
     }
     $instanceName = !empty($arrSettings['payrexx_instance_name']['value']) ? $arrSettings['payrexx_instance_name']['value'] : '';
     $apiSecret = !empty($arrSettings['payrexx_api_secret']['value']) ? $arrSettings['payrexx_api_secret']['value'] : '';
     if (empty($instanceName) || empty($apiSecret)) {
         return false;
     }
     $payrexx = new \Payrexx\Payrexx($instanceName, $apiSecret);
     $invoice = new \Payrexx\Models\Request\Invoice();
     $invoice->setId($invoiceId);
     try {
         $invoice = $payrexx->getOne($invoice);
     } catch (\Payrexx\PayrexxException $e) {
         return false;
     }
     return $invoice->getStatus() === $_POST['transaction']['status'];
 }