drop the middleware, refactor address transfer, update content, remove locations

pull/3/head
lalanza808 5 years ago
parent 398481a78e
commit 0210715937

@ -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

@ -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

@ -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]

@ -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

@ -6,8 +6,8 @@
{% if request.user.is_authenticated %}
<h2>Home</h2>
<ul class="actions">
<li><a href="{% url 'create_item' %}" class="button">Create Item</a></li>
<li><a href="{% url 'list_items' %}?user={{ request.user.id }}" class="button">Your Items</a></li>
<li><a href="{% url 'create_item' %}" class="button">Sell An Item</a></li>
<li><a href="{% url 'list_items' %}" class="button">View Items</a></li>
<li><a href="{% url 'list_bids' %}" class="button">Your Bids</a></li>
<li><a href="{% url 'edit_shipping' %}" class="button">Edit Shipping</a></li>
</ul>

@ -10,7 +10,7 @@
</header>
<section>
{% if not item.available %}<p>This item is currently pending sale. Bidding is temporarily closed.</p>{% endif %}
<p class="sale-info"><strong>Seller</strong>: <a href="{% url 'list_items' %}?user={{ item.owner.id }}">{{ item.owner }}</a></p>
<p class="sale-info"><strong>Whereabouts</strong>: Whereabouts</p>
<p class="sale-info"><strong>Creation</strong>: {{ item.list_date | date:"d M Y H:i:s" }}</p>
<p class="sale-info"><strong>Last Updated</strong>: {{ item.last_updated | date:"d M Y H:i:s" }}</p>
<p class="sale-info"><strong>Description</strong>: {{ item.description }}</p>

@ -10,7 +10,7 @@
<table class="table">
<tr>
<th>ID</th>
<th>Seller</th>
<th>Whereabouts</th>
<th>Name</th>
<th>List Date</th>
<th>Asking Price (XMR)</th>
@ -18,7 +18,7 @@
{% for item in items %}
<tr>
<td>#{{ item.id }}</td>
<td><a href="{% url 'list_items' %}?user={{ item.owner.id }}">{{ item.owner }}</a></td>
<td>Whereabouts</td>
<td><a href="{% url 'get_item' item.id %}">{{ item.name }}</a></td>
<td>{{ item.list_date | date:"d M, Y H:i:s" }}</td>
<td>{{ item.ask_price_xmr }}</td>

@ -33,7 +33,7 @@
<p class="sale-info">Congratulations {{ sale.bid.bidder.username }},</p>
<p class="sale-info">Your funds have been confirmed!</p>
<p class="sale-info">
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: <a href="{% url 'edit_shipping' %}" target="_blank">Edit Shipping Address</a>
</p>
@ -86,17 +86,22 @@
<p class="sale-info">
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:
</p>
{% if shipping_address %}
<p class="sale-info"><strong>Address 1</strong>: {{ shipping_address.address1 }}</p>
<p class="sale-info"><strong>Address 2</strong>: {{ shipping_address.address2 }}</p>
<p class="sale-info"><strong>City</strong>: {{ shipping_address.city }}</p>
<p class="sale-info"><strong>State</strong>: {{ shipping_address.state }}</p>
<p class="sale-info"><strong>Country</strong>: {{ shipping_address.country }}</p>
<p class="sale-info"><strong>Zip</strong>: {{ shipping_address.zip }}</p>
<br>
<p class="sale-info">If you have shipped the item please confirm by clicking this button:</p>
<p class="sale-info"><a href="{% url 'confirm_shipment' sale.id %}" class="button">Confirm Item Shipped</a></p>
{% else %}
<br>
<p><strong>The buyer has not provided a shipping address yet - check back later!</strong></p>
{% endif %}
{% elif sale.item_shipped and sale.item_received == False %}
<p class="sale-info">Hello {{ sale.item.owner.username }},</p>
<p class="sale-info">You've shipped the item, now you need to wait for the buyer to confirm they received it on their end.</p>

@ -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 }}

@ -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