Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/www/public/stripe-payment/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/www/public/stripe-payment/payment.js
const stripe = Stripe("pk_live_51PxVaOGmxCnMwmmLLYmgMhI1Xbvz7pxWTl502Y34kGWt3NLcPT1P7zg4Q5j6YSFFKCzzRs7WNFBZ418ABl8Tb5Kz00jxKLNwUt"); // publishable key
console.log(stripe);
const elements = stripe.elements();

const card = elements.create("card");

card.mount("#card-element");

const form = document.getElementById("payment-form");

form.addEventListener("submit", async (e) => {

    e.preventDefault();

    document.getElementById("payBtn").disabled = true;

    // create payment method
    const { paymentMethod, error } = await stripe.createPaymentMethod({
        type: "card",
        card: card
    });

    if (error) {
        document.getElementById("error-message").innerText = error.message;
        return;
    }

    // get client secret from server

    // const response = await fetch("create_payment_intent.php", {
    //     method: "POST",
    //     headers: {
    //         "Content-Type": "application/json",
    //         "Authorization": "Bearer wMXtvZtN4GmZNh0rDTPxU5UFMwMheQRkwMpV6vAUAgnWCi2u8cTUER5oQg0i"
    //     },
    //     body: JSON.stringify({
    //         paymentMethodId: paymentMethod.id
    //     })
    // });

    const response = await fetch("https://test.tradze.com/api/create-payment-intent-with-payout", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer wMXtvZtN4GmZNh0rDTPxU5UFMwMheQRkwMpV6vAUAgnWCi2u8cTUER5oQg0i"
        },
        body: JSON.stringify({
            paymentMethodId: paymentMethod.id
        }),
        credentials: "include"
    });

    const data = await response.json();
    console.log(data);
    if (data.error) {
        alert(data.error);
        return;
    }

    // confirm payment
    const result = await stripe.confirmCardPayment(data.client_secret, {
        payment_method: paymentMethod.id
    });

    if (result.error) {

        alert(result.error.message);

    } else {
        if (result.paymentIntent.status === "succeeded") {
            alert("Payment Success ✅");
        }

        // if (result.paymentIntent.status === "requires_capture") {

        //     await fetch("process_payment.php", {
        //         method: "POST",
        //         headers: {
        //             "Content-Type": "application/json"
        //         },
        //         body: JSON.stringify({
        //             paymentIntentId: result.paymentIntent.id,
        //             paymentMethodId: paymentMethod.id
        //         })
        //     });

        //     alert("Payment Success");
        // }
    }

});

ZeroDay Forums Mini