#meesterdjango_api

1 messages ยท Page 1 of 1 (latest)

rain ibexBOT
lapis willowBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

rain ibexBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1260293832755511408

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

dim leaf
tribal bronze
#

What are you using to accept a Payment Method?

dim leaf
tribal bronze
#

Payment Element? Checkout?

dim leaf
#

i use a checkout page for that im pretty sure

tribal bronze
#

No, that looks like the Card Element, which is deprecated, but should still function if setup properly. Any reason you're using that over the Payment Element?

dim leaf
#

flow is as follows : shopping cart -> checkout_page -> 'payment_method'_setup.html -> checkout_success_page or checkout_failed_page depending on answer

#

to be fair im working on a project that i didnt build. The person who build it used alot of old apis and packages but the webshop is accually pretty huge so they wanted to add some payment methods

#

im simply working with what i have got

#

so i can use payment element rather then card-element? this should fix the issue u think ?

#

never ever have i worked with stripe so hence the unfamiliarity with its way of working

tribal bronze
#

There will be a lot of refactoring in your code, but at the end of it, you'll have something that can accept other payment methods and which is a bit more future-proof

dim leaf
#

doesnt seem a valid option for me to be honest. It doesnt fit in the way the checkout flows. I will have to do alot more than just refactoring. The way my intents are being created after the form is submitted makes it almost impossible to even start with integrating the payment element since i need a client_secret. im still not getting my head around the fact that even the card-element doesnt work at all

tribal bronze
rain ibexBOT
dim leaf
#

because for payment element i need to update the submit handler so that it works totally different but i handle all of this on the backend view for the checkout page and a seperate .py file to create the intents when the form is submitted

#

and in documentation its client sided ?

gaunt dome
#

Hi there
Taking over here as two-shoes needs to step away

#

What sort of PaymentMethods are you trying to integrate?

dim leaf
#

i will send you a screen shot wait

#

at the screen shot u see i integrated the different methods in radio buttons. this is all backend nothing client side

#

this is an example of a bancontact_setup.html wich processes the payment and redirects a user to the payment page of bacontact.

#

so i never created this payment flow to begin with and to just change it completely kinda scares me alot because this is a live webshop

gaunt dome
dim leaf
#

For both bancontact and ideal the integration works as it is

#

its just for card that im having trouble

gaunt dome
#

Are you trying to integrate Card Element or is this an existing integration that used CardElement?

dim leaf
#

so to clarify i have two working methods : bancontact and ideal wich both redirect and complete payments correctly on there bancontact_setup.html and ideal_setup.html

#

this is what i added to it yes

#

i just followed a old guide i guess

gaunt dome
#

Gotcha. Do you have a link to the guide you followed?

We generally recommend using the latest elements for security as well as scalability reasons.

dim leaf
#

configuration wise and server sided everything should be correct the main issue im facing is : completing the card payment and redirecting the user to the payment page on the card_setup.html

#

and yeah i do understand that and i am of the same believe. However the person who owns the webshop isnt really that mindfull about all the trouble older integrations bring with them.

#

money money money

#

thats all they can see

#

they never intented to go international

#

but all of a sudden they just did

#

and now they are pushing me to add these payment methods in the existing code

#

almost impossible tbh

gaunt dome
#

