示例#1
0
 /**
  * Void payments.
  *
  * @param string                   $context
  * @param object                   $item
  * @param Joomla\Registry\Registry $params
  *
  * @return array|null
  */
 public function onPaymentsVoid($context, &$item, &$params)
 {
     $allowedContext = array("com_crowdfunding.payments.void.paypal", "com_crowdfundingfinance.payments.void.paypal");
     if (!in_array($context, $allowedContext)) {
         return null;
     }
     if (!$this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     // Create transport object.
     $options = new Joomla\Registry\Registry();
     /** @var  $options Joomla\Registry\Registry */
     $transport = new JHttpTransportCurl($options);
     $http = new JHttp($options, $transport);
     // Create payment object.
     $options = new Joomla\Registry\Registry();
     /** @var  $options Joomla\Registry\Registry */
     $this->prepareCredentials($options);
     $options->set("payment.preapproval_key", $item->txn_id);
     $options->set("request.envelope", $this->envelope);
     // Get API url.
     $apiUrl = $this->getApiUrl();
     try {
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_DOVOID_OPTIONS"), $this->debugType, $options) : null;
         $adaptive = new Prism\Payment\PayPal\Adaptive($apiUrl, $options);
         $adaptive->setTransport($http);
         $response = $adaptive->doVoid();
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_DOVOID_RESPONSE"), $this->debugType, $response) : null;
         // Include extra data to transaction record.
         if ($response->isSuccess()) {
             $note = JText::_("PLG_CROWDFUNDINGPAYMENT_PAYPALADAPTIVE_RESPONSE_NOTE_CANCEL_PREAPPROVAL");
             $extraData = $this->prepareExtraData($response, $note);
             $transaction = new Crowdfunding\Transaction(JFactory::getDbo());
             $transaction->load($item->id);
             $transaction->addExtraData($extraData);
             $transaction->updateExtraData();
             // DEBUG DATA
             JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_DOVOID_TRANSACTION"), $this->debugType, $transaction->getProperties()) : null;
         }
     } catch (Exception $e) {
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_ERROR_DOVOID"), $this->debugType, $e->getMessage()) : null;
         $message = array("text" => JText::sprintf($this->textPrefix . "_VOID_UNSUCCESSFULLY", $item->txn_id), "type" => "error");
         return $message;
     }
     $message = array("text" => JText::sprintf($this->textPrefix . "_VOID_SUCCESSFULLY", $item->txn_id), "type" => "message");
     return $message;
 }