#joeeyireland_code

1 messages ยท Page 1 of 1 (latest)

versed geyserBOT
obtuse meadowBOT
#

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.

versed geyserBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1245026909713207441

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

leaden briar
#
        var cardStripe = Stripe('<?php echo $publishable_key; ?>');
        const cardOptions = {
        mode: 'payment',
        amount: 1000,
        currency: 'gbp',
        paymentMethodTypes: ['card']
        };

        const elements = cardStripe.elements(cardOptions);

        const cardPaymentElement = elements.create('payment', {
        layout: {
            type: 'tabs',
            defaultCollapsed: false
        }
        });
        cardPaymentElement.mount('#card-payment-element');

        const cardform = document.getElementById('donation-form-single');
    </script>```

```if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['payment_method']) && $_POST['payment_method'] === 'Single Donation') {

        $secret_key = get_option('stripe_secret_key');
        \Stripe\Stripe::setApiKey($secret_key);

        $amount_in_pence = (floatval($amount) * 100);
        
        $payment_intent = \Stripe\PaymentIntent::create([
            'amount' => $amount_in_pence,
            'currency' => 'gbp',
            'payment_method' => 'card',
            'payment_method_types' => ['card'],
            'metadata' => [
                'title' => $data['title'],
                'first_name' => $data['first_name'],
                'last_name' => $data['last_name'],
                'email' => $data['email'],
                'phone_number' => $data['phone_number'],
                'address_line_1' => $data['address_line_1'],
                'address_line_2' => $data['address_line_2'],
                'postcode' => $data['postcode'],
                'why_donating' => $data['why_donating'],
                'comments' => $data['comments'],
                'contact' => $data['contact'],
                'gift_aid' => $data['gift_aid']
            ]
        ]);

        echo json_encode(array('client_secret' => $payment_intent->client_secret));
    }```
#

it creates the intent in the test transaction tab but not sure how to finish it so it takes the data from the card element form and processes it

leaden briar
#

do i need to make the intent as soon as the page is loaded instead of on form post in php because seems like ill get alot of incompletes if a user comes on the donate page and then leaves

quaint laurel
leaden briar
#

i have followed this, the form shows and when i hit submit then php creates the intent but i dont know how to link the JS card details section to it

quaint laurel
#

Take a look at Step 5, it shows how to submit the payment, including passing your instance of elements when calling confirmPayment

leaden briar
#

yep doing that code which works but am getting an error on here const res = await fetch("/create-intent", {
method: "POST",
});

#

Failed to load resource: the server responded with a status of 403 ()

#

Unhandled Promise Rejection: SyntaxError: The string did not match the expected pattern.

quaint laurel
#

Hm, seems like your server wasn't happy with what it was sent, or there is some sort of authentication requirement in place that isn't being satisfied.

leaden briar
#

i am on a development website that to access needs a username and password could that be why ?

versed geyserBOT
obtuse meadowBOT
quaint laurel
#

Quite possibly, it's hard to say, we don't have insight into your server. If it's responding with a 403 (Forbidden) though, I think it's very likely.

leaden briar
#

i dont have anything on my server for /create-intent though as am using pure html for my form and js for the script to get the elements, is there a better way to do this in php on submission of the form ?