diff --git a/core/middleware.py b/core/middleware.py deleted file mode 100644 index 2bfb213..0000000 --- a/core/middleware.py +++ /dev/null @@ -1,28 +0,0 @@ -from django.shortcuts import HttpResponseRedirect, reverse -from core.models import UserShippingAddress - - -class EnforceShippingAddressCreationMiddleware(object): - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - - # If current user is authenticated, get their shipping information and current page - # If current page is not them editing their address or logging out, redirect them - if request.user.is_authenticated: - profile = UserShippingAddress.objects.filter(user=request.user).first() - is_profile_absent = profile is None - - allowed_paths = [ - reverse('edit_shipping'), - reverse('logout') - ] - on_allowed_path = request.path not in allowed_paths - - if is_profile_absent and on_allowed_path: - return HttpResponseRedirect(reverse('edit_shipping')) - - response = self.get_response(request) - - return response diff --git a/core/models.py b/core/models.py index 54bec96..4fea52c 100644 --- a/core/models.py +++ b/core/models.py @@ -13,7 +13,3 @@ class UserShippingAddress(models.Model): def __str__(self): return self.user.username - - -# Enforce unique email addresses -# User._meta.get_field('email')._unique = True diff --git a/sales/tasks.py b/sales/tasks.py index 6171300..2746086 100644 --- a/sales/tasks.py +++ b/sales/tasks.py @@ -102,7 +102,7 @@ def notify_seller_of_shipment_receipt(): else: return False -@periodic_task(crontab(minute='*/2')) +@periodic_task(crontab(minute='*/5')) def notify_seller_of_funds_received(): item_sales = ItemSale.objects.filter(seller_notified=False, buyer_notified=True).filter(payment_received=True) for sale in item_sales: @@ -119,7 +119,7 @@ def notify_seller_of_funds_received(): else: return False -@periodic_task(crontab(minute='*/12')) +@periodic_task(crontab(minute='*/30')) def pay_sellers_on_sold_items(): aw = AuctionWallet() if aw.connected is False: @@ -142,7 +142,6 @@ def pay_sellers_on_sold_items(): txs = aw.wallet.accounts[sale.escrow_account_index].transfer( sale.item.payout_address, sale.agreed_price_xmr, relay=True ) - print(txs) if txs: sale.seller_paid = True sale.escrow_complete = True @@ -154,9 +153,36 @@ def pay_sellers_on_sold_items(): print('unable to make payment: ', e) return False -@periodic_task(crontab(minute='*/5')) +@periodic_task(crontab(hour='*/6')) +def pay_platform_on_sold_items(): + aw = AuctionWallet() + if aw.connected is False: + return False + + aof = settings.PLATFORM_WALLET_ADDRESS + if aof is None: + aof = aw.wallet.accounts[0].address() + + item_sales = ItemSale.objects.filter(escrow_complete=True, seller_paid=True, item_received=True).filter(platform_paid=False) + for sale in item_sales: + try: + txs = aw.wallet.accounts[sale.escrow_account_index].sweep_all(aof) + if txs: + sale.platform_paid = True + sale.sale_finalized = True + sale.save() + return True + except Exception as e: + print('unable to sweep funds: ', e) + return False + + +@periodic_task(crontab(minute='*/3')) def poll_for_buyer_escrow_payments(): aw = AuctionWallet() + if aw.connected is False: + return False + item_sales = ItemSale.objects.filter(payment_received=False) for sale in item_sales: sale_account = aw.wallet.accounts[sale.escrow_account_index] diff --git a/sales/views.py b/sales/views.py index 822e357..0ae70eb 100644 --- a/sales/views.py +++ b/sales/views.py @@ -39,6 +39,8 @@ def get_sale(request, bid_id): def confirm_shipment(request, sale_id): sale = ItemSale.objects.get(id=sale_id) + # TODO - dont allow shipment if we dont have an address + # Only proceed if current user is the seller if request.user == sale.item.owner: sale.item_shipped = True diff --git a/web/templates/home.html b/web/templates/home.html index 963fa03..54c68c2 100644 --- a/web/templates/home.html +++ b/web/templates/home.html @@ -6,8 +6,8 @@ {% if request.user.is_authenticated %}

Home

