Пример #1
0
 function createCustomerProfile(Invoice $invoice)
 {
     $tr = new Am_Paysystem_Transaction_AuthorizeCim_CreateCustomerProfile($this, $invoice);
     $result = new Am_Paysystem_Result();
     $tr->run($result);
     if (!$result->isSuccess()) {
         throw new Am_Exception_Paysystem("Failed Am_Paysystem_Transaction_AuthorizeCim_CreateCustomerProfile " . $result->getLastError());
     }
     $invoice->getUser()->data()->set(Am_Paysystem_AuthorizeCim::USER_PROFILE_KEY, $tr->getProfileId())->update();
     return $tr->getProfileId();
 }
Пример #2
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();
 }