Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Stripe Google Pay Button not render for me on the UI despite not having any errors or exceptions?

I've used the Stripe Payment Request Button HTML code from the stripe docs on https://stripe.com/docs/stripe-js/elements/payment-request-button to incorporate the Google Pay button on my UI but the stripe component is not being rendered on the UI.

I'm using a Windows 10 machine and have served my application over a https server, the HTML code that I took from Stripe Docs does not show any errors or exceptions on the developer console, the iframe component can be seen on the Elements tab but the button is not being rendered on the UI.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Google Pay Payment</title>


</head>
<body>
<h1>This is a sample payment page using Stripe</h1>


    <label for="card-element">
      Credit or debit card
    </label>
    <form action="{{ url_for('pay')}}" method="post" id="payment-form">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <div id="payment-request-button">
      <!-- A Stripe Element will be inserted here. -->
    </div>
    </form>





<script src="https://js.stripe.com/v3/"></script>
<script type="text/javascript">
  var stripe = Stripe('pk_test_IVLw1g5rpDe7MwEu6PpxKxFL00SQlZd4eB');
  var paymentRequest = stripe.paymentRequest({
    country: 'US',
    currency: 'usd',
    total: {
      label: 'Demo total',
      amount: 1000,
    },
    requestPayerName: true,
    requestPayerEmail: true,
  });
  var elements = stripe.elements();
  var prButton = elements.create('paymentRequestButton', {
    paymentRequest: paymentRequest,
  });

  // Check the availability of the Payment Request API first.
  paymentRequest.canMakePayment().then(function(result) {
    if (result) {
      prButton.mount('#payment-request-button');
    } else {
      document.getElementById('payment-request-button').style.display = 'none';
    }
  });



  // Check the availability of the Payment Request API first.
  paymentRequest.canMakePayment().then(function(result) {
    if (result) {
      prButton.mount('#payment-request-button');
    } else {
      document.getElementById('payment-request-button').style.display = 'none';
    }
  });

</script>
</body>
</html>
like image 218
S C Avatar asked Apr 19 '19 19:04

S C


People also ask

Can I use Google Pay with stripe?

Google Pay is fully compatible with Stripe’s products and features (e.g., subscriptions ), allowing you to use it in place of a traditional payment form whenever possible. Use it to accept payments for physical goods, donations, subscriptions, and more. Use the Stripe Android SDK to start accepting Google Pay in your Android apps.

How to integrate Apple Pay with Stripe for your website?

Your Stripe publishable API key is also required as it identifies your website to Stripe: Create an instance of stripe.paymentRequest with all required options. Use the requestPayerName parameter to collect the payer’s billing address for Apple Pay. You can use the billing address to perform address verification and block fraudulent payments.

Can I use stripe elements with Apple Pay with react?

Apple Pay with the Payment Request Button requires macOS 10.12.1+ or iOS 10.1+. If you intend to use Stripe Elements with React, use react-stripe-elements , our open source library that wraps Stripe Elements in a set of convenient React components.

How do I integrate with Apple Pay and Google Pay?

The Payment Request Button Element gives you a single integration for Apple Pay, Google Pay. The relevant button will be displayed automatically. Customers see an Apple Pay button or a Google Pay button, depending on what their device and browser combination supports. If no option is available, they don’t see the button.


1 Answers

Faced same issue and finally solved it. Looks like it depends on country in you google payment profile. So my solution is:

  1. Open https://pay.google.com/gp/w/u/0/home/settings
  2. Tap on edit icon on Country/Region row.
  3. Add fake profile with US as country, it OK to use any random address and phone
  4. It's impossible to add test stripe card from here, so
  5. Open chrome://settings/payments and add card like 4242 4242 4242 4242 from here.
  6. Now open https://stripe-payments-demo.appspot.com/ again and check if you can see Pay Now button.
like image 81
toxa_xa Avatar answered Oct 07 '22 12:10

toxa_xa