factory() public static method

factory method: returns an instance of CreditCard to the requesting method, with populated properties
public static factory ( $attributes ) : CreditCard
return CreditCard
 public function testVerificationIsLatestVerification()
 {
     $creditCard = Braintree\CreditCard::factory(['verifications' => [['id' => '123', 'createdAt' => DateTime::createFromFormat('Ymd', '20121212')], ['id' => '932', 'createdAt' => DateTime::createFromFormat('Ymd', '20121215')], ['id' => '456', 'createdAt' => DateTime::createFromFormat('Ymd', '20121213')]]]);
     $this->assertEquals('932', $creditCard->verification->id);
 }
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new CreditCard or PayPalAccount object
  * and encapsulates it inside a Result\Successful object, or
  * encapsulates a Errors object inside a Result\Error
  * alternatively, throws an Unexpected exception if the response is invalid.
  *
  * @ignore
  * @param array $response gateway response values
  * @return Result\Successful|Result\Error
  * @throws Exception\Unexpected
  */
 private function _verifyGatewayResponse($response)
 {
     if (isset($response['creditCard'])) {
         return new Result\Successful(CreditCard::factory($response['creditCard']), 'paymentMethod');
     } else {
         if (isset($response['paypalAccount'])) {
             return new Result\Successful(PayPalAccount::factory($response['paypalAccount']), "paymentMethod");
         } else {
             if (isset($response['coinbaseAccount'])) {
                 return new Result\Successful(CoinbaseAccount::factory($response['coinbaseAccount']), "paymentMethod");
             } else {
                 if (isset($response['applePayCard'])) {
                     return new Result\Successful(ApplePayCard::factory($response['applePayCard']), "paymentMethod");
                 } else {
                     if (isset($response['androidPayCard'])) {
                         return new Result\Successful(AndroidPayCard::factory($response['androidPayCard']), "paymentMethod");
                     } else {
                         if (isset($response['amexExpressCheckoutCard'])) {
                             return new Result\Successful(AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']), "paymentMethod");
                         } else {
                             if (isset($response['europeBankAccount'])) {
                                 return new Result\Successful(EuropeBankAccount::factory($response['europeBankAccount']), "paymentMethod");
                             } else {
                                 if (isset($response['venmoAccount'])) {
                                     return new Result\Successful(VenmoAccount::factory($response['venmoAccount']), "paymentMethod");
                                 } else {
                                     if (isset($response['apiErrorResponse'])) {
                                         return new Result\Error($response['apiErrorResponse']);
                                     } else {
                                         if (is_array($response)) {
                                             return new Result\Successful(UnknownPaymentMethod::factory($response), "paymentMethod");
                                         } else {
                                             throw new Exception\Unexpected('Expected payment method or apiErrorResponse');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new CreditCard object and encapsulates
  * it inside a Result\Successful object, or
  * encapsulates a Errors object inside a Result\Error
  * alternatively, throws an Unexpected exception if the response is invalid
  *
  * @ignore
  * @param array $response gateway response values
  * @return Result\Successful|Result\Error
  * @throws Exception\Unexpected
  */
 private function _verifyGatewayResponse($response)
 {
     if (isset($response['creditCard'])) {
         // return a populated instance of Address
         return new Result\Successful(CreditCard::factory($response['creditCard']));
     } elseif (isset($response['apiErrorResponse'])) {
         return new Result\Error($response['apiErrorResponse']);
     } else {
         throw new Exception\Unexpected("Expected address or apiErrorResponse");
     }
 }
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  * @return void
  */
 protected function _initialize($customerAttribs)
 {
     // set the attributes
     $this->_attributes = $customerAttribs;
     // map each address into its own object
     $addressArray = [];
     if (isset($customerAttribs['addresses'])) {
         foreach ($customerAttribs['addresses'] as $address) {
             $addressArray[] = Address::factory($address);
         }
     }
     $this->_set('addresses', $addressArray);
     // map each creditCard into its own object
     $creditCardArray = [];
     if (isset($customerAttribs['creditCards'])) {
         foreach ($customerAttribs['creditCards'] as $creditCard) {
             $creditCardArray[] = CreditCard::factory($creditCard);
         }
     }
     $this->_set('creditCards', $creditCardArray);
     // map each coinbaseAccount into its own object
     $coinbaseAccountArray = [];
     if (isset($customerAttribs['coinbaseAccounts'])) {
         foreach ($customerAttribs['coinbaseAccounts'] as $coinbaseAccount) {
             $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
         }
     }
     $this->_set('coinbaseAccounts', $coinbaseAccountArray);
     // map each paypalAccount into its own object
     $paypalAccountArray = [];
     if (isset($customerAttribs['paypalAccounts'])) {
         foreach ($customerAttribs['paypalAccounts'] as $paypalAccount) {
             $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
         }
     }
     $this->_set('paypalAccounts', $paypalAccountArray);
     // map each applePayCard into its own object
     $applePayCardArray = [];
     if (isset($customerAttribs['applePayCards'])) {
         foreach ($customerAttribs['applePayCards'] as $applePayCard) {
             $applePayCardArray[] = ApplePayCard::factory($applePayCard);
         }
     }
     $this->_set('applePayCards', $applePayCardArray);
     // map each androidPayCard into its own object
     $androidPayCardArray = [];
     if (isset($customerAttribs['androidPayCards'])) {
         foreach ($customerAttribs['androidPayCards'] as $androidPayCard) {
             $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
         }
     }
     $this->_set('androidPayCards', $androidPayCardArray);
     $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
 }