#shy_payment-extradata
1 messages ¡ Page 1 of 1 (latest)
đ 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/1245792619100110868
đ Have more to share? Add details, code, screenshots, videos, etc. below.
Hey @celest ridge ! I'm happy to help! Can you clarify what part you're blocked on right now?
yes yes one moment
heres how my submissions are working currently:
I have a jsonlist created and saved that looks like this
they get saved like this
function save_cornhole_registration() {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['cornhole_registration'])) {
global $wpdb;
$table_name = $wpdb->prefix . 'cornhole_registrations';
$data = json_decode(stripslashes($_POST['cornhole_registration']), true);
// Log received data
error_log('Received data: ' . print_r($data, true));
if (!isset($data[0]['email'], $data[0]['firstName'], $data[0]['lastName'], $data[0]['selectedItems'], $data[0]['dataSharing'])) {
wp_send_json_error('Required fields are missing.');
return;
}
foreach ($data as $registration) {
foreach ($registration['selectedItems'] as $item) {
// Determine the lower tier for doubles events
$tier = '';
if (isset($item['player1Tier'], $item['player2Tier'])) {
$tier = min($item['player1Tier'], $item['player2Tier']);
} else {
$tier = isset($item['tier']) ? sanitize_text_field($item['tier']) : '';
}
// Set manually_verify based on PPR
$manually_verify = $item['tier'] === 'Tier 0' ? 'yes' : 'no';
$result = $wpdb->insert(
$table_name,
[
'event_name' => sanitize_text_field($item['name']),
'email' => sanitize_email($registration['email']),
'first_name' => sanitize_text_field($registration['firstName']),
'last_name' => sanitize_text_field($registration['lastName']),
'tier' => $tier,
'player1_first_name' => sanitize_text_field($registration['firstName']),
'player1_last_name' => sanitize_text_field($registration['lastName']),
'player1_email' => sanitize_email($registration['email']),
'player2_first_name' => isset($item['player2FirstName']) ? sanitize_text_field($item['player2FirstName']) : '',
'player2_last_name' => isset($item['player2LastName']) ? sanitize_text_field($item['player2LastName']) : '',
'player2_email' => isset($item['player2Email']) ? sanitize_email($item['player2Email']) : '',
'data_sharing' => sanitize_text_field($registration['dataSharing']),
'manually_verify' => $manually_verify,
]
);
if ($result === false) {
wp_send_json_error('Database insert failed: ' . $wpdb->last_error);
return;
}
}
}
wp_send_json_success('Registration saved successfully.');
} else {
wp_send_json_error('Invalid request.');
}
}
add_action('wp_ajax_save_cornhole_registration', 'save_cornhole_registration');
add_action('wp_ajax_nopriv_save_cornhole_registration', 'save_cornhole_registration');
ill get to the stripe in a second
Let's focus on the exact question about Stripe. All of this is too specific about your plugin so I'll just ignore all of that for now
function displayFinalData() {
console.log('Final Form Data:', finalFormData);
// Display the order summary
const orderSummaryList = document.getElementById('order-summary-list');
orderSummaryList.innerHTML = '';
selectedItems.forEach(item => {
const teammate = item.player2FirstName ? ` (Teammate: ${item.player2FirstName} ${item.player2LastName})` : '';
orderSummaryList.innerHTML += `<li>${item.name} (${item.tier ? item.tier : 'No tier'}): $${item.cost}${teammate}</li>`;
});
const totalCostInDollars = (totalCostInCents / 100).toFixed(2);
document.getElementById('order-total').innerHTML = `<strong>Total: $${totalCostInDollars}</strong>`;
document.getElementById('order-summary').style.display = 'block';
// Hide additional player information forms, Overall PPR, and Total Cost
document.getElementById('additional-form').style.display = 'none';
document.getElementById('ppr-message').style.display = 'none';
document.getElementById('total-cost').style.display = 'none';
// AJAX call to fetch the button HTML
fetch(`${window.location.origin}/wp-admin/admin-ajax.php?action=create_stripe_button&totalCost=${totalCostInDollars}`)
.then(response => response.text())
.then(html => {
document.getElementById('BuyNowButton').innerHTML = html;
document.getElementById('stripe-checkout').style.display = 'block';
// Add event listener to the button
document.getElementById('BuyNowButton').querySelector('button').addEventListener('click', handleStripeCheckout);
})
.catch(error => console.error('Error:', error));
}
this is what im using for stripe payments rn
it works fine the payments go through
Sorry all f that is client-side code in Javascript
Let's pause for a sec. You want to do some reconciliation. This usually is done by writing a webhook handler in PHP that listens to Events such as payment_intent.succeeded and the storing the information you need at that point.
yes I was wondering if you knew how to save the data or even push the data in my json list to stripe to be saved or dealt with after the payment suceeds
Ive tried adding a listener before I just get weird erorrs
and ive spent aroudn 3 hours trying to fix it and it just wont work
Okay so you want the JSON/info to be on the PaymentIntent when it's created so that when you get the payment_intent.succeeded Event it's still there?
Sorry I'm still barely grasping what you seem to nbe asking right now
essentially, i have a registration form that takes in a bunch of data. I want the data to be sent to a database only after the payment is completed. I have a stripe webhook that does the listening and can get when a payment is completed, im having trouble with after and going back to submit the data i wanted
Ah gotcha. I recommend changing your approach entirely. Way easier to save upfront before the payment and have a column saying pending or similar and update that column to succeeded after the payment succeeds than try to pass around the JSON
oh as in have a field in my database that says payment-status?
yes that's what I would do. I mean you can store some info on the PaymentIntent's metadata and then get that back in the payment_intent.succeeded Event but that seems much more complex
shy_payment-extradata
id have to find a way to edit the database with the data storage method im using
i appreciate the help im still just sorta lost on how to use the webhook in general for this
Okay so let's focus on that for a bit. What exactly is your issue?
im not sure of how calling the webhook listener in client side works
Ah gotcha. That's normal, they basically have absolutely nothing to do with each other
Whenever something happens in your Stripe account such as a payment succeeded, a Payout being created, a Refund failing, etc. then Stripe will generate an Event object to describe what happened. For example if you call the Create Customer API it creates a Customer so we create a customer.created Event.
If you then call the Update Customer API then we will generate the Event customer.updated that tells you what changed on the Customer.
Each Event will be sent to the WebhookEndpoint's URL that you configure in your account. When that happens we (Stripe) make an HTTP POST request to that URL and send the JSON of the Event.
So none of this is related to your Javascript client-side code in any way (other than you do things that can trigger Events)
ah so we cannot even feed stripe data to carry over?
@celest ridge not from the client-side code no. But you can from your server. The PHP code where you create the PaymentIntent
How am I suppose to talk to customer service when you delete my thread?
Your thread won't be deleted, it'll stay public and you can access it here: https://discord.com/channels/841573134531821608/1245792619100110868
so i need a payintent
a payintent is not a thing. I assume you meant PaymentIntent?
and yes you do, that's how you accept a payment in the first place on Stripe
well i mean the way my button is hooked up it just takes you to an external website for checkout and we still recieve payments
Okay so you are using Stripe Checkout?
yes yes
Okay so you create a Checkout Session server-side in PHP using our API https://docs.stripe.com/api/checkout/sessions/create?
and then i can feed my json list to it?
Can you answer my question first? Sorry I want to ignore your JSON list because you seem a bit lost
oh no im pretty sure its client sided
function displayFinalData() {
console.log('Final Form Data:', finalFormData);
// Display the order summary
const orderSummaryList = document.getElementById('order-summary-list');
orderSummaryList.innerHTML = '';
selectedItems.forEach(item => {
const teammate = item.player2FirstName ? ` (Teammate: ${item.player2FirstName} ${item.player2LastName})` : '';
orderSummaryList.innerHTML += `<li>${item.name} (${item.tier ? item.tier : 'No tier'}): $${item.cost}${teammate}</li>`;
});
const totalCostInDollars = (totalCostInCents / 100).toFixed(2);
document.getElementById('order-total').innerHTML = `<strong>Total: $${totalCostInDollars}</strong>`;
document.getElementById('order-summary').style.display = 'block';
// Hide additional player information forms, Overall PPR, and Total Cost
document.getElementById('additional-form').style.display = 'none';
document.getElementById('ppr-message').style.display = 'none';
document.getElementById('total-cost').style.display = 'none';
// Show the Stripe checkout button
document.getElementById('stripe-checkout').style.display = 'block';
}
yeah I don't understand that code at all. This is purely your own code and not Stripe code
sorry yes its all client sided using a plugin that uses a shortcode
for a button
I'm sorry I need you to share the relevant code for Stripe though