def main(override_payday_checks=False): from liberapay.billing.transactions import sync_with_mangopay from liberapay.main import website from liberapay.payin import paypal # https://github.com/liberapay/salon/issues/19#issuecomment-191230689 from liberapay.billing.payday import Payday if not website.env.override_payday_checks and not override_payday_checks: # Check that payday hasn't already been run this week r = website.db.one(""" SELECT id FROM paydays WHERE ts_start >= now() - INTERVAL '6 days' AND ts_end >= ts_start """) assert not r, "payday has already been run this week" # Prevent a race condition, by acquiring a DB lock with website.db.lock('payday', blocking=False): try: sync_with_mangopay(website.db) paypal.sync_all_pending_payments(website.db) Payday.start().run(website.env.log_dir, website.env.keep_payday_logs) except KeyboardInterrupt: # pragma: no cover pass except Exception as e: # pragma: no cover website.tell_sentry(e, {}, allow_reraise=False) raise
def test_payin_paypal(self): self.add_payment_account(self.creator_2, 'paypal', 'US') tip = self.donor.set_tip_to(self.creator_2, EUR('0.01')) # 1st request: test getting the payment page r = self.client.GET('/donor/giving/pay/paypal?beneficiary=%i' % self.creator_2.id, auth_as=self.donor) assert r.code == 200, r.text # 2nd request: initiate the payment form_data = { 'amount': '10.00', 'currency': 'EUR', 'tips': str(tip['id']) } r = self.client.PxST('/donor/giving/pay/paypal', form_data, auth_as=self.donor) assert r.code == 200, r.text assert r.headers[b'Refresh'] == b'0;url=/donor/giving/pay/paypal/1' payin = self.db.one("SELECT * FROM payins") assert payin.status == 'pre' assert payin.amount == EUR('10.00') pt = self.db.one("SELECT * FROM payin_transfers") assert pt.status == 'pre' assert pt.amount == EUR('10.00') # 3rd request: redirect to PayPal r = self.client.GxT('/donor/giving/pay/paypal/1', auth_as=self.donor) assert r.code == 302, r.text assert r.headers[b'Location'].startswith( b'https://www.sandbox.paypal.com/') payin = self.db.one("SELECT * FROM payins") assert payin.status == 'pending' # 4th request: execute the payment qs = '?paymentId=PAYID-LROG6RI5M728524H1063005Y&token=EC-9X899333Y0716272U&PayerID=6C9EQBCEQY4MA' r = self.client.GET('/donor/giving/pay/paypal/1' + qs, auth_as=self.donor) assert r.code == 200, r.text payin = self.db.one("SELECT * FROM payins") assert payin.status == 'succeeded' assert payin.error is None pt = self.db.one("SELECT * FROM payin_transfers") assert pt.status == 'pending' assert pt.error == 'RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION' assert pt.amount == EUR('10.00') # While we're at it, test syncing payments sync_all_pending_payments(self.db)
def test_payin_paypal(self): self.add_payment_account(self.creator_2, 'paypal', 'US') tip = self.donor.set_tip_to(self.creator_2, EUR('0.01')) # 1st request: test getting the payment page r = self.client.GET( '/donor/giving/pay/paypal?beneficiary=%i' % self.creator_2.id, auth_as=self.donor ) assert r.code == 200, r.text # 2nd request: initiate the payment form_data = { 'amount': '10.00', 'currency': 'EUR', 'tips': str(tip['id']) } r = self.client.PxST('/donor/giving/pay/paypal', form_data, auth_as=self.donor) assert r.code == 200, r.text assert r.headers[b'Refresh'] == b'0;url=/donor/giving/pay/paypal/1' payin = self.db.one("SELECT * FROM payins") assert payin.status == 'pre' assert payin.amount == EUR('10.00') pt = self.db.one("SELECT * FROM payin_transfers") assert pt.status == 'pre' assert pt.amount == EUR('10.00') # 3rd request: redirect to PayPal r = self.client.GxT('/donor/giving/pay/paypal/1', auth_as=self.donor) assert r.code == 302, r.text assert r.headers[b'Location'].startswith(b'https://www.sandbox.paypal.com/') payin = self.db.one("SELECT * FROM payins") assert payin.status == 'pending' # 4th request: execute the payment qs = '?paymentId=PAYID-LROG6RI5M728524H1063005Y&token=EC-9X899333Y0716272U&PayerID=6C9EQBCEQY4MA' r = self.client.GET('/donor/giving/pay/paypal/1' + qs, auth_as=self.donor) assert r.code == 200, r.text payin = self.db.one("SELECT * FROM payins") assert payin.status == 'succeeded' assert payin.error is None pt = self.db.one("SELECT * FROM payin_transfers") assert pt.status == 'pending' assert pt.error == 'RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION' assert pt.amount == EUR('10.00') # While we're at it, test syncing payments sync_all_pending_payments(self.db)
conf = website.app_conf if conf: intervals = conf.cron_intervals cron = Cron(website) cron(intervals.get('check_db', 600), website.db.self_check, True) cron(intervals.get('dequeue_emails', 60), Participant.dequeue_emails, True) cron(intervals.get('send_newsletters', 60), Participant.send_newsletters, True) cron(intervals.get('refetch_elsewhere_data', 120), refetch_elsewhere_data, True) cron(intervals.get('refetch_repos', 60), refetch_repos, True) cron(Weekly(weekday=3, hour=2), create_payday_issue, True) cron(intervals.get('clean_up_counters', 3600), website.db.clean_up_counters, True) cron(Daily(hour=3), send_upcoming_debit_notifications, True) cron(Daily(hour=4), execute_scheduled_payins, True) cron(Daily(hour=8), clean_up_closed_accounts, True) cron(Daily(hour=16), lambda: fetch_currency_exchange_rates(website.db), True) cron(Daily(hour=17), lambda: paypal.sync_all_pending_payments(website.db), True) cron(Daily(hour=18), Payday.update_cached_amounts, True) cron(intervals.get('notify_patrons', 1200), Participant.notify_patrons, True) cron(intervals.get('migrate_identities', 120), Participant.migrate_identities, True) if conf.ses_feedback_queue_url: cron(intervals.get('fetch_email_bounces', 60), handle_email_bounces, True) cron(Daily(hour=1), clean_up_emails, True) cron('once', website.cryptograph.rotate_stored_data, True) # Website Algorithm # ================= noop = lambda: None algorithm = website.state_chain