/**
  *
  * @param User 
  * @param Am_Paysystem_Abstract $payplugin
  * @param array $product_ids array of product_id to use for generation
  * @param int $invCnt count of invoices per user
  * @param int $invVar variation of count of invoices per user
  * @param int $prdCnt count of products per invoice
  * @param int $prdVar variation of products per invoice 
  */
 public function createInvoices($user, $payplugin, $product_ids, $invCnt, $invVar, $prdCnt, $prdVar)
 {
     $invoiceLimit = $this->getLimit($invCnt, $invVar);
     for ($j = 1; $j <= $invoiceLimit; $j++) {
         //subscribe user for some subscriptions
         $invoice = $this->getDi()->invoiceTable->createRecord();
         $productLimit = $this->getLimit($prdCnt, $prdVar);
         for ($k = 1; $k <= $productLimit; $k++) {
             $invoice->add(Am_Di::getInstance()->productTable->load(array_rand($product_ids)), 1);
         }
         $invoice->setUser($user);
         $invoice->setPaysystem($payplugin->getId());
         $invoice->calculate();
         $invoice->save();
         $transaction = new Am_Paysystem_Transaction_Manual($payplugin);
         $transaction->setAmount($invoice->first_total)->setInvoice($invoice)->setTime(new DateTime('-' . rand(0, 200) . ' days'))->setReceiptId('demo-' . uniqid() . microtime(true));
         $invoice->addPayment($transaction);
         //            $cc = $this->createCcRecord($user);
         //
         //            Am_Paysystem_Transaction_CcDemo::_setTime(new DateTime('-'.rand(0,200).' days'));
         //            $payplugin->doBill($invoice, true, $cc);
         $transaction = null;
         unset($transaction);
         $invoice = null;
         unset($invoice);
     }
 }
Example #2
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest("https://" . $this->getConfig('login') . ":" . $this->getConfig('password') . "@payment.architrade.com/cgi-adm/refund.cgi");
     $invoice = $payment->getInvoice();
     $currency = $this->getCurrencyCode($invoice);
     $post_params = new stdclass();
     $post_params->merchant = $this->getConfig('merchant');
     $post_params->amount = $amount * 100;
     $count = $this->getDi()->db->selectCol("SELECT COUNT(*) FROM ?_invoice_payment\n                WHERE invoice_id=?d AND dattm < ?\n                ", $payment->invoice_id, $payment->dattm);
     $post_params->orderId = $invoice->public_id . "-" . sprintf("%03d", array_shift($count));
     $post_params->transact = $invoice->data()->get(self::TICKET);
     $post_params->textreply = 'true';
     $post_params->currency = $currency;
     $post_params->md5key = md5($s2 = $this->getConfig('key2') . md5($s1 = $this->getConfig('key1') . "merchant=" . $this->getConfig('merchant') . "&orderid=" . $invoice->public_id . "&transact=" . $invoice->data()->get(self::TICKET) . "&amount=" . $amount));
     $request->addPostParameter((array) $post_params);
     $response = $request->send();
     $response = $this->parseResponse($response->getBody());
     if ($response['result'] === 0) {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-dibs-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund!'));
     }
 }
 function addpaymentAction()
 {
     $invoice = $this->getDi()->invoiceTable->load($this->_request->getInt('invoice_id'));
     if (!$invoice || $invoice->user_id != $this->user_id) {
         throw new Am_Exception_InputError("Invoice not found");
     }
     $form = $this->getAddForm();
     if (!$form->validate()) {
         echo $form;
         return;
     }
     $vars = $form->getValue();
     $transaction = new Am_Paysystem_Transaction_Manual($this->getDi()->plugins_payment->get($vars['paysys_id']));
     $transaction->setAmount($vars['amount'])->setReceiptId($vars['receipt_id'])->setTime(new DateTime($vars['dattm']));
     $invoice->addPayment($transaction);
     $form->setDataSources(array(new Am_Request(array())));
     $form->addHidden('saved-ok');
     echo $form;
 }
