示例#1
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if (isset($cc->omise_token) && $cc->omise_token) {
         $t = new Am_Paysystem_Transaction_Omise_CreateCustomer($this, $user, $cc->omise_token);
         $r = new Am_Paysystem_Result();
         $t->run($r);
         if ($r->isFailure()) {
             $result->setFailed($r->getErrorMessages());
             return;
         }
     }
     if (!$user->data()->get(self::OMISE_CARD_ID)) {
         $result->setFailed('Can not process payment: customer has not associated CC');
         return;
     }
     if ($doFirst && !(double) $invoice->first_total) {
         //free trial
         $t = new Am_Paysystem_Transaction_Free($this);
         $t->setInvoice($invoice);
         $t->process();
         $result->setSuccess();
     } else {
         $t = new Am_Paysystem_Transaction_Omise_Charge($this, $invoice, $doFirst);
         $t->run($result);
     }
 }
示例#2
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if ($cc->user_id != $user->pk()) {
         throw new Am_Exception_Paysystem("Assertion failed: cc.user_id != user.user_id");
     }
     // will be stored only if cc# or expiration changed
     $this->storeCreditCard($cc, $result);
     if (!$result->isSuccess()) {
         return;
     }
     $user->refresh();
     // we have both profile id and payment id, run the necessary transaction now if amount > 0
     $result->reset();
     if ($doFirst && !$invoice->first_total) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $tr = new Am_Paysystem_Transaction_Securepaycomau_Payment($this, $invoice, $doFirst);
         $tr->run($result);
     }
 }
示例#3
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if ($cc->user_id != $user->pk()) {
         throw new Am_Exception_Paysystem("Assertion failed: cc.user_id != user.user_id");
     }
     // will be stored only if cc# or expiration changed
     $this->storeCreditCard($cc, $result);
     if (!$result->isSuccess()) {
         return;
     }
     $user->refresh();
     // we have both profile id and payment id, run the necessary transaction now if amount > 0
     $result->reset();
     if ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $request = array($this->getConfig('key'), $this->getConfig('testing'), $user->data()->get(self::CUSTOMER_VAULT_ID), null, $this->getConfig('project'), '', '', '', $doFirst ? intval($invoice->first_total * 100) : intval($invoice->second_total * 100), $invoice->currency, $invoice->getLineDescription(), $invoice->getLineDescription(), $user->remote_addr ? $user->remote_addr : $_SERVER['REMOTE_ADDR']);
         $tr = new Am_Paysystem_Transaction_MicropaymentDbtSale($this, $invoice, $request, $doFirst);
         $tr->run($result);
     }
 }
示例#4
0
文件: paymill.php 项目: grlf/eyedock
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $token = $invoice->getUser()->data()->get(self::TOKEN);
     if (!$token) {
         return $result->setErrorMessages(array(___('Payment failed')));
     }
     if ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $tr = new Am_Paysystem_Transaction_Paymill($this, $invoice, $doFirst);
         $tr->run($result);
     }
 }
示例#5
0
 public function _doTheBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         //fix for previously not saved payment profile
         if (!$invoice->getUser()->data()->get(Am_Paysystem_AuthorizeCim::PAYMENT_PROFILE_KEY)) {
             $this->loadLastProfile($invoice);
         }
         $tr = new Am_Paysystem_Transaction_AuthorizeCim_CreateCustomerProfileTransaction($this, $invoice, $doFirst);
         $tr->run($result);
     }
 }
示例#6
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($doFirst && !(double) $invoice->first_total) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $request = $this->createHttpRequest();
         $request->addPostParameter(array('vendor_name' => $this->getConfig('account_name'), 'vendor_password' => $this->getConfig('account_pass'), 'card_number' => $cc->cc_number, 'card_type' => 'AUTO', 'card_expiry' => $cc->getExpire(), 'card_holder' => sprintf('%s %s', $cc->cc_name_f, $cc->cc_name_l), 'payment_amount' => ($doFirst ? $invoice->first_total : $invoice->second_total) * 100, 'payment_reference' => $invoice->public_id));
         $request->setMethod(Am_HttpRequest::METHOD_POST);
         $request->setUrl($this->getConfig('testing') ? self::SANDBOX_URL : self::LIVE_URL);
         $transaction = new Am_Paysystem_Transaction_DirectOne($this, $invoice, $request, $doFirst);
         $transaction->run($result);
     }
 }
