loading...

testing Apple Pay on the web with Stripe (Rails)

andy4thehuynh profile image Andy Huynh ・2 min read

Proof

Following this guide to render an Apply Pay button with Stripe.

Stripe provided a fantastic tutorial to integrate Apple Pay with Stripe. It took me half a day to render a button on the page. Here are the fine details of the guide I overlooked to eventually succeed in rendering Apple Pay.

1) Ensure a credit card exists in your Chrome browser wallet. I had Google Pay in my wallet. It was oddly frustrating, and understandable, Apple Pay didn't recognize Google Pay. Anyways, use a CC

Credit card

2) Enable HTTPS with ngrok. I'm on ngrok version 2.2.4. Adjust your domain port accordingly

> ngrok http -host-header=rewrite localhost:3000

3) Render text from the controller, explicitly

# In `config/routes.rb` point the weirdly dotted namespaced controller endpoint to `ApplePayController` 
get ".well-known/apple-developer-merchantid-domain-association" => "apple_pay#show"
# `app/controllers/apple_pay_controller.rb` render text
class ApplePayController < ApplicationController
  def show
    respond_to do |format|
      format.html do
        render text: DomainAssociationFile.()
      end
    end
  end
end

I initially served html from the controller. I saw text rendered in the web browser.

When registering my domain with Apple, I got 500 errors.

Apple pinged my controller to retrieve the domain association file. It didn't know how to respond to the HTML I gave back. Stripe expected a text format in the return response. Format it like the above.

# I threw this in a presenter
class DomainAssociationFile
  def self.call
    <<-FILE
      # download and paste your domain association file, here
    FILE
  end
end

Posted on Jun 12 by:

andy4thehuynh profile

Andy Huynh

@andy4thehuynh

πŸ‘¨πŸ»β€πŸ’» software developer πŸ’™ kajabi.com | homecook β€’ telecaster β€’ minimalist | #ruby #rails

Discussion

markdown guide