This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13e36a6
commit 681c6ff
Showing
6 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
BEGIN; | ||
CREATE TYPE follow_up AS ENUM ('monthly', 'quarterly', 'yearly', 'never'); | ||
CREATE TABLE payments_for_open_source | ||
( uuid text PRIMARY KEY | ||
, ctime timestamptz NOT NULL DEFAULT now() | ||
|
||
-- card charge | ||
, amount bigint NOT NULL | ||
, transaction_id text UNIQUE NOT NULL | ||
|
||
-- contact info | ||
, name text NOT NULL | ||
, follow_up follow_up NOT NULL | ||
, email_address text NOT NULL | ||
, message_id bigint REFERENCES email_messages(id) | ||
|
||
-- promotion details | ||
, promotion_name text NOT NULL DEFAULT '' | ||
, promotion_url text NOT NULL DEFAULT '' | ||
, promotion_twitter text NOT NULL DEFAULT '' | ||
, promotion_message text NOT NULL DEFAULT '' | ||
); | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import uuid as uuidlib | ||
from postgres.orm import Model | ||
|
||
|
||
class PaymentForOpenSource(Model): | ||
|
||
typname = "payments_for_open_source" | ||
|
||
def __repr__(self): | ||
return '<PaymentForOpenSource: %s>'.format(repr(self.amount)) | ||
|
||
|
||
@classmethod | ||
def from_uuid(cls, uuid, cursor=None): | ||
return (cursor or cls.db).one(""" | ||
SELECT pfos.*::payments_for_open_source | ||
FROM payments_for_open_source pfos | ||
WHERE uuid = %s | ||
""", (uuid,)) | ||
|
||
|
||
@classmethod | ||
def insert(cls, amount, transaction_id, name, follow_up, email_address, message_id, | ||
promotion_name, promotion_url, promotion_twitter, promotion_message, | ||
cursor=None): | ||
uuid = uuidlib.uuid4().hex | ||
return (cursor or cls.db).one(""" | ||
INSERT INTO payments_for_open_source | ||
(uuid, amount, transaction_id, name, follow_up, email_address, message_id, | ||
promotion_name, promotion_url, promotion_twitter, promotion_message) | ||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) | ||
RETURNING payments_for_open_source.*::payments_for_open_source | ||
""", (uuid, amount, transaction_id, name, follow_up, email_address, message_id, | ||
promotion_name, promotion_url, promotion_twitter, promotion_message)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
from gratipay.models.exchange_route import ExchangeRoute | ||
from gratipay.models.package import NPM, Package | ||
from gratipay.models.participant import Participant, MAX_TIP, MIN_TIP | ||
from gratipay.models.payment_for_open_source import PaymentForOpenSource | ||
from gratipay.models.team import Team | ||
from gratipay.security import user | ||
from gratipay.testing import P | ||
|
@@ -142,6 +143,24 @@ def clear_tables(self): | |
self.db.run("INSERT INTO worker_coordination DEFAULT VALUES") | ||
|
||
|
||
def make_payment_for_open_source(self, **info): | ||
defaults = dict( amount='1000' | ||
, name='Alice Liddell' | ||
, transaction_id='deadbeef' | ||
, email_address='[email protected]' | ||
, follow_up='monthly' | ||
, message_id=None # TODO call gratipay._send and grab id | ||
, promotion_name='Wonderland' | ||
, promotion_url='http://www.example.com/' | ||
, promotion_twitter='thebestbutter' | ||
, promotion_message='Love me! Love me! Say that you love me!' | ||
) | ||
for key, value in defaults.items(): | ||
if key not in info: | ||
info[key] = value | ||
return PaymentForOpenSource.insert(**info) | ||
|
||
|
||
def make_elsewhere(self, platform, user_id, user_name, **kw): | ||
"""Factory for :py:class:`~gratipay.models.account_elsewhere.AccountElsewhere`. | ||
""" | ||
|
@@ -318,6 +337,7 @@ def make_exchange(self, route, amount, fee, participant, status='succeeded', err | |
record_exchange_result(self.db, e_id, status, error, participant) | ||
return e_id | ||
|
||
|
||
def make_payment(self, participant, team, amount, direction, payday, timestamp=utcnow()): | ||
"""Factory for payment""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.testing import Harness | ||
from gratipay.models.payment_for_open_source import PaymentForOpenSource | ||
|
||
|
||
class Tests(Harness): | ||
|
||
def test_can_insert(self): | ||
self.make_payment_for_open_source() | ||
assert self.db.one('SELECT * FROM payments_for_open_source').name == 'Alice Liddell' | ||
|
||
def test_can_fetch(self): | ||
uuid = self.make_payment_for_open_source().uuid | ||
assert PaymentForOpenSource.from_uuid(uuid).name == 'Alice Liddell' |