#moon-boy_code

1 messages Β· Page 1 of 1 (latest)

red marshBOT
#

πŸ‘‹ 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.

limber yacht
#

Error:

#

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()]);
}

limpid holly
#

Do you have a published test page using your test api keys we can look at to repro?

limber yacht
#

Where can I send you the repro?

limpid holly
#

You don't want to send in here?

limber yacht
#

I don't want to share my keys

limpid holly
#

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

limber yacht
#

πŸ‘

#

Just uploaded everything to github because I'm using php

limpid holly
#

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

limber yacht
#

ok

#

Should I just upload it to my domain?

limpid holly
#

How you publish is up to you

#

I just need a url I can go to to repro

limber yacht
#

Ok

#

It's going to take up to 3 minutes

#

@limpid holly Here you go

limpid holly
#

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

limber yacht
limpid holly
#

I got a 500 error, so you'll need to check

#

This will need debugging on your end

limber yacht
#

I'm as* at this 😭

#

I don't understand anything

limpid holly
#

Is this your code? Or are you trying to work with someone else's code or adapt theirs to your usecase?

limber yacht
#

It's my code for my website.

limpid holly
#

Ok

#

What guide did you follow to implement?

#

Which piece do you not understand

limber yacht
#

I followed the stripe docs

limpid holly
#

which one

limber yacht
limber yacht
limpid holly
#

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

limber yacht
#

Ok, I will see what I can find.

limber yacht
#

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?

red marshBOT
agile bloom
agile bloom
# limber yacht **Error:**

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