#axelmora2011
1 messages · Page 1 of 1 (latest)
I see you updated your first message, having a look.
this is the create.php from the quickstart that is on my amazon ec2 instance:
<?php
require_once '../vendor/autoload.php';
require_once '../secrets.php';
$stripe = new \Stripe\StripeClient($stripeSecretKey);
function calculateOrderAmount(array $items): int {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// people from directly manipulating the amount on the client
return 1400;
}
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' => 'usd',
// 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,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
hi! that all seems sensible enough. I would try to add more logs and debug exactly what your server is sending back/what the app is receiving.
if you run this on a physical phone then https://developer.apple.com/documentation/foundation/url_loading_system/analyzing_http_traffic_with_instruments is super useful to see the exact network traffic but unfortuantely Apple doesn't support that in Simulator.app
I'm seeing this in my Xcode Output Pane:
View loaded, fetching payment intent.
Fetching Payment Intent
URL for Payment Intent: http://ec2-54-219-186-173.us-west-1.compute.amazonaws.com/create.php/create-payment-intent
Shopping Cart Content: ["items": [["id": "xl-shirt"]]]
HTTP Status Code: 500
Error parsing JSON: The data couldn’t be read because it isn’t in the correct format.
sounds like the PHP server returned a 500
try checking the logs for the server and/or your Stripe API request logs to see what might be happening
as a a guess — do you know what Composer is? did you set up the server to install the Composer dependencies (for require_once '../vendor/autoload.php' ) so that the Stripe libraries are actually installed? If you add logging to the PHP script, how far is it getting/exactly what line is it encountering errors on
Thank you so much!
You helped me a lot
I had composer installed on the root of my ec2 instance by mistake
I installed composer in the html folder where i have all my php api endpoints
and I also fixed the file paths within create.php
require_once 'vendor/autoload.php'; // Adjusted path
require_once 'secrets.php'; // Adjusted path
This is what i adjusted
because the file paths were mistakenly going back one directory before i did this