studybuffalo / django-helcim

A Django-based integration with the Helcim Commerce API
GNU General Public License v3.0
4 stars 5 forks source link

Response field not in FROM_API_FIELDS: csrfmiddlewaretoken #268

Open desphixs opened 1 year ago

desphixs commented 1 year ago

I am trying to integrate Helcim Payment Method in django, i have written all the logic to make the payment, when i open up the page page, fill in my cards detail and amount to be paid and hit the submit button, it shows processing then refresh the page, then in the terminal i got this error that says Response field not in FROM_API_FIELDS: csrfmiddlewaretoken.

I know this error is related to a csrf issue, i have added csrf_token to my form and even added csrf_exempt to the View but the error keeps showing up, i would really appreciate it if i can get some guide on what to look for or do concerning this issue.

This is the view to process the payment


@method_decorator(csrf_exempt, name='dispatch')
class HelcimJSPaymentView(HelcimJSMixin, FormView):
    form_class = HelcimjsPaymentForm
    success_url = 'example:complete'
    template_name = 'core/example_app/helcimjs_payment_details.html'

    def get_success_url(self, **kwargs): # pylint: disable=arguments-differ
        """Returns the success URL."""
        return reverse_lazy(self.success_url, kwargs=kwargs)

    def post(self, request, *args, **kwargs):
        """Handles remaining processing after Helcim.js processing."""
        response = HelcimJSResponse(
            response=request.POST, save_token=True, django_user=request.user
        )

        if response.is_valid():
            # NOTE: the type of transaction made by Helcim.js is determined by
            # the Helcim.js configuration. You will need to decide on the
            # proper "record" method to use for your situation.
            transaction, token = response.record_purchase()

            # NOTE: you generally wouldn't want to transmit these
            # details as query parameters; this is just done to
            # simplify this sandbox example
            url = '{}?transaction_type={}&transaction={}&token={}'.format(
                self.get_success_url(),
                'helcimjs',
                transaction.id,
                token.id,
            )
            return HttpResponseRedirect(url)

        # Invalid form submission/payment - render payment details again
        # TODO: add some basic initial data to the form
        form = self.get_form()

        return self.form_invalid(form)
pikashie commented 1 year ago

Have you fixed the issue yet, i have been trying to fix it for over a month and still no luck, do you have any idea if the error is from the django-helcim package https://pypi.org/project/django-helcim/ or if it's from the API, i am using the helcim.js lib??

desphixs commented 1 year ago

I have contacted developer support but still the issue persist, I'm thinking it's an API error.