示例#7
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($this->getConfig('set_failed')) {
         $result->setFailed('Transaction declined.');
     } elseif ($cc->cc_number != '4111111111111111') {
         $result->setFailed("Please use CC# 4111-1111-1111-1111 for successful payments with demo plugin");
     } elseif ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $tr = new Am_Paysystem_Transaction_CcDemo($this, $invoice, null, $doFirst);
         $result->setSuccess($tr);
         $tr->processValidated();
     }
 }
示例#8
0
 public function _doBill(Invoice $invoice, $doFirst, EcheckRecord $echeck, Am_Paysystem_Result $result)
 {
     if ($doFirst && !(double) $invoice->first_total) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $user = $invoice->getUser();
         $ps = new stdclass();
         $ps->x_Invoice_Num = $invoice->public_id;
         $ps->x_Cust_ID = $invoice->user_id;
         $ps->x_Description = $invoice->getLineDescription();
         $ps->x_First_Name = $echeck->cc_name_f;
         $ps->x_Last_Name = $echeck->cc_name_l;
         $ps->x_Address = $echeck->cc_street;
         $ps->x_City = $echeck->cc_city;
         $ps->x_State = $echeck->cc_state;
         $ps->x_Country = $echeck->cc_country;
         $ps->x_Zip = $echeck->cc_zip;
         $ps->x_Tax = $doFirst ? $invoice->first_tax : $invoice->second_tax;
         $ps->x_Email = $user->email;
         $ps->x_Phone = $echeck->cc_phone;
         $ps->x_Amount = $doFirst ? $invoice->first_total : $invoice->second_total;
         $ps->x_Currency_Code = $invoice->currency;
         $ps->x_Type = 'AUTH_CAPTURE';
         $ps->x_Customer_IP = $user->remote_addr ? $user->remote_addr : $_SERVER['REMOTE_ADDR'];
         $ps->x_Relay_Response = 'FALSE';
         $ps->x_Delim_Data = 'TRUE';
         $ps->x_bank_acct_num = $echeck->echeck_ban;
         $ps->x_bank_aba_code = $echeck->echeck_aba;
         $ps->x_bank_acct_type = $echeck->echeck_type;
         $ps->x_bank_name = $echeck->check_bank_name;
         $ps->x_bank_acct_name = $echeck->echeck_account_name;
         $ps->x_echeck_type = 'WEB';
         $ps->x_recurring_billing = $invoice->rebill_times ? 'TRUE' : 'FALSE';
         $request = $this->_sendRequest($this->createHttpRequest());
         $request->addPostParameter((array) $ps);
         $transaction = new Am_Paysystem_Transaction_AuthorizeEcheck_Payment($this, $invoice, $request, $doFirst);
         $transaction->run($result);
     }
 }
