Pages:
Author

Topic: Zen Cart Bitcoin Payment Module (Read 8090 times)

newbie
Activity: 51
Merit: 0
July 24, 2011, 03:01:20 AM
#27
small donation sent, thanks for your contribution to the bitcoin community.

are there any problems with multiple zen cart installations sharing the same bitcoind?
It seems to work at first glance, both instances show all transactions from both sites in the Bitcoin Payment area, but  orders only get highlighted/linked in the correct respective site it was ordered from so that's good.
newbie
Activity: 51
Merit: 0
July 02, 2011, 11:52:55 PM
#26
Hey,
I haven't forgotten about my donation pledge, I'm just waiting for some customers to spend bitcoin in my store.

I do have a couple of comments on issues that have popped up for me with the zen cart bitcoin module -


lets say the BTC/USD exchange rate today was $17, and I have an item in my store that costs $17.  I set the price in the zen cart backend in USD and the default currency to USD, but then in the template files I switch that to BTC as you have suggested so my prices  show up as BTC on the store. 

Now lets say someone orders that item, it will correctly tell them the price is 1 BTC and give the payment address.  But when I go to the zen cart admin area,  Extra->Bitcoin Payment Center it shows
Order 1 |  Due 17 BTC | Received 1 BTC

in other words, it puts the USD price in as what is Due, and even after they paid in full (in BTC) it shows Pending because the module thinks they haven't paid in full due to being confused about the currency.



Secondly, it would be neat if it automatically cancelled orders after X number of hours with no payment.  I have been getting people who have never heard of bitcoins and/or don't have any, but go through the whole checkout process and then just never pay.  I guess they just want to see what a bitcoin checkout looks like, and had no intentions of paying in the first place.  Or, they think I'm listing a $17 item for $1 (ignoring the bitcoin symbol listed next to the price I guess) so they think they are getting some amazing deal and then when they go to check out and there is no place to put a credit card or paypal info (just lists a bitcoin address) they are like 'WTF is a Bitcoin?' and leave and never return.   

So I should try and mod the zen cart files so it gives some kind of warning like 'don't checkout if you don't already have bitcoins and are ready to spend them', but it would also be cool if the system automatically canceled orders after say 24 hours w/o payment.
newbie
Activity: 51
Merit: 0
June 09, 2011, 08:57:25 PM
#25
Yo
I'ma let you finish...
http://www.polyvore.com/cgi/img-thing?.out=jpg&size=l&tid=11793371

but what I would consider doing is setting USD as default. Pricing things in terms of USD, updating just the BTC currency rate table at cron.  Then in your template header, set the $_SESSION['currency'] to bitcoin so it is the default.  This way you don't have to continually modify your script every time you add a new product.


http://farm5.static.flickr.com/4133/4981138976_b541eeca56.jpg


nice, thanks again.  soon as I get some bitcoin I owe you a tip
newbie
Activity: 31
Merit: 0
June 09, 2011, 07:27:54 PM
#24
Yo
I'ma let you finish...
http://www.polyvore.com/cgi/img-thing?.out=jpg&size=l&tid=11793371

but what I would consider doing is setting USD as default. Pricing things in terms of USD, updating just the BTC currency rate table at cron.  Then in your template header, set the $_SESSION['currency'] to bitcoin so it is the default.  This way you don't have to continually modify your script every time you add a new product.
newbie
Activity: 51
Merit: 0
June 09, 2011, 06:00:40 PM
#23
thanks for the code!   I think what I could do is use this to get the exchange rate, and then just divide it by my static USD price, and update the prices in bitcoin terms via mysql
newbie
Activity: 31
Merit: 0
June 09, 2011, 05:52:50 PM
#22
As I understand it, zencart requires a fixed point of reference and then you put in the currency conversion for all other currencies.  There may be a way to hack around this, but what I think you are suggesting is in zencart when you create or edit a product, you want a list of currencies and how much to charge for the item for each currency regardless of conversion equality?

Otherwise, I think you may just be mixed up, if BTC is set as the default, and you set a product at that BTC value, then you would be adjusting the USD equivalent with the rate update script, and vice versa for USD is the default (frame of reference).

Anywho, as promised, here is a short little script to take the mtgox ticker and break it down into an array.  I've included a curl function to make it even easier for you.

Code:


$data 
curl_grab_page('https://mtgox.com/code/data/ticker.php');

