Closed warmwhisky closed 4 years ago
@warmwhisky Can you provide some sample code that you are using that is not working?
@ajohnson6494 Absolutley.
// Check for affiliate_id in session
Session::has('affiliate_id') ? $affiliate_id = Session::get('affiliate_id') : $affiliate_id = 0;
// initiate InfusionAPI with upwebdesign/laravel-infusionsoft
$infusionsoft = new Infusionsoft();
// create new infusion invoice
$newOrder = $infusionsoft->invoices()->createBlankOrder($infusionUser, 'NG Online Shop', new DateTime('now'), 0, (int)$affiliate_id);
Other ways I have tried
// normal without casting to int
$newOrder = $infusionsoft->invoices()->createBlankOrder($infusionUser, 'NG Online Shop', new DateTime('now'), 0, $affiliate_id);
// with casting
$newOrder = $infusionsoft->invoices()->createBlankOrder($infusionUser, 'NG Online Shop', new DateTime('now'), 0, (int)$affiliate_id);
// hardcoding the affiliateID
$newOrder = $infusionsoft->invoices()->createBlankOrder($infusionUser, 'NG Online Shop', new DateTime('now'), 0, 2249;
All of the above execute without error. The AffId just never gets set
@warmwhisky Looking into this a little bit....Are you passing in theleadAffiliateID
or aContactId
?
Only theleadAffiliateID
will work. A ContactId
will not work here.
If you only have theContactId
of the affiliate, you could retrieve theleadAffiliateID
by making the following call.
$infusionsoft::data()->query('Affiliate', 1, 0, ['ContactId' => '114333'], ['Id', 'ContactId'], 'Id', false);
@ajohnson6494 Thanks you so much for the query to get the AffId. I will try this out.
I'm passing the ContactId of the affiliate. Looking at our list of affiliates it gives us their ContactId. I assumed from the documentation that that is what I am supposed to pass as an INT and not their Affiliate Code which has letters.
I thought the leadAffiliateID
would just be the ContactId
. A "lead" is a possible conversion and a saleAffiliateID
would be a real conversion? Edit: I have just checked the Affiliate table on the table schema. So I guess the ID that they show on the affiliate contact list is just showing the Contact ID which is the wrong ID to insert to the database. So I have to make another API call to get the AffiliateId
. The API is slow enough already. I wish I didn't have to make so many API calls. I push them to the background into queued jobs. but its not ideal in some cases. Their documentation is crazy difficult to get right. If fact It makes you chase your tail.
I don't know how often you are adding affiliates, but could you cache the relation of contact id to affiliate id on your end in a DB. Then you wouldn't have to make the extra api call every-time. You would only need to make an api call when a new affiliate is added or do a nightly check for new affiliates.
We're not likely to be adding affiliates all that often at all. We only have 4 main agents at the moment. I already have their ContactId in the local DB. Thanks for the pointer on caching their IDs. I will make another column in our local users table for their AffId and populate that once I get blank invoices working.
Thanks for all of your help.
When I create a blank invoice the Affiliate ID does not get inserted to the blank invoice. The invoice gets created without any errors, but no Sale Referral Partner is set. I have checked what gets inserted before creating and if I do not have an affiliate_id setup in my session I simply add a 0, but I know there is an affiliate id there.
It was my understanding that if I add the affiliate ContactId when I create the blank invoice then when the Invoice has all items added and then marked as paid the affiliate would get a commission. Have I got this concept correct?
Edit: After some more tests I hardcoded the $saleAffiliateId into the function and still does not get inserted to the invoice.