示例#9
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $client = new SoapClient(self::WSDL);
     $user = $invoice->getUser();
     if ($cc) {
         $data = array('customer_firstname' => $user->name_f ? $user->name_f : $cc->cc_name_f, 'customer_lastname' => $user->name_l ? $user->name_l : $cc->cc_name_l, 'customer_email' => $user->email, 'holder_firstname' => $cc->cc_name_f, 'holder_lastname' => $cc->cc_name_l, 'pan' => $cc->cc_number, 'digit' => $cc->getCvv(), 'exp' => $cc->getExpire('%02d-20%02d'));
         $data = base64_encode(serialize($data));
         $param = array($this->getConfig('apiKey'), $data);
         $request = new SoapRequestWrapperComenpay($client, 'AddCustomerData', $param);
         $t = new Am_Paysystem_Transaction_CreditCard_Comenpay_AddCustomerData($this, $invoice, $request, $user);
         $r = new Am_Paysystem_Result();
         $t->run($r);
         if ($r->isFailure()) {
             $result->setFailed($r->getErrorMessages());
             return;
         }
     }
     if (!$user->data()->get(self::COMENPAY_CARD_TOKEN)) {
         $result->setFailed('Can not process payment: customer has not associated CC');
         return;
     }
     if ($doFirst && !(double) $invoice->first_total) {
         //free trial
         $t = new Am_Paysystem_Transaction_Free($this);
         $t->setInvoice($invoice);
         $t->process();
         $result->setSuccess();
     } else {
         $payment = null;
         @(list($payment) = $invoice->getPaymentRecords());
         $data = array('paccount_id' => $this->getConfig('paccount_id'), 'type' => $payment ? 'REBILL' : 'BILL', 'transaction_ip' => $user->last_ip, 'amount_cnts' => 100 * ($doFirst ? $invoice->first_total : $invoice->second_total), 'client_reference' => $invoice->public_id, 'client_customer_id' => $user->pk(), 'affiliate_id' => 0, 'site_url' => $this->getDi()->config->get('site_url'), 'member_login' => $user->login, 'support_url' => $this->getDi()->config->get('site_url'), 'support_tel' => 'N/A', 'support_email' => $this->getDi()->config->get('admin_email'), 'customer_lang' => 'en', 'customer_useragent' => $user->last_user_agent, 'billing_invoicing_id' => 0, 'billing_description' => $invoice->getLineDescription(), 'billing_preauth_duration' => 0, 'billing_rebill_period' => 0, 'billing_rebill_duration' => 0, 'billing_rebill_price_cnts' => 100 * $invoice->second_total);
         if ($payment) {
             $data['billing_initial_transaction_id'] = $payment->receipt_id;
         }
         $param = array($this->getConfig('apiKey'), $user->data()->get(self::COMENPAY_CARD_TOKEN), $user->data()->get(self::COMENPAY_CARD_KEY), $data);
         $request = new SoapRequestWrapperComenpay($client, 'Transaction', $param);
         $t = new Am_Paysystem_Transaction_CreditCard_Comenpay_Transaction($this, $invoice, $request, $doFirst);
         $t->run($result);
     }
 }
示例#10
0
 public function _doBill(Invoice $invoice, $doFirst, EcheckRecord $echeck, Am_Paysystem_Result $result)
 {
     if (!is_null($echeck)) {
         $user = $this->getDi()->userTable->load($echeck->user_id);
         $tr = new Am_Paysystem_Transaction_PaymillDd_Payment($this, $user, $echeck->paymill_token);
         $tr->run($result);
     }
     $pay = $invoice->getUser()->data()->get(self::PAYMENT_ID);
     if (!$pay) {
         return $result->setFailed(array(___('Payment failed')));
     }
     if ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $tr = new Am_Paysystem_Transaction_PaymillDd_Transaction($this, $invoice, $doFirst);
         $tr->run($result);
     }
 }
