#moon-boy_code
1 messages Β· Page 1 of 1 (latest)
π 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/1315756901061099613
π Have more to share? Add more details, code, screenshots, videos, etc. below.
Error:
Checkout.js:
complete.js:
completePayment.php
<?php
require 'config.php';
header('Content-Type: application/json');
$data = json_decode(file_get_contents('php://input'), true);
if (!$data) {
echo json_encode(['success' => false, 'message' => 'Invalid request']);
exit;
}
try {
// Extract data
$fullName = $data['fullName'];
$address = $data['address'];
$postcode = $data['postcode'];
$city = $data['city'];
$state = $data['state'];
$country = $data['country'];
$phone = $data['phone'];
$items = $data['items'];
// Create SQL query to save data
$stmt = $pdo->prepare('INSERT INTO payments (full_name, address, postcode, city, state, country, phone, items) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->execute([$fullName, $address, $postcode, $city, $state, $country, $phone, json_encode($items)]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
create.php:
<?php
require_once '../vendor/autoload.php';
require_once 'secrets.php';
$stripe = new \Stripe\StripeClient($stripeSecretKey);
function calculateOrderAmount(array $items): int {
// Calculate the order total on the server to prevent
// people from directly manipulating the amount on the client
$total = 0;
foreach($items as $item) {
$total += $item->amount;
}
return $total;
}
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
// Create a PaymentIntent with amount and currency
$paymentIntent = $stripe->paymentIntents->create([
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'sek',
// In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
'automatic_payment_methods' => [
'enabled' => true,
],
]);
$output = [
'clientSecret' => $paymentIntent->client_secret,
// [DEV]: For demo purposes only, you should avoid exposing the PaymentIntent ID in the client-side code.
'dpmCheckerLink' => "https://dashboard.stripe.com/settings/payment_methods/review?transaction_id={$paymentIntent->id}",
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Do you have a published test page using your test api keys we can look at to repro?
Yes, I removed them just because I don't want to share them.
Where can I send you the repro?
You don't want to send in here?
I don't want to share my keys
No I don't want you to share the keys
Just a link to a test page where I can repro
Never share your keys with anyone if they ask
That's sensitive data
π
Just uploaded everything to github because I'm using php
No do you have a published test page
I don't want the source code
Just a link to a test page I can go to to repro
This uses your test keys?
I just got a 500 error when I clicked complete payment
So you'll need to check your server logs
Yes
Is this your code? Or are you trying to work with someone else's code or adapt theirs to your usecase?
It's my code for my website.
I followed the stripe docs
I don't understand the problem
When i clicked the pay button on your site I got a 500 error. That means there was an error on the request clicking that button makes to your server
To figure out what the problem was, you'll need to check the server logs
That will tell you what broke
Ok, I will see what I can find.
Iβm sorry, I canβt figure it out. Is it possible if I pay you or someone else in the stripe team that can do it for me because I have been sitting with this for about a year now, trying different integrations and not figuring anything out?
Stripe doesn't build integrations directly for you, but you can find developer partners we work with here:
We have partner agencies in a directory here: https://stripe.partners/implementation-specialization?f_specialization=services-implementation
And certified solo developers here: https://stripe.credential.net/
Looking again at the erro you shared here, it looks like you might be making an API request to your own API (perhaps to get a payment intent?) that is return an HTML error page instead of a JSON response as expected