Exemple #1
0
def resp_no_user(client, pagarme_responses):
    def factory(pagarme_transaction):
        raise facade.ImpossibleUserCreation()

    facade.set_user_factory(factory)
    yield client.get(reverse('django_pagarme:capture', kwargs={'token': TOKEN}))
    facade.set_user_factory(facade._default_factory)
def resp_no_user(client, pagarme_responses, payment_item):
    def factory(pagarme_transaction):
        raise facade.ImpossibleUserCreation()

    facade.set_user_factory(factory)
    yield client.get(
        reverse('django_pagarme:capture',
                kwargs={
                    'token': TRANSACTION_ID,
                    'slug': payment_item.slug
                }))
    facade.set_user_factory(facade._default_factory)
def refused_resp(client, payment_item, payment_status_listener,
                 raw_refused_post, refused_transaction_signature, user):
    # this user is not logged, will be used as return of factory function
    factory_user = user

    def factory(pagarme_transaction):
        return factory_user

    facade.set_user_factory(factory)
    yield _make_signed_post(client, payment_item, raw_refused_post,
                            refused_transaction_signature)
    # returning factory to original function
    facade._user_factory = facade._default_factory
Exemple #4
0
def resp_user_factory(client, pagarme_responses, logged_user, captured_json):
    # this user is not logged, will be used as return of factory function
    factory_user = logged_user

    def factory(pagarme_transaction):
        assert pagarme_transaction == captured_json
        return factory_user

    facade.set_user_factory(factory)

    yield client.get(reverse('django_pagarme:capture', kwargs={'token': TOKEN}))
    # returning factory to original function
    facade._user_factory = facade._default_factory
        user_id = None
    email_marketing_facade.create_or_update_with_no_role.delay(
        name, email, f'{payment_item_slug}-form', id=user_id, phone=str(phone))


django_pagarme_facade.add_contact_info_listener(contact_info_listener)


def user_factory(pagarme_transaction):
    customer = pagarme_transaction['customer']
    customer_email = customer['email'].lower()
    customer_first_name = customer['name'].split()[0]
    return user_facade.force_register_lead(customer_first_name, customer_email)


django_pagarme_facade.set_user_factory(user_factory)

GENERATED_BOLETO_TAG = 'generated-boleto'


@shared_task()
def payment_handler_task(payment_id):
    payment = django_pagarme_facade.find_payment(payment_id)
    try:
        slug = payment.first_item_slug()
    except django_pagarme_facade.PagarmePaymentItemDoesNotExist:
        pass  # no need to handle payment with no Item
    else:
        status = payment.status()
        if status == django_pagarme_facade.PAID:
            user = payment.user
from django.shortcuts import render

from django_pagarme import facade


def user_factory(pagarme_transaction):
    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)