diff --git a/web/templates/items/get_item.html b/web/templates/items/get_item.html index 394cebc..42a26e7 100644 --- a/web/templates/items/get_item.html +++ b/web/templates/items/get_item.html @@ -10,7 +10,7 @@
{% if not item.available %}

This item is currently pending sale. Bidding is temporarily closed.

{% endif %} -

Seller: {{ item.owner }}

+

Whereabouts: Whereabouts

Creation: {{ item.list_date | date:"d M Y H:i:s" }}

Last Updated: {{ item.last_updated | date:"d M Y H:i:s" }}

Description: {{ item.description }}

diff --git a/web/templates/items/list_items.html b/web/templates/items/list_items.html index 4028387..10d7193 100644 --- a/web/templates/items/list_items.html +++ b/web/templates/items/list_items.html @@ -10,7 +10,7 @@ - + @@ -18,7 +18,7 @@ {% for item in items %} - + diff --git a/web/templates/sales/get_sale.html b/web/templates/sales/get_sale.html index 4fb788b..3877dc0 100644 --- a/web/templates/sales/get_sale.html +++ b/web/templates/sales/get_sale.html @@ -33,7 +33,7 @@

Congratulations {{ sale.bid.bidder.username }},

Your funds have been confirmed!

- The seller has been notified of the proof of payment and has been provided with your shipping address. + The seller has been notified of the proof of payment and has been provided with a link to your shipping address. Please make sure it is correct and will result in successful package delivery. You can edit the address here: Edit Shipping Address

@@ -86,17 +86,22 @@

The bidder for your item has sent the proper amount of funds to the escrow wallet address. You may now proceed with shipping the item they agreed to purchase from you. - Here is the physical address you will need to mail it to: + You may need to wait some time for the buyer to provide their location:

+ {% if shipping_address %}

Address 1: {{ shipping_address.address1 }}

Address 2: {{ shipping_address.address2 }}

City: {{ shipping_address.city }}

State: {{ shipping_address.state }}

Country: {{ shipping_address.country }}

Zip: {{ shipping_address.zip }}

-

If you have shipped the item please confirm by clicking this button:

Confirm Item Shipped

+ {% else %} +
+

The buyer has not provided a shipping address yet - check back later!

+ {% endif %} + {% elif sale.item_shipped and sale.item_received == False %}

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

You've shipped the item, now you need to wait for the buyer to confirm they received it on their end.

diff --git a/web/templates/sales/notify/sale_created/buyer/body.txt b/web/templates/sales/notify/sale_created/buyer/body.txt index 212e3e0..a144d45 100644 --- a/web/templates/sales/notify/sale_created/buyer/body.txt +++ b/web/templates/sales/notify/sale_created/buyer/body.txt @@ -5,7 +5,7 @@ Your bid on item "{{ sale.item.name }}" (#{{ sale.item.id }}), was accepted by t Expected Payment (XMR): {{ sale.expected_payment_xmr }} Escrow Address: {{ sale.escrow_address }} -Once the funds are confirmed at this address the seller will be notified to ship the item. You can see more information about the sale at the following URL: +Once the funds are confirmed at this address the seller will be notified to ship the item. We will provide them with a temporary link to view your Shipping Profile; your profile will be wiped out once the sale is complete. You can see more information about the sale at the following URL: https://{{ site_url }}{{ sale_path }} diff --git a/xmrauctions/settings.py b/xmrauctions/settings.py index 129beab..0dce80f 100644 --- a/xmrauctions/settings.py +++ b/xmrauctions/settings.py @@ -26,7 +26,7 @@ DEBUG = os.environ.get('DEBUG', False) ALLOWED_HOSTS = str(os.environ['ALLOWED_HOSTS']).split(',') ESCROW_PERIOD_DAYS = os.environ.get('ESCROW_PERIOD_DAYS', 30) PLATFORM_FEE_PERCENT = os.environ.get('PLATFORM_FEE_PERCENT', 5) - +PLATFORM_WALLET_ADDRESS = os.environ.get('PLATFORM_WALLET_ADDRESS', None) # Application definition
IDSellerWhereabouts Name List Date Asking Price (XMR)
#{{ item.id }}{{ item.owner }}Whereabouts {{ item.name }} {{ item.list_date | date:"d M, Y H:i:s" }} {{ item.ask_price_xmr }}