Example #4
0
 function processARUDD($uri)
 {
     $request = new Am_HttpRequest($uri, Am_HttpRequest::METHOD_POST);
     $request->setAuth($this->getConfig('login'), $this->getConfig('passwd'));
     $response = $request->send();
     $origXml = simplexml_load_string($response->getBody());
     $xml = simplexml_load_string(base64_decode((string) $origXml->file));
     //       $log = $this->logRequest($request, 'ARUDD');
     //       $log->add($response);
     //       $log->add($origXml->asXML());
     //       $log->add($xml->asXML());
     foreach ($xml->Data->ARUDD->Advice->OriginatingAccountRecords->OriginatingAccountRecord->ReturnedDebitItem as $ARUDD) {
         $ref = (string) $ARUDD['ref'];
         /* @var $invoice Invoice */
         $invoice = $this->getDi()->invoiceTable->findFirstByPublicId(substr($ref, strlen(self::REF_PREFIX)));
         if ($invoice) {
             $payments = $invoice->getPaymentRecords();
             $p = array_pop($payments);
             $tr = new Am_Paysystem_Transaction_Manual($this);
             $tr->setInvoice($invoice);
             $tr->setReceiptId(sprintf('%s-%s', (string) $ARUDD['transCode'], (string) $ARUDD['returnCode']));
             $invoice->addVoid($tr, $p->receipt_id);
         }
     }
 }
Example #5
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest(self::API_URL, Am_HttpRequest::METHOD_POST);
     $post_params = new stdclass();
     $post_params->protocol = '6';
     $post_params->msgtype = 'refund';
     $post_params->merchant = $this->getConfig('merchant');
     $post_params->amount = intval($amount * 100);
     $post_params->transaction = $payment->receipt_id;
     foreach ((array) $post_params as $k => $v) {
         $cstr .= $v;
     }
     $cstr .= $this->getConfig('secret');
     $post_params->md5check = md5($cstr);
     $request->addPostParameter((array) $post_params);
     $response = $request->send();
     $parsedResponse = simplexml_load_string($response->getBody());
     if ((string) $parsedResponse->qpstat != '000') {
         $result->setFailed("Payment failed: Description - " . $this->getErrorMessage((string) $parsedResponse->qpstat) . " QuickPay message - " . $parsedResponse->qpstatmsg);
     } else {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-quickpay-refund');
         $result->setSuccess($trans);
     }
 }
Example #6
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     list(, $trans_id) = split("-", $payment->receipt_id);
     try {
         $r = new Am_HttpRequest($this->getAPIURL(self::API_REFUND, array('TRANSACTION_ID' => $trans_id, 'MERCHANT_ID' => $this->getConfig("merchant_id"), 'ZombaioGWPass' => $this->getConfig("password"), 'Refund_Type' => 1)));
         $response = $r->send();
     } catch (Exception $e) {
         $this->getDi()->errorLogTable->logException($e);
     }
     if ($response && $response->getBody() == 1) {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-zombaio-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund!'));
     }
 }
Example #7
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $result = $this->APIRequest("payment", "credit", array('merchantnumber' => $this->getConfig('id'), 'transactionid' => $payment->receipt_id, 'amount' => $amount * 100));
     $xml = $this->getResponseXML($result);
     if ($xml->creditResponse->creditResult == 'true') {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-epay-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund!'));
     }
 }
Example #8
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $log = Am_Di::getInstance()->invoiceLogRecord;
     $log->title = "refundTransaction";
     $log->paysys_id = $this->getId();
     $apireq = new Am_Paysystem_PaypalApiRequest($this);
     $apireq->refundTransaction($payment);
     $res = $apireq->sendRequest($log);
     $log->setInvoice($payment->getInvoice());
     $log->update();
     if ($res['ACK'] != 'Success') {
         throw new Am_Exception_InputError('Transaction was not refunded. Got error from paypal: ' . $res['L_SHORTMESSAGE0']);
     }
     $trans = new Am_Paysystem_Transaction_Manual($this);
     $trans->setAmount($amount);
     $trans->setReceiptId($res['REFUNDTRANSACTIONID']);
     $result->setSuccess();
 }
