Amy Neville
Amy Neville

Reputation: 10581

Stripe Simple Checkout Custom Data Field

I am trying to use Stripe's simple checkout system.

I want to include a custom field so that I can match an item_id to an order in my database.

https://stripe.com/docs/checkout#integration-simple

They don't seem to mention it in their documentation but it seems pretty essential for online services. How do I attach a custom id field that will be recorded with the order?

echo '<form action="/charge" method="POST">';
echo '<script ';
  echo 'src="https://checkout.stripe.com/checkout.js" class="stripe-button" ';
  echo 'data-key="pk_test_ksdjhg8dsgsghdsgh" ';
  echo 'data-email="[email protected]" ';
  echo 'data-name="example.com" ';
  //echo 'data-bitcoin="true" ';
  echo 'data-description="Campaign" ';
  echo 'data-currency="usd" ';
  echo 'data-amount="2000" ';
  echo 'data-locale="auto">';
echo '</script>';
echo '</form>';

Upvotes: 4

Views: 6666

Answers (3)

johan
johan

Reputation: 1

you could do something like this to add extra information

echo '<form action="/charge?item_id=123" method="POST">';

and use $_REQUEST['item_id'] in stead of $_POST['item_id'] in the charge page to get the value.

Not my preferred way of working, but in this case it solves the problem.

Upvotes: 0

Alex
Alex

Reputation: 335

My experience, which is that custom fields are not possible using the basic Stripe checkout, concurs with the accepted answer on this very similar question:

How to add custom fields to popup form of Stripe Checkout

I believe the best route forward would be to get handy with stripe.js and create a custom payment form:

https://stripe.com/docs/custom-form

I am working around that at present by using different endpoint URLs in the form actions to do different things. This works fine, but I may end up using stripe.js in the production code.

Upvotes: 0

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

I hope you require to send your custom data-field with stripe checkout and trying to match with your data base. If I'm right? Follow below detail.

For include custom data you need to use hidden input like below:

echo '<form action="/charge" method="POST">';
echo '<script ';
  echo 'src="https://checkout.stripe.com/checkout.js" class="stripe-button" ';
  echo 'data-key="pk_test_ksdjhg8dsgsghdsgh" ';
  echo 'data-email="[email protected]" ';
  echo 'data-name="example.com" ';
  //echo 'data-bitcoin="true" ';
  echo 'data-description="Campaign" ';
  echo 'data-currency="usd" ';
  echo 'data-amount="2000" ';
  echo 'data-locale="auto">';
echo '</script>';
echo '<input name="item_id" value="SOMEVALUEHERE" type="hidden">';
echo '</form>';

In above code, I include hidden for item_id. You can get the value from that input field in your PHP page like:

$item_id = $_POST["item_id"];

Upvotes: 5

Related Questions