-3

This is the code of JavaScript I have used to developed Apple Payment Request button with Stripe where I have placed a related code in the above and I also have added related stripe v3 library and added a div with payment-request-button id in html

var stripe = Stripe('pk_test_ZjbcGwDeoJsycvIs7KGEFkVR00qOzHxlrX');
    elements = stripe.elements();

    // Config payment request
    paymentRequest = stripe.paymentRequest({
     country: 'US',
     currency: 'usd',
     total: {
      label: 'Demo total',
      amount: 100,
     },
    });
    paymentRequest.on('source', function(event) {
     console.log('Got source: ', event.source.id);
     event.complete('success');
     ChromeSamples.log(JSON.stringify(event.source, 2));
     // Send the source to your server to charge it!
    });
    prButton = elements.create('paymentRequestButton', {
     paymentRequest,
    });
    // Check the availability of the Payment Request API first.
    paymentRequest.canMakePayment().then((result) => {
     //console.log(prButton);
     if (result) {
      prButton.mount('#payment-request-button');
     } else {
      document.getElementById('payment-request-button').style.display = 'none';
      ChromeSamples.setStatus("Not supported, please check: https://stripe.com/docs/elements/payment-request-button#testing");
     }
    });

    // Helpers
    var ChromeSamples = {
     log: function() {
      var line = Array.prototype.slice.call(arguments).map(function(argument) {
       return typeof argument === 'string' ? argument : JSON.stringify(argument);
      }).join(' ');

      document.querySelector('#log').textContent += line + '\n';
     },

     clearLog: function() {
      document.querySelector('#log').textContent = '';
     },

     setStatus: function(status) {
      document.querySelector('#status').textContent = status;
     },

     setContent: function(newContent) {
      var content = document.querySelector('#content');
      while (content.hasChildNodes()) {
       content.removeChild(content.lastChild);
      }
      content.appendChild(newContent);
     }
    };
halfer
  • 19,824
  • 17
  • 99
  • 186
mukesh kumar
  • 28
  • 10
  • 1
    I have to imagine that there are integration/implementation documents for you to follow. This isn't really the place for general "I need a step-by-step guide for building my payment process" – Patrick Q Feb 07 '20 at 13:50
  • I am following those steps but i did not able to visualize the button. – mukesh kumar Feb 07 '20 at 14:33
  • If you have code that you've attempted, please update your question to include it. Also include a detailed description of the expected result and the actual result, along with what debugging you have already done. Please also take some time to review [How To Ask](https://stackoverflow.com/help/how-to-ask) for a guide to constructing better questions. – Patrick Q Feb 07 '20 at 14:43
  • @mukeshkumar What browser are you testing with? The Apple Pay button will only show up in iOS or Mac, and only when using Safari. It won't show up in Firefox, or on Windows. – ceejayoz Feb 11 '20 at 16:08
  • I have followed this link to create a Stripe Apple Pay Payment Request button for web https://stripe.com/docs/stripe-js/elements/payment-request-button – mukesh kumar Feb 11 '20 at 16:08
  • **Don’t** include API keys in code snippets you post on the Internet. Even if they are test mode keys. – Martin Bean Feb 11 '20 at 16:10
  • @MartinBean The key in this code snippet is the client-side public "publishable" Stripe key. It's fine; the entire Internet gets to see it. Stripe's secret keys start with `sk_`. – ceejayoz Feb 11 '20 at 16:19
  • @ceejayoz I’m aware it’s the (test) publishable key; I’m a heavy Stripe user myself. But it’s also good practice to redact API keys when pasting code publicly on the Internet, even if they are public keys. – Martin Bean Feb 11 '20 at 17:30
  • I have edited the Key It will not work – mukesh kumar Feb 13 '20 at 13:42
  • @ceejayoz I am testing it in Chrome 80+ Version in Window 10 OS – mukesh kumar Feb 13 '20 at 13:43
  • @mukeshkumar Well, that's why. https://support.apple.com/en-us/HT208531 – ceejayoz Feb 13 '20 at 14:16

1 Answers1

1

I am testing it in Chrome 80+ Version in Window 10 OS

Per Apple's "Apple Pay is compatible with these devices" page, Apple Pay is only available on Mac, iPhone, iPad, and Apple Watch devices, and only in Safari.

The Stripe docs you linked also say:

Apple Pay with the Payment Request Button requires macOS 10.12.1+ or iOS 10.1+.

You will need an Apple device to test your Apple Pay integration.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368