示例#11
0
文件: Nmi.php 项目: irovast/eyedock
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if ($doFirst) {
         if (!(double) $invoice->first_total) {
             $trAuth = new Am_Paysystem_Networkmerchants_Transaction_Authorization($this, $invoice, $cc);
             $trAuth->run($result);
             $transactionId = $trAuth->getUniqId();
             $customerVaultId = $trAuth->getCustomerVaultId();
             if (!$transactionId || !$customerVaultId) {
                 return $result->setFailed(array("NMI Plugin: Bad auth response."));
             }
             $trVoid = new Am_Paysystem_Networkmerchants_Transaction_Void($this, $invoice, $transactionId, $customerVaultId);
             $trVoid->run($result);
             $trFree = new Am_Paysystem_Transaction_Free($this);
             $trFree->setInvoice($invoice);
             $trFree->process();
             $result->setSuccess($trFree);
         } else {
             $trAuth = new Am_Paysystem_Networkmerchants_Transaction_Authorization($this, $invoice, $cc, $invoice->first_total);
             $trAuth->run($result);
             $transactionId = $trAuth->getUniqId();
             $customerVaultId = $trAuth->getCustomerVaultId();
             if (!$transactionId || !$customerVaultId) {
                 return $result->setFailed(array("NMI Plugin: Bad auth response."));
             }
             $trSale = new Am_Paysystem_Networkmerchants_Transaction_Capture($this, $invoice, $doFirst, $transactionId);
             $trSale->run($result);
         }
         $user->data()->set($this->getCustomerVaultVariable(), $customerVaultId)->update();
     } else {
         $customerVaultId = $user->data()->get($this->getCustomerVaultVariable());
         if (!$customerVaultId) {
             return $result->setFailed(array("No saved reference transaction for customer"));
         }
         $trSale = new Am_Paysystem_Networkmerchants_Transaction_Sale($this, $invoice, $doFirst, $customerVaultId);
         $trSale->run($result);
     }
 }
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if ($doFirst) {
         if (!(double) $invoice->first_total) {
             $trAddFree = new Am_Paysystem_Paymentsystemsworldwide_Transaction_Authorization($this, $invoice, $cc);
             $trAddFree->run($result);
             $transactionId = $trAddFree->getUniqId();
             $customerVaultId = $trAddFree->getCustomerVaultId();
             if (!$transactionId || !$customerVaultId) {
                 return $result->setFailed(array("PSWW Plugin: Bad auth response."));
             }
             $trVoid = new Am_Paysystem_Paymentsystemsworldwide_Transaction_Void($this, $invoice, $transactionId, $customerVaultId);
             $trVoid->run($result);
             $trFree = new Am_Paysystem_Transaction_Free($this);
             $trFree->setInvoice($invoice);
             $trFree->process();
             $result->setSuccess($trFree);
         } else {
             $trAddPay = new Am_Paysystem_Paymentsystemsworldwide_Transaction_AddCustomer($this, $invoice, $cc);
             $trAddPay->run($result);
             $customerVaultId = $trAddPay->getCustomerVaultId();
             if (!$customerVaultId) {
                 return $result->setFailed(array("PSWW Plugin: Bad add response."));
             }
             $trSale = new Am_Paysystem_Paymentsystemsworldwide_Transaction_Sale($this, $invoice, $doFirst, $customerVaultId);
             $trSale->run($result);
         }
         $user->data()->set(self::CUSTOMER_VAULT_ID, $customerVaultId)->update();
     } else {
         $customerVaultId = $user->data()->get(self::CUSTOMER_VAULT_ID);
         if (!$customerVaultId) {
             return $result->setFailed(array("No saved reference transaction for customer"));
         }
         $trSale = new Am_Paysystem_Paymentsystemsworldwide_Transaction_Sale($this, $invoice, $doFirst, $customerVaultId);
         $trSale->run($result);
     }
 }
示例#13
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $this->getTicketSession();
     if ($doFirst && !(double) $invoice->first_total) {
         $transactionAuth = new Am_Paysystem_Transaction_CreditCard_Intuit_Authorization($this, $invoice, $doFirst, $cc);
         $transactionAuth->run($result);
         $transactionId = $transactionAuth->getUniqId();
         if (!$transactionId) {
             $result->setFailed(array('Authorization failed'));
         }
         $transactionVoid = new Am_Paysystem_Transaction_CreditCard_Intuit_Void($this, $invoice, $doFirst, $transactionId);
         $transactionVoid->run($result);
         $transactionFree = new Am_Paysystem_Transaction_Free($this);
         $transactionFree->setInvoice($invoice);
         $transactionFree->process();
         $result->setSuccess($transactionFree);
     } else {
         $transaction = new Am_Paysystem_Transaction_CreditCard_Intuit_Charge($this, $invoice, $doFirst, $cc);
         $transaction->run($result);
     }
 }
示例#14
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($doFirst) {
         try {
             // We was redirected from Braintree so need to get result;
             $res = Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
             if ($res instanceof Braintree_Result_Error) {
                 $result->setFailed($res->message);
                 return;
             } else {
                 $invoice->getUser()->data()->set(self::CUSTOMER_ID, $res->customer->id)->update();
             }
         } catch (Braintree_Exception_NotFound $e) {
         } catch (Exception $e) {
             $result->setFailed($e->getMessage());
             return;
         }
     }
     if (!($customer_id = $invoice->getUser()->data()->get(self::CUSTOMER_ID))) {
         $result->setFailed('Empty customer ID. Please update CC info');
         return;
     }
     // Now attempt to submit transaction if required;
     if (doubleval($invoice->first_total) > 0) {
         $transaction = new Am_Paysystem_Transaction_CreditCard_Braintree_Sale($this, $invoice, null, $doFirst);
         $transaction->run($result);
     } else {
         $transaction = new Am_Paysystem_Transaction_Free($this);
         $transaction->setInvoice($invoice);
         $transaction->process();
         $result->setSuccess($transaction);
     }
 }
