Jump to content

SnipWire - Snipcart integration for ProcessWire


Gadgetto

Recommended Posts

15 hours ago, Gadgetto said:

Hey guys,

I'm indeed starting further development on this module in the next days! It needs a lot of work to be done. The main part will be the transition to Snipcart 3.0 engine + a robust EU VAT tax integration. As usual I'll report the progress to this thread.

Please stay tuned!

Greetings,
Martin

This is great news and highly appreciated. The module as is works great for the most parts. But to make it work with snipcart v3, it does need some adjustments. Other than that I have it running without major issues. Since I thought that it won't be continued, I did quite some changes to the code in my install. Might turn that into a fork. Maybe there's something you can make use of.

EDIT: Oh, I just saw that I had already forked it. But needs some cleanup, I guess...

Link to comment
Share on other sites

  • 4 months later...
22 hours ago, Gadgetto said:

With the next SnipWire release I plan to support only V3 of the Snipcart engine. Supporting both versions would be too much effort. How do you think about this?

After 4 years, it should be okay in my opinion.

 

22 hours ago, Gadgetto said:

Which min. required PHP version would be OK for you?
How many of you are still running your servers with PHP < 7.4?

All my E-Commerce are on 8.x. I personal see no reason for 7.4.

 

Since SnipCart self is again awake in developing, maybe a major version bump on the module side for a chance to cut old branches?

  • Like 2
Link to comment
Share on other sites

23 hours ago, Gadgetto said:

Which min. required PHP version would be OK for you?
How many of you are still running your servers with PHP < 7.4?

Same for me here, PHP 8 is ok. Also Snipcart v3 only.

Thanks for updating the module!

  • Like 2
Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

@Gadgetto I am struggling with webhooks :-)

In the docs it says:

 * All hookable event handler methods will return an array containing payload Snipcart sent to your endpoint.
 * In addition, the following class properties will be set:
 *
 * $this->payload (The payload Snipcart sent to your endpoint)
 * $this->responseStatus (The response status your endpoint sent to Snipcart)
 * $this->responseBody (The response body your endpoint sent to Snipcart)
 *
 * (Use the appropriate getter methods to receive these values!)
 *
 * How to use the hookable event handler methods (sample):
 * ~~~~~
 * $webhooks->addHookAfter('handleOrderCompleted', function($event) {
 *     $payload = $event->return;
 *     //... your code here ...
 * }); 
 * ~~~~~
 *
 * PLEASE NOTE: those hooks will currently only work when placed in init.php or init() or ready() module methods!
 *

I have setup a hook for order.completed in the init method of a custom autoload module

  public function init()
  {
    ...
    // SnipWire Webhooks
    $this->wire->webhooks->addHookAfter('handleOrderCompleted', $this, 'handleOrderCompleted');
    
  }

Issueing post requests to the endpoint returns an empty response body

webhooks-response.thumb.png.3a012c3811a162c4728766b8232d2060.png

While in the docs it says:
 

Quote

* In addition, the following class properties will be set:

*

* $this->payload (The payload Snipcart sent to your endpoint)

* $this->responseStatus (The response status your endpoint sent to Snipcart)

* $this->responseBody (The response body your endpoint sent to Snipcart)

when I var_dump($event->object->getResponseBody()) in my handler method, it gives an empty string which explains why the response body is empty.

How can I set responseBody from within my hook handler method? There is no setter for that and Webhooks::responseBody is private, so I have no way to set it in my handler.

To solve this, I introduced a setter method to the Webhooks class

    /**
     * Setter for responseBody.
     *
     * @param string $responseBody
     * @return void
     *
     */
    public function setResponseBody(string $responseBody)
    {
        $this->responseBody = $responseBody;
    }

Now in my handler method I can do $event->object->setResponseBody('{"test": "test"}'); Which results in

webhooks-response-1.png.8b7ba43e9713ff5971faff325a283816.png

While I was at it, I also added a setter for responseStatus.

Not sure if you still maintain this module, so I will add this to my fork just in case anyone still needs it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...