コード例 #1
0
 def make_member(self, request, queryset):
     from pythonpro.domain import user_facade
     for user in queryset:
         try:
             user_facade.promote_member(user, 'django_admin')
         except UserRoleException:
             pass  # No need to handle on admin
コード例 #2
0
def capture_payment(token, user, source='unknow'):
    pagarme_resp = _payment_facade.membership_capture(
        calculate_membership_price(user), token)
    customer = pagarme_resp['customer']
    customer_email = customer['email']
    customer_first_name = customer['name'].split()[0]
    payment_method = pagarme_resp['payment_method']
    if payment_method == 'credit_card':
        if user.is_authenticated:
            _user_facade.promote_member(user, source)
        else:
            _user_facade.force_register_member(customer_first_name,
                                               customer_email, source)
        dct = {'redirect_url': reverse('payments:membership_thanks')}
    elif payment_method == 'boleto':
        if not user.is_authenticated:
            user = _user_facade.force_register_lead(customer_first_name,
                                                    customer_email, source)
        _user_facade.member_generated_boleto(user)
        path = reverse('payments:membership_boleto')
        qs = urlencode(
            {k: pagarme_resp[k]
             for k in ['boleto_barcode', 'boleto_url']})
        dct = {'redirect_url': f'{path}?{qs}'}
    else:
        raise ValueError(f'Invalid payment method {payment_method}')
    return dct
コード例 #3
0
def _promote(user, slug):
    if 'pytools' in slug:
        user_facade.promote_client(user, 'unknow')
    elif 'membership' in slug:
        user_facade.promote_member(user, 'unknow')
    else:
        raise ValueError(f'{slug} should contain pytools or membership')
コード例 #4
0
def _promote(user, slug: str):
    if slug.startswith('membership'):
        user_facade.promote_member(user, 'unknown')
    elif slug.startswith('webdev'):
        user_facade.promote_webdev(user, 'unknown')
    elif slug.startswith('data-science'):
        user_facade.promote_data_scientist(user, 'unknown')
    else:
        raise ValueError(f'{slug} should contain webdev or membership')
コード例 #5
0
def subscribe_member_who_paid_boleto(user_id: int,
                                     notification_data: dict,
                                     raw_post: str,
                                     signature: str,
                                     source: str = 'unknow') -> _User:
    try:
        _payment_facade.confirm_membership_boleto_payment(
            user_id, notification_data, raw_post, signature)
    except _PagarmeNotPaidTransaction:
        pass
    else:
        user = _user_facade.find_user_by_id(user_id)
        _user_facade.promote_member(user, source)
        return user
コード例 #6
0
def subscribe_anonymous_member_who_paid_boleto(
        notification_data: dict,
        raw_post: str,
        signature: str,
        source: str = 'unknow') -> _User:
    try:
        transaction = _payment_facade.extract_transaction(
            notification_data, raw_post, signature)
    except PagarmeNotPaidTransaction:
        pass  # No problem, we need to handle only paid transactions
    else:
        user = _user_facade.find_user_by_email(
            transaction['customer']['email'])
        _user_facade.promote_member(user, source)
        return user
コード例 #7
0
def _promote(user, slug: str):
    if slug.startswith('membership'):
        user_facade.promote_member(user, 'unknown')
    elif slug == 'pacote-proximo-nivel-67-discount':
        user_facade.promote_pythonista(user, 'unknown')
    elif slug.startswith('webdev'):
        user_facade.promote_webdev(user, 'unknown')
    elif slug.startswith('data-science'):
        user_facade.promote_data_scientist(user, 'unknown')
    elif slug in {'bootcamp', 'bootcamp-webdev'}:
        user_facade.promote_bootcamper(user, 'unknown')
        user_facade.promote_pythonista(user, 'unknown')
    elif slug.startswith('bootcamp'):
        user_facade.promote_bootcamper(user, 'unknown')
    else:
        raise ValueError(f'{slug} should contain webdev or membership or data-science')
コード例 #8
0
 def make_member(self, request, queryset):
     from pythonpro.domain import user_facade
     for user in queryset:
         user_facade.promote_member(user, 'django_admin')