Exemplo n.º 1
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $this->invoice = $invoice;
     list($payment) = $invoice->getPaymentRecords();
     $params = array('key' => $this->getConfig('key'), 'ref' => $payment->receipt_id, 'uid' => $payment->user_id, 'type' => 2);
     $params['sign'] = $this->calculateSignature($params, $this->getConfig('secret'));
     $requst = new Am_HttpRequest(self::URL_TICKET, Am_HttpRequest::METHOD_POST);
     $requst->addPostParameter($params);
     $log = $this->logRequest($requst);
     $responce = $requst->send();
     $log->add($responce);
     if ($responce->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $responce->getStatus());
         return;
     }
     $res = Am_Controller::decodeJson($responce->getBody());
     if ($res['result'] == 1) {
         $invoice->setCancelled();
         $result->setSuccess();
         return;
     }
     $result->setFailed($res['errors']);
 }
Exemplo n.º 2
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $invoice->setCancelled(true);
 }
Exemplo n.º 3
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $payment = current($invoice->getPaymentRecords());
     try {
         $this->cancelInvoice($payment, $result);
         $invoice->setCancelled(true);
     } catch (Exception $e) {
         $result->setFailed($e->getMessage());
     }
 }
Exemplo n.º 4
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     if ($actionName == 'cancel-admin') {
         $invoice->setCancelled(true);
     } else {
         parent::cancelAction($invoice, $actionName, $result);
     }
 }
Exemplo n.º 5
0
 function doUpgrade(Invoice $invoice, InvoiceItem $item, Invoice $newInvoice, ProductUpgrade $upgrade)
 {
     if (!$this->getConfig('datalink_user') || !$this->getConfig('datalink_pass')) {
         $this->getDi()->errorLogTable->log("ccBill plugin error: Datalink is not configured!");
         return;
     }
     $payments = $invoice->getPaymentRecords();
     $subscriptionId = $payments[0]->transaction_id;
     $vars = array('clientAccnum' => $this->getConfig('account'), 'usingSubacc' => $this->getConfig('subaccount_id'), 'subscriptionId' => $subscriptionId, 'newClientAccnum' => $this->getConfig('account'), 'newClientSubacc' => $this->getConfig('subaccount_id'), 'sharedAuthentication' => 1, 'action' => 'chargeByPreviousTransactionId', 'currencyCode' => $this->currency_codes[$invoice->currency], 'initialPrice' => $newInvoice->first_total, 'initialPeriod' => $this->getDays($newInvoice->first_period), 'returnXML' => 1, 'username' => $this->getConfig('datalink_user'), 'password' => $this->getConfig('datalink_pass'));
     if ($newInvoice->rebill_times) {
         $vars['recurringPrice'] = $newInvoice->second_total;
         $vars['recurringPeriod'] = $this->getDays($newInvoice->second_period);
         $vars['rebills'] = $newInvoice->rebill_times == IProduct::RECURRING_REBILLS ? 99 : $newInvoice->rebill_times;
     } else {
         $vars['recurringPrice'] = 0;
         $vars['recurringPeriod'] = 0;
         $vars['rebills'] = 0;
     }
     $r = new Am_HttpRequest($requestString = "https://bill.ccbill.com/jpost/billingApi.cgi?" . http_build_query($vars, '', '&'));
     $response = $r->send();
     if (!$response) {
         $this->getDi()->errorLogTable->log('ccBill Billing API  error: Unable to contact datalink server');
         throw new Am_Exception_InternalError('ccBill Billing API  error: Unable to contact datalink server');
     }
     $resp = $response->getBody();
     // Log datalink requests;
     $this->getDi()->errorLogTable->log(sprintf("ccBill billing API  debug:\n%s\n%s", $requestString, $resp));
     $xml = simplexml_load_string($resp);
     if ((string) $xml->approved != "1") {
         throw new Am_Exception_InternalError('ccBill Subscription Management error: Incorrect response received while attempting to upgrade subscription!');
     }
     $tr = new Am_Paysystem_Transaction_Ccbill_Upgrade($this, $xml);
     // Add payment to new invocie;
     $newInvoice->addPayment($tr);
     // Cancel old one
     $invoice->setCancelled(true);
 }