Example #9
0
 public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = $this->createHttpRequest();
     $ps = new stdclass();
     $ps->type = 'rfnd';
     $ps->reason = 'ticket.type.refund.8';
     $ps->comment = 'refund request for aMember user (' . $payment->getUser()->login . ')';
     if (doubleval($amount) == doubleval($payment->amount)) {
         $ps->refundType = 'FULL';
     } else {
         $ps->refundType = 'PARTIAL_AMOUNT';
         $ps->refundAmount = $amount;
     }
     $get_params = http_build_query((array) $ps, '', '&');
     $request->setUrl($s = 'https://api.clickbank.com/rest/1.3/tickets/' . $payment->receipt_id . "?{$get_params}");
     $request->setHeader(array('Content-Length' => '0', 'Accept' => 'application/xml', 'Authorization' => $this->getConfig('dev_key') . ':' . $this->getConfig('clerk_key')));
     $request->setMethod(Am_HttpRequest::METHOD_POST);
     $this->logRequest($request);
     $request->setMethod('POST');
     $response = $request->send();
     $this->logResponse($response);
     if ($response->getStatus() != 200 && $response->getBody() != 'Refund ticket already open') {
         throw new Am_Exception_InputError("An error occurred during refund request");
     }
     $trans = new Am_Paysystem_Transaction_Manual($this);
     $trans->setAmount($amount);
     $trans->setReceiptId($payment->receipt_id . '-clickbank-refund');
     $result->setSuccess($trans);
 }
Example #10
0
 public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     // Request to check state of payment ; must be confirmed / paid_out
     $response = $this->_sendRequest('/payments/' . $payment->transaction_id, null, 'GET');
     if ($response->getStatus() !== 200) {
         $result->setFailed('An error occured, unable to find the payment.');
         return $result;
     }
     $response = json_decode($response->getBody(), true);
     if (!in_array($response['payments']['status'], array('confirmed', 'paid_out'))) {
         $result->setFailed('Payment status must be either "Confirmed" or "Paid out" at GoCardLess. Current state is "' . $response['payments']['status'] . '"');
         return $result;
     }
     $response = $this->_sendRequest('/refunds/', array('refunds' => array('amount' => intval(doubleval($amount) * 100), 'total_amount_confirmation' => intval(doubleval($amount) * 100), 'links' => array('payment' => $payment->transaction_id))));
     if ($response->getStatus() !== 201) {
         throw new Am_Exception_InputError("An error occurred while cancellation request");
     }
     $trans = new Am_Paysystem_Transaction_Manual($this);
     $trans->setAmount($amount);
     $trans->setReceiptId($payment->receipt_id . '-gocardlesspro-refund');
     $result->setSuccess($trans);
 }
Example #11
0
 function processRefund__(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     list(, $trans_id) = split("-", $payment->receipt_id);
     try {
         $r = new Am_HttpRequest('http://srs.segpay.com/ADM.asmx/CancelMembership' . '?Userid=' . $this->getConfig('userid') . '&UserAccessKey=' . $this->getCOnfig('useraccesskey') . '&PurchaseID=' . $trans_id . '&CancelReason=');
         $response = $r->send();
     } catch (Exception $e) {
         $this->getDi()->errorLogTable->logException($e);
     }
     if ($response && $response->getBody() == '<string>Successful</string>') {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id);
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund! ' . $response->getBody()));
     }
 }
