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

Coinbase #2053

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7149657
Update profile style
kyungmin Feb 17, 2014
1ec3fd4
Connect to balanced.js for Coinbase integration
kyungmin Feb 17, 2014
b095f89
Show dialog only if no payment method is set
kyungmin Feb 17, 2014
39a03ef
Add connected accounts
kyungmin Feb 18, 2014
a858b01
Merge remote-tracking branch 'matthewfl/balanced-rev1.1' into coinbase
kyungmin Feb 18, 2014
3929484
Connect to coinbase
kyungmin Feb 20, 2014
7f4151f
Update payment message
kyungmin Feb 20, 2014
39dd8b9
Regroup accounts elsewhere for #2053
chadwhitacre Feb 20, 2014
1397901
Switch order of Venmo and Bitcoin
chadwhitacre Feb 20, 2014
7eca20d
Tweak a couple template includes
chadwhitacre Feb 20, 2014
9c0d311
Take out promo note about Coinbase
chadwhitacre Feb 20, 2014
4858bb4
Pop gift amount on focus
chadwhitacre Feb 20, 2014
0e26cf1
Merge branch 'master' into coinbase
chadwhitacre Feb 20, 2014
98a6569
start to coinbase on the backend, not tested or working yet
matthewfl Feb 20, 2014
ffd174b
Fix button size and restore edit button
kyungmin Feb 20, 2014
6b2b45d
Fix input field and button style for the giving page
kyungmin Feb 20, 2014
6d7ae45
Revert back changes made out of scope
kyungmin Feb 20, 2014
211d6cb
Merge remote-tracking branch 'origin/coinbase' into coinbase-backend
matthewfl Feb 20, 2014
30356dc
adding coinbase to payday
matthewfl Feb 20, 2014
c9bb09f
moving db migration in branch.sql thanks to the info from @zwn
matthewfl Feb 20, 2014
0c0a66d
add more vendor files
matthewfl Feb 20, 2014
0098c8d
Connect/disconnect coinbase from gittip account
kyungmin Feb 21, 2014
44628a7
Require deleting coinbase to add credit card
kyungmin Feb 21, 2014
01b6994
Make payment method dialog buttons large
kyungmin Feb 21, 2014
cecb027
Disable Add link if credit card is connected
kyungmin Feb 21, 2014
4b4875c
some issues with balanced backend getting fixed atm
matthewfl Feb 22, 2014
b41e913
Fix edit bitcoin address
kyungmin Feb 22, 2014
445e0e0
tests working with external account
matthewfl Feb 22, 2014
feb798a
Merge branch 'coinbase-backend' into coinbase
matthewfl Feb 22, 2014
0b96b4b
Merge remote-tracking branch 'origin/master' into coinbase
matthewfl Feb 22, 2014
96179d2
fixing last issues with merge
matthewfl Feb 22, 2014
644baab
Integrate with the latest backend and add confirmation messages
kyungmin Feb 24, 2014
6681e2b
Fix test failure
kyungmin Feb 25, 2014
17165c1
Minor fix
kyungmin Feb 25, 2014
c00b183
Resolved merge conflict. (Needs some CSS fixes)
kyungmin Mar 1, 2014
665fb58
Update connected accounts table
kyungmin Mar 5, 2014
d8846e5
Resolve merge conflict
kyungmin Mar 5, 2014
8f8a56e
Re-apply changes
kyungmin Mar 5, 2014
ad2c654
Merge branch 'coinbase' of https://github.com/gittip/www.gittip.com i…
kyungmin Mar 5, 2014
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
3 changes: 3 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE participants ADD COLUMN last_coinbase_result text DEFAULT NULL;
END;
2 changes: 1 addition & 1 deletion defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GITTIP_COMPRESS_ASSETS=no
STRIPE_SECRET_API_KEY=1
STRIPE_PUBLISHABLE_API_KEY=1

BALANCED_API_SECRET=90bb3648ca0a11e1a977026ba7e239a9
BALANCED_API_SECRET=ak-test-21vi4ozmxY4RPh5A3O9cqvp7AVcFSKGTP

DEBUG=1 # Used by oauthlib to bypass security checks. We need it because when
# running locally the OAuth callbacks are http:, not https:. Of course
Expand Down
10 changes: 7 additions & 3 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def ach_credit(self, ts_start, participant, tips, total):
log(msg + "succeeded.")
error = ""
except balanced.exc.HTTPError as err:
error = err.message.message
error = err.description
except:
error = repr(sys.exc_info()[1])

