Stripe Simple Checkout Custom Data Field

南楼画角 提交于 2019-12-22 08:59:28

问题


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@example.com" ';
  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>';

回答1:


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@example.com" ';
  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"];



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/34946355/stripe-simple-checkout-custom-data-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!