#hanis-paymentelement-email
1 messages · Page 1 of 1 (latest)
@minor cape hello! I'm happy to help but I will need more words/details from you so that I can help you
I´m using Stripe payments "Custom payment flow", there is required field email, how i get value of email or how to disable it and insert email from our field
Sorry that's still really vague unfortunately. There are dozens of ways to integrate our products and APIs
Are you using PaymentElement? Because that does not require email for all payment methods, only some, but you didn't give any information about what you're doing yet
yeah sorry now that's a picture in a language I don't speakunfortunately. Please try and put yourself in my shoes. Give me actionable information about the docs you're following, your integration, what UI elements you use, etc.
I need to take value "email" from stripe generated form and save it for example to metadata or somewhere
please try to give more context as a developer with code. Not just words I don't understand. You say "stripe generated form" but it's not
many parts of those are your own UI in another language. That email field is not part of PaymentElement
I need from email value, which is iframe of your code
create.php
<?php
require_once 'vendor/autoload.php';
require_once 'secrets.php';
$stripe = new \Stripe\StripeClient($stripeSecretKey);
function calculateOrderAmount(array $items): int {
$payment = $_SESSION['priceAll'] * 100;
return $payment;
}
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
$_SESSION['myData'] = $jsonStr;
$paymentIntent = $stripe->paymentIntents->create([
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'czk',
'setup_future_usage' => 'off_session',
'payment_method_types' => ['card'],
/*'automatic_payment_methods' => [
'enabled' => true,
],*/
]);
$paymentIntent->confirmation_method = 'manual';
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
$_SESSION['output'] = $output;
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
I have this template:
https://stripe.com/docs/payments/quickstart?lang=php#collect-billing-address-details
Where I pick JavaScript SDK, Frontend: HTML and backend PHP
Okay so all the code you share is all PHP
What I need is for you to explain what you do client side
hanis-paymentelement-email
I think the problem is in Link service, that it requires email address, so I removed link integration from my code, but now, it caused issue ...
error from create.php
- {
error: "calculateOrderAmount(): Argument #1 ($items) must be of type array, null given, called in /data/web/virtuals/314556/virtual/www/subdom/admin/admin/novyshop/platby/create.php on line 26"
}
code:
<?php
require_once 'vendor/autoload.php';
require_once 'secrets.php';
$stripe = new \Stripe\StripeClient($stripeSecretKey);
$stripe->paymentMethodDomains->create([
'domain_name' => 'admin.fenixcraft.cz',
]);
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
$payment = $_SESSION['priceAll'] * 100;
return 1500;
}
header('Content-Type: application/json');
try {
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
$paymentIntent = $stripe->paymentIntents->create([
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'czk',
'setup_future_usage' => 'off_session',
'payment_method_types' => ['card'],
'automatic_payment_methods' => [
'enabled' => true,
],
]);
$paymentIntent->confirmation_method = 'manual';
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
$_SESSION['output'] = $output;
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
- checkout.php :
<form id="payment-form" style="background: white;color:black;" class="container">
<div id="minecraft-nick" style="display: flex; justify-content: space-between;">
<div class="form-group" style="flex: 1;">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa-solid fa-user"></i> Minecraft nick: </span>
</div>
<input type="text" name="mcnick" class="form-control" placeholder="Herní nick" disabled required value="<?php echo $mcnick; ?>">
</div>
</div>
<span><a style="text-decoration: none" class="btn" href="?id=2">Změnit</a></span>
</div>
<div id="payment-element">
</div>
<div id="minecraft-nick" style="display: flex; justify-content: space-between;">
<div style="flex: 1;">
Konečná cena: <b><?php echo $_SESSION['priceAll']; ?>.00 Kč</b>
</div>
<span><a style="text-decoration: none" class="btn" href="./">Upravit produkty</a></span>
</div>
<button id="submit" class="btn btn-primary" style="margin: 10px 0; background-color: #d85e0e">
<div class="spinner hidden" id="spinner"></div>
<span id="button-text">Zaplatit</span>
</button>
<div id="payment-message" class="hidden"></div>
<div id="payment-message" class="hidden payment-message-err">
<div class="alert alert-warning" id="warnings">
</div>
</div>
</form>
JS
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
const stripe = Stripe("--OWN--");
// The items the customer wants to buy
const items = [{ id: "xl-tshirt" }];
let elements;
initialize();
checkStatus();
document
.querySelector("#payment-form")
.addEventListener("submit", handleSubmit);
// Fetches a payment intent and captures the client secret
async function initialize() {
const { clientSecret } = await fetch("create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());
elements = stripe.elements({ clientSecret });
const paymentElementOptions = {
layout: "accordion",
};
const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
e.preventDefault();
setLoading(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: "--return--",
},
});
if (error.type === "card_error" || error.type === "validation_error") {
errShowMessage(error.message);
console.log(error.message);
} else {
showMessage("Vyskytla se neočekávaná chyba.");
}
setLoading(false);
}
async function checkStatus() {
const clientSecret = new URLSearchParams(window.location.search).get(
"payment_intent_client_secret"
);
if (!clientSecret) {
return;
}
const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);
switch (paymentIntent.status) {
case "succeeded":
showMessage("Zaplaceno!");
break;
case "processing":
showMessage("Platba je v procesu.");
break;
case "requires_payment_method":
showMessage("Vaše platba nebyla úspěšná, zkuste to prosím znovu.");
break;
default:
showMessage("Vyskytla se chyba.");
break;
}
}
function showMessage(messageText) {
const messageContainer = document.querySelector("#payment-message");
messageContainer.classList.remove("hidden");
messageContainer.textContent = messageText;
/*
setTimeout(function () {
messageContainer.classList.add("hidden");
messageContainer.textContent = "";
}, 5000);*/
}
function errShowMessage(messageText) {
const messageContainer = document.querySelector("#warnings");
const containerBox = document.querySelector(".payment-message-err");
containerBox.classList.remove("hidden");
messageContainer.textContent = messageText;
}
function setLoading(isLoading) {
if (isLoading) {
document.querySelector("#submit").disabled = true;
document.querySelector("#spinner").classList.remove("hidden");
document.querySelector("#button-text").classList.add("hidden");
} else {
document.querySelector("#submit").disabled = false;
document.querySelector("#spinner").classList.add("hidden");
document.querySelector("#button-text").classList.remove("hidden");
}
}
I see. Thanks. Could you provide the URL?
You mean of checkout?
https://admin.fenixcraft.cz/admin/novyshop/platby/?step=3
But you must add some item and proceed the cart