$data str_replace('{"ticker":','',$data);
$data str_replace('}}','}',$data);

$mtgox json_decode($data,true);

var_dump($mtgox);  //This is your mtgox data, use this to perform some math and update the currency table

function 
curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
    if(
$login == 'true') {
        
$fp fopen("cookie.txt""w");
        
fclose($fp);
    }
    
$ch curl_init();
    
curl_setopt($chCURLOPT_COOKIEJAR"cookie.txt");
    
curl_setopt($chCURLOPT_COOKIEFILE"cookie.txt");
    
curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    
curl_setopt($chCURLOPT_TIMEOUT40);
    
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    if (
$proxystatus == 'true') {
        
curl_setopt($chCURLOPT_HTTPPROXYTUNNELTRUE);
        
curl_setopt($chCURLOPT_PROXY$proxy);
    }
    
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);

    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_REFERER$ref_url);

    
curl_setopt($chCURLOPT_HEADERFALSE);
    
curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
    
curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    
curl_setopt($chCURLOPT_POSTTRUE);
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    
ob_start();
    
$output curl_exec ($ch);
    
ob_end_clean();
    
curl_close ($ch);
    unset(
$ch);
    return  
$output;// execute the curl command    
}



edit: realized i left a header() in there.  removed.
newbie
Activity: 51
Merit: 0
June 09, 2011, 05:26:04 PM
#21
I just realized that as I have it setup, with products in zen cart priced in bitcoin and bitcoin shown as the prices on the storefront, I wouldn't be able to set a static price in, say, US dollars - I'd still have to constantly adjust the prices in bitcoin with the exchange rate.

is it possible to set a fixed price for zen cart products in one currency, but not actually use that currency as the default?
newbie
Activity: 31
Merit: 0
June 09, 2011, 09:25:38 AM
#20
Valhalla1,

I have a script at home that pulls down mtgox ticker data and puts it into php variables.  Keep in mind that you will probably want some kind of average to be taken rather than the most current price.

I will post the snippet later today.

Kind Regards
newbie
Activity: 51
Merit: 0
June 09, 2011, 02:17:07 AM
#19
I really want to get a semi-automated exchange rate setup for my zen cart store, especially with this recent bitcoin price volatility I'd like to run it at least once an hour.

I found a Zen Cart currency updater module here.

Run by cron, it fetches this XML file from the European Central Bank to get the current exchange rates, and repopulates the zen cart mysql database with the latest exchange rates.

Problem is of course, bitcoin exchange rates aren't listed on by the Euro Central Bank.  

I see mtgox has this feed - https://mtgox.com/code/data/ticker.php

here's the code of the zen cart currency updater module.  now if I can figure out how to modify it to uses the mtgox feed...

Code:
#!/usr/bin/php

/**
 * Automatic Currency Update v4.0
 * Originally by Richard Fink (masterblaster)  based on Zen Cart manual currency update
 * updated by Kuroi to include Zen Cart's currency uplift ratio
 * further updated by Kuroi to use European Central Bank reference rates  (adapted from ECB-supplied code)
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * license: GNU Public License V2.0
 *
 **/

# Set this to the physical path of your installation.
# Make sure to include the trailing "/"
define('PATH_TO_STORE_ROOT','');

// Get Zen Cart configuration data
require_once(PATH_TO_STORE_ROOT 'includes/configure.php');
require_once(
PATH_TO_STORE_ROOT 'includes/database_tables.php');

if (! 
$mysqli=new mysqli(DB_SERVERDB_SERVER_USERNAMEDB_SERVER_PASSWORDDB_DATABASE))
    die(
"Can't connect to DB");

# Get default currency.
$row=$mysqli->query("select configuration_value from " TABLE_CONFIGURATION .
                    
" WHERE configuration_key='DEFAULT_CURRENCY' LIMIT 1 ")->fetch_row();
define('DEFAULT_CURRENCY'$row[0]);

#Get currency conversion ratio.
$row=$mysqli->query("select configuration_value from " TABLE_CONFIGURATION .
                    
" WHERE configuration_key='CURRENCY_UPLIFT_RATIO' LIMIT 1 ")->fetch_row();
define('CURRENCY_UPLIFT_RATIO'$row[0]);

# Create new SimpleXML element from the Euro zone file
# If your PHP configuration does not have allow_url_fopen, you may need to
# write a script to pick it up using wget:
# wget -O eurofxref-daily.xml www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
# and then uncomment/comment these next two lines:
#$xml = new SimpleXMLElement(file_get_contents("eurofxref-daily.xml"));
$xml= new SimpleXMLElement(file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));

