#joeeyireland_error

1 messages ¡ Page 1 of 1 (latest)

ruby hollowBOT
icy wolfBOT
#

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.

ruby hollowBOT
#

👋 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/1245480051584274464

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

digital raft
#
            try {
                const amount = getAmount();
                if (!amount) {
                    console.error('Amount not specified.');
                    return;
                }

                const amountInPence = Math.round(amount * 100);

                const response = await fetch("/wp-content/plugins/stripe-donation-plugin/create.php", {
                    method: "POST",
                    headers: { "Content-Type": "application/json" },
                    body: JSON.stringify({ amount: amountInPence, payment_method_types: ['bacs_debit'] })
                });

                const rawText = await response.text();
                console.log('Raw Response:', rawText);

                const data = JSON.parse(rawText);
                console.log('Parsed Data:', data);

                const client_secret = data.clientSecret || data.client_secret;
                console.log('Client Secret:', client_secret);

                return client_secret;
            } catch (error) {
                console.error('Error:', error);
                throw new Error('Initialization failed');
            }
        }```
#
CREATE.PHP
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once(__DIR__ . '/stripe-php/init.php');
require_once (__DIR__ . '/secrets.php');

$stripe = new \Stripe\StripeClient($stripeSecretKey);

header('Content-Type: application/json');

try {
    // Retrieve JSON from POST body
    $jsonStr = file_get_contents('php://input');
    $jsonObj = json_decode($jsonStr);

    // Check if amount and currency are set
    if (!isset($jsonObj->amount)) {
        throw new Exception('Amount is not set');
    }

    // Create a PaymentIntent with amount and currency
    $paymentIntent = $stripe->paymentIntents->create([
        'amount' => $jsonObj->amount,
        'currency' => 'gbp',
        'payment_method_types' => $jsonObj->payment_method_types
    ]);

    $output = [
        'client_secret' => $paymentIntent->client_secret,
    ];

    echo json_encode($output);
} 
catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}```
#

the form shows the DD element and whne i submit it asks me to confirm the dd in the modal but then the error shows like the attached SS

#

when i go into the transaction on stripe dashboard it says allowed is only card

cobalt linden
#

Can you paste the code that instantiates and mounts the Element?

digital raft
#
        const directDebitOptions = {
        mode: 'payment',
        amount: 800,
        currency: 'gbp',
        paymentMethodTypes: ['bacs_debit']
        };

        const ddelements = directDebitStripe.elements(directDebitOptions);

        const directDebitPaymentElement = ddelements.create('payment', {
            layout: {
                type: 'tabs',
                defaultCollapsed: false
            },
        });
        directDebitPaymentElement.mount('#dd-payment-element');```
cobalt linden
#

Where do you create the variable payment_method_types on the server-side? Like, you pass payment_method_types as a parameter when you create the Payment Intent, but I don't see where that's actually being instantiated.

digital raft
#

const response = await fetch("/wp-content/plugins/stripe-donation-plugin/create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ amount: amountInPence, payment_method_types: ['bacs_debit'] })
});

#

I was that JSON to create.php

cobalt linden
#

Ahhh, got it. So you're passing payment_method_types: 'bacs_debit' from client to server when you fetch() the function for creating a Payment Intent.

Can you grab a Payment Intent ID? It seems like something might be going wrong with how the Payment Intent is created.

digital raft
#

pi_3PLtRIA63eAAyRBb1bhJ5vfO

#

is the latest one

#

i can see in the request params it thinks i past card

cobalt linden
digital raft
#

ok just gonna try something

#

pi_3PLtm3A63eAAyRBb1Ouh89sC

#

it was because i have 2 forms on the same page which then means i had 2 initalize methods so i changed them

cobalt linden
#

Alright, so it looks like it's working now, yes?

digital raft
#

yes mate many thanks for you help