Woo Solo Api

Image with a two by two brick

I’d like to say – new year, new plugin, but this one was released back in November 2017 xD. Still I’m glad that I can write a bit about my new plugin called Woo Solo Api.

This plugin was a result of a client work here in Croatia. There is an accounting on line service called Solo, and a client I was working for was using their services. One thing they have been missing is a way to connect their API to the WooCommerce store on their site. And the client really wanted to have this ability to have her bill created simultaneously in WooCommerce and in the Solo service. Also one other bit the client wanted was to have the pdf of the Solo bill be sent to the customer with email.

API was there, so connecting it shouldn’t be that hard… Well I had to roam around the WooCommerce code to find the right hook to attach to, and after some testing I had a working version of the plugin.

Nothing is that simple…

First obstacle was testing if all the fields were correctly connected so that the API response doesn’t fail. Also, I needed to make sure to handle any failure. So there were lots of api calls being made from my test environment back and forth until all was correctly set up. Then came the tricky part. How do you send a pdf, if you are making an API call using wp_remote_post ? This is not ajax call, it’s php. No JavaScript whatsoever. Luckily the success response from the Solo API contains a link to the pdf, which you can visit and a pdf will be downloaded. So how do you send an email with a pdf attachment if, when visiting the link with the pdf, it will be automatically downloaded?!

I’ve never done something like this before. This made no sense to me. But there was something I could try. I knew of WordPress filesystem API, maybe I could use this somehow? The idea was this: I have the link that comes from the API response, I could use wp_remote_get , from this I’d get some jumbled code, but I could take the body of this response, and using filesystem create a pdf! I created a directory with all the bills and/or offers, and used $wp_filesystem->put_contents() method to create a pdf. Once this worked (luckily for me it did), I could easily use wp_mail() to send a custom mail to the customer with the pdf attachment.

A lesson learned

In the end I added several more options. I also got some comments what other clients wanted, and because one client didn’t receive the mail with the pdf from the API, I managed to find there was a tiny sneaky bug in my code that prevented the pdf to be sent if the bill type was set to offer. All this is fixed in the 1.2 version.

I also learned quite a bit about using WP_Filesystem, using namespaces in plugins, and a lot more.

Also since my last post, which was in March of 2017, I got a new job as a WordPress engineer at Infinum (April 2017), a superb company which works on  producing awesome software. I couldn’t be happier about that. I’ve learned bunch since I started working there Infinum. I also gave my first talk at WordCamp Zagreb, which was a great experience. You can find the presentation of my talk here. All in all, bunch of changes happened. Sadly, I haven’t been able to write tutorials, although I have so much to write about.

Lately I’ve been working on several open source projects at Infinum, one of which is WordPress boilerplate – a theme starter written in object oriented way, using namespaces and autoloading, webpack and all that jazz. I’ve also created a JSON post parser plugin, which parses your post content and stores it in a database as JSON (super useful if you are using decoupled WordPress approach). There are some projects that we are currently working on, and should release them on wordpress.org, hopefully they’ll be out soon as plugins, so keep an eye out on either my twitter, or Infinum’s twitter.

I have a huge article in my draft about using ajax. It’s basically a rewrite of my most popular article here. I hope I’ll find some more time to finish it, and publish it in several parts, so that every part is well covered and explained :)

Hope you like the plugin, and find it useful. If you do, be sure to give it a good rating, or if you find a bug, don’t hesitate to ask in the support so that I can fix it : ) As always feel free to comment below and happy coding : )

8 responses

  1. Florin Avatar
    Florin

    Hello,

    Is this Plugin also working for the Romanian website solo.ro ?

    Thank you

    Grats!

    1. Hi! No, this is the plugin for https://solo.com.hr/ accounting service.

  2. Greeting.
    Since the switch to the euro, the plugin doesn’t work on WordPress, so it doesn’t send offers, nor do I receive email notifications that an order has arrived.
    We have reinstalled, the version is 6.1
    php also updated. Please help, where are we going wrong?

    1. Try clearing the exchange rate transiente (there should be a button in the settings Solo Api Test part to clear it), if that doesn’t work, try uninstalling it and reinstalling it, so that all the saved options are cleared.

  3. Poštovanje Denis,

    Pred osnivanjem tvrtke, našao sam SOLO i normalno, još ga ne koristim. Jedna stvar me zbunjuje. Recimo imamo situacije:

    Račun broj 1 – plaćeno virmanom – ne treba fiskalizirati
    Račun broj 2 – plaćeno Internet bankarstvom – ne treba fiskalizirati
    Račun broj 3 – besplatan paket – 0 kn – da li trebamo izdati i račun za 0 kn ili se ispušta/preskače?
    Račun broj 4 – Plaćeno karticom preko MyPOS – ovo se treba fiskalizirati – ok, to ide preko SOLO
    itd.

    Da li SOLO zna što treba fiskalizirati a što ne ili je SOLO glup (ne radi automatski) i mi trebamo kliknuti na nešto da bi se to nešto provelo kroz SOLO?

    Što je s računom od 0 kn jer WooCommerce će obračunati i to?

    Hvala unaprijed. Lijepi pozdrav,

    1. Pozdrav!

      U opcijama plugina bi trebalo za svaki payment type biti moguće odabrati hoće li se taj račun fiskalizirati ili ne. Tako da ako je ta opcija odabrana, račun će se fiskalizirati – ako je sve podešeno na Solo servisu kako spada. Solo servis vrši fiskalizaciju.

      Besplatan paket će se isto poslati kao račun. Upit prema Solo servisu se radi sa svim podacima u košarici, tako da, ako se taj besplatan paket nalazi u košarici, bit će na računu (iako je 0 kn). Koliko je to validno sa neke računovodstvene strane nisam ovlašten za reći :D To bi trebalo provjeriti s nekim računovodstvenim servisom.

      Pozdrav

  4. e meni pise 2 put ponudu. i kad se napravi narudzba i kada se izvrši narudzba. kako se to moze popraviti. pozz

    1. Je li sigurno sve postavljeno kako treba u postavkama?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.