Example #12
0
 /**
  *
  * @param User
  * @param Am_Paysystem_Abstract $payplugin
  * @param array $product_ids array of product_id to use for generation
  * @param int $invCnt count of invoices per user
  * @param int $invVar variation of count of invoices per user
  * @param int $prdCnt count of products per invoice
  * @param int $prdVar variation of products per invoice
  * @param int $start timestamp period begin
  * @param int $end timestamp period end
  */
 public function createInvoices($user, $payplugin, $product_ids, $invCnt, $invVar, $prdCnt, $prdVar, $start, $end, $coupons = array())
 {
     $invoiceLimit = $this->getLimit($invCnt, $invVar);
     for ($j = 1; $j <= $invoiceLimit; $j++) {
         $tm = mt_rand($start, $end);
         /* @var $invoice Invoice */
         $invoice = $this->getDi()->invoiceTable->createRecord();
         $productLimit = max(1, $this->getLimit($prdCnt, $prdVar));
         for ($k = 1; $k <= $productLimit; $k++) {
             try {
                 $product = Am_Di::getInstance()->productTable->load(array_rand($product_ids));
                 if (!($err = $invoice->isProductCompatible($product))) {
                     $invoice->add($product, 1);
                 }
             } catch (Am_Exception_InputError $e) {
             }
         }
         if (!count($invoice->getItems())) {
             continue;
         }
         if (count($coupons) && rand(1, 5) == 5) {
             $invoice->setCouponCode($coupons[array_rand($coupons)]);
             $invoice->validateCoupon();
         }
         $invoice->tm_added = sqlTime($tm);
         $invoice->setUser($user);
         $invoice->calculate();
         $invoice->setPaysystem($payplugin->getId());
         $invoice->save();
         $this->getDi()->setService('dateTime', new DateTime('@' . $tm));
         if ($invoice->isZero()) {
             $tr = new Am_Paysystem_Transaction_Free($this->getDi()->plugins_payment->loadGet('free'));
             $tr->setInvoice($invoice)->setTime(new DateTime('@' . $tm))->process();
         } else {
             $tr = new Am_Paysystem_Transaction_Manual($payplugin);
             $tr->setAmount($invoice->first_total)->setInvoice($invoice)->setTime(new DateTime('@' . $tm))->setReceiptId('demo-' . substr(sprintf('%.4f', microtime(true)), -7))->process();
             //recurring payments
             $i = 1;
             while ((double) $invoice->second_total && $invoice->rebill_date < sqlDate($end) && $invoice->rebill_times >= $i && !$invoice->isCancelled()) {
                 $this->getDi()->setService('dateTime', new DateTime('@' . amstrtotime($invoice->rebill_date)));
                 $tr = new Am_Paysystem_Transaction_Manual($payplugin);
                 $tr->setAmount($invoice->second_total)->setInvoice($invoice)->setTime(new DateTime('@' . amstrtotime($invoice->rebill_date)))->setReceiptId('demo-rebill-' . $i++ . '-' . substr(sprintf('%.4f', microtime(true)), -7))->process();
                 if (rand(1, 5) == 5) {
                     //20% probability
                     $invoice->setCancelled(true);
                 }
             }
             //            $cc = $this->createCcRecord($user);
             //
             //            Am_Paysystem_Transaction_CcDemo::_setTime(new DateTime('-'.rand(0,200).' days'));
             //            $payplugin->doBill($invoice, true, $cc);
         }
         $tr = null;
         unset($tr);
         $invoice = null;
         unset($invoice);
     }
 }
 public function handleRecord($id, $record)
 {
     if (!$this->_vars['add_payment']) {
         $a = $this->grid->getDi()->accessRecord;
         $a->begin_date = $this->_vars['start_date'];
         $a->expire_date = $this->_vars['expire_date'];
         $a->product_id = $this->_vars['product_id'];
         $a->user_id = $id;
         $a->insert();
     } else {
         $invoice = $this->grid->getDi()->invoiceRecord;
         $invoice->user_id = $id;
         $invoice->add($this->_getProduct($this->_vars['product_id']));
         $invoice->paysys_id = 'free';
         $invoice->comment = 'mass-subscribe';
         $invoice->calculate();
         $invoice->save();
         $tr = new Am_Paysystem_Transaction_Manual($this->grid->getDi()->plugins_payment->loadGet('free'));
         $tr->setAmount($this->_vars['amount']);
         $tr->setTime(new DateTime($this->_vars['start_date']));
         $tr->setReceiptId('mass-subscribe-' . uniqid());
         $invoice->addPayment($tr);
     }
 }
