Giter Club home page Giter Club logo

Comments (1)

EduardoZepeda avatar EduardoZepeda commented on August 23, 2024

Hello, sorry for the late response, because of some reason I never noticed this issue notification neither the other one.

As you stated, I'm seeing that the self.create_payment is being created unconditionally. You're totally right, two preferences aren't needed.

I'm using this library along with a customized version of an old saleor version. I think the way saleor handled the payments allowed the tricky behavior to pass without causing any trouble. But let's change it so it can be used in any implementation of django-payments.

How about something like this?

def get_form(self, payment: BasePayment) -> None:
        if not payment.id:
            payment_data = self.create_payment(payment)
            redirect_to = self.get_value_from_response(
                payment_data, self.init_point)
            payment.change_status(PaymentStatus.WAITING)
            payment.save()
            raise RedirectNeeded(redirect_to)
        redirect_to = self.get_value_from_response(json.loads(payment.extra_data), self.init_point)
        raise RedirectNeeded(redirect_to)

If there is not payment.id (the payment has never been saved) we send the preference to mercadopago via create_payment, we get the the full response from mercadopago and save it in payment.extra_data, which contains the required payment url in "init_point" key. If there is a payment.id (a preference was previously created) we simply redirect the user to the same payment url we received from mercadopago response.

It appears to work, what do you think about it? I may be forget something.

from django-payments-mercadopago.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.