简体   繁体   English

如何使用锚标记触发Stripe信用卡结帐?

[英]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.

相关问题 如何在Stripe Checkout中禁用默认付款方式(信用卡) - How to disable default payment method (Credit Card) in Stripe Checkout 如何使用 Vue Stripe Checkout 库为信用卡信息创建离散输入? - How to create discrete inputs for credit card information with the Vue Stripe Checkout library? 从其API检索条纹发票时,如何扩展对象以检索信用卡详细信息和其他信息? - When retrieving a Stripe invoice from their API, how do I expand an object to retrieve credit card details and other info? 如何使用 Javascript 验证信用卡到期日期? - How do I validate a credit card expiry date with Javascript? 如何向此信用卡表单添加有效期验证 - How do I add a expiration date validation to this credit card form 如何将信用卡号添加到另一个列表? - How do I add a credit card number to another list? 如何使用livevalidation验证信用卡有效期(2个字段) - How do I validate a credit card exp date (2 fields) with livevalidation 如何解析JS信用卡功能中的连字符“-” - How do I parseInt out the hyphens “ -” in a Credit Card Function in JS 如何使用stripe.js和python更新信用卡 - How to update credit card using stripe.js and python 条纹:如何在给定信用卡信息的情况下创建客户对象 - Stripe: how to create a customer object given credit card information
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM