Ejemplo n.º 1
0
def patch_email(g):
    SENDGRID_USER = SENDGRID_USERNAME = env_or('SENDGRID_USERNAME', None)
    SENDGRID_PASSWORD = env_or('SENDGRID_PASSWORD', None)

    if SENDGRID_USERNAME and SENDGRID_PASSWORD:
        EMAIL_BACKEND = 'sgbackend.SendGridBackend'
    else:
        EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

    log_setting('EMAIL_BACKEND', EMAIL_BACKEND)

    install_caps(g, locals())
Ejemplo n.º 2
0
    def paypal_sub_click_initial(self, initial: dict):
        """
        Data for the pay over time paypal form
        """

        if env_or('PAYPAL_DISABLE_SUBSCRIPTION', False, bool):
            return {}

        if (
            not self.should_any_invoice  # the ticket or addons need invoicing
            or not self.invoice.total  # this invoice has no total, so no button
        ):
            return {}

        PAYPAL_DEBUG = self.tier_id == env_or('PAYPAL_DEBUG_TICKET_TIER_ID', -1, int)

        if PAYPAL_DEBUG:
            # allow for debug testing of duration
            duration = env_or('PAYPAL_DEBUG_DURATION', 30, int)
        else:
            duration = 30

        pay_by = self.event.start_date - datetime.timedelta(days=7)
        days = days_between(pay_by)
        periods = number_periods(days, period=duration)

        if PAYPAL_DEBUG:
            # allow for debug testing of number of periods
            periods = env_or('PAYPAL_DEBUG_PERIODS', periods, int)

        monthly_payment, remainder = divmod(self.invoice.total, periods)
        first_payment = monthly_payment + remainder

        logger.info('[payment] periods %s', periods)
        logger.info('[payment] monthly_payment $%s', monthly_payment)
        logger.info('[payment] first_payment $%s', first_payment)

        # if there there is only one payment window, return falsy
        if (
            periods <= 1 or  # if there is only one period there is no subscription
            first_payment <= 0 or  # if the first payment is zero there is no subscription
            monthly_payment <= 0  # if the monthly payment is zero there is no subscription
        ):
            return {}

        #  Subscription Related.
        # a1 Trial 1 Price
        # p1 Trial 1 Duration
        # t1 Trial 1 unit of Duration, default to Month
        # a2 Trial 2 Price
        # p2 Trial 2 Duration
        # t2 Trial 2 unit of Duration, default to Month
        # a3 Subscription Price
        # p3 Subscription Duration
        # t3 Subscription unit of Duration, default to Month
        # src Is billing recurring? default to yes
        # sra Reattempt billing on failed cc transaction

        # https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
        sub_click_initial = {
            # payment plan
            # 'cmd': '_xclick-payment-plan',
            # 'disp_tot': 'Y',
            # 'option_index': 0,
            # 'option_select1': 1,

            # subscription
            'cmd': '_xclick-subscriptions',

            # first month "trial"
            'a1': str(first_payment),
            'p1': duration,
            't1': 'D',

            # rest of stuff
            'a3': str(monthly_payment),  # Regular subscription price
            'p3': duration,  # Subscription duration of each unit (depends on unit)
            't3': 'D',  # duration unit ('M for Month', 'D' for Day)
            'src': 1,  # make payments recur
            'srt': periods - 1,  # Recurring times
            'sra': 1,  # reattempt payment on payment error
            'no_note': 1,  # remove extra notes (optional)
            'item_name': self.invoice_item_name,
        }

        sub_click_initial.update(initial)
        return sub_click_initial