Exemplo n.º 1
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();
     $profileId = $user->data()->get(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY);
     $payProfileId = $user->data()->get(self::PAYMENT_PROFILE_KEY);
     // 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_AuthorizeCim_CreateCustomerProfileTransaction($this, $invoice, $doFirst);
         $tr->run($result);
     }
 }
Exemplo n.º 2
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);
     }
 }