What happens if you change confirmPayment to confirmCardPayment and call something like

    payment_method: {
      card: elements.getElement(CardElement)
    }
  });```
dim leaf
#

im confused where should i call the await ? in the card_setup.html or checkout?

gaunt dome
#

It should be in your JS code...

dim leaf
#

yeah but even that is not the way the previous person worked. They added inline scripts in different pages ...

#

im losing more hair the more im understanding that the last person just freestyled a little and im stuck with this mess

#

<script>
var stripe = Stripe('{{ stripe_public_key }}');

// Redirects to Bancontact website or app
stripe.confirmBancontactPayment(
'{{ payment_intent }}',
{
    payment_method: {
    billing_details: {
        name: "{{ name }}"
    }
    },
    return_url: '{{ root_url }}/shop/checkout/processing/?order={{ order.id }}',
}
).then(function(result) {
if (result.error) {
}
});

</script>

#

thats the js for bancontact_setup

#

so you have an idea on how i confirm it

#

because i just think you dont get how the code is build

#

<script>
document.addEventListener("DOMContentLoaded", function() {
var stripe = window.stripeInstance;
var elements = window.elementsInstance;

    stripe.confirmPayment({
        elements: elements,
        clientSecret: "{{ payment_intent }}",
        confirmParams: {
            return_url: '{{ root_url }}/shop/checkout/processing/?order={{ order.id }}',
        },
    }).then(function(result) {
        if (result.error) {
            console.error("Error code:", result.error.code);
            console.error("Error message:", result.error.message);
            console.error("Error type:", result.error.type);
            console.error("Error payment_intent:", result.error.payment_intent);
            alert(result.error.message); // Display the error to the user
        }
    });
});

</script>

#

this is js for card_setup

#

and this is wrong

#

i dont seem to find a working way for : confirmCardPayment()

#

If i would change it to for example this : <script>
document.addEventListener("DOMContentLoaded", function() {
var stripe = Stripe('{{ stripe_public_key }}');

    var elements = window.elementsInstance;

    stripe.confirmCardPayment("{{ payment_intent }}",
    {
        payment_method: {
        billing_details: {
            name: "{{ name }}"
        }
        },
        return_url: '{{ root_url }}/shop/checkout/processing/?order={{ order.id }}',
    }
    ).then(function(result) {
        if (result.error) {
            console.error("Error code:", result.error.code);
            console.error("Error message:", result.error.message);
            console.error("Error type:", result.error.type);
            console.error("Error payment_intent:", result.error.payment_intent);
            alert(result.error.message); // Display the error to the user
        }
    });
});

</script>

#

then i get an error that looks like this : Uncaught IntegrationError: Missing value for confirmCardPayment: payment_method.card should be an object or element.

#

but then comes the main issue i cannot pass the card-element instance to the setup page. Objet keeps coming up as empty or null

gaunt dome
dim leaf
#

elements.getElement(CardElement) = null

gaunt dome
#

Ah that's because CardElement in that example is a variable..

dim leaf
#

like i said i dont think u get the way the good is setup. Ill just wait for stripe support to finish there code review because im losing it slowly ... Thanks for the help !

gaunt dome
#

Your code sets var elements = window.elementsInstance;

So running above line should get you the card element instance on the page unless every reference to it keeps getting destoryed..

dim leaf
#

its not youre traditional code

#

its django

#

wich is python

#

front and backend

#

with html templates

#

yeah still it gives me null

#

var elemets = window.elementsInstance = null on the setup page

#

eventhough i set it globally on the checkout

#

thats why it makes no sense to me

#

im trying to access this simple object and its just gone

#

and i cannot declare variables globally in html templates

#

so i have to make them in the backend

#

and pass them to the template

#

wich is not possible for the card-element

#

and it bugs me because for ideal i have for example this js : <script>
var stripe = Stripe('{{ stripe_public_key }}');

// Redirects to iDEAL website or app
stripe.confirmIdealPayment(
    '{{ payment_intent }}',
    {
        payment_method: {
            ideal: {},
            billing_details: {
                name: "{{ name }}"
            }
        },
        return_url: '{{ root_url }}/shop/checkout/processing/?order={{ order.id }}',
    }
).then(function(result) {
    if (result.error) {
        console.error(result.error.message);
        // Handle error here
    }
});

</script>

#

and that does work and redirect me to ideal payment page etc

gaunt dome
#

Because iDEAL doesn't really add any elements to the page.. It just redirects to third-party page where payment information is provided. Card Element is injected on the same page

dim leaf
#

jup exactly

#

thats why i have an issue with confirming card payments

#

because i have no access to the card elements

gaunt dome
#

Let me see if anyone on my team is familiar with persisting elements object over embedded html

dim leaf
#

i understand how stripe works and what every different methods expects but this small thing keeps preventing me from accepting the card payments.

#

and its just bcs its django with html templating

#

if it was for example

#

dajngo backend

#

and react frontend

#

i would have no issue

#

but its a pretty old school vanilla django webshop fully build in python / html and plain js

#

but its build this way because the webshop itself is build modulair so i can create multiple webshops with specific frontend and backend configurations

#

through wagtail

#

wich is a cms

#

thats why i cannot just start changing a huge part of the way the webshop works

#

this affects like 100+ webshops

#

because they are build modulair so this gives me less space to do special adjustmants or adaptations

gaunt dome
#

I've asked a teammate to take a look, we will respond as soon as we have something

dim leaf
#

no need to rush anything ! i sometimes have to let things sink in and most of the time overnight i come up with a solution

#

so we will fix this either way !!!

keen parrot
#

Hi there

#

Trying to catch up

#

Where is window.stripeInstance coming from?

#

Are you somehow rendering multiple templates on a page?