diff --git a/items/forms.py b/items/forms.py index 12b02aa..653142d 100644 --- a/items/forms.py +++ b/items/forms.py @@ -13,7 +13,7 @@ class CreateItemForm(forms.ModelForm): help_texts = { 'name': 'Use a succinct name for your item. Don\'t be spammy or obscene.', 'description': 'Describe the condition of the item and any important information. Try to refrain from sharing personally identifiable information like phone numbers or social media links.', - 'whereabouts': 'A simple pointer to your general region - a nearby ZIP code or capital city would be perfect.', + 'whereabouts': 'A simple pointer to your general region - a nearby capital city and your state would be perfect.', 'ask_price_xmr': 'How many moneroj do you want for your item?', 'payout_address': 'A Monero wallet address where funds will be sent after sale is confirmed.', } diff --git a/sales/migrations/0004_auto_20200113_2127.py b/sales/migrations/0004_auto_20200113_2127.py new file mode 100644 index 0000000..c97351d --- /dev/null +++ b/sales/migrations/0004_auto_20200113_2127.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.8 on 2020-01-13 21:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sales', '0003_itemsale_sale_cancelled'), + ] + + operations = [ + migrations.AddField( + model_name='itemsale', + name='network_fee_xmr', + field=models.FloatField(default=0.0), + ), + migrations.AddField( + model_name='itemsale', + name='seller_payout_transaction', + field=models.CharField(blank=True, max_length=150), + ), + ] diff --git a/sales/models.py b/sales/models.py index 0ac88a8..55b3d02 100644 --- a/sales/models.py +++ b/sales/models.py @@ -12,6 +12,8 @@ class ItemSale(models.Model): escrow_account_index = models.IntegerField() agreed_price_xmr = models.FloatField() platform_fee_xmr = models.FloatField() + network_fee_xmr = models.FloatField(default=0.0) + seller_payout_transaction = models.CharField(max_length=150, blank=True) expected_payment_xmr = models.FloatField() received_payment_xmr = models.FloatField(default=0.0) escrow_period_days = models.PositiveSmallIntegerField(default=settings.ESCROW_PERIOD_DAYS) diff --git a/sales/tasks.py b/sales/tasks.py index 59866c2..1966f9a 100644 --- a/sales/tasks.py +++ b/sales/tasks.py @@ -122,7 +122,7 @@ def poll_for_buyer_escrow_payments(): sale.save() -@periodic_task(crontab(minute='*/5')) +@periodic_task(crontab(minute='*')) def pay_sellers_on_sold_items(): aw = AuctionWallet() if aw.connected is False: @@ -134,12 +134,22 @@ def pay_sellers_on_sold_items(): # Take platform fees from the sale - the 50:50 split between buyer/seller sale_total = sale.agreed_price_xmr - sale.platform_fee_xmr sale_account = aw.wallet.accounts[sale.escrow_account_index] - logger.info(f'[INFO] Sending {sale_total} XMR from wallet account #{sale.escrow_account_index} to item owner\'s payout address for sale #{sale.id}.') - if sale_account.balances()[1] > Decimal(sale.agreed_price_xmr): + + if sale_account.balances()[1] >= Decimal(sale.agreed_price_xmr): try: - sale_account.transfer( - sale.item.payout_address, sale_total + # Construct a transaction so we can get current fee and subtract from the total + _tx = sale_account.transfer( + sale.item.payout_address, Decimal(.01), relay=False ) + new_total = sale_total - float(_tx[0].fee) + + logger.info(f'[INFO] Sending {new_total} XMR from wallet account #{sale.escrow_account_index} to item owner\'s payout address for sale #{sale.id}.') + # Make the transaction with network fee removed + tx = sale_account.transfer( + sale.item.payout_address, new_total, relay=True + ) + sale.network_fee_xmr = _tx[0].fee + sale.seller_payout_transaction = tx[0] sale.seller_paid = True sale.escrow_complete = True sale.save() @@ -175,9 +185,13 @@ def pay_platform_on_sold_items(): sale_account = aw.wallet.accounts[sale.escrow_account_index] bal = sale_account.balances()[1] if bal >= 0: - logger.info(f'[INFO] Getting platform fees of {bal} XMR') try: - sale_account.sweep_all(aof) + if settings.PLATFORM_FEE_PERCENT > 0: + logger.info(f'[INFO] Getting platform fees of {bal} XMR') + sale_account.sweep_all(aof) + else: + logging.info('No platform fees are set - proceeding without taking fees.') + sale.platform_paid = True sale.sale_finalized = True sale.save() diff --git a/sales/views.py b/sales/views.py index 98f8c71..6bcaa9f 100644 --- a/sales/views.py +++ b/sales/views.py @@ -35,6 +35,9 @@ def get_sale(request, sale_id): address_qr = qrcode_make(qr_uri).save(_address_qr) total_seller_payout = sale.agreed_price_xmr - sale.platform_fee_xmr + if sale.network_fee_xmr: + total_seller_payout = total_seller_payout - sale.network_fee_xmr + context = { 'sale': sale, 'qrcode': b64encode(_address_qr.getvalue()).decode(), diff --git a/web/templates/sales/get_sale.html b/web/templates/sales/get_sale.html index 20d3822..7082608 100644 --- a/web/templates/sales/get_sale.html +++ b/web/templates/sales/get_sale.html @@ -116,11 +116,13 @@ {% elif sale.item_received %}

Hey {{ sale.item.owner.username }},

The buyer confirmed receipt of their shipment which means things worked out. It's time for you to get paid!

-

Your payout address provided during item creation will be paid the accepted bid amount out of the escrow wallet.

+

Your payout address provided during item creation will be paid the accepted bid amount out of the escrow wallet. Please note, transaction fees will come out of the payout total.

Accepted Bid (XMR): {{ sale.bid.bid_price_xmr }}

Platform Fee (XMR): {{ sale.platform_fee_xmr }}

+

Network Fee (XMR): {{ sale.network_fee_xmr }}

Total Payout (XMR): {{ total_seller_payout }}

Payout Address: {{ sale.item.payout_address }}

+

Payout Transaction ID: {{ sale.seller_payout_transaction }}


If you found the site useful and had a good experience, please consider donating to the developer address provided at the bottom of the page.

Thanks for using {{ site_meta.name }}!

diff --git a/web/templates/sales/notify/sale_completed/seller/body.txt b/web/templates/sales/notify/sale_completed/seller/body.txt index 5d59887..5a435e2 100644 --- a/web/templates/sales/notify/sale_completed/seller/body.txt +++ b/web/templates/sales/notify/sale_completed/seller/body.txt @@ -1,6 +1,6 @@ Congratulations {{ sale.item.owner }}, -The sale of your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has concluded. The agreed upon bid price has been transferred to the payout address provided when posting the item. +The sale of your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has concluded. The agreed upon bid price minus any network fees has been transferred to the payout address provided when posting the item. In a few more minutes post-processing will complete, the platform will receive it's fees, and the sale, item, and bids will all be removed from the system. If your fees were waived, please consider donating to the development fund. The address is at the bottom of the {{ site_name }} site pages.