# extract your preferred currency's exchange rate.
$nzd $xml->xpath("//*[@currency='".DEFAULT_CURRENCY."']");
$base = (float)$nzd[0]['rate'];

# If our default currency is the Euro, it won't be in the XML,
# so set the base exchange rate to 1
if (DEFAULT_CURRENCY == 'EUR')
    
$base=(float)1;

# Get array of currency data from the XML file.
$currencies=$xml->xpath("//*[@currency]");

# Use a prepared query for slightly faster execution.
# Note this is an update, not and insert or replace.
# This statement assumes that your currency codes are the same
# as the international standard ones.
$stmt=$mysqli->prepare("update ".TABLE_CURRENCIES" set value=?,last_updated=now() where code=?");

# Iterate over array, pulling out currency code and rate.
# Convert into your preferred currency.
# Pump it into the database.
foreach ($currencies as $curr) {
    
$cc  $curr[0]['currency'];
    
$rr  = (float)$curr[0]['rate'] * CURRENCY_UPLIFT_RATIO;
    
$new $rr/$base;
# But don't uplift your default currency!
    
if ( $cc != DEFAULT_CURRENCY ) {
        
$stmt->bind_param("ds",$new,$cc);
        
$stmt->execute();
    }
}

# Feed is based on the Euro, which is not included in the feed,
# therefore we need to update it manually,
# unless of course our preferred currency is the Euro
$cc='EUR';
$rr=1/$base*CURRENCY_UPLIFT_RATIO;
if (
DEFAULT_CURRENCY != $cc) {
    
$stmt->bind_param("ds",$rr,$cc);
    
$stmt->execute();
}

$mysqli->close();

?>









newbie
Activity: 51
Merit: 0
June 08, 2011, 04:05:12 AM
#18
automatic currency updates is something that has been discussed for a while.  It really wouldnt be too difficult to do, I could write up a cron job that will run every X minutes/hours to average the mtgox USD rate and update the zencart rate.

I have to finish a few other projects I've been working on in my free time before I can write that script though.


playing with it more and learning as I go, I was able to manually add Bitcoin as a currency in the zen cart 'currencies' table, and set it as the default currency, and added its symbol as 'Ƀ'

the exchange rate is set the the database as well.  I could just write a script which gets the mtgox exchange rate every 1-5 mins and run a sql command to update the exchange rate.  Is this right?
newbie
Activity: 51
Merit: 0
June 06, 2011, 02:17:57 PM
#17
I posted on zen cart forum about how to not reduce the inventory when payment status is pending, and they are indicating its not possible, but I could try and code it myself.  Unfortunately I'm not up to that skill level yet, but perhaps some day. 

I'll just have to stay on top of things and monitor payment status and BTC/USD exchange rates and keep everything up to date, at least until I build up some bitcoins and contribute some kind of bounty/donation for a skilled programmer to do it. 

thanks again
newbie
Activity: 31
Merit: 0
June 06, 2011, 01:38:52 PM
#16
automatic currency updates is something that has been discussed for a while.  It really wouldnt be too difficult to do, I could write up a cron job that will run every X minutes/hours to average the mtgox USD rate and update the zencart rate.

I have to finish a few other projects I've been working on in my free time before I can write that script though.
newbie
Activity: 51
Merit: 0
June 06, 2011, 01:02:08 PM
#15
thanks for the reply.  Indeed I was testing all from 1 session and 1 fake customer/email address, thats why I was only getting bitcoin payment 1 address, thanks for that information. Obviously I didn't test too thoroughly, lol. Glad to know it does indeed generate new addresses.  I'll check into fixing my zencart settings so it doesn't nuke my inventory numbers on pending payments.

also I had the bitcoin_extras_dhtml.php in /[zencart]/boxes/extra_boxes  but I just copied it to /[zencart]/[admindir]/boxes/extra_boxes and now I have the bitcoin.php link, sweet.


I see this site http://www.bitcoinmart.com    uses Zen Cart and bitcoin and lists prices in ' ฿' so I now see it is possible.  I'm guessing they modified some core zencart template file, I just don't know which one.. I'm totally new to zencart.  Maybe I'll email them and see if they will enlighten me.


