Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions board/templates/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<i id="clear_lines_tool" class="fa fa-trash-o fa-2x"></i>
<i id="undo-tool" class="fa fa-undo fa-2x"></i>
<i id="save-tool" class="fa fa-download fa-2x"></i>
{% if not user.is_authenticated and not user.get_profile.is_premium %}
<i id="premium-tool" class="fa fa-shopping-cart fa-2x"></i>
{% endif %}
</div>
<div id="dialog" title="Cleaning drawings..." style="display: none;">
Are you sure about this?
Expand Down Expand Up @@ -99,6 +102,48 @@ <h4 class="modal-title">{% trans "Set this boardino as private ..." %}</h4>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="get-premium-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Get Boardino Premium" %}</h4>
</div>
<div class="modal-body">
<div id="get-prmium-error" class="alert alert-danger" style="display: none">
<span id="get-premium-error-msg">{% trans "Couldn't get premium" %}</span>
</div>
{% if user.is_authenticated and user.get_profile.is_premium %}
<p>{% trans "You are already Premium user" %}</p>
{% else %}
{% if user.is_authenticated %}
<form action="" method="POST">
{% csrf_token %}
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_cClDior095M0UPHu3cTHIwkx"
data-email="{{ user.email }}"
data-amount="100"
data-name="Boardino.com"
data-description="Boardino Premium ($1.00)"
data-image="/128x128.png">
</script>
</form>
{% else %}
<p>{% trans "Please register and login before get premium." %}</p>
{% endif %}
{% endif %}
</div>
<div class="modal-footer">
{% if user.is_authenticated and user.get_profile.is_premium %}
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Cancel" %}</button>
{% else %}
<button type="button" class="btn btn-primary" data-dismiss="modal">{% trans "Accept" %}</button>
{% endif %}
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="set-public-modal">
<div class="modal-dialog">
<div class="modal-content">
Expand Down
32 changes: 30 additions & 2 deletions board/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from board.models import Board, PostIt, Line, Text
from board.serializers import PostitSerializer, LineSerializer, BoardSerializer, UserProfileSerializer, TextSerializer
from accounts.models import UserProfile
import stripe


# Main Page where you can see the created boards if you're authenticated
Expand Down Expand Up @@ -144,7 +145,10 @@ def board(request, board_hash):
board.last_visit = datetime.now()
board.save()

return render_to_response('board.html',{'board': board, 'postits':board.postit_set.all()}, context_instance=RequestContext(request))
if 'stripeToken' in request.POST:
payment(request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se puede pasar esto a un llamado por API ? así queda independiente, porque es un poco raro usar esta misma ruta para el pago.
También creo que podríamos adaptar este llamado para que se haga por Ajax y así mostrar la notificación inmediatamente sin hacer un reload de la página.


return render_to_response('board.html', {'board': board, 'postits':board.postit_set.all()}, context_instance=RequestContext(request))

# Clear all drawed lines of the board
@csrf_exempt
Expand Down Expand Up @@ -188,6 +192,30 @@ def download(request, board_hash):
response['Content-Disposition'] = 'attachment; filename=boardino_%s.png' % board_hash
return response

def payment(request):
# Set your secret key: remember to change this to your live secret key in production
# See your keys here https://manage.stripe.com/account
from settings import STRIPE_API_KEY
stripe.api_key = STRIPE_API_KEY

# Get the credit card details submitted by the form
token = request.POST['stripeToken']

# Create the charge on Stripe's servers - this will charge the user's card
try:
charge = stripe.Charge.create(
amount=100, # amount in cents, again
currency="usd",
card=token,
description=request.user.email
)
up = request.user.get_profile()
up.is_premium = True
up.save()
except stripe.CardError, e:
# The card has been decline
pass

# API
@api_view(['GET'])
def api_root(request, format=None):
Expand Down Expand Up @@ -276,4 +304,4 @@ def get_object(self):
if not self.request.user.is_authenticated():
return None
profile = get_object_or_404(UserProfile, user=self.request.user)
return profile
return profile
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pyyaml
django-userena
mock
django-simple-captcha
stripe
2 changes: 2 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,5 @@ def env(key, default = None):
},
}
}

STRIPE_API_KEY = env('STRIPE_API_KEY', 'sk_test_Ikylm2T3IkWrhIUVRqj1eV4f')
2 changes: 1 addition & 1 deletion static/css/home.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions static/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,14 +1431,16 @@ define('app/views/main',[
"click #set-alias-btn": "setBoardAlias",
"click #zoom_in": "zoomIn",
"click #zoom_out": "zoomOut",
"click #connected_users_btn": "toggleUsers"
"click #connected_users_btn": "toggleUsers",
"click #premium-tool": "showGetPremiumModal"
},
initialize: function(attrs){
this.boardView = attrs.boardView;
this.board = attrs.board;
this.menu = $("#menu");
this.menu.menu();
var _this = this;
$("#get-premium-modal").modal({show:false});
$("#set-private-modal").modal({show:false});
$("#set-alias-modal").modal({show:false});
$( "#zoom-slider" ).slider({
Expand Down Expand Up @@ -1564,7 +1566,11 @@ define('app/views/main',[
toggleUsers: function(e){
e.preventDefault();
$("#online_users_container").toggle("slow");
}
},
showGetPremiumModal: function(e) {
e.preventDefault();
$("#get-premium-modal").modal('show');
}
});
return MainView;
});
Expand Down
4 changes: 2 additions & 2 deletions static/js/application.min.js

Large diffs are not rendered by default.