示例#15
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     $soapData = new stdClass();
     $soapData->merchantID = $this->getConfig('merchant_id');
     $soapData->merchantReferenceCode = $invoice->public_id . '/' . $invoice->getLineDescription();
     $soapData->clientLibrary = 'aMember';
     $soapData->clientLibraryVersion = '4.x';
     $soapData->clientEnvironment = php_uname();
     $soapData->customerID = $user->pk();
     $soapData->customerFirstName = $user->name_f;
     $soapData->customerLastName = $user->name_l;
     $billTo = new stdClass();
     $billTo->firstName = $cc->cc_name_f ? $cc->cc_name_f : $user->name_f;
     $billTo->lastName = $cc->cc_name_l ? $cc->cc_name_l : $user->name_l;
     $billTo->street1 = $cc->cc_street ? $cc->cc_street : $user->street;
     $billTo->city = $cc->cc_city ? $cc->cc_city : $user->city;
     $billTo->state = $cc->cc_state ? $cc->cc_state : $user->state;
     $billTo->postalCode = $cc->cc_zip ? $cc->cc_zip : $user->zip;
     $billTo->country = $cc->cc_country ? $cc->cc_country : $user->country;
     $billTo->email = $user->email;
     $billTo->ipAddress = $this->getDi()->request->getClientIp();
     $soapData->billTo = $billTo;
     $card = new stdClass();
     $card->accountNumber = $cc->cc_number;
     $card->expirationMonth = substr($cc->cc_expire, 0, 2);
     $card->expirationYear = 2000 + substr($cc->cc_expire, 2, 2);
     $card->cvNumber = $cc->getCvv();
     $soapData->card = $card;
     $purchaseTotals = new stdClass();
     $purchaseTotals->currency = $invoice->currency;
     $soapData->purchaseTotals = $purchaseTotals;
     $soapData->item = array();
     $id = 0;
     foreach ($invoice->getItems() as $item) {
         $itm = new stdClass();
         $itm->unitPrice = $doFirst ? (double) $invoice->first_total ? $item->first_total : 1.0 : $item->second_total;
         $itm->quantity = $item->qty;
         $itm->id = $id++;
         $soapData->item[] = $itm;
     }
     if ($doFirst && !(double) $invoice->first_total) {
         $ccAuthService = new stdClass();
         $ccAuthService->run = "true";
         $soapData->ccAuthService = $ccAuthService;
         $trAuth = new Am_Paysystem_Transaction_CreditCard_Cybersource_Auth($this, $invoice, $doFirst, $soapData);
         $trAuth->run($result);
         $requestId = $trAuth->getRequestId();
         $requestToken = $trAuth->getToken();
         if (!$requestId || !$requestToken) {
             return $result->setFailed(array("CyberSource Plugin: Bad auth response."));
         }
         $soapData->ccAuthService = null;
         $ccAuthReversalService = new stdClass();
         $ccAuthReversalService->authRequestID = $requestId;
         $ccAuthReversalService->authRequestToken = $requestToken;
         $ccAuthReversalService->run = "true";
         $soapData->ccAuthReversalService = $ccAuthReversalService;
         $trVoid = new Am_Paysystem_Transaction_CreditCard_Cybersource_Auth($this, $invoice, $doFirst, $soapData);
         $trVoid->run($result);
         $trFree = new Am_Paysystem_Transaction_Free($this);
         $trFree->setInvoice($invoice);
         $trFree->process();
         $result->setSuccess($trFree);
     } else {
         $ccCreditService = new stdClass();
         $ccCreditService->run = "true";
         $soapData->ccCreditService = $ccCreditService;
         $tr = new Am_Paysystem_Transaction_CreditCard_Cybersource($this, $invoice, $doFirst, $soapData);
         $tr->run($result);
     }
 }
示例#16
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);
     }
 }