Nullcorps / woocommerce-gateway-bitcoin

Self custody bitcoin checkout/payment-gateway for woocommerce. Accept Bitcoin on your wordpress+woocommerce shop without needing to sign up for any centralised services or be subject to any Terms of Service. Totally self-custody, uses HD wallet so payments drop straight into your electrum or other wallet. Uses only free, public APIs with a choice (and failover) between blockstream or blockchain.info
GNU General Public License v3.0
4 stars 5 forks source link

Great work; fork #1

Open BrianHenryIE opened 2 years ago

BrianHenryIE commented 2 years ago

Hey,

Great job.

I've forked it and am about to test in production: https://github.com/BrianHenryIE/woocommerce-gateway-bitcoin/releases/

One of the composer dependencies is yet to be uploaded to GitHub, so you won't be able to build it yet. It's a library called "private uploads" which adds the rewrite (htaccess) rules to WordPress so the woobtc folder is not publicly accessible, and shows an admin notice to WordPress administrators if it is. Eventually I'll make a PR.

Changes:

It's at 40% unit test coverage. TBH, that's mostly the WooCommerce end of the code. I did write some tests on the external APIs (and confirmed the wallet generation against Electrum's result, which was reassuring), but the big hole in tested code is the API class which is the glue of the whole thing.

It's gone from 3 PHP files to almost 40 classes! (+ >20 test classes!)

Fingers crossed this works on my hosting.

Again, really great job ✨. This is exactly what everyone should be using. It's so much more aligned with the philosophy of Bitcoin and WordPress than any of the other WooCommerce solutions.

Brian.

Nullcorps commented 2 years ago

heya,

Great job.

thanks for your message! oh wow this is exciting tbh and I understood some/most of what you said xD

I've forked it https://github.com/BrianHenryIE/woocommerce-gateway-bitcoin and am about to test in production: https://github.com/BrianHenryIE/woocommerce-gateway-bitcoin/releases/tag/1.0.0

One of the composer dependencies is yet to be uploaded to GitHub, so you won't be able to build it yet. It's a library called "private uploads" which adds the rewrite (htaccess) rules to WordPress so the woobtc folder is not publicly accessible, and shows an admin notice to WordPress administrators if it is.

ooh damn so the woobtc folder is publicly accessable? hmm that would be bad. I've just checked on my live installs and I'm not able to pull the addresses files and there looks to be an .htaccess in place and tbh I think I would have had it make that automatically though looking at it I can't find where it does it in the code (but then I just woke up and am still kinda fuzzy). [edit just found it.. in i_subs.php].. i guess your way improves that somehow? the admin notice sounds useful.

Eventually I'll make a PR.

does that mean you'll ..whatever, propose the code as changes which can be merged into the original project (or something like that)? tbh I'd welcome any help as I'm just kinda doing my best here but am at the edge of my knowledge with this stuff. But of course I want it to be better. I was dragged kicking and screaming into using git by a friend a couple of years back and am starting to love it but my understanding of the more advanced stuff is still pretty basic.

Changes:

  • Addresses are generated in the background, automatically when below 50

that would be neat, tbh we've not really had many (or any) people use BTC on the test sites but then that's for porn and porn users tend to be ...er..somewhat technically limited as well as being focused on other things at the time, so they've not really been a great test crowd like we'd hoped. My plan was to just have a cron/webcron hit the addresses page but..yeah, not ideal.

ooh so segwit support? That would be significant and I'd really like it to support segwit addresses. I tried but couldn't get that working.. again, started to get beyond my php/maths skills there. Would love to make a version which supported LTC payments too (i know, i know, but getting paid is getting paid) since I occasionally use that when there's a spam attack on btc or fees are just crazy. It looked like bitwasp could do LTC addresses but I couldn't get the addresses to line up with electrum-ltc. I managed to get the addresses all deriving correctly using https://github.com/sanderkruger/hd-wallet-derive#installation-and-running but that's even more demanding to install and then life stuff got in the way and I never got any further with it.

  • Orders are checked in the background every five minutes as long as they are on-hold

oh nice idea! wouldn't have known how to do that.

  • Uses WooCommerce templates (wc_get_template()) for displaying the payment instructions, i.e. can be easily overridden in a theme

I think that sounds good, kinda at the edge of my understanding there..so I guess rather than just dumping the content to the page..that seems like a good move.

sounds good but don't really know what that does (yet)..

so then it wouldn't offer the option of a discount for BTC payments? I see that plugin seems to allow discounts based on a particular payment gateway being used.. ok does the same thing. sweet!

It's at 40% unit test coverage. TBH, that's mostly the WooCommerce end of the code. I did write some tests on the external APIs (and confirmed the wallet generation against Electrum's result, which was reassuring), but the big hole in tested code is the API class https://github.com/BrianHenryIE/woocommerce-gateway-bitcoin/blob/1.0.0/src/API/class-api.php which is the glue of the whole thing.

ok tbh here's where you lose me..I'm self taught and kinda developed in isolation so never even spoke to another coder for most of the last 20 years, so some stuff has just passed me by completely. Still not exactly sure what unit tests are/do or how to go about implementing that, so this seems like steps towards making it "proper" code.

It's gone from 3 PHP files to almost 40 classes! (+ >20 test classes!)

yikes but ok..

Fingers crossed this works on my hosting.

Again, really great job ✨. This is exactly what everyone should be using. It's so much more aligned with the philosophy of Bitcoin and WordPress than any of the other WooCommerce solutions.

Thank you, this really means a lot and strongly agree. Like wow, someone who gets it! Literally was starting to think I was the only one xD. I am so sick of all the plugins which require registration and have someone trying to rentseek/control my content as a result, and/or trying to pimp their premium plugin, or use bad techniques (address reuse, having to enter addresses manually). Honestly, just NO. This stuff needs to be #foss and work better.

And wow you've done loads, that's awesome!

Welcome to the "team" :) Just followed you on twitter.

best wishes,

Nullcorps

BrianHenryIE commented 2 years ago

Hey,

You did already have the .htaccess, yes, but I was adding a logger which uses this library anyway, to protect the log files, so it made sense to use it for both.

Once this is tested working well enough, I'll make a PR, to request you pull my changes into your repository.

I have the plugin live now. I've used WooCommerce Conditional Shipping and Payments to make it visible only for orders under $80. Hopefully there will be one or two soon and I can confirm this is working.

TBH I barely know what segwit is. I don't know what a HD wallet is. I do want to clean up the Bitcoin API classes with more comments and tests. The address generation now is different to what you wrote. I had created a new wallet in Electrum and it was a zpub. Eventually I found some code that generated addresses that matched the addresses Electrum was generating, so I think it's ok, at least for zpub. Again, I've never heard of zpub or ypub before, so I'm a bit nervous around this (don't want to lose loads of money!).

WooCommerce supports templates, basically I took out the display code into its own file, put it in templates/bitcoin-unpaid.php and now anyone using the plugin can create a bitcoin-unpaid.php file, save it in their theme folder, and our plugin will use that to display the instructions.

Unit tests are great for 1: developing a small part of the code without having to load the entire plugin, 2: finding where the small change you made in one location is affecting the rest of the code. E.g. we can write a unit test that tests fetching transactions and we get to quickly edit our code, run again, edit, run, again, again, without loading the full plugin, then later (months later) we always know whether or not the code for fetching transactions is still working because we run all the tests before creating a new release.

I pushed an update earlier with a few fixes: https://github.com/BrianHenryIE/woocommerce-gateway-bitcoin/releases/tag/1.0.1

And I have some more in the pipeline:

I edited your README lots to add information and to strikethrough where I had changed things.