$this->merchantId, 'merchantIdInPayPal' => $this->merchantIdInPayPal, 'clientId' => $this->clientId, 'clientSecret' => $this->clientSecret, 'token' => $this->tokenDetails, 'accountIsReady' => $this->accountIsReady, 'supportsCustomPayments' => $this->supportsCustomPayments, 'accountCountry' => $this->accountCountry, ]; } /** * Make MerchantDetail object from array. * * @since 2.9.0 * * @param array $merchantDetails * * @return MerchantDetail */ public static function fromArray($merchantDetails) { $obj = new static(); if ( ! $merchantDetails) { return $obj; } $obj->validate($merchantDetails); $obj->setupProperties($merchantDetails); return $obj; } /** * Setup properties from array. * * @since 2.9.0 * * @param $merchantDetails * */ private function setupProperties($merchantDetails) { $this->merchantId = $merchantDetails['merchantId']; $this->merchantIdInPayPal = $merchantDetails['merchantIdInPayPal']; $this->clientId = $merchantDetails['clientId']; $this->clientSecret = $merchantDetails['clientSecret']; $this->tokenDetails = $merchantDetails['token']; $this->accountIsReady = $merchantDetails['accountIsReady']; $this->supportsCustomPayments = $merchantDetails['supportsCustomPayments']; $this->accountCountry = $merchantDetails['accountCountry']; $this->accessToken = $this->tokenDetails['accessToken']; } /** * Validate merchant details. * * @since 2.9.0 * * @param array $merchantDetails */ private function validate($merchantDetails) { $required = [ 'merchantId', 'merchantIdInPayPal', 'clientId', 'clientSecret', 'token', 'accountIsReady', 'supportsCustomPayments', 'accountCountry', ]; if (array_diff($required, array_keys($merchantDetails))) { throw new InvalidArgumentException( esc_html__( 'To create a MerchantDetail object, please provide the following: ', 'give' ) . implode(', ', $required) ); } } /** * Get refresh token code. * * @since 2.32.0 Set default value for empty tokenDetails. * @since 2.25.0 Set accessToken property. * @since 2.9.0 * * @param array $tokenDetails * * @return mixed */ public function setTokenDetails($tokenDetails) { $this->tokenDetails = array_merge($this->tokenDetails ?? [] , $tokenDetails); $this->accessToken = $tokenDetails['accessToken']; } }