digitalwithyou / craft-facebook-conversion

Craft CMS plugin to send web events directly to Facebook
https://digitalwithyou.com/en/plugins/facebook-conversion/getting-started
Other
0 stars 3 forks source link

Error when using Web Payments plugin #6

Closed Tam closed 3 years ago

Tam commented 3 years ago

We're getting this error on one of our sites that's also using our Web Payments plugin.

FacebookAds\Http\Exception\AuthorizationException: Invalid parameter in /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Exception/RequestException.php:174
Stack trace:
#0 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response))
#1 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Request.php(286): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request))
#2 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(165): FacebookAds\Http\Request->execute()
#3 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(214): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request))
#4 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/ApiRequest.php(187): FacebookAds\Api->call('/13896427114044...', 'POST', Array, Array)
#5 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Object/AdsPixel.php(180): FacebookAds\ApiRequest->execute()
#6 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/EventRequest.php(243): FacebookAds\Object\AdsPixel->createEvent(Array, Array)
#7 /var/www/html/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/EventRequest.php(235): FacebookAds\Object\ServerSide\EventRequest->defaultExecute()
#8 /var/www/html/vendor/dwy/facebook-conversion/src/services/FacebookBusinessApi.php(53): FacebookAds\Object\ServerSide\EventRequest->execute()
#9 /var/www/html/vendor/dwy/facebook-conversion/src/listeners/commerce/BaseCommerceEvent.php(24): dwy\FacebookConversion\services\FacebookBusinessApi->sendEvent('AddToCart', Object(FacebookAds\Object\ServerSide\UserData), Object(FacebookAds\Object\ServerSide\CustomData))
#10 /var/www/html/vendor/dwy/facebook-conversion/src/listeners/commerce/order/AfterAddLineItem.php(28): dwy\FacebookConversion\listeners\commerce\BaseCommerceEvent->sendEvent('AddToCart', Object(craft\commerce\models\Customer), Object(FacebookAds\Object\ServerSide\CustomData))
#11 [internal function]: dwy\FacebookConversion\listeners\commerce\order\AfterAddLineItem->__invoke(Object(craft\commerce\events\LineItemEvent))
#12 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(dwy\FacebookConversion\listeners\commerce\order\AfterAddLineItem), Object(craft\commerce\events\LineItemEvent))
#13 /var/www/html/vendor/yiisoft/yii2/base/Component.php(637): yii\base\Event::trigger('craft\\commerce\\...', 'afterAddLineIte...', Object(craft\commerce\events\LineItemEvent))
#14 /var/www/html/vendor/craftcms/commerce/src/elements/Order.php(1669): yii\base\Component->trigger('afterAddLineIte...', Object(craft\commerce\events\LineItemEvent))
#15 /var/www/html/vendor/ether/web-payments/src/services/StripeService.php(112): craft\commerce\elements\Order->addLineItem(Object(craft\commerce\models\LineItem))
#16 /var/www/html/vendor/ether/web-payments/src/web/Variable.php(134): ether\webpayments\services\StripeService->buildOrder(NULL, Array)
#17 /var/www/html/vendor/ether/web-payments/src/web/Variable.php(57): ether\webpayments\web\Variable->_getCart(Array)
#18 /var/www/html/vendor/twig/twig/src/Extension/CoreExtension.php(1511): ether\webpayments\web\Variable->button(Array)
#19 /var/www/html/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(ether\webpayments\web\Variable), 'button', Array, 'method', false, false)
#20 /var/www/html/storage/runtime/compiled_templates/00/0039f5f01b94a043ae3f3cd99597dd2aad1351e1b4aa7eeb398621a3c6cabeaf.php(312): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(ether\webpayments\web\Variable), 'button', Array, 'method')
#21 /var/www/html/vendor/twig/twig/src/Template.php(182): __TwigTemplate_915b7743d48613b58ad9051b2b519422fdd8886f4fa3ce20496cdcddb5f54590->block_content(Array, Array)
#22 /var/www/html/storage/runtime/compiled_templates/c9/c98c2f6d3f7388f1f9856d516a83342ae406297bc6c1ca6482580878a23582e3.php(368): Twig\Template->displayBlock('content', Array, Array)
#23 /var/www/html/vendor/twig/twig/src/Template.php(182): __TwigTemplate_0a23c213c8219f563319e6ebcef36e095c4704ae274f107ce890574088ad2565->block_markup(Array, Array)
#24 /var/www/html/storage/runtime/compiled_templates/13/13a536f42c18c9f19a0130685653f678636b6f15962e81b3c94958affe30e4f6.php(149): Twig\Template->displayBlock('markup', Array, Array)
#25 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_ee7adec04ebf40bbef44c548f15ddb6b0bb8183d2ca70b0758f988c56c310306->doDisplay(Array, Array)
#26 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#27 /var/www/html/storage/runtime/compiled_templates/c9/c98c2f6d3f7388f1f9856d516a83342ae406297bc6c1ca6482580878a23582e3.php(44): Twig\Template->display(Array, Array)
#28 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_0a23c213c8219f563319e6ebcef36e095c4704ae274f107ce890574088ad2565->doDisplay(Array, Array)
#29 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#30 /var/www/html/storage/runtime/compiled_templates/00/0039f5f01b94a043ae3f3cd99597dd2aad1351e1b4aa7eeb398621a3c6cabeaf.php(74): Twig\Template->display(Array, Array)
#31 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_915b7743d48613b58ad9051b2b519422fdd8886f4fa3ce20496cdcddb5f54590->doDisplay(Array, Array)
#32 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#33 /var/www/html/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#34 /var/www/html/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#35 /var/www/html/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#36 /var/www/html/vendor/craftcms/cms/src/web/View.php(390): Twig\Environment->render('coffee/_coffee', Array)
#37 /var/www/html/vendor/craftcms/cms/src/web/View.php(451): craft\web\View->renderTemplate('coffee/_coffee', Array)
#38 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(257): craft\web\View->renderPageTemplate('coffee/_coffee', Array, 'site')
#39 /var/www/html/vendor/craftcms/cms/src/controllers/TemplatesController.php(100): craft\web\Controller->renderTemplate('coffee/_coffee', Array)
#40 [internal function]: craft\controllers\TemplatesController->actionRender('coffee/_coffee', Array)
#41 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#42 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#43 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('render', Array)
#44 /var/www/html/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('render', Array)
#45 /var/www/html/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('templates/rende...', Array)
#46 /var/www/html/vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction('templates/rende...', Array)
#47 /var/www/html/vendor/craftcms/cms/src/web/Application.php(259): yii\web\Application->handleRequest(Object(craft\web\Request))
#48 /var/www/html/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#49 /var/www/html/web/index.php(21): yii\base\Application->run()
#50 {main}

By the looks, you're listening for an "add line item" event and sending stuff to Facebook. In Web Payments we create a temporary order that's never saved to calculate the costs required for the payment button. It looks like the issue is when you try to send an order that hasn't been saved to the database.

This could probably be fixed by checking if the line item's order has an ID (and is therefore saved) before sending data to Facebook.

Diewy commented 3 years ago

Hi @Tam ,

Thank you for letting me know, I'll take a look to support your plugin over the weekend.

Diewy commented 3 years ago

The latest release (v1.0.9) should support the Web Payments Plugin. Let me know if there would be any issues.

alexjcollins commented 3 years ago

Thanks @Diewy 🙌