Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
bitcoin payment management for django
Python
Branch: master
Pull request Compare This branch is 5 commits ahead, 144 commits behind kangasbros:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
django_litecoin
.gitignore
LICENSE
README.markdown
setup.py

README.markdown

THIS CODE IS BROKEN, DO NOT USE IT, IT IS IN EXTREMELY EARLY DEVELOPMENT

INSTALLATION

To install, just add the app to your settings.py INSTALLED_APPS like:

INSTALLED_APPS = [
    ...
    'django_litecoin',
    ...
]

Also you have to run a local litecoind instance, and specify connection string in settings.

LITECOIND_CONNECTION_STRING = "http://litecoinuser:password@localhost:8332"

USAGE

Tutorial

There is a small tutorial about how to use django-litecoin to create your own instawallet: http://blog.kangasbros.fi/?p=85

Wallet websites, escrow services using the "Wallet"-model

You can use the Wallet class to do different litecoin-moving applications. Typical example would be a marketplace-style site, where there are multiple sellers and buyer. Or job freelance site, where escrow is needed. Or even an exchange could be done with this abstraction (a little extra classes would be needed however).

Note that while you move litecoins between Wallet-objects, only litecoin transactions needed are incoming and outgoing transactions. Transactions between the system "Wallet"-objects don't generate "real" litecoin transactions. Every transaction (except incoming transactions) is logged to WalletTransaction object to ease accounting.

This also means that outgoing litecoin transactions are "mixed".

from django_litecoin import Wallet, currency

class Profile(models.Model):
    wallet = ForeignKey(Wallet)
    outgoing_litecoin_address = CharField()

class Escrow(models.Model):
    wallet = ForeignKey(Wallet)
    buyer_happy = BooleanField(default=False)

buyer=Profile.objects.create()
seller=Profile.objects.create()

purchase=Escrow.objects.create()

AMOUNT_USD="9.99"

m=currency.Money(AMOUNT_USD, "USD")
ltc_amount=currency.exchange(m, "LTC")

print "Send "+str(ltc_amount)+" LTC to address "+buyer.wallet.receiving_address()

sleep(5000) # wait for transaction

if p1.wallet.total_balance()>=ltc_amount:
    p1.send_to_wallet(purchase, ltc_amount)

    sleep(1000) # wait for product/service delivery

    if purchase.buyer_happy:
        purchase.wallet.send_to_wallet(seller.wallet)
        seller.wallet.send_to_address(seller.outgoing_litecoin_address, seller.wallet.total_balance())
    else:
        print "WHY U NO HAPPY"
        #return litecoins to buyer, 50/50 split or something

Templatetags

To display transaction history and simple wallet tagline in your views, use the following templatetags:

{% load currency_conversions %}
<!-- display balance tagline, estimate in USD and received/sent -->
{% wallet_tagline profile.litecoin_wallet %}
<!-- display list of transactions as a table -->
{% wallet_history profile.litecoin_wallet %} 

Easy way to convert currencies from each other: ltc2usd, usd2ltc, eur2ltc, ltc2eur

Also currency2ltc, ltc2currency for any currencies on litecoincharts.com

{% load currency_conversions %}
Hi, for the pizza: send me {{litecoin_amount}}LTC (about {{ litecoin_amount|ltc2usd }}USD).

Display QR code of the litecoin payment using google charts API.

{% load currency_conversions %}
Pay the following payment with your android litecoin wallet:
{% litecoin_payment_qr wallet.receiving_address litecoin_amount %}.

The same but display also description and an estimate in EUR:
{% litecoin_payment_qr wallet.receiving_address litecoin_amount "One beer" "EUR" %}.

Transaction notifications

To enable litecoin transaction notifications, set the following flag in your settings.py

LITECOIN_TRANSACTION_SIGNALING = True

After that, you need to setup a cron job to run each minute, something like the following:

* * * * * (cd $APP_PATH && python manage.py python manage.py CheckTransactions >> $APP_PATH/logs/email_sends.log 2>&1)

After that you can define your balance_changed and balance_changed_confirmed signals:

from django_litecoin.models import balance_changed, balance_changed_confirmed
from django.dispatch import receiver


@receiver(balance_changed)
def balance_changed_handler(sender, **kwargs):
    pass
    # try:
    # print "balance changed", sender.id, kwargs["changed"], sender.total_balance()


@receiver(balance_changed_confirmed)
def balance_changed_confirmed_handler(sender, **kwargs):
    pass

obsolete

There is older Payment -class, which can be used for simpler things (direct payments etc):

from django_litecoin import Payment, new_litecoin_payment, litecoinprice
from decimal import Decimal

bp=new_litecoin_payment(Decimal("0.32"))
bp2=new_litecoin_payment(Decimal("0.99")/litecoinprice("USD")) # convert from USD

if bp.is_paid(minconf=5):
    # send 5% of payment to litecoin address someaddress
    bp.withdraw_proportion(someaddress, Decimal("5.0"))
    if bp.is_paid() and bp2.is_paid():
        # send from both bp and bp2 (95% from both, only single litecoin transaction)
        Payment.withdraw_all(someaddress2,  {bp, bp2})

USED AT

Currently django-litecoin is used at production in bountychest.com

More to come!

If you have a site using django-litecoin, drop me an email and I will link to it here.

NOTE

I don't have time to answer to email support requests, sorry guys.

Something went wrong with that request. Please try again.