Bitcoin Forum

Bitcoin => Project Development => Topic started by: weex on March 03, 2012, 08:35:22 AM



Title: osCommerce Bitcoin Payment Module
Post by: weex on March 03, 2012, 08:35:22 AM
This is a work in progress but the goal will be automated Bitcoin payment processing using just oscommerce, bitcoind running locally, and a bit of python. In regards to whether it's wise to store BTC locally, the python script will offload BTC to the shopkeeper's address of choice not long after it's confirmed.

https://github.com/weex/oscommerce-bitcoin

Part of the python script monitors bitcoind and restarts it if it doesn't answer.

Feel free to comment or make suggestions or ask questions or dismiss this entirely or code something better or hack another bitcoin service or ...

Update You can now see a working demo store using this module at http://owneo.com


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 04, 2012, 09:40:43 AM
An update on current status..and this is exciting! Did you know there are 12,700 live osCommerce webstores?

This project now works with the following features and was tested against osCommerce v2.3.1

* Bitcoind and monitor.py can be run on a server other than the osCommerce hosting server
* Creates a unique payment address for each order
* Updates order to Delivered when payment is received (# of confirmations is configurable)
* Forwards Bitcoins to forwarding address once the local bitcoind has more than a threshold amount
* Python script monitors bitcoind and will restart it if it becomes unresponsive

Todo:

* Update readme and write an installation guide with tips on configuring osCommerce with the BTC currency
* Include BTCUSD exchange rate update in python script
* Include a watchdog script to make sure monitor.py is running via cronjob.

It's been fun testing with 0 confirmations and seeing the order status update all by itself.  8)


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 04, 2012, 06:33:14 PM
Enabling the module doesn't work for me. It redirects me to a blank page, and when I go back it doesn't show up in the payment module menu, even though under "install modules" it says that it is enabled.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 04, 2012, 08:47:59 PM
This is fixed. I tested it by uninstalling the module and reinstalling it.

When I removed it in the half-installed state you encountered, it appeared to have removed another payment module. If you know more about how osCommerce determines if a module is installed, you might want to edit the sql directly. I'm thinking it's just removing the MODULE_PAYMENT_BITCOIN_ records from the configuration table.

Thanks for testing, create an issue at github if you run into any other problems.

-weex


Title: Re: osCommerce Bitcoin Payment Module
Post by: koin on March 04, 2012, 09:18:21 PM
is there a link to any site that uses this, to demonstrate?


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 04, 2012, 10:48:21 PM
Thank you for fixing the bug.

I'd like to use this on my website, but I am inexperienced with bitcoin servers.. I host my website on a webserver, so I can't run bitcoind and the python script there, right? Can I run bitcoind and the python script on my home computer that I turn off every night, or does it have to be online 24/7? Do I have to forward any ports?

Alternatively, are there any free or very cheap VPS's that I can use for this purpose?


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 12:10:21 AM
Thank you for fixing the bug.

I'd like to use this on my website, but I am inexperienced with bitcoin servers.. I host my website on a webserver, so I can't run bitcoind and the python script there, right? Can I run bitcoind and the python script on my home computer that I turn off every night, or does it have to be online 24/7? Do I have to forward any ports?

Alternatively, are there any free or very cheap VPS's that I can use for this purpose?

The python script and bitcoind will require shell access which is more likely to be available in a VPS or dedicated server. You should be able to get cheap VPS for $10-20 a month to try it out.

Starting out I would recommend bitcoind and the python script (monitor.py) be running 24x7 on the webserver. Running it only part time will not work and running it on your home computer will require a stable internet connection and the bitcoin RPC port to be opened on your firewall. Like I said, a cheap vps with everything running there is best.

Then you can set a FORWARDING_ADDRESS  and the script can forward any funds to your home or company wallet.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Daily Anarchist on March 05, 2012, 02:43:46 AM
There's already a pretty nice oscommerce Bitcoin payment module available here:

http://addons.oscommerce.com/info/8170

One of my forum members wrote it specifically for me. My oscommerce store section uses it and it works great. It generates a new address for each purchase.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 03:16:01 AM
There's already a pretty nice oscommerce Bitcoin payment module available here:

http://addons.oscommerce.com/info/8170

One of my forum members wrote it specifically for me. My oscommerce store section uses it and it works great. It generates a new address for each purchase.

If it weren't for that module, I wouldn't have worked on this. It was a great starting point since the author appears to have known a lot more about oscommerce than I.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Daily Anarchist on March 05, 2012, 05:04:56 AM
There's already a pretty nice oscommerce Bitcoin payment module available here:

http://addons.oscommerce.com/info/8170

One of my forum members wrote it specifically for me. My oscommerce store section uses it and it works great. It generates a new address for each purchase.

If it weren't for that module, I wouldn't have worked on this. It was a great starting point since the author appears to have known a lot more about oscommerce than I.

Actually, he didn't know anything about oscommerce before he started the project.

What will your addition bring the to table that his currently doesn't?


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 05:18:19 AM
The module I started with asked bitcoind for a new address and associated it with an account name given by the buyer's email address and the osCommerce session id with which the purchase was made. At that point it was up to the store owner to monitor those addresses and update the order status. Maybe you had something more that wasn't released as part of that module?

The additions I made automate this process. The python script monitor.py periodically looks at the osCommerce database to find orders with order status Pending and that used the Bitcoin Payment module. It then queries bitcoind to see if enough funds have been sent to the addresses associated with Pending orders. If enough were sent it takes the next step.

That step is to call another part of this module called the bpn.php script. This script was derived from a Paypal IPN script (IPN is where Paypal can tell osCommerce at some later time that payment has been made, cleared, etc). When called with the notification key and an order id, it will fire off an email to the buyer and set the order status to Delivered. 

I'm actually not sure what is the best order status to change to but it's a simple change to make in the bpn.php script for anyone who wants to customize it.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Daily Anarchist on March 05, 2012, 05:40:27 AM
That sounds really badass. I'm looking forward to the update. Will it require the phoenix mod be installed underneath yours? Will yours include all of the phoenix mod? Will I have to delete the phoenix mod to get yours to work?

Right now when people order it puts them in pending status. It's a pain in the ass though because I have to log into my server every day and see if anybody has sent the coins, usually not. Most people order and then never send, I think it's because they ordered not knowing that I only accept Bitcoin as payment, and they're like "huh?"

When somebody does pay I put them in "processing" and send them a thank you email. After I've stuck the envelope in the mail I change it to delivered.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 05:46:28 AM
Will it require the phoenix mod be installed underneath yours? Will yours include all of the phoenix mod? Will I have to delete the phoenix mod to get yours to work?

When the update is ready, you can probably just remove the phoenix mod as this one includes (really was built from) that one.

When somebody does pay I put them in "processing" and send them a thank you email. After I've stuck the envelope in the mail I change it to delivered.

Processing does make more sense. I'm going to change that with the next update.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 07:21:52 AM
The module has been updated with the following:

* Exchange rate updated periodically from mtgox with fallback to bitcoinexchangerate.org
* Payment recieved sets order status to Processing instead of Delivered

https://github.com/weex/oscommerce-bitcoin


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 05, 2012, 03:49:43 PM
When do you expect this to be finished/good enough for long term reliable use?


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 05, 2012, 04:48:17 PM
When do you expect this to be finished/good enough for long term reliable use?
That's a good question and I suppose it's ready for someone running a test store or someone with php/python/mysql experience. I've been testing it as I go and it is based in part on some code that has seen long term use. I'll setup a test store in the next couple days so people can try it out.

To get this ball rolling, I'll start a bounty of 2 BTC for the first person other than myself who gets a store running. Contribute if you'd like:
1D3NrskpzB5Ydzs2RByDavbqqenbksgNoB  (Bounty thread (https://bitcointalk.org/index.php?topic=67439.0))

Thanks,

weex


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 05, 2012, 07:57:34 PM
I'm trying to get bitcoind on a VPS to work, but oh my is it hard.. If anyone are willing to help, I've made a thread here: https://bitcointalk.org/index.php?topic=67472.msg784871


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 06, 2012, 03:21:10 PM
I don't know if I've set up everything correctly, but when I run the monitor.py, I get this message:

Code:
[root@grixserver python]# ./monitor.py &
[1] 7588
[root@grixserver python]# Traceback (most recent call last):
  File "./monitor.py", line 169, in <module>
    d.check()
  File "./monitor.py", line 52, in check
    p = Popen(command, stdout=PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 639, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory


Title: Re: osCommerce Bitcoin Payment Module
Post by: Raoul Duke on March 06, 2012, 03:46:06 PM
Using your quote, 12700 oscommerce shops. Do you realise those numbers are very low?
Prestashop has more than 80,000 active shops and yet we don't see much of them using bitcoin.
Also, Prestashop is still in active development.
I suspect you targeted the wrong platform.
Nonetheless: Great work!


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 06, 2012, 04:51:53 PM
Using your quote, 12700 oscommerce shops. Do you realise those numbers are very low?
Prestashop has more than 80,000 active shops and yet we don't see much of them using bitcoin.
Also, Prestashop is still in active development.
I suspect you targeted the wrong platform.
Nonetheless: Great work!

Thanks, this is what I'm hearing and after a bit of browsing of the example shops I think many links are dead. Still, this project was sparked by a request from someone who needs it so I don't feel it is diminished.

Much of the code in monitor.py can be reused to support Prestashop, Zencart, and others. What I've found is several modules that are not comfortable talking to bitcoind and this one may help on that front.

One shopping in cart in particular that is interesting is Shopify. To support them you pretty much have to run bitcoind for anyone who wants to add your app.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 06, 2012, 04:53:41 PM
I don't know if I've set up everything correctly, but when I run the monitor.py, I get this message:

Code:
[root@grixserver python]# ./monitor.py &
[1] 7588
[root@grixserver python]# Traceback (most recent call last):
  File "./monitor.py", line 169, in <module>
    d.check()
  File "./monitor.py", line 52, in check
    p = Popen(command, stdout=PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 639, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Ahh, this is because bitcoind is not in your path. Please see: http://www.troubleshooters.com/linux/prepostpath.htm

You can use `which bitcoind` to check that the folder containing bitcoind has been added to the path successfully.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Andrew Vorobyov on March 07, 2012, 10:30:58 AM
Good start... where to send donations?

Next step must be http://www.magentocommerce.com. Anyone interested?


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 07, 2012, 01:55:34 PM
I don't know if I've set up everything correctly, but when I run the monitor.py, I get this message:

Code:
[root@grixserver python]# ./monitor.py &
[1] 7588
[root@grixserver python]# Traceback (most recent call last):
  File "./monitor.py", line 169, in <module>
    d.check()
  File "./monitor.py", line 52, in check
    p = Popen(command, stdout=PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 639, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Ahh, this is because bitcoind is not in your path. Please see: http://www.troubleshooters.com/linux/prepostpath.htm

You can use `which bitcoind` to check that the folder containing bitcoind has been added to the path successfully.

Ah, thanks, that did the trick.

I'm almost ready to launch a humble webshop using this, just need to get DNS servers working, and order some stock. Maybe I'll even be fast enough for the little bounty you have going :)


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 07, 2012, 03:59:01 PM
Good start... where to send donations?

Thanks Andrew. My donation address is 1G9EYbrFYyVeGcG4HJiCYQdXugRBb454dJ

About Magento, it looks quite a bit more complicated than an osCommerce module but the monitor.py script should be useful with some modifications.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Andrew Vorobyov on March 07, 2012, 04:35:44 PM
It's also in PHP


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 07, 2012, 04:41:08 PM
I've got another bug or misconfig.. Anyone have any idea? When I confirm a test order, I just get this error, and the order doesn't register:

Code:
1054 - Unknown column 'delivery_date' in 'field list'

insert into orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, delivery_date, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, date_purchased, orders_status, currency, currency_value) values ('1', 'test user test user', '', 'test user', '', 'test user', 'test user', 'test user', 'Antigua and Barbuda', 'test user', '*', '1', 'test user test user', '', 'test user', '', 'test user', 'test user', 'test user', 'Antigua and Barbuda', '1', '', 'test user test user', '', 'test user', '', 'test user', 'test user', 'test user', 'Antigua and Barbuda', '1', 'Bitcoin Payment', '', '', '', '', now(), '1', 'BTC', '0.20208800')

[TEP STOP]


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 07, 2012, 05:08:31 PM
I think that's a bug in osCommerce as delivery_date is nowhere in the Bitcoin module. Are you using version 2.3.1? If you're using 3.0, you should probably remove that and start again with 2.3.1 since the osCommerce website says that version is not as complete. And here it appears you've found a bug in it.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 07, 2012, 05:40:27 PM
Nah, I'm using 2.3.1. But I found out the module "Coupon codes" was causing the problem, so never mind I guess.

EDIT:

About security.. What would you recommend regarding wallet encryption? I guess the python script's automatic forwarding of payments wouldn't work if the wallet is encrypted, but then again an unencrypted wallet for commercial purposes seems awfully insecure.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 07, 2012, 10:54:38 PM
So I got a couple of things to say..

I enabled encryption on my wallet, and now I can't figure out how to remove it. So I tried editing the python script to decrypt the wallet before doing stuff. But I don't have any python experience, does this look alright?

I added a var on settings.py (BTCPASS, with the password for the wallet in a string)
I added on daemon on monitor.py:

Code:
        def walletpassphrase(self):
                command = self.bitcoind_command[:]
                command.extend(['walletpassphrase',BTCPASS,str(20)])
                p = Popen(command, stdout=PIPE)
                io = p.communicate()[0]


        def walletlock(self):
                command = self.bitcoind_command[:]
                command.extend(['walletlock'])
                p = Popen(command, stdout=PIPE)
                io = p.communicate()[0]

And then I called the functions d.walletpassphrase() and d.walletlock() in the start and end of the while loop.

I don't get any errors, but it's not working either.

Problem 1: I ran two test purchases and nothing happened. The order shows as pending on osC. monitor.log says that none of the bitcoins have been paid in to the addresses, even though bitcoind getbalance says that they are indeed received. When I reach the min amount of transaction confirmations, nothing happens either.

Problem 2: The python script will randomly exit. Sometimes I just come back to the server and notice that the script is not running for no reason.

Problem 3: When I start the script, sometimes (maybe when it's waiting for payment), I get an "insufficient funds" error message.

Problem 4: I'd like to display prices as USD on my website, it's more convenient than BTC. But when I complete an order of 6 dollars when the currency is set to dollars, monitor.py expects 6 bitcoins instead.

Some of these problems are probably the fault of my messing around in the python file. If you could make a proper version with the changes I suggested, I would be very grateful.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 07, 2012, 11:28:17 PM
Thanks Grix for working so hard on this. I think we may have a better time squashing bugs if you create issues at at the github repo but we'll see what we can do here until then.

So I got a couple of things to say..

I enabled encryption on my wallet, and now I can't figure out how to remove it. So I tried editing the python script to decrypt the wallet before doing stuff. But I don't have any python experience, does this look alright?


I'll have to admit I have not attempted to do wallet encryption on bitcoind. Part of the monitor script is to send funds to an off-server address and I would encourage you to use that first. Your exposure then is just whatever has been received in the past hour or two.


I added a var on settings.py (BTCPASS, with the password for the wallet in a string)
I added on daemon on monitor.py:

Code:
        def walletpassphrase(self):
                command = self.bitcoind_command[:]
                command.extend(['walletpassphrase',BTCPASS,str(20)])
                p = Popen(command, stdout=PIPE)
                io = p.communicate()[0]


        def walletlock(self):
                command = self.bitcoind_command[:]
                command.extend(['walletlock'])
                p = Popen(command, stdout=PIPE)
                io = p.communicate()[0]

And then I called the functions d.walletpassphrase() and d.walletlock() in the start and end of the while loop.

I don't get any errors, but it's not working either.

Problem 1: I ran two test purchases and nothing happened. The order shows as pending on osC. monitor.log says that none of the bitcoins have been paid in to the addresses, even though bitcoind getbalance says that they are indeed received. When I reach the min amount of transaction confirmations, nothing happens either.

Is the orders_status_history table showing bitcoin addresses in the comments field? If you do a bitcoind getbalance on the account holding that address does it show funds received at that address? I wonder if the funds are being sent off before they are seen by the receiving part of the script.

Problem 2: The python script will randomly exit. Sometimes I just come back to the server and notice that the script is not running for no reason.


To be sure, error handling can be improved. To help troubleshoot I would suggest you install screen and run bitcoind in a screen session. Then when bitcoind quits an error message should appear in that screen session.


Problem 3: When I start the script, sometimes (maybe when it's waiting for payment), I get an "insufficient funds" error message.

This would make sense if the script was attempting to send out BTC that no longer exist.

Problem 4: I'd like to display prices as USD on my website, it's more convenient than BTC. But when I complete an order of 6 dollars when the currency is set to dollars, monitor.py expects 6 bitcoins instead.

Check out this addon http://addons.oscommerce.com/info/3333

If you set Bitcoin as your default currency, it will always display the amount in Bitcoins. If this data is present in the order_total table after you put in an order we should be able to pick that up. Regardless USD totals should never be expected in BTC so that would be a good bug to file.

Some of these problems are probably the fault of my messing around in the python file. If you could make a proper version with the changes I suggested, I would be very grateful.

Actually it is great that you're making changes and testing them. You might even want to fork the project on github and push commits to your forked repo. Once reviewed and tested, those commits could then be pulled into my branch via github's Pull Request feature.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 07, 2012, 11:31:36 PM
About security.. What would you recommend regarding wallet encryption? I guess the python script's automatic forwarding of payments wouldn't work if the wallet is encrypted, but then again an unencrypted wallet for commercial purposes seems awfully insecure.

Having this script work with wallet encryption is a nice-to-have. Let's get it tested without first.

With the part of the script that sends funds off-server, I think the risk is minimal. We also request a new address for every order so there's not much value to having stolen the keys at some time in the past.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 08, 2012, 12:06:52 PM
I just woke up today and saw that monitor.py suddenly had registered the payment I made yesterday. So I guess that's ok. However, it was only about 1 btc out of 6 btc because of the currency issue. Thanks for the addon link, that'll probably fix it.

About the encryption, I don't think it's possible to unencrypt the wallet.. If I just delete wallet.dat after unloading funds, will bitcoind just create a new one and everything will continue as normal?

I've never used github, so I don't know how to use it :)


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 08, 2012, 04:56:02 PM
I just woke up today and saw that monitor.py suddenly had registered the payment I made yesterday. So I guess that's ok. However, it was only about 1 btc out of 6 btc because of the currency issue. Thanks for the addon link, that'll probably fix it.

About the encryption, I don't think it's possible to unencrypt the wallet.. If I just delete wallet.dat after unloading funds, will bitcoind just create a new one and everything will continue as normal?

I've never used github, so I don't know how to use it :)
Bitcoind will create another wallet.dat if you delete that one. I would make double sure it shows zero balance and would probably keep a labeled copy of it somewhere just in case. They're small valuable files!

I have a store running now but have a few polishes to make on it before giving the link.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 08, 2012, 06:07:31 PM
I'm having more trouble, with addresses. My site does not provide the correct address when I check out, and it seems the "Display Price in Default Currency" addon just caused more problems..

I just cleared my orders database, made a new wallet and restarted monitor.py. Then  I made a test order. First of all, I had set the currency to USD to test out the addon, but at the checkout it said "Order total in BTC: 6 BTC" when the total was 6 USD. So that's not working properly.

I then made another order with BTC currency, and paid for it. The address I was given was "1GAeYv******".

Then I visited "order history" on my site. There, the payment address was completely different. It was "1CHkpay******". Monitor.log reports waiting for payment to the latter address, not the one I was given at checkout.

And there's more!

This is monitor.log:
Code:
2012-03-08 20:51:02,065 INFO Check for 1.211 BTC to be sent to 1QJJq*
2012-03-08 20:51:02,070 INFO Amount still needed: 1.211
2012-03-08 20:51:02,070 INFO Check for 6.00 BTC to be sent to 1QJJq*
2012-03-08 20:51:02,077 INFO Amount still needed: 6.00
2012-03-08 20:51:02,077 INFO Check for 1.211 BTC to be sent to 1CHkpa*
2012-03-08 20:51:02,084 INFO Amount still needed: 1.211
2012-03-08 20:51:02,084 INFO Check for 6.00 BTC to be sent to 1CHkpa*
2012-03-08 20:51:02,089 INFO Amount still needed: 6.00

I don't know where the 1QJJ payment request come from. But I do know that's an address of the last wallet I had, I remember the address. Somehow it's still there after clearing the orders table in the database. Are the more tables that the python script uses?

Also, as you can see, both addresses are waiting for both 1.211 BTC (which is correct), AND 6 BTC (which is the USD amount). I guess this is caused by the "Display Price in Default Currency", but I can't see how it would affect the bitcoin payment..


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 08, 2012, 07:08:07 PM
Oh yes, you'll need to delete those records from the orders_status_history table.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 08, 2012, 08:43:59 PM
Ok, everything seems to be working OK now, except for the problem about the wrong addresses. Do you have any idea what could be wrong? Have you tested the addon successfully yourself?

EDIT: Ok, I'll try to use github for bug reports and feature suggestions from now on.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 08, 2012, 09:19:51 PM
I'm not sure about the wrong addresses. You're saying that each new order shows one address on the order confirmation page but inserts another into the orders_status_history table(the one the python script checks)?

I have tested it on two machines now and it is working. I did modify the Display Addon in Default Currency addon so it always displayed in USD. I made the following changes at line 28 of /includes/modules/order_total/ot_total_defaultcurrency.php:

Code:
   
    #if ($order->info['currency'] != DEFAULT_CURRENCY){
    if ($order->info['currency'] != 'USD'){

    $this->output[] = array('title' => $this->title . ':',
                            #'text' => '<b>' . $currencies->format($order->info['total'], false, DEFAULT_CURRENCY, $order->info['currency_value']) . '</b>',
                            'text' => '<b>' . $currencies->format($order->info['total'], false, 'USD', $order->info['currency_value']) . '</b>',

and then in the languages file at /includes/languages/english/modules/order_total/ot_total_defaultcurrency.php:

Code:
#define('MODULE_ORDER_TOTAL_TOTAL_DEFAULTCURRENCY_TITLE', 'Equivalent total in ' . DEFAULT_CURRENCY);
#define('MODULE_ORDER_TOTAL_TOTAL_DEFAULTCURRENCY_DESCRIPTION', 'Display Additional Order Total in ' . DEFAULT_CURRENCY);
define('MODULE_ORDER_TOTAL_TOTAL_DEFAULTCURRENCY_TITLE', 'Equivalent total in USD');
define('MODULE_ORDER_TOTAL_TOTAL_DEFAULTCURRENCY_DESCRIPTION', 'Display Additional Order Total in USD');

I'm not sure if this addon with these changes should be included with the module but hopefully putting them here is helpful. I'm going to run through the procedure soon and update it so nobody else has to fiddle with tables like orders_status_history, etc.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on March 08, 2012, 09:28:45 PM
Thanks for the currency mod.

btw, check github, I've added a little pull request. I've not used github before though, so I don't know if I did it right or not.

I also created an issue about the addresses. I'll investigate more  ;)


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 08, 2012, 11:37:36 PM
The issue of the wrong addresses has been fixed. This happened when payment was made before confirmation due the way bitcoind hands out addresses per account. If an address is used it thinks you should use a new one. So to get around this, the module creates a new account and address for each visit to the confirmation page.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 09, 2012, 12:31:13 AM
I have setup a test store at http://Owneo.com

Note there is no SSL but on the upside, you only have to fill in an email, country, and password to register for checkout.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 12, 2012, 02:10:10 AM
Thanks to Grix for helping me test the module. I've just committed some changes that should make it somewhat usable now.

The payment process has now been changed so a Bitcoin address is only generated and shown (along with a the BTC payment amount) once an order is confirmed.

You are free to put in an order to see how it works at http://www.owneo.com.

You'll have to create an account with an email address to see the entire process but don't worry, you don't have to pay. (maybe we should expire unpaid orders...)


Title: Re: osCommerce Bitcoin Payment Module
Post by: HostFat on March 12, 2012, 04:30:23 PM
I don't know if you are the right person, but do you think that it's difficult to make this mod (http://invisionmodding.com/topic/42273-e32-ibeconomy-points-system/) compatible with Bitcoin as you did with this osCommerce module?
( this is just the first mod that I found, I don't know if it is the better one ... )


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 12, 2012, 04:49:12 PM
I don't know if you are the right person, but do you think that it's difficult to make this mod (http://invisionmodding.com/topic/42273-e32-ibeconomy-points-system/) compatible with Bitcoin as you did with this osCommerce module?
( this is just the first mod that I found, I don't know if it is the better one ... )

I think you're best bet is to start a new thread (maybe a bounty) and explain what this is, where it's used, and why it would be good for Bitcoin.


Title: Re: osCommerce Bitcoin Payment Module
Post by: sergio on March 15, 2012, 11:20:04 AM
Weex, thanks for the oscommerce bitcoin payment module, I have been doing some testing for a couple of days and it works great, however I would like to point a few details.

The python script seems to run fine with version simplejson-2.1.0, however there were problems when using version 2.4.

The other thing I noticed, is with all the bitcoind daemons I tried, at times there is a delay is responding caused by the bitcoin daemon, it is something that happens once a while, and it does not mean that the bitdoind daemon has died, on the other hand there were a few bitcoin daemons that did crash, and it would also kill the python script monitor.py, after some testing I decided to run a bitcoin daemon that was stable but the random delay was there and  does not occur frequently.

Maybe it would be a good idea in the part of the script when it checks to see if the daemon has died, not to assume that it has died if it does not respond immediately, but have a second check lets say a minute latter, and if both checks fail then assume the daemon has died and then restart the bitcoin daemon, or somehow have the python script  wait a little longer for bitcoind to respond in the part of the code where it kills the daemon and then restarts it, will the goal of avoid killing it if it is running fine with an occasional slowdown.

In the meantime what I did to get around this problem is to use an stable bitcoin daemon like 0.502, and comment out the part of the code that tries to restart the daemon, and once a while I will get an error message from monitor.py "error: no response from server" when bitcoind does  not reply on time, but the scripts and bitcoind keeps running fine after a small delay and there is no need to restart the daemon.

The other thing I noticed is that it gets the prices from mtgox, and it does a dollar convertion to bitcoins, so it automatically sets the prices in bitcoins and I think this is a good idea for now, however as bitcoin grows it will become someday a currency of its own and in the near future it will be best to set prices directly in bitcoins not tied to the dollar, but for now I think it would be nice  to have a check box next to the price for the admin, so he/she can decide if the price is dollars converted to bitcoins, or bitcoins by themselves not tied to any other currency.

Weex your script is great, I tested a few other ones, and what I liked about yours is that in monitors when payment is received, and automatically updates the status of the order, most other scripts generate the bitcoin address  for the payment, but it is a manual job to verify that the payment has been  made, this scripts automates everything and it is very reliable.

Thanks for the payment modules, it is very good.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 15, 2012, 05:31:11 PM
Sergio,

And thank you very much for implementing it and providing your comments. I have not tried with more unstable versions of bitcoind but your point is well taken. If you would like to submit a patch I will test it and merge it. You can just pm me your new monitor.py file if you want.

About the price options, I have thought about that and yes a checkbox is a good way to do it. I would need to look into this further but if you have any more ideas on it, I'm all ears.

Thanks,

weex


Title: Re: osCommerce Bitcoin Payment Module
Post by: zer0 on March 17, 2012, 11:33:45 PM
I like how it displays both regular prices and the bitcoin price, as 90% of customers I've run into have no clue what bitcoin is. This saves many support emails "How much is 3.5BTC???"


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 21, 2012, 08:50:23 AM
Glad to hear that. Ease of use for the customer and site owner are primary goals. Any suggestions anyone has to improve this project are greatly appreciated.


Title: Re: osCommerce Bitcoin Payment Module
Post by: finway on March 21, 2012, 08:52:43 AM
This is great!

As good as django-bitcoin  !    https://github.com/kangasbros/django-bitcoin


Title: Re: osCommerce Bitcoin Payment Module
Post by: Andrew Vorobyov on March 21, 2012, 01:26:43 PM
http://www.google.com/trends/?q=magento,osCommerce,opencart,+prestashop,+ubercart,+zen+cart


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on March 21, 2012, 04:17:38 PM
http://www.google.com/trends/?q=magento,osCommerce,opencart,+prestashop,+ubercart,+zen+cart
Well said. I looked at https://github.com/ticean/magento-bitcoin and it appears to have it all. Didn't get a chance to test it though.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Andrew Vorobyov on March 21, 2012, 04:22:46 PM
I already donated to this guy.. Show him some Bitcoin love


Title: Re: osCommerce Bitcoin Payment Module
Post by: sergio on April 01, 2012, 05:37:18 AM
weex, the bitcoin module is working as far as the sale goes, but it has a problem, let me describe the problem, and if you know how to fix it please let me know.

Let say I am selling calling cards, after a customer does the checkout the item should be placed on a hold status, and allow payment to be received within certain amount of hours, if payment is received then the item should be removed from inventory if inventory is 1,  if payment is not received the item should be made available and the hold remove.

The current problem is that inventory is not being  updated, not only that but once a customer does the checkout, the item is always available for sale.

The way it is  working now, it is fine for items that have infinite inventory, like selling a picture, photograph, a howto, a pdf, but for items that can only be sold a single not having the inventory being updated it is a problem.

Please let me know where I should look to try to fix this.

thanks



Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on April 01, 2012, 07:20:56 AM
The current problem is that inventory is not being  updated, not only that but once a customer does the checkout, the item is always available for sale.

The way it is  working now, it is fine for items that have infinite inventory, like selling a picture, photograph, a howto, a pdf, but for items that can only be sold a single not having the inventory being updated it is a problem.

Please let me know where I should look to try to fix this.

I looked at the code and I see all the updating of stock that is done in the other payment modules is missing from this module.

For example look at all the code that includes the word stock, $stock_check, $stock_left etc in includes/modules/payment/bitcoin.php. I

t is probably going to work to transplant this code from the paypal module to this one but since our payment order is a little different, this stuff will want to be executed as part of the ext/modules/payment/bitcoin/bpn.php script.

Now in terms of timing it might be a little tricky for me but hopefully someone else can take this if I don't get to it within the next week or so.

BTW, I tested your store and it qualifies for the bounty so to claim it, post the url in the bounty thread along with your address.

-weex


Title: Re: osCommerce Bitcoin Payment Module
Post by: sergio on April 03, 2012, 08:22:45 AM
weex, let us know when you include the part of the code that updates the inventory, I tried doing it but was not simple.

it basically should work this way, someone buys a product, then that item is put on hold in other words not made available, when the item is fully paid the stock on the item is updated, but if the item is not paid within a certain amount of time, lets say 24 hours, then the item is made available again for purchase, it would also be a good idea to limit the amount of purchases to a given customer to prevent a possible denial of service attack where a customer makes many purchases but pays for none.

Once you have the code, I will be more than happy to test it out.

In regards to the bounty, I still have not received it, could you check if it was sent correctly.



Title: Re: osCommerce Bitcoin Payment Module
Post by: sergio on April 05, 2012, 04:43:38 AM
weex thanks for the bounty is has been received.

It regards the shoping cart module, if you implement updating the stock on items, let me know.
In the meantime I will try to do the same.

Thanks















Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on April 05, 2012, 04:55:11 AM
Thanks sergio, I have a lot on my plate as I've just launched coinDL but let me know if you'd like to talk design and I'll help as much as I can.


Title: Re: osCommerce Bitcoin Payment Module
Post by: sergio on April 10, 2012, 10:09:57 PM
weex, I will try to update the code to handle the stock of  items, first I am going to do it the simple way, that is once the bitcoins have been paid, I will update the code in bpn.php  to subtract  from  the items in stock the items sold, that should be fairly easy, but a better approach to the problem would be to reduce the item from stock once the bitcoin address for payment is generated, and if the payment is not made within a certain amount of hours put the item back in stock since the purchase was never completed since the payment was not sent.

The table orders_products has the stock information, since I will be working on this part time it will take me a few weeks to have something working.

I post back once I have it working.


Title: Re: osCommerce Bitcoin Payment Module
Post by: weex on April 11, 2012, 04:59:18 AM
Good to hear sergio, that sounds like a reasonable plan. For the improved version, including a query or two in the monitor.py script should allow unpurchased stock to be released.


Title: Re: osCommerce Bitcoin Payment Module
Post by: Grix on April 14, 2012, 05:49:09 PM
Finally I am ready (sort of) to open my little shop. I sell handheld lasers and accessories. Thanks to weex for this wonderful payment module!

http://BitLasers.com (http://BitLasers.com)