public function testapi()
 {
     $o_bcpc = new BaseCommerceClient(RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS, RENTSQUARE_MERCH_KEY);
     $o_bcpc->setSandbox(BC_SANDBOXVALUE);
     $o_address = new Address();
     $o_address->setName(Address::$XS_ADDRESS_NAME_BILLING);
     $o_address->setLine1("123 Some Address");
     $o_address->setCity("Tempe");
     $o_address->setState("AZ");
     $o_address->setZipcode("12345");
     $o_bc = new BankCard();
     $o_bc->setBillingAddress($o_address);
     $o_bc->setExpirationMonth("02");
     $o_bc->setExpirationYear("2015");
     $o_bc->setName("Nick 2");
     $o_bc->setNumber("4111111111111111");
     $o_bc->setToken("myToken12asdfas3");
     $o_bc = $o_bcpc->addBankCard($o_bc);
     if ($o_bc->isStatus(BankCard::$XS_BC_STATUS_FAILED)) {
         //the add Failed, look at messages array for reason(s) why
         //var_dump( $o_bc->getMessages() );
         $this->set('message', $o_bc->getMessages());
     } else {
         if ($o_bc->isStatus(BankCard::$XS_BC_STATUS_ACTIVE)) {
             //Card added successfully
             //var_dump( $o_bc->getToken() );
             $this->set('message', $o_bc->getToken());
         }
     }
 }
Exemple #2
0
 /**
  * Creates a BankCard PHP object from the passed in JSON Object
  * 
  * @param type $o_data  The json representation of the object to be built.
  * @return A BankCard object with fields based on the input json object.
  * @author Ryan Murphy <*****@*****.**>
  * @author Steven Wright <*****@*****.**>
  */
 static function buildFromJSON($o_data)
 {
     $o_instance = new BankCard();
     if (array_key_exists('bank_card_name', $o_data)) {
         $o_instance->setName($o_data['bank_card_name']);
     }
     if (array_key_exists('bank_card_number', $o_data)) {
         $o_instance->setNumber($o_data['bank_card_number']);
     }
     if (array_key_exists('bank_card_token', $o_data)) {
         $o_instance->setToken($o_data['bank_card_token']);
     }
     if (array_key_exists('bank_card_expiration_month', $o_data)) {
         $o_instance->setExpirationMonth($o_data['bank_card_expiration_month']);
     }
     if (array_key_exists('bank_card_expiration_year', $o_data)) {
         $o_instance->setExpirationYear($o_data['bank_card_expiration_year']);
     }
     if (array_key_exists('bank_card_billing_address', $o_data)) {
         $o_instance->setBillingAddress(Address::buildFromJSON($o_data['bank_card_billing_address']));
     }
     if (array_key_exists('bank_card_creation_date', $o_data)) {
         $o_instance->setCreationDate(date("m/d/Y H:i:s", strtotime($o_data["bank_card_creation_date"])));
     }
     if (array_key_exists('bank_card_last_used_date', $o_data)) {
         $o_instance->setLastUsedDate(date("m/d/Y H:i:s", strtotime($o_data["bank_card_last_used_date"])));
     }
     if (array_key_exists('bank_card_status', $o_data)) {
         if (gettype($o_data['bank_card_status']) === "array") {
             $o_status = (array) $o_data['bank_card_status'];
             if (array_key_exists('bank_card_status_name', $o_status)) {
                 $o_instance->setStatus($o_status['bank_card_status_name']);
             }
         } else {
             $o_instance->setStatus($o_data['bank_card_status']);
         }
     }
     if (array_key_exists('bank_card_alias', $o_data)) {
         $o_instance->setAlias($o_data['bank_card_alias']);
     }
     return $o_instance;
 }
 public function vault_add_creditcard($paydata)
 {
     $status = '';
     $result = '';
     $o_bcpc = new BaseCommerceClient(RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS, RENTSQUARE_MERCH_KEY);
     $o_bcpc->setSandbox(BC_SANDBOXVALUE);
     $o_bc = new BankCard();
     $o_bc->setExpirationMonth($paydata['expire_dt_month']);
     $o_bc->setExpirationYear($paydata['expire_dt_year']);
     $o_bc->setName($paydata['first_name'] . " " . $paydata['last_name']);
     $o_bc->setNumber($paydata['card_number']);
     $o_billing_address = new Address(Address::$XS_ADDRESS_NAME_BILLING);
     $o_billing_address->setLine1($paydata['billing_address1']);
     if (!empty($paydata['billing_address2'])) {
         $o_billing_address->setLine2($paydata['billing_address2']);
     } else {
         $o_billing_address->setLine2(" ");
     }
     $o_billing_address->setCity($paydata['billing_city']);
     if (!empty($paydata['billing_state_id'])) {
         $States = new State();
         $billing_state = $States->findById($paydata['billing_state_id']);
         $billing_state = $billing_state['State']['abbr'];
     }
     $o_billing_address->setState($billing_state);
     $o_billing_address->setZipcode($paydata['billing_zip']);
     $o_billing_address->setCountry("USA");
     $o_bc->setBillingAddress($o_billing_address);
     /*
     echo "<pre>";
     print_r($o_bc);
     echo "</pre>";
     exit;
     */
     $o_bc = $o_bcpc->addBankCard($o_bc);
     $status = $o_bc->getStatus();
     if ($status == BankCard::$XS_BC_STATUS_FAILED) {
         // Fail
         $status = 0;
         $result = $o_bc->getMessages();
     } else {
         if ($status == BankCard::$XS_BC_STATUS_ACTIVE) {
             // Success
             $status = 1;
             $result = $o_bc->getToken();
         }
     }
     return array($status, $result);
 }