[英]How do I trigger Stripe Credit Card Checkout with an anchor tag?
Background 背景
I am trying to integrate Stripe into our website. 我正在尝试将Stripe集成到我们的网站中。 The checkout page has two button options, PayPal or Visa/Credit Card. 结帐页面有两个按钮选项,贝宝(PayPal)或Visa /信用卡。
This is the code at the moment. 这是目前的代码。
<div class="pull-right">
<a class="btn btn-lg btn-paypal" href="#">
<i class="fa fa-paypal" aria-hidden="true"></i>
PayPal
</a>
<form action="<?php echo base_url() . 'stripe/process'; ?>" method="POST">
<script src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="xxxx"
data-image="your site image"
data-name="w3code.in"
data-description="Demo Transaction ($100.00)"
data-amount="10000" />
</script>
</form>
</div>
It produces this... 它产生了这个...
The button and everything works perfectly... however I want it to look like this. 该按钮和一切正常工作...但是我希望它看起来像这样。
The code looks like this... 代码看起来像这样...
<div class="pull-right">
<a class="btn btn-lg btn-paypal" href="#">
<i class="fa fa-paypal" aria-hidden="true"></i>
PayPal
</a>
<a type="submit" class="btn btn-lg btn-stripe">
Visa/Credit Card
<i class="fa fa-cc-stripe" aria-hidden="true"></i>
</a>
</div>
I am wondering if there is a way to make the clicking of the <a>
anchor tag sort of trigger the form (perhaps a hidden form). 我想知道是否有一种方法可以使点击<a>
锚标签的某种形式触发表单(也许是隐藏表单)。
I have a vague idea of how this might work so I will try my best to show you guys what I have attempted... 我对这可能如何工作有一个模糊的想法,所以我会尽力向大家展示我所尝试的...
My Attempt 我的尝试
I removed the stripe-button
class from the script tags and added onclick="document.getElementById('stripe').submit();"
我从脚本标记中删除了stripe-button
类,并添加了onclick="document.getElementById('stripe').submit();"
to my new anchor tag to submit the form, however this does not have the same effect. 到我的新锚标签以提交表单,但是效果不一样。
<a type="submit" class="btn btn-lg btn-stripe" href="javascript:{}" onclick="document.getElementById('stripe').submit();">
Visa/Credit Card
<i class="fa fa-cc-stripe" aria-hidden="true"></i>
</a>
<form id="stripe" action="<?php echo base_url() . 'stripe/process'; ?>" method="POST">
<script src="https://checkout.stripe.com/checkout.js"
data-key="xxx"
data-image="your site image"
data-name="w3code.in"
data-description="Demo Transaction ($100.00)"
data-amount="10000" />
</script>
</form>
The original stripe button that is displayed by the tag is showing the stripe popup window before the form is submitted... how do I trigger the same process with my anchor tag? 标签显示的原始条纹按钮在提交表单之前显示了条纹弹出窗口...我该如何用我的锚标签触发相同的过程?
Where am I going wrong? 我要去哪里错了?
UPDATE-1: UPDATE-1:
Still not working unfortunately... here is what I have tried... 仍然无法正常工作...这是我尝试过的...
<a type="submit" class="btn btn-lg btn-stripe" onclick="document.getElementByClass('stripe-button').submit();">
Visa/Credit Card
<i class="fa fa-cc-stripe" aria-hidden="true"></i>
</a>
<form action="<?php echo base_url() . 'stripe/process'; ?>" method="POST">
<script src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_uT2PnISTl40vQWojZAngFlu6"
data-image="your site image"
data-name="w3code.in"
data-description="Demo Transaction ($100.00)"
data-amount="10000" />
</script>
</form>
您需要使用Checkout的“自定义集成” ,这将允许您以所需的样式使用自己的按钮,并使用JavaScript将Checkout的弹出窗口绑定到按钮的click事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.