#joeeyireland_code
1 messages ยท Page 1 of 1 (latest)
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.
- joeeyireland_api, 5 hours ago, 15 messages
- joeeyireland_api, 6 days ago, 15 messages
๐ 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.
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
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
Hi ๐ you can postpone creating the intent until the time of submission if you like, our full guide for building a flow like that can be found here:
https://docs.stripe.com/payments/accept-a-payment-deferred
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
Take a look at Step 5, it shows how to submit the payment, including passing your instance of elements when calling confirmPayment
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.
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.
i am on a development website that to access needs a username and password could that be why ?
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.
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 ?