<p>Here is my working solution, basically all you need to do is grab the token from stripe and then submit it with the form.</p>

<pre><code>&lt;script src="https://checkout.stripe.com/checkout.js"&gt;&lt;/script&gt;

&lt;form method="POST" id="payment-form"&gt;
  &lt;input type="hidden" name="action" value="commerce/payments/pay"&gt;
  &lt;input type="hidden" name="cancelUrl" value="/checkout/payment"&gt;
  &lt;input type="hidden" name="redirect" value="/orders/order?number={number}"&gt;
  &lt;input type="hidden" name="token" id="stripe-token" value=""&gt;
  {{ getCsrfInput() }}

  &lt;button id="paymentButton" class="button is-primary"&gt;
      &lt;span class="icon"&gt;
        &lt;i class="fa fa-check" aria-hidden="true"&gt;&lt;/i&gt;
      &lt;/span&gt;
      &lt;span&gt;
        Purchase
      &lt;/span&gt;
  &lt;/button&gt;

  &lt;script&gt;
    var handler = StripeCheckout.configure({
      key: '{{ cart.paymentMethod.settings.publishableKey ?? '' }}',
      image: '/assets/img/tfa-logo-128.png',
      locale: 'auto',
      token: function(token) {
        // You can access the token ID with `token.id`.
        var stripeToken = token.id;
        // Get the token ID to your server-side code for use.
        document.getElementById('stripe-token').value = stripeToken;
        document.getElementById('payment-form').submit();
      }
    });

    document.getElementById('paymentButton').addEventListener('click', function(evt) {
      // Open Checkout with further options:
      handler.open({
        name: '{{ siteName }}',
        email: '{{ cart.email }}',
        currency: '{{ cart.paymentCurrency }}',
        description: 'Membership',
        zipCode: true,
        amount: {{ cart.totalPrice|commerceCurrency(cart.paymentCurrency,convert=true,format=false) * 100 }}
      });
      evt.preventDefault();
    });

    // Close Checkout on page navigation:
    window.addEventListener('popstate', function() {
      handler.close();
    });
  &lt;/script&gt;
&lt;/form&gt;
</code></pre>

CC BY-SA 3.0
2017-10-31T06:31:40.573Z
2017-10-31T20:31:06.377Z
2017-10-31T20:31:06.377Z
Gareth
<p>I know there is the Stripe checkout button that is in the example docs but I would like more control over how things look and work.</p>

<p>I guess this is where it's over to me to look at the Stripe docs:</p>

<ul>
<li><a href="https://stripe.com/docs/checkout#integration-custom" rel="nofollow noreferrer">Styled Custom Button</a></li>
</ul>

<p>It's difficult to work out what exactly is required in order to send all the details Stripe requires and then process the response giving Craft Commerce everything it needs. Then send the user to an order complete screen.</p>

<p>I have the custom button sort of working using:</p>



<pre><code>&lt;form method="POST"&gt;
  &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;

  &lt;button id="paymentButton" class="button is-primary"&gt;Purchase&lt;/button&gt;

  &lt;script&gt;
    var handler = StripeCheckout.configure({
      key: '{{ cart.paymentMethod.settings.publishableKey ?? '' }}',
      image: '/assets/img/tfa-logo-128.png',
      locale: 'auto',
      token: function(token) {
        // You can access the token ID with `token.id`.
        // Get the token ID to your server-side code for use.
      }
    });

    document.getElementById('paymentButton').addEventListener('click', function(evt) {
      // Open Checkout with further options:
      handler.open({
        name: '{{ siteName }}',
        email: '{{ cart.email }}',
        currency: '{{ cart.paymentCurrency }}',
        description: 'Membership',
        zipCode: true,
        amount: {{ cart.totalPrice|commerceCurrency(cart.paymentCurrency,convert=true,format=false) * 100 }}
      });
      evt.preventDefault();
    });

    // Close Checkout on page navigation:
    window.addEventListener('popstate', function() {
      handler.close();
    });
  &lt;/script&gt;
&lt;/form&gt;
</code></pre>

<p>This looks to work but doesn't send a charge to Stripe or save in the commerce plugin (it just sits as an active cart). I guess this is down to the token not being set but how do you do that? </p>

<plugin-craftcommerce>
Using the custom styled Stripe button with Craft Commerce
# Using the custom styled Stripe button with Craft Commerce

(Asked by: username_0 on 2017-10-28)

I know there is the Stripe checkout button that is in the example docs but I would like more control over how things look and work.
I guess this is where it's over to me to look at the Stripe docs:

Styled Custom Button

It's difficult to work out what exactly is required in order to send all the details Stripe requires and then process the response giving Craft Commerce everything it needs. Then send the user to an order complete screen.
I have the custom button sort of working using:

  

  Purchase

  


This looks to work but doesn't send a charge to Stripe or save in the commerce plugin (it just sits as an active cart). I guess this is down to the token not being set but how do you do that?

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_0 on 2017-10-31. Score: 0 | Accepted answer

Here is my working solution, basically all you need to do is grab the token from stripe and then submit it with the form.



  
  
  
  
  {{ getCsrfInput() }}

  
      
        
      
      
        Purchase


---

