Exemplo n.º 1
0
 public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $this->getDi()->userTable->load($cc->user_id);
     $profileId = $user->data()->get(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY);
     if ($this->invoice) {
         // to link log records with current invoice
         $invoice = $this->invoice;
     } else {
         // updating credit card info?
         $invoice = $this->getDi()->invoiceRecord;
         $invoice->invoice_id = 0;
         $invoice->user_id = $user->pk();
     }
     // compare stored cc for that user may be we don't need to refresh?
     if ($profileId && $cc->cc_number != '0000000000000000') {
         $storedCc = $this->getDi()->ccRecordTable->findFirstByUserId($user->pk());
         if ($storedCc && ($storedCc->cc != $cc->maskCc($cc->cc_number) || $storedCc->cc_expire != $cc->cc_expire)) {
             $user->data()->set(self::USER_PROFILE_KEY, null)->set(self::PAYMENT_PROFILE_KEY, null)->update();
             $deleteTr = new Am_Paysystem_Transaction_AuthorizeCim_DeleteCustomerProfile($this, $invoice, $profileId);
             $deleteTr->run($res = new Am_Paysystem_Result());
             $profileId = null;
         }
     }
     if (!$profileId) {
         try {
             $tr = new Am_Paysystem_Transaction_AuthorizeCim_CreateCustomerProfile($this, $invoice, $cc);
             $tr->run($result);
             if (!$result->isSuccess()) {
                 return;
             }
             $user->data()->set(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY, $tr->getProfileId())->update();
             $user->data()->set(Am_Paysystem_AuthorizeCim::PAYMENT_PROFILE_KEY, $tr->getPaymentId())->update();
         } catch (Am_Exception_Paysystem $e) {
             $result->setFailed($e->getPublicError());
             return false;
         }
     }
     ///
     $cc->cc = $cc->maskCc(@$cc->cc_number);
     $cc->cc_number = '0000000000000000';
     if ($cc->pk()) {
         $cc->update();
     } else {
         $cc->replace();
     }
     $result->setSuccess();
 }
Exemplo n.º 2
0
 /**
  * Process a transaction using saved customer payment profile
  * and do either success redirect, or display error
  * @return Am_Paysystem_Result
  */
 protected function ccActionProcessAfterProfileExists()
 {
     $result = new Am_Paysystem_Result();
     $this->plugin->_doTheBill($this->invoice, true, $this->getDi()->CcRecordTable->createRecord(), $result);
     if (@$result->errorCode == 'E00040') {
         // cleanup customer payment profile
         $user = $this->invoice->getUser();
         $user->data()->set(Am_Paysystem_AuthorizeCim::PAYMENT_PROFILE_KEY, null);
         $tr = new Am_Paysystem_Transaction_AuthorizeCim_DeleteCustomerProfile($this->plugin, $this->invoice, $user->data()->get(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY));
         $tr->run(new Am_Paysystem_Result());
         $user->data()->set(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY, null);
         $user->data()->update();
     }
     return $result;
 }