Example #14
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $this->invoice = $payment->getInvoice();
     $params = array('key' => $this->getConfig('key'), 'ref' => $payment->receipt_id, 'uid' => $payment->user_id, 'type' => 1);
     $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) {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id);
         $result->setSuccess($trans);
         return;
     }
     $result->setFailed($res['errors']);
 }
 public function handleRecord($id, $record)
 {
     switch ($this->_vars['action']) {
         case 'access':
             switch ($this->_vars['access_type']) {
                 case 'exact':
                     $begin_date = $this->_vars['begine_date'];
                     $expire_date = $this->_vars['expire_date'];
                     break;
                 case 'period':
                     $invoice = $this->grid->getDi()->invoiceRecord;
                     $invoice->setUser($this->grid->getDi()->userTable->load($id));
                     $product = $this->grid->getDi()->productTable->load($this->_vars['product_id']);
                     $begin_date = $product->calculateStartDate($this->grid->getDi()->sqlDate, $invoice);
                     $p = new Am_Period($this->_vars['period']);
                     $expire_date = $p->addTo($begin_date);
                     break;
             }
             $a = $this->grid->getDi()->accessRecord;
             $a->begin_date = $begin_date;
             $a->expire_date = $expire_date;
             $a->product_id = $this->_vars['product_id'];
             $a->user_id = $id;
             $a->comment = $this->_vars['comment'];
             $a->insert();
             break;
         case 'payment':
             $invoice = $this->grid->getDi()->invoiceRecord;
             $invoice->user_id = $id;
             $invoice->add($this->grid->getDi()->productTable->load($this->_vars['product_id']));
             $items = $invoice->getItems();
             $item = $items[0];
             $item->first_price = $item->first_total = $this->_vars['amount'];
             $item->second_price = $item->second_total = 0;
             $item->rebill_times = 0;
             $item->second_period = null;
             $invoice->first_subtotal = $invoice->first_total = $this->_vars['amount'];
             $invoice->second_subtotal = $invoice->second_total = 0;
             $invoice->rebill_times = 0;
             $invoice->second_period = null;
             $invoice->first_period = $item->first_period;
             $invoice->paysys_id = $this->_vars['paysys_id'];
             $invoice->comment = $this->_vars['comment'] ? $this->_vars['comment'] : 'mass-subscribe';
             $invoice->save();
             $tr = new Am_Paysystem_Transaction_Manual($this->grid->getDi()->plugins_payment->loadGet($invoice->paysys_id));
             $tr->setAmount($this->_vars['amount']);
             $tr->setTime(new DateTime($this->_vars['dattm']));
             $tr->setReceiptId('mass-subscribe-' . uniqid() . '-' . $invoice->pk());
             $invoice->addPayment($tr);
             break;
     }
 }
Example #16
0
 public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest(self::REFUND_URL, Am_HttpRequest::METHOD_POST);
     $vars = array('MerchantId' => $this->getConfig('merchant_id'), 'TransactionId' => $payment->receipt_id, 'Amount' => $amount, 'ContentType' => 'text');
     $vars['SecurityKey'] = $this->getRefundSecurityKey($vars);
     foreach ($vars as $k => $v) {
         $request->addPostParameter($k, $v);
     }
     $this->logRequest($request);
     $response = $request->send();
     $this->logResponse($response);
     if ($response->getStatus() != 200) {
         throw new Am_Exception_InputError("An error occurred during refund request");
     }
     parse_str($response->getBody(), $parsed);
     if ($parsed['Result'] != 'Ok') {
         throw new Am_Exception_InputError("An error occurred during refund request: " . $parsed['Message']);
     }
     $trans = new Am_Paysystem_Transaction_Manual($this);
     $trans->setAmount($amount);
     $trans->setReceiptId($parsed['TransactionId'] . '-refund');
     $result->setSuccess($trans);
 }
Example #17
0
 public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     if (!$this->getApi()) {
         throw new Am_Exception_Paysystem_NotConfigured("No 2Checkout API username/password configured - could not do refund");
     }
     $log = $this->getDi()->invoiceLogRecord;
     $log->setInvoice($payment->getInvoice());
     $return = $this->getApi()->refundInvoice($payment->receipt_id, 5, "Customer Request");
     $log->add($return);
     if ($return['response_code'] == 'OK') {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-2co-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed($return['response_message']);
     }
 }