Example #1
0
def payment_status_listener(mocker):
    mock = mocker.Mock()
    facade.add_payment_status_changed(mock)
    yield mock
    facade._payment_status_changed_listeners.pop()
        status = payment.status()
        if status == django_pagarme_facade.PAID:
            user = payment.user
            if payment.payment_method == django_pagarme_facade.BOLETO:
                email_marketing_facade.remove_tags.delay(
                    user.email, user.id, f'{slug}-boleto')
            _promote(user, slug)
        elif status == django_pagarme_facade.WAITING_PAYMENT:
            user = payment.user
            email_marketing_facade.tag_as.delay(user.email, user.id,
                                                f'{slug}-boleto')


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 or data-science')


def payment_change_handler(payment_id):
    payment_handler_task.delay(payment_id)


django_pagarme_facade.add_payment_status_changed(payment_change_handler)
Example #3
0
    User = get_user_model()
    customer = pagarme_transaction['customer']
    try:
        return User.objects.get(email=customer['email'])
    except User.DoesNotExist:
        return User.objects.create(first_name=customer['name'],
                                   email=customer['email'])


facade.set_user_factory(user_factory)


def print_contact_info(name, email, phone, payment_item_slug, user=None):
    print('Contact Data:', name, email, phone, payment_item_slug, user)


facade.add_contact_info_listener(print_contact_info)


def print_payment_id(payment_id):
    payment = facade.find_payment(payment_id)
    print(payment, payment.status())


facade.add_payment_status_changed(print_payment_id)


def home(request):
    ctx = {'payment_items': facade.list_payment_item_configs()}
    return render(request, 'home.html', ctx)