WhyNotHugo / django-mercadopago

⚠️ Deprecated. Use https://github.com/jazzband/django-payments/ instead.
ISC License
33 stars 12 forks source link

Could the MercadoPagoService class be customizable through settings.py ? #21

Open pwqw opened 5 years ago

pwqw commented 5 years ago

https://github.com/WhyNotHugo/django-mercadopago/blob/0cf8a43dce4f9097073993c4fc1ab9137c9c60d5/django_mercadopago/models.py#L20

I need to personalize some of this..

WhyNotHugo commented 5 years ago

I'm happy to discuss any changes/features that you might need, but you've given me absolutely NO information about what you're trying to do.

On Mon, Nov 4, 2019, at 15:55, Alexis Caffa wrote:

https://github.com/WhyNotHugo/django-mercadopago/blob/master/django_mercadopago/models.py#L20

I need to personalize some of this..

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/WhyNotHugo/django-mercadopago/issues/21?email_source=notifications&email_token=AAFSNOY5TEKOBUPFGI7PKXDQSAZV7A5CNFSM4JIUXWD2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HWT6BDA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSNO5EEJR5XX3A656OVZTQSAZV7ANCNFSM4JIUXWDQ.

-- Hugo Osvaldo Barrera

pwqw commented 4 years ago

This issue is related to a capability for create a MercadoPago Marketplace, in my case.

First of all, I need to use another token (obtained from a link to my account with the account of a third party).

The most practical, it would be to be able to use a custom class, set from the settings.py, as most libraries do.

Alternatively, I show you my solution, an inject-wrapper:

def apply_monkeypatch_to_mp_account(mp_account):
    def get_service(self):
        service = MP(self.third_party_related_account.mp_access_token)
        service.sandbox_mode(self.sandbox)
        return service
    setattr(mp_account.__class__, 'service', property(get_service))
    return mp_account

But.. I still can't size the amount of possibilities that would open just by admitting this configuration.

WhyNotHugo commented 4 years ago

Including it in settings is problematic since it would override all accounts in all environments (so payments made to any account would all go to the same one).

I've been looking at the docs, and it seems the simplest clean approach would be to:

I'll start fiddling with some bits of this. Does the general idea make sense to you? Do you see any problems with it, or me missing anything?

pwqw commented 4 years ago

Then it would be necessary to implement the task for the token refresh, which expires every 6 months. If it serves you as data, I am currently saving all this:

class MyAccount(models.Model):
    mp_account = models.OneToOneField(
        django_mercadopago.models.Account,
        on_delete=models.CASCADE,
        related_name='wallet_account',
        blank=True,
        null=True,
    )
    mp_public_key = models.CharField(
        verbose_name='Clave pública',
        help_text='La "Public key" dada por Mercado Pago',
        max_length=255,
        blank=True,
        null=True,
    )
    owner = models.ForeignKey(
        User,
        help_text='A quién le corresponde esta cuenta de Mercado Pago',
        related_name='accounts',
        on_delete=models.CASCADE,
        blank=True,
        null=True,
    )
    mp_user_id = models.IntegerField(
        verbose_name='Mercado Pago user_id',
        blank=True,
        null=True,
    )
    mp_access_token = models.CharField(
        verbose_name='Token de acceso',
        help_text='Token de acceso para marketplace',
        max_length=255,
        blank=True,
        null=True,
    )
    mp_token_type = models.CharField(
        verbose_name='Tipo de token',
        help_text='Tipo de access token',
        max_length=32,
        blank=True,
        null=True,
    )
    mp_expires_in = models.PositiveIntegerField(
        verbose_name='Expira en',
        help_text='Tiempo que expira el token',
        blank=True,
        null=True,
    )
    mp_scope = models.CharField(
        verbose_name='Permisos del token',
        help_text='Accesos brindados por el marketplace',
        max_length=255,
        blank=True,
        null=True,
    )
    mp_refresh_token = models.CharField(
        verbose_name='Token de refresco',
        help_text='Token para actualizar el token de acceso. Cada 6 meses se vence.',
        max_length=255,
        blank=True,
        null=True,
    )
WhyNotHugo commented 4 years ago

Haciéndo eso sigue siendo compatible con no-marketplaces?