smsapi / smsapi-php-client

SMSAPI PHP client that allows you to send messages, manage Short URLs and administrate your SMSAPI account.
https://www.smsapi.pl
Other
64 stars 39 forks source link

Problem with findContact by SMS API #89

Closed piotrp321 closed 4 years ago

piotrp321 commented 4 years ago

Hello

I have a searching phone number like this:

/**
 * @param string $phone
 * @return array
 */
public function findByPhone(string $phone): array
{
    $params = new FindContactsBag();
    $params->phoneNumber = $phone;

    return $this->getService()->contactsFeature()->findContacts($params);
}

And sometimes this code return error

Argument 2 passed to Smsapi\Client\Feature\Contacts\Data\ContactCustomFieldFactory::create() must be of the type string, int given, called in ...../vendor/smsapi/php-client/src/Feature/Contacts/Data/ContactFactory.php on line 66

maciejlew commented 4 years ago

I cannot reproduce this issue. Could you provide us with more details? You can also contact SMSAPI support so we would be able to track your issue.

piotrp321 commented 4 years ago

Ok, i am trying do debug this problem. I have a fix

vendor/smsapi/php-client/src/Feature/Contacts/Data/ContactFactory.php

private function createCustomFieldsFromObject(stdClass $object): array
{
    $objectCustomFieldsProperties = array_filter(
        get_object_vars($object),
        [$this, 'isCustomFieldProperty'],
        ARRAY_FILTER_USE_KEY
    );

    $customFields = [];

    foreach ($objectCustomFieldsProperties as $name => $value) {
        $customFields[] = $this->contactCustomFieldFactory->create($name, (string)$value);
    }

    return $customFields;
}

I added transform value to string because in my case $objectCustomFieldsProperties look like that:

image

maciejlew commented 4 years ago

Thanks for your input. The problem is somewhere else. The 'undelivered messages' contact field is dynamic and was mistakenly omitted on built in contact fields list.

Fix is already in master branch. It is now under code review and test. It will be included in next minor release.