One more question - how possible would it be to have prices automatically change with the bitcoin exchange rate?  For now as long as the price doesn't move too violently I can just update the price manually daily or whatever, especially since I will be started with only a handful of products.  But thinking long term, it would be handy to enter my price in some fiat currency like dollars and it automatically lists them in the equivalent bitcoin price, fluctuating with the exchange rate.
newbie
Activity: 31
Merit: 0
June 06, 2011, 10:47:51 AM
#14
Hi Valhalla1,

Regarding the addresses, from this line you can see that it generates a new account and address for each transaction:
$address = $bitcoin->getaccountaddress($order->customer['email_address'].'-'.session_id());

So the customers email address- session_id are the unique identifiers for the account.  By this method it creates a unique payment address for each session, as a typical user would make one checkout per session.  You are experiencing the same payment address over and over as you are testing with the same session.  This can be modified in a future release if you would like.

Regarding the link, do you have this file uploaded? / includes / boxes / extra_boxes / bitcoin_extras_dhtml.php

If so, it should automagically create the link, let me know otherwise.

The currency aspect is kind of decoupled from the payment gateway.  So this question may be a bit outside my area of expertise.  I will look further into it and let you know of any updates.

As for the repeated ordering, it leaves the payment state as Pending, I think there may be a setting in zencart to not deduct from quantity dependant on the order status.  Currently the module requires manual confirmation of the funds being deposited into the account.  There are some helper links at the admin/bitcoin.php table.
newbie
Activity: 51
Merit: 0
June 06, 2011, 02:43:43 AM
#13
thanks for this module.  I am trying to setup a web store selling a product for bitcoins.   I have not had luck yet with the wordpress-e-commerce plugin, or the drupal/ubercart module, so now I turned to this ZenCart module.

I have setup a testbed and installed ZenCart and this Bitcoin Payment module, and have a few questions.

Does it automatically check for payment? What happens if someone orders and never pays?  From my testing, it appears that someone can just order over and over again and never pay and drain your store of apparent in-stock inventory (denial of service attack)

Also, it always gives the same bitcoin address for payment.  I assume this is because it is connecting to my bitcoind and I only have 1 address.  Is there any way to make it generate a new payment address for each sale?  I am not even sure why this is done, but this is how the wordpress and drupal modules work I think.  Is this for anonymity and/or security concerns?

Also in the installation text, it says there should be a link under Admin-> Extras to 'bitcoin.php' to view  bitcoin transactions.  This link wasn't present for me, but I could manually type in /[myadmindir]/bitcoin.php to access it.  Minor gripe.

Finally, is there a way to make the prices show in ฿, Ƀ,  Ⓑ, β, ⓑ, or BTC?    As it is setup by default, I have bitcoin as the only accepted payment form but the prices are all listed by ZenCart in $'s.   So my product costs BTC 3 but it looks like it costs $3

Thanks for any help, hope to be serving the bitcoin community with more products to spend bitcoins on soon.
hero member
Activity: 504
Merit: 502
May 22, 2011, 06:48:26 PM
#12
Nice cart addon.

In its current state is there no way to just support mybitcoin wallets via their SCI implementation ?
newbie
Activity: 31
Merit: 0
May 14, 2011, 11:29:33 AM
#11
Hi Neil,

I foresaw that as a problem people would encounter.  I am currently building a platform for hosted bitcoind instance for end users.  This way you don't need to keep you home computer on all the time and will be able to connect to my service which will offer isolated bitcoind instances and wallets, unlike mybitcoin....  It will be a hosting service similar to a hosted website service (if that clarifies things for you).

I will be looking for beta testers very soon.  If you are interested in beta testing, PM me with your website and email and we can take it from there.

Best Regards,
face
member
Activity: 130
Merit: 10
May 14, 2011, 07:27:10 AM
#10
Hi

I'm really excited about this, but having problems understanding how to configure the rpc info in this module. Do I have to run this locally on my own computer (which isn't running all the time), our site is hosted by someone else. Is there some more info on how to set this up etc.

Sorry for the dumb question
Thanks
Neil
newbie
Activity: 5
Merit: 0
May 10, 2011, 02:03:05 AM
#9
Ah, will have to look into bitcoind rpc server bit lol, us damn noobs!!!

Thanks for your reply.
newbie
Activity: 31
Merit: 0
May 09, 2011, 09:44:23 PM
#8
Please pull a fresh copy from github.  I have added more verbose error messages for when the server cannot be reached.
Pages:
Jump to: