Apple Pay button selection and onclick

969 views
Skip to first unread message

Borge Strand-Bergesen

unread,
Jan 7, 2019, 3:19:38 PM1/7/19
to api-d...@lists.stripe.com
Hi guys, 

I've implemented the Apple Pay button, and that is all good and well. However, when Apple Pay is not available, it is often still displayed but with a hideous "Buy Now" button which relates to some browser-specific payment solution. 

I'd like to achieve two things:

1 - Only display the button when it is actual Apple Pay, or at least know which payment feature is going to be displayed before I enable it

2 - Add onclick="" code to the button in order to track it in ecommerce. 

Please let me know if this is available. I wish to run AB tests comparing [Apple Pay only], [AP or ugly button], [no button] against each other. 


Best,
Børge

Børge Strand-Bergesen
bo...@henryaudio.com | Mobile: +47 90 63 99 18
www.henryaudio.com

Remi J.

unread,
Jan 7, 2019, 3:28:56 PM1/7/19
to api-d...@lists.stripe.com
Hello Børge,

You should only show the button if Apple Pay is available on the device and otherwise hide otherwise. This is covered in our documentation here [1] where we show how to detect if Apple Pay is available and if so to mount the button.

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';
  }
});

I hope this helps!
Remi


--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.
Reply all
Reply to author
Forward
0 new messages