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

Commit

Permalink
Receipt -> Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Sep 11, 2017
1 parent b58d2c6 commit 07d6164
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 141 deletions.
13 changes: 6 additions & 7 deletions emails/paid-for-open-source.spt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{{ _("Payment for open source") }}
{{ _("Invoice from Gratipay") }}

[---] text/html
{{ _( "Congratulations! You now have a moral license to use community-built open source software, because you paid {amount} to the open source community through Gratipay. Thank you for your purchase!"
{{ _( "Thank you for your payment of {amount} for open source!"
, amount=format_currency(amount, 'USD')
) }}
<br>
<br>
<a href="{{ receipt_url }}"
style="{{ button_style }}">{{ _("View Receipt") }}</a>
<a href="{{ invoice_url }}" style="{{ button_style }}">{{ _("View Invoice") }}</a>

[---] text/plain
{{ _( "Congratulations! You now have a moral license to use community-built open source software, because you paid {amount} to the open source community through Gratipay. Thank you for your purchase!"
{{ _( "Thank you for your payment of {amount} for open source!"
, amount=format_currency(amount, 'USD')
) }}

{{ _("Follow this link to view your receipt:") }}
{{ _("Follow this link to view your invoice:") }}

{{ receipt_url }}
{{ invoice_url }}
6 changes: 3 additions & 3 deletions gratipay/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ def _send(app, pfos):
, template='paid-for-open-source'
, email=pfos.email_address
, amount=pfos.amount
, receipt_url=pfos.receipt_url
, invoice_url=pfos.invoice_url
)


def pay_for_open_source(app, raw):
parsed, errors = _parse(raw)
out = {'errors': errors, 'receipt_url': None}
out = {'errors': errors, 'invoice_url': None}
if not errors:
payment_method_nonce = parsed.pop('payment_method_nonce')
pfos = _store(parsed)
_charge(app, pfos, payment_method_nonce)
if pfos.succeeded:
out['receipt_url'] = pfos.receipt_url
out['invoice_url'] = pfos.invoice_url
if pfos.email_address:
_send(app, pfos)
else:
Expand Down
4 changes: 2 additions & 2 deletions gratipay/models/payment_for_open_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def succeeded(self):


@property
def receipt_url(self):
def invoice_url(self):
if not self.succeeded:
return None
return '{}/browse/payments/{}/receipt.html'.format(gratipay.base_url, self.uuid)
return '{}/browse/payments/{}/invoice.html'.format(gratipay.base_url, self.uuid)


@classmethod
Expand Down
2 changes: 1 addition & 1 deletion js/gratipay/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Gratipay.homepage.submitFormWithNonce = function(nonce) {
$('.'+fieldName, self.$form).addClass('error');
}
} else {
$('.payment-complete a.receipt').attr('href', data.receipt_url);
$('.payment-complete a.invoice').attr('href', data.invoice_url);
$('form').slideUp(500, function() {
$('.payment-complete').fadeIn(500);
});
Expand Down
12 changes: 6 additions & 6 deletions tests/py/test_www_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ def test_stores_info(self):

class Send(QueuedEmailHarness):

def test_sends_receipt_link(self):
def test_sends_invoice_link(self):
parsed, errors = _parse(GOOD)
parsed.pop('payment_method_nonce')
payment_for_open_source = _store(parsed)
_send(self.app, payment_for_open_source)
msg = self.get_last_email()
assert msg['to'] == '[email protected]'
assert msg['subject'] == 'Payment for open source'
assert msg['subject'] == 'Invoice from Gratipay'


class PayForOpenSource(PayForOpenSourceHarness):
Expand All @@ -155,13 +155,13 @@ def test_pays_for_open_source(self):
assert self.fetch() is None
result = pay_for_open_source(self.app, self.good)
assert not result['errors']
assert result['receipt_url'].endswith('receipt.html')
assert result['invoice_url'].endswith('invoice.html')
assert self.fetch().succeeded

def test_flags_errors_and_doesnt_store(self):
assert self.fetch() is None
result = pay_for_open_source(self.app, self.bad)
assert result == {'errors': ALL, 'receipt_url': None}
assert result == {'errors': ALL, 'invoice_url': None}
assert self.fetch() is None

def test_flags_errors_with_no_transaction_id(self):
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_post_gets_json(self):
assert response.headers['Content-Type'] == 'application/json'
result = json.loads(response.body)
assert not result['errors']
assert result['receipt_url'].endswith('receipt.html')
assert result['invoice_url'].endswith('invoice.html')
assert self.fetch().succeeded

def test_bad_post_gets_400(self):
Expand All @@ -213,5 +213,5 @@ def test_partial_post_is_fine(self):
assert response.headers['Content-Type'] == 'application/json'
result = json.loads(response.body)
assert not result['errors']
assert result['receipt_url'].endswith('receipt.html')
assert result['invoice_url'].endswith('invoice.html')
assert self.fetch().succeeded
3 changes: 3 additions & 0 deletions tests/ttw/test_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def test_anon_can_post(self):
'[email protected]', 'Wonderland', 'http://www.example.com/',
'thebestbutter', 'Love me! Love me! Say that you love me!')
assert self.submit_succeeds()
self.wait_for('a.invoice').click()
self.wait_for('#txnid')
assert self.css('#items tbody tr').text == 'open source software $ 537.00'

def test_options_are_optional(self):
self.fill_form('537', '4242424242424242', '1020', '123')
Expand Down
120 changes: 0 additions & 120 deletions www/browse/payments/%uuid.html.spt

This file was deleted.

Loading

0 comments on commit 07d6164

Please sign in to comment.