Infusionsoft PHP CC info with Novak Solutions SDK - php

I am having issues getting a users credit card info using Novak Solutions Infusionsoft SDK. Both systems say that I can use a "Find by Field" query but I seem to get an error with the CC object.
So it would look something like this:
Infusionsoft_DataService::findByField(new Infusionsoft_CreditCard(), 'ContactId', 9 (the id), null, 0, false, null);
Response:
Fatal error: Uncaught [NoFieldAccess]Access denied to field CreditCard.CardNumber Attempted: 3 time(s).
The DataService seems to work with all object but the Infusionsoft_CreditCard() one.

As you can see in Infusionsoft API documentation, CreditCard.CardNumber field is not readable, Add access is only allowed.
To avoid the error throwing, the simplest fix is to pass the 6th parameter: array of $returnFields. For example:
Infusionsoft_DataService::findByField(new Infusionsoft_CreditCard(), 'ContactId', 9, null, 0, ['Id', 'Last4', 'ContactId'], null);
For another solution take a look at Infusionsoft_DataService.load() method implementation, specifically lines 101 to 105.
if(!$returnFields){
$object->removeRestrictedFields();
$returnFields = $object->getFields();
$object->addRestrictedFields();
}
These lines either need to replace lines 40 to 42 in the same file (changing findByField() method implementation, and I'm just mentioning here it would be better to further refactor the code after that, abstracting these lines for multiple usages).
Or use them in your code (with needed updates) to get $requiredFields without read-restricted fields for further passing them to Infusionsoft_DataService.findByField() method as shown above.
One more useful reference is Infusionsoft_CreditCard.removeRestrictedFields() method implementation

Try creating the Infusionsoft_CreditCard object first then removing the restricted fields before passing it on to the query!
$CC = new Infusionsoft_CreditCard();
$CC->removeRestrictedFields();
// Now continue with your former query and use the above object.
Infusionsoft_DataService::findByField( $CC, 'ContactId', 9, null, 0, false, null);
// Or use the query method.
Infusionsoft_DataService::query( $CC, array( 'ContactId' => 9 ) );
This should return all the CC fields except the restricted ones.

Related

How does the Google Service Client (PHP) method documentation work?

I have consistent difficulty using any client service method that is not explicitly exampled somewhere. Despite following the docs and even reading the sourcecode, The class or method names I come up with following the scheme are never right.
The documentation at Packagist (see 'Making Requests") says the client library classes are autogenerated from the Google endpoints, which agrees with the description in the library's docs on Github that say the pattern for accessing methods should be "$service->resource->method(args)".
So why the following?
// works:
// I get a countable object of active classrooms owner by the specified id
$response = $this->ClassroomService->courses->listCourses([
'courseStates' => 'ACTIVE',
'teacherId' => 'me']);
// works:
// I get an instance of the single classroom's object containing lots of meta data
$response = $this->ClassroomService->courses->get( $id );
// does not work:
// 500 error, obj has no such method
$response = $this->ClassroomService->topics->listCoursesTopics( $id );
According to the API Explorer all three should be fine.
What am I missing about using client service objects?
Edit
Ultimately I determined the resource in my example to be 'courses_topics'; the method was correct per the docs. Thanks for the idea #ebram.
The question remains how the methods are named though. courseWork is my next challenge and it does not fit the the naming pattern of topics.
There is no topics member of ClassroomService.
The member is named courses_topics.
This is documented in the "Properties summary" at the bottom of the Classroom documentation.
Your code should look like this:
$response = $this->ClassroomService->courses_topics->listCoursesTopics( $id );
The documentation for Google_Service_Classroom_CoursesTopics_Resource does incorrectly give sample code where the member is named ->topics.
Given that API documentation is generated from source, but sample code is (generally) written by hand, I'll assume the API documentation is correct and the sample code is incorrect. I'd file a documentation-bug with Google.
Update:
I looked at the PHP source code for Google_Service_Classroom in GitHub and verified that the property is named courses_topics instead of topics, so in conclusion: the sample code is wrong.
What's also interesting is the resource-type in the actual source-code is Google_Service_Classroom_Resource_CoursesTopics but the documentation refers to it as Google_Service_Classroom_CoursesTopics_Resource - so that documentation is definitely wrong.

What is the best way to troubleshoot this error with parent::find?

I'm trying to build a PHP RESTful service using PhalconPHP. I'm new to PHP, so this may be a beginner question. I am following a tutorial https://www.toptal.com/phalcon/phalcon-php-restful-apis, and in the tutorial there is a section where it makes a call to pull the list of users.
public static function find($parameters = null)
{
return parent::find($parameters);
}
I am passing in a list of parameters listed below.
Array
(
[conditions] =>
[bind] => Array()
[columns] => users_id
)
but I keep getting a 500 error. I'm fairly sure it has to do with how I am connecting (or in this case, NOT connecting to the database).
I'm not 100% sure on what the 'parent' part does either, nor how it connects up to my MySQL database - I think I've gotten the config setup, and I've passed in the tablename that I'm expecting it to be under, but I have no idea if it's actually connecting up and then failing, or if the call itself is failing. So far I've tried echo and print_r with as many variables as I can find, but so far I'm not getting any information on why this is failing.
What is a good way to go about troubleshooting this? How can I find out what the 'parent' is? How can I find out if I'm connecting to my database even, or if it's failing before then?
In your concrete example, the quotes are missing in your conditions and columns parameters, it should be:
$users = Users::find(
[
'conditions' => '',
'bind' => [],
'columns' => "users_id"
]
);
Which should return a list of users ids (if any).
That tutorial from Andrew Belousoff is very good but maybe the next step after Phalcon's REST tutorial, since it explains step by step the inner workings of Phalcon.
For debugging, you can also check Phalcon's guide about it: https://docs.phalconphp.com/en/3.4/debug
And after Belousoff, you can dive into deeper waters with this one: https://github.com/phalcon/phalcon-api
Error 500 means error in php, just check logs. Im not sure how this parent thing is related to phalcon. This is just OOP, you mean you are using framework without knowledge about php/oop? Parent is just parent class which you extends.

Laravel 5 > Using monolog introspection processor

I have configured Laravel 5 to use a custom logging configuration (default is way too simple). I've added monolog's IntrospectionProcessor to log the file name and line number of the log call.
The problem is that all lines get the same file and line number:
[2015-06-29 17:31:46] local.DEBUG (/home/vagrant/project/vendor/laravel/framework/src/Illuminate/Log/Writer.php#201): Loading view... [192.168.10.1 - GET /loans/create]
Is there a way to config the IntrospectionProcessor to print the actual lines and not the facade ones?
If I do Log::getMonolog()->info('Hello'); it works and prints the correct file and line number... but I don't know how safe is to avoid calling the Writer.writeLog function because it fires a log event (is it safe to not fire that event?).
(Only tried in Laravel 4.2!)
When pushing the Introspection Processor to Monolog it is possible to give an skipClassesPartial array as second parameter in the IntrospectionProcessor contructor. With this array it is possible to skip the Laravel Illuminate classes and the logger logs the class calling the log method.
$log->pushProcessor(new IntrospectionProcessor(Logger::DEBUG, array('Illuminate\\')));
also see: https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/IntrospectionProcessor.php
I know this is an old question but I thought I'd give a quick update because it's pretty easy to get this done now.
I haven't tried with Laravel but My own logging mechanism is within a LoggingService wrapper class. As such the introspection was only giving details about the service rather than the caller.
after reading Matt Topolski's answer, I had a look in the IntrospectionProcessor.php. the constructor looks like this:
__construct($level = Logger::DEBUG, array $skipClassesPartials = array(), $skipStackFramesCount = 0)
All I had to do was add the processor like this:
log->pushProcessor(new IntrospectionProcessor(Logger::DEBUG, array(), 1));
This is actually the expected functionality unless you're having the handler process the logs directly (check out the comments at the top of IntrospectionProcessor.php). My guess is you have a wrapper function around the logger and you're calling it from Writer.php -- BUT
If you look at the code for IntrospectionProcessor.php you'll see a bit of code on lines 81 to 87 that decides how to format that stack trace, and it still has access to the stack. If you bump the $i values for $trace[$i - 1] / $trace[$i] up one (aka $trace[$i]/$trace[$i + 1] respectively) you can 'climb' the stack back to where you want.
It's important to note that the 'class' and 'function' parts of the trace need to be one level of the stack higher than the 'file' and 'line.'
On a personal (plz dont mod me bruhs) note, I'd like to see functionality to include a stack offset when throwing the log in. I know what function I want to blame if an error shoots out when I write the error_log('ut oh') but I might(will) forget that by the time the 'ut oh' comes.

How to do ItemLookup with Zend Service Amazon?

I would appreciate if anyone could guide me on the correct way on doing an ItemLookup by ISBN using the Zend Amazon Service module (with Zend 2.0).
Here is my attempt:
$query = new ZendService\Amazon\Query($appId, 'UK', $secretKey);
$query->Category('Books')->IdType('ISBN')->ItemID('978-0321784070')->AssociateTag($tag);
$result = $query->ItemLookup();
But I get the following errors:
Missing argument 1 for ZendService\Amazon\Amazon::itemLookup(), called in D:\wamp\www\site\controllers\dev.php on line 122 and defined
Undefined variable: asin
There is no way I can define the ASIN because the only information I will have is the ISBN.
I have already consulted the Zend Service Amazon user guide in the zend framework website but it is outdated and doesn't demonstrate how to do an ISBN lookup. I have also looked at the demo that came with the zend amazon package but that only details how to do item searches, not lookups.
Here is a way to get the ISBN search working, it took me a little while to get it figured out as well. The problem was that in order to search for ISBN you must use the ItemLookup method rather than the ItemSearch method which was getting set by the query() method.
There may be a better way to get this to work using the OO interface but I haven't tried that yet.
$query = new ZendService\Amazon\Query($appId, 'US', $secretKey);
$item = $query->itemLookup('9780321784070',
array('SearchIndex' => 'Books',
'AssociateTag' => $tag,
'IdType' => 'ISBN',
'ResponseGroup' => 'Small',));
Searching by ISBN should return a single ZendService\Amazon\Item object rather than an array of results. Also be aware, if you search by ISBN-13, you need to strip the - from the number or it won't find a match.
Credit to this blog post by Manas Tungare which hinted to me that we need to use IteamLookup instead of ItemSearch.

Define a custom ExceptionStrategy in a ZF2 module

Hi all,
I've been struggling with this issue for more than a week and finally decided to ask for help hoping that someone knows the answer.
I am developing an application, which is using Google's Protocol Buffers as the data exchange format. I am using DrSlump's PHP implementation, which let's you populate class instances with data and then serialize them into a binary string (or decode binary strings into PHP objects).
I have managed to implement my custom ProtobufStrategy whose selectRenderer(ViewEvent $e) returns an instance of ProtobufRenderer in case the event contains an instance of ProtobufModel. The renderer then extracts my custom parameters from the model by calling $model->getOptions() to determine which message needs to be sent back to the client, serializes the data and outputs the binary string to php://output.
For it to make more sense, let's look at the following sample message:
message SearchRequest {
required string query = 1;
optional int32 page_number = 2;
optional int32 result_per_page = 3;
}
If I wanted to respond to the client with this message, I would return something like this from my action:
public function getSearchRequestAction()
{
[..]
$data = array(
'query' => 'my query',
'page_number' => 3,
'result_per_page' => 20,
);
return new ProtobufModel($data, array(
'message' => 'MyNamespace\Protobuf\SearchRequest',
));
}
As you can see I am utilizing ViewModel's second parameter, $options, to tell which message needs to be serialized. That can then, as mentioned earlier, be extracted inside the renderer by calling $model->getOptions().
So far, so good. My controller actions output binary data as expected.
However, I am having issues with handling exceptions. My plan was to catch all exceptions and respond to the client with an instance of my Exception message, which looks like this:
message Exception {
optional string message = 1;
optional int32 code = 2;
optional string file = 3;
optional uint32 line = 4;
optional string trace = 5;
optional Exception previous = 6;
}
In theory it should work out of the box, but it does not. The issue is that Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel(MvcEvent $e) returns an instance of ViewModel, which obviously does not contain the additional $options information I need.
Also it returns ViewModel and not ProtobufModel, which means that the Zend invokes the default ViewPhpRenderer and outputs the exception as an HTML page.
What I want to do is replace the default ExceptionStrategy (and eventually also the RouteNotFoundStrategy) with my own classes, which would be returning something like this:
$data = array(
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
'previous' => $e->getPrevious(),
);
return new ProtobufModel($data, array(
'message' => 'MyNamespace\Protobuf\Exception',
));
...and I can't find the way to do it...
I tried creating my own ExceptionStrategy class and alias it to the existing ExceptionStrategy service but Zend complained that a service with such name already exists.
I have a suspicion that I am on the right path with the custom strategy extension I can't find a way to override the default one.
I noticed that the default ExceptionStrategy and the console one get registered in Zend/Mvc/View/Http/ViewManager. I hope I won't have to add custom view managers to achieve such a simple thing but please, correct me if I'm wrong.
Any help will be appreciated!
The easiest way is to do a little fudging.
First, register your listener to run at a higher priority than the ExceptionStrategy; since it registers at default priority, this means any priority higher than 1.
Then, in your listener, before you return, make sure you set the "error" in the the MvcEvent to a falsy value:
$e->setError(false);
Once you've done that, the default ExceptionStrategy will say, "nothing to do here, move along" and return early, before doing anything with the ViewModel.
While you're at it, you should also make sure you change the result instance in the event:
$e->setResult($yourProtobufModel)
as this will ensure that this is what is inspected by other listeners.

Categories