I am using codeigniter framework.
but for normal php I suppose it is identical.
Here I show the way I managed to send additional data from javascript to php using the card form.
I hope it helps you.
I managed to correctly integrate the card form on my client’s website successfully.
if you have any other questions
<script>
const appId = 'app id here';
const locationId = 'location id here';
// const variable, declare variable for receive data
const idSolicitud = '<?php echo $idSolicitud; ?>'; // collect data from php
const ListingId = '<?php echo $ListingId; ?>'; // collect data from php
const aplicante = '<?php echo $aplicante; ?>'; // collect data from php
async function initializeCard(payments) {
const card = await payments.card();
await card.attach('#card-container');
return card;
}
// We send the data in Json to the controller or php file as you require
async function createPayment(token) {
const body = JSON.stringify({
locationId,
lang,
idSolicitud,
ListingId,
aplicante,
sourceId: token,
});
//I send the data in a json to the controller, in my case it is to a controller, and its method
const paymentResponse = await fetch('https://myurlhere.com/payment/proccess', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
});
that is part of my code of how to insert additional data to what the javascript sends.
IN my php file receive →
// Get the data sent from the Javascript v_payment_capture.php
$json = json_decode($this->input->raw_input_stream); //for codeigniter
// $json = json_decode(file_get_contents('php://input')); //for php pure.
$cnon = $json->sourceId; //We obtain the Nonce of the card to use it below in the payment request.
$languaje = $json->lang; //Get the language ES/EN passed in from the view.
$solicitud = $json->idSolicitud; // Get the form request code from the view.
$Idlisting = $json->ListingId; // We get the Listing ID from the view passed from the form, it is the ID of the rental or property.
$Quienaplica = $json->aplicante; // Name of the applicant to the request, person who is going to pay, data comes from the view, from the form.
I hope my code is helpful to understand how to send additional information from javascript to php in the card form.