I would like to add STRIPE in my website but I'm noticing that is very difficult to use and there aren't more helps in the web.

My first problem is about "Pass the PaymentIntent’s client secret to the client, so how to pass a php variable in my html form.

Before I should create a PaymentIntent object:

\Stripe\Stripe::setApiKey('sk_test_8cpWr3HupPdvL9QK9cVToa4w009OYgxfNm');

$intent = \Stripe\PaymentIntent::create([
    'amount' => 0.89,
    'currency' => 'eur',
]);

Then API Stripe suggest to pass the PaymentIntent’s client secret to the client in this way:

<?php
    $intent = # ... Fetch or create the PaymentIntent;
?>
...
<input id="cardholder-name" type="text">
<!-- placeholder for Elements -->
<div id="card-element"></div>
<button id="card-button" data-secret="<?= $intent->client_secret ?>">
  Submit Payment
</button>
...

This is page of API: https://stripe.com/docs/payments/payment-intents/quickstart#passing-to-client

But how can I pass a php variable in html page ?

And someone can explain me what is this client secret ?

I hope you can help me (sorry for my english but I'm italian). Thanks a lot!

1 Answers

0
taintedzodiac On

The client_secret is a property of a PaymentIntent that you can use on the frontend with your publishable key.

Based on the example in the Quick Start guide, this is a basic example:

<?php
$intent =\Stripe\PaymentIntent::create([
    "amount" => 2000,
    "currency" => "usd",
    "payment_method_types" => ["card"],
]);
?>
...
<input id="cardholder-name" type="text">
<!-- placeholder for Elements -->
<div id="card-element"></div>
<button id="card-button" data-secret="<?= $intent->client_secret ?>">
  Submit Payment
</button>
...

The key things to note are that you're creating $intent in your code, and then echoing $intent->client_secret as the proper value in your form later on.