Expand All @@ -656,11 +656,15 @@ def charge_on_balanced(self, username, balanced_customer_href, amount):

try:
customer = balanced.Customer.fetch(balanced_customer_href)
customer.cards.one().debit(amount=cents, description=username)
try:
source = customer.cards.one()
except balanced.exc.wac.NoResultFound:
source = customer.external_accounts.one()
source.debit(amount=cents, description=username)
log(msg + "succeeded.")
error = ""
except balanced.exc.HTTPError as err:
error = err.message.message
error = err.description
except:
error = repr(sys.exc_info()[1])

Expand Down
17 changes: 9 additions & 8 deletions gittip/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def is_yesish(val):
envvar('BITBUCKET_CONSUMER_SECRET'),
envvar('BITBUCKET_CALLBACK'),
),
Bountysource(
website.db,
None,
envvar('BOUNTYSOURCE_API_SECRET'),
envvar('BOUNTYSOURCE_CALLBACK'),
envvar('BOUNTYSOURCE_API_HOST'),
envvar('BOUNTYSOURCE_WWW_HOST'),
),
OpenStreetMap(
website.db,
envvar('OPENSTREETMAP_CONSUMER_KEY'),
Expand All @@ -198,15 +206,8 @@ def is_yesish(val):
]
website.signin_platforms = PlatformRegistry(signin_platforms)
AccountElsewhere.signin_platforms_names = tuple(p.name for p in signin_platforms)

