From 170d7f6e0d79a13742feb279ae22ac83038b83d8 Mon Sep 17 00:00:00 2001 From: Rohit Paul Kuruvilla Date: Thu, 2 Apr 2015 00:41:28 +0530 Subject: [PATCH] Create coinbase order and place iframe --- js/gratipay/payments.js | 14 ++++++++--- www/%username/routes/bitcoin-payin.html.spt | 21 +++++++--------- www/%username/routes/bitcoin-payin.json.spt | 28 +++++++++++++-------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/js/gratipay/payments.js b/js/gratipay/payments.js index 131d96ba2f..ac45b535a2 100644 --- a/js/gratipay/payments.js +++ b/js/gratipay/payments.js @@ -331,16 +331,24 @@ Gratipay.payments.cc.submit = function(e) { Gratipay.payments.bc = {}; Gratipay.payments.bc.init = function () { - $('form#bitcoin-payin').submit(Gratipay.payments.bc.createOrder); + $('button#pay').click(Gratipay.payments.bc.createOrder); }; Gratipay.payments.bc.createOrder = function () { var amount = $('form#bitcoin-payin input#amount').val(); + $('button#pay').prop('disabled', true); jQuery.ajax({ url: "/" + Gratipay.username + "/routes/bitcoin-payin.json", - data: { amount: amount }, + data: {}, type: "POST", - success: function(data) {}, + success: function(data) { + var iframe = $(''); + $('button#pay').remove(); + $('.coinbase-box').append(iframe); + }, error: Gratipay.error }); return false; diff --git a/www/%username/routes/bitcoin-payin.html.spt b/www/%username/routes/bitcoin-payin.html.spt index 7c5ce4cbb5..d668932cac 100644 --- a/www/%username/routes/bitcoin-payin.html.spt +++ b/www/%username/routes/bitcoin-payin.html.spt @@ -12,7 +12,6 @@ title = _("Bitcoin Payin")

{{ _("Bitcoin Payin") }}

{{ _("We currently support one-time payins via Bitcoin.") }} {{ _("You can either send bitcoins manually, or use your coinbase account to complete the transaction.") }} - {% endblock %} {% block scripts %} @@ -29,16 +28,14 @@ title = _("Bitcoin Payin") {% endblock %} {% block content %} - {% if user.ANON %} - {% include "templates/sign-in-using.html" %} - {{ _("and then you'll be able to payin with bitcoin.") }} - {% else %} -

- - $ - -
- - {% endif %} + + {% if user.ANON %} + {% include "templates/sign-in-using.html" %} + {{ _("and then you'll be able to payin with bitcoin.") }} + {% else %} +
+ +
+ {% endif %} {% endblock %} diff --git a/www/%username/routes/bitcoin-payin.json.spt b/www/%username/routes/bitcoin-payin.json.spt index ed8cae5e68..0d9f7218a3 100644 --- a/www/%username/routes/bitcoin-payin.json.spt +++ b/www/%username/routes/bitcoin-payin.json.spt @@ -1,20 +1,26 @@ -from decimal import Decimal, InvalidOperation - -from gratipay.utils import get_participant from aspen import Response +from aspen import log_dammit +from coinbase.error import APIError +from gratipay.utils import get_participant [---] request.allow('POST') -get_participant(state, restrict=True) +participant = get_participant(state, restrict=True) +account = website.coinbase.get_account('primary') -amount = request.body['amount'] -try: - amount = Decimal(amount) -except InvalidOperation: - raise Response(400, "Invalid Amount!") +out = {} -accounts = website.coinbase.get_authorization() +try: + out = account.create_button( + "Gratipay (%s)" % participant.username, # name + "100", # price_string + "USD", # price_currency_iso + description="Gratipay Bitcoin Payin", + choose_price=True + ) +except APIError: + raise Response(500, "We're having trouble communicating with Coinbase, please try again.") [---] -{{ accounts }} +out