Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Create coinbase order and place iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed Apr 1, 2015
1 parent 85a1b07 commit 170d7f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
14 changes: 11 additions & 3 deletions js/gratipay/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<iframe src="https://sandbox.coinbase.com/checkouts/' +
data.code +
'/inline"' +
'frameborder="0"></iframe>');
$('button#pay').remove();
$('.coinbase-box').append(iframe);
},
error: Gratipay.error
});
return false;
Expand Down
21 changes: 9 additions & 12 deletions www/%username/routes/bitcoin-payin.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ title = _("Bitcoin Payin")
<h1>{{ _("Bitcoin Payin") }}</h1>
<p>{{ _("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 %}
Expand All @@ -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 %}
<form id="bitcoin-payin">
<label for="amount">Amount:</label>
$ <input name="amount" id="amount" type="text">
<button class="selected larger" type="submit">{{ _("Pay") }}</button>
</form>

{% endif %}

{% if user.ANON %}
{% include "templates/sign-in-using.html" %}
{{ _("and then you'll be able to payin with bitcoin.") }}
{% else %}
<div class="coinbase-box">
<button class="selected larger" id="pay">{{ _("Pay") }}</button>
</div>
{% endif %}

{% endblock %}
28 changes: 17 additions & 11 deletions www/%username/routes/bitcoin-payin.json.spt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 170d7f6

Please sign in to comment.