other_platforms = [
Bountysource(
website.db,
None,
envvar('BOUNTYSOURCE_API_SECRET'),
envvar('BOUNTYSOURCE_CALLBACK'),
envvar('BOUNTYSOURCE_API_HOST'),
envvar('BOUNTYSOURCE_WWW_HOST'),
),
Venmo(
website.db,
envvar('VENMO_CLIENT_ID'),
Expand Down
113 changes: 102 additions & 11 deletions js/gittip/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,38 @@ Gittip.payments.havePayments = false;
Gittip.payments.processorAttempts = 0;

Gittip.payments.submitDeleteForm = function(e) {
var item = $("#payout").length ? "bank account" : "credit card";
var slug = $("#payout").length ? "bank-account" : "credit-card";
var msg = "Really disconnect your " + item + "?";
var item, slug;
var type = e.target.id.slice(-2);
if (type == "cc") {
item = "credit card";
slug = "credit-card";
} else if (type == "ba") {
item = "bank account";
slug = "bank-account";
} else if (type == "cb") {
item = "Coinbase account";
slug = "coinbase";
}

var msg = "Are you sure you want to remove " + item + "?";
if (!confirm(msg)) {
e.stopPropagation();
e.preventDefault();
return false;
}

jQuery.ajax(
{ url: '/' + slug + '.json'
, data: {action: "delete"}
, type: "POST"
, success: function() {
window.location.href = '/' + slug + '.html';
if (type !== "cb") {
window.location.href = '/' + slug + '.html';
} else {
$('html, body').animate({scrollTop: 0}, 500);
var coinbase_confirm = $('<div class="confirm">Successfully deleted your Coinbase account.</div>');
$('#hero').prepend(coinbase_confirm);
location.reload();
}
}
, error: function(x,y,z) {
select(cur);
Expand All @@ -52,7 +69,7 @@ Gittip.payments.ba = {};

Gittip.payments.ba.init = function(balanced_uri, participantId) {
Gittip.participantId = participantId;
$('#delete form').submit(Gittip.payments.submitDeleteForm);
$('#ba-delete form').submit(Gittip.payments.submitDeleteForm);
$('#payout').submit(Gittip.payments.ba.submit);

// Lazily depend on Balanced.
Expand Down Expand Up @@ -170,7 +187,7 @@ Gittip.payments.ba.handleResponse = function (response) {
setTimeout(function() {
$('#status').removeClass('highlight');
}, 8000);
$('#delete').show();
$('#ba-delete').show();
Gittip.forms.clearFeedback();
$('button#save').text('Save');
setTimeout(function() {
Expand All @@ -180,7 +197,7 @@ Gittip.payments.ba.handleResponse = function (response) {

function detailedFeedback(data) {
$('#status').text('failing');
$('#delete').show();
$('#ba-delete').show();
var messages = [data.error];
if (data.problem == 'More Info Needed') {
messages = [ "Sorry, we couldn't verify your identity. Please "
Expand Down Expand Up @@ -209,7 +226,7 @@ Gittip.payments.cc = {};

Gittip.payments.cc.init = function(balanced_uri, participantId) {
Gittip.participantId = participantId;
$('#delete form').submit(Gittip.payments.submitDeleteForm);
$('#cc-delete form').submit(Gittip.payments.submitDeleteForm);
$('form#payment').submit(Gittip.payments.cc.submit);

// Lazily depend on Balanced.
Expand Down Expand Up @@ -332,7 +349,7 @@ Gittip.payments.cc.handleResponse = function(response) {
setTimeout(function() {
$('#status').removeClass('highlight');
}, 8000);
$('#delete').show();
$('#cc-delete').show();
Gittip.forms.clearFeedback();
$('button#save').text('Save');
setTimeout(function() {
Expand All @@ -342,7 +359,7 @@ Gittip.payments.cc.handleResponse = function(response) {

function detailedFeedback(data) {
$('#status').text('failing');
$('#delete').show();
$('#cc-delete').show();
var details = [];
Gittip.forms.showFeedback(data.problem, [data.error]);
$('button#save').text('Save');
Expand All @@ -354,3 +371,77 @@ Gittip.payments.cc.handleResponse = function(response) {
, detailedFeedback
);
};

// Coinbase
// ============

Gittip.payments.cb = {};

Gittip.payments.cb.init = function(balanced_uri, participantId) {
Gittip.participantId = participantId;
$('#cb-delete form').submit(Gittip.payments.submitDeleteForm);

// Lazily depend on Balanced.
var balanced_js = "https://js.balancedpayments.com/1.1/balanced.js";
jQuery.getScript(balanced_js, function() {
balanced.init(balanced_uri);
balanced.externalAccount.create('coinbase', Gittip.payments.cb.handleResponse);
});
};
Gittip.payments.cb.handleResponse = function(response) {
if (response.status_code !== 201) {
var msg = response.status.toString() + " " + response.error.description;
jQuery.ajax(
{ type: "POST"
, url: "/coinbase.json"
, data: {action: 'store-error', msg: msg}
}
);

Gittip.forms.showFeedback(null, [response.error.description]);
return;
}

$('html, body').animate({scrollTop: 0}, 500);
if ($(".confirm").length > 0){
$(".confirm").text('Connecting to your Coinbase account..');
} else {
$('#hero').prepend('<div class="confirm">Connecting to your Coinbase account..</div>');
}

function success() {
$('.confirm').text('Successfully connected to your Coinbase account.');
location.reload();
}

function detailedFeedback(data) {
$('#status').text('failing');
$('#cb-delete').show();
var messages = [data.error];
if (data.problem == 'More Info Needed') {
messages = [ "Sorry, we couldn't verify your identity. Please "
+ "check, correct, and resubmit your details."
];
}
Gittip.forms.showFeedback(data.problem, messages);
$('button#save').text('Save');
}

Gittip.forms.submit( "/coinbase.json"
, {coinbase_uri: response.external_accounts[0].href}
, success
, detailedFeedback
);
}


// templates/connected-accounts.html
// ============

// connect to coinbase
$('#connect-coinbase').click(function (e) {
e.preventDefault();
Gittip.payments.cb.init(marketplace_uri, participant_username);
});
// for delete buttons in connected-accounts.html
$('body').on('click', '#cc-delete .close, #ba-delete .close, #cb-delete .close', Gittip.payments.submitDeleteForm);
10 changes: 5 additions & 5 deletions js/gittip/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ Gittip.profile.init = function() {
$('a.bitcoin').text(d.bitcoin_address);
$('.bitcoin').toggle();
if (d.bitcoin_address === '') {
html = "Add a <a href=\"javascript:;\" class=\"toggle-bitcoin\">Bitcoin address</a>.";
html = '<span class="none">none</span><a class="btn small toggle-bitcoin" href="javascript:;">+ Add</a>';
} else {
html = "<a rel=\"me\" href=\"http://blockchain.info/address/";
html += d.bitcoin_address + "\">" + d.bitcoin_address + "</a>";
html += "<div class=\"edit-bitcoin\"><a href=\"javascript:;\" class=\"toggle-bitcoin\">Edit</a> bitcoin address ";
html += "</div>";
html = '<a class="address" rel="me" href="http://blockchain.info/address/';
html += d.bitcoin_address + '">' + d.bitcoin_address + '</a>';
html += '<a href="javascript:;" class="edit-bitcoin btn small toggle-bitcoin">Edit</a>';
html += '</div>';
}
$('div.bitcoin').html(html);
$this.text('Save');
Expand Down
61 changes: 58 additions & 3 deletions js/gittip/tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Gittip.tips.init = function() {
var $this = $(this),
$myTip = $this.parents('form').find('.my-tip');

$myTip.val($this.text().match(/\d+/)[0] / ($this.hasClass('cents') ? 100 : 1)).change();
var amount = $this.text().match(/\d+.\d+/);
$myTip.val(amount).change();

});

$('form.my-tip').on('reset', function() {
Expand All @@ -65,6 +67,7 @@ Gittip.tips.init = function() {

$('form.my-tip').submit(function(event) {
event.preventDefault();

var $this = $(this),
$myTip = $this.find('.my-tip'),
amount = parseFloat($myTip.val(), 10),
Expand All @@ -75,8 +78,9 @@ Gittip.tips.init = function() {
if (amount == oldAmount)
return;

if(isAnon)
if(isAnon) {
alert("Please sign in first");
}
else {
// send request to change tip
$.post('/' + tippee + '/tip.json', { amount: amount }, function(data) {
Expand All @@ -95,11 +99,28 @@ Gittip.tips.init = function() {
if(!oldAmount)
$('.on-elsewhere .ready .number').text(
parseInt($('.on-elsewhere .ready .number').text(),10) + 1);

// show payment method dialog
if (has_payment_method === "False") {
$('#payment-method-dialog').show();
$("#payment-method").css({
"marginLeft": -($("#payment-method").width()/2),
"marginTop": -($("#payment-method").height()/2)
});
}

// update quick stats
$('.quick-stats a').text('$' + data.total_giving + '/wk');

alert("Tip changed to $" + amount + "!");
// show confirmation message once
if ($(".confirm").length > 0){
$(".confirm").remove();
}
var notice = $('<div class="confirm">Your weekly gift has been updated.</div>');
$('#hero').prepend(notice);

// update amount
$('.weekly-gift .amount').text('$' + $('input.my-tip').val() + ' / wk');
})
.fail(function() {
alert('Sorry, something went wrong while changing your tip. :(');
Expand All @@ -108,5 +129,39 @@ Gittip.tips.init = function() {
}
});

// highlight radio selection
$paymentOption = $('#payment-method input:radio[name=payment-option]');
$paymentOption.click(function(e) {
$paymentOption.each(function (index, item){
if($(item).is(":checked")){
$(item).parent().addClass('selected');
} else {
$(item).parent().removeClass('selected');
}
});
});

// connect to coinbase
$('.promo-bar a.coinbase').click(function(e) {
e.preventDefault();
Gittip.payments.cb.init(marketplace_uri, participant_username);
});

// payment method selection
$('#payment-method .primary').click(function(e) {
e.preventDefault();

if($('input:radio[name=payment-option]:checked').val() == 'coinbase') {
Gittip.payments.cb.init(marketplace_uri, participant_username);
$('#payment-method-dialog').hide();
} else {
window.location.href="/credit-card.html"
}
});

// close payment method dialog
$('#payment-method .close, #payment-method .secondary, #payment-method-dialog .overlay').click(function(e) {
$('#payment-method-dialog').hide();
});
};

5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

./vendor/iso8601-0.1.4.tar.gz
./vendor/mock-0.8.0.tar.gz
./vendor/balanced-1.0.1beta2.tar.gz
./vendor/wac-0.22.tar.gz
./vendor/uritemplate-0.6.tar.gz
./vendor/balanced-1.0.1beta3.tar.gz
./vendor/python-bitcoinaddress-0.2.2.tar.gz

./vendor/pytz-2012j.tar.gz
Expand All @@ -39,4 +41,5 @@
./vendor/libsass-0.2.4.tar.gz
./vendor/honcho-0.5.0.tar.gz

./vendor/PyYAML-3.10.tar.gz
./vendor/vcrpy-0.6.0.tar.gz
Loading