#Umeed Emad - PaymentIntent
1 messages · Page 1 of 1 (latest)
Hi
yes using strip-php and stripe js
<?php
require_once dirname(FILE)."/../lib/stripe-php-master/init.php";
// This is your test secret API key.
\Stripe\Stripe::setApiKey('sk_test_qzbXmmPBenmZOPIKxfEqpwMC');
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\PaymentIntent::create([
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'usd',
'automatic_payment_methods' => [
'enabled' => false,
],
]);
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
?>
Do I need payment intent for one time donation too?
So you create a PaymentIntent on the backend, and then collect payment information with the PaymentElement?
If so, yes you first need to create a PaymentIntent to display the payment form.
Is it possible to create payment intent when user clicks on submit? Can't I initiate card element without payment intent?
Not the Payment Element, no
what is the alternative solution? I only need a basic donation form which I can enable donors to pay for specific event. So the only thing I need to pass some meta data and make the payment and store the data in WordPress database.
Have you considered using Payment Links?
no. Actually I am quite new to stripe integration. I appreciate if you can guide please
It supports custom amounts too, perfect for donations: https://stripe.com/docs/payments/checkout/pay-what-you-want
Thank you.