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();
 }
 public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $this->getDi()->userTable->load($cc->user_id);
     $customerVaultId = $user->data()->get(self::CUSTOMER_VAULT_ID);
     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 ($customerVaultId && $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::CUSTOMER_VAULT_ID, null)->update();
             $customerVaultId = null;
         }
     }
     if (!$customerVaultId) {
         $trAdd = new Am_Paysystem_Paymentsystemsworldwide_Transaction_AddCustomer($this, $invoice, $cc);
         $trAdd->run($result);
         $customerVaultId = $trAdd->getCustomerVaultId();
         if (!$customerVaultId) {
             return $result->setFailed(array("PSWW Plugin: Bad add response."));
         }
         $user->data()->set(self::CUSTOMER_VAULT_ID, $customerVaultId)->update();
     }
     ///
     $cc->cc = $cc->maskCc(@$cc->cc_number);
     $cc->cc_number = '0000000000000000';
     if ($cc->pk()) {
         $cc->update();
     } else {
         $cc->replace();
     }
     $result->setSuccess();
 }
Exemple #3
0
 public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result)
 {
     $user = $this->getDi()->userTable->load($cc->user_id);
     $profileId = $user->data()->get(self::CUSTOMER_VAULT_ID);
     if ($this->invoice) {
         // to link log records with current invoice
         $invoice = $this->invoice;
     } else {
         // updating debit 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) {
         if ($cc->cc_number != '0000000000000000') {
             $storedCc = $this->getDi()->ccRecordTable->findFirstByUserId($user->pk());
             if ($storedCc && $storedCc->cc != $cc->maskCc($cc->cc_number)) {
                 $update = true;
             }
         } else {
             $result->setSuccess();
             return;
         }
     }
     if (!$profileId) {
         try {
             $res = self::$dispatcher->customerCreate($this->getConfig('key'), $this->getConfig('testing'), null, null);
             if ($res) {
                 $profileId = $res['customerId'];
             } else {
                 return;
             }
             $user->data()->set(self::CUSTOMER_VAULT_ID, $profileId)->update();
         } catch (Exception $e) {
             $result->setFailed($e->getMessage());
             return false;
         }
     }
     try {
         $res = self::$dispatcher->addressSet($this->getConfig('key'), $this->getConfig('testing'), $profileId, $cc->cc_name_f, $cc->cc_name_l, $cc->cc_street, $cc->cc_zip, $cc->cc_city, $cc->cc_country);
         $res = self::$dispatcher->bankaccountSet($this->getConfig('key'), $this->getConfig('testing'), $profileId, $cc->cc_country, $cc->cc_company, $cc->cc_number, $cc->cc_name_f . ' ' . $cc->cc_name_l);
     } catch (Exception $e) {
         $result->setFailed($e->getMessage());
         return false;
     }
     ///
     $cc->cc = $cc->maskCc(@$cc->cc_number);
     $cc->cc_number = '0000000000000000';
     if ($cc->pk()) {
         $cc->update();
     } else {
         $cc->replace();
     